Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor state.dart (part 2) #596

Closed
wants to merge 50 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ada5786
move main_screen.dart into a separate folder
d-uzlov Oct 26, 2022
2cf0706
extract downloading screen into a separate class
d-uzlov Oct 26, 2022
7a30db9
extract ready screen into a separate class
d-uzlov Oct 26, 2022
6161510
extract aborting screen into a separate class
d-uzlov Oct 26, 2022
1711d08
move firebaseManager out of state
d-uzlov Oct 27, 2022
56db9a2
move boardDecoder out of state
d-uzlov Oct 27, 2022
26e4e9d
refactor state.dart
d-uzlov Oct 27, 2022
2e5255d
try to isolate state usage in ui
d-uzlov Oct 27, 2022
61c0649
refactor result screen
d-uzlov Oct 27, 2022
a0f92c0
refactor result screen
d-uzlov Oct 27, 2022
2b47f60
refactor config manager
d-uzlov Oct 27, 2022
683a9fa
refactor config manager
d-uzlov Oct 27, 2022
3d49ad6
refactor config manager
d-uzlov Oct 27, 2022
46f344e
refactor config manager
d-uzlov Oct 28, 2022
26dfc4c
refactor benchmarkstate
d-uzlov Oct 28, 2022
f2774be
refactor result manager
d-uzlov Oct 28, 2022
74c653e
refactor state.dart
d-uzlov Oct 28, 2022
288883f
refactor benchmarkstate, configmanager, taskrunner
d-uzlov Oct 28, 2022
1ec9391
refactor benchmarkstate
d-uzlov Oct 28, 2022
190682b
make resourcemanager private
d-uzlov Oct 28, 2022
69a962f
refactor benchmarkstate
d-uzlov Oct 28, 2022
4ea6914
extract lastresultmanager
d-uzlov Oct 28, 2022
454d781
refactor result restoration
d-uzlov Oct 28, 2022
6b520c2
refactor task selection saving
d-uzlov Oct 28, 2022
a96bcdc
add lastresultmanager provider
d-uzlov Oct 28, 2022
b2fa7c7
refactor benchmarkstate
d-uzlov Oct 28, 2022
5657c2f
move benchmarklist into tasklistmanager
d-uzlov Oct 28, 2022
49e6dbd
remove benchmarks getter from benchmarkstate
d-uzlov Oct 28, 2022
840af29
refactor benchmarkstate
d-uzlov Oct 28, 2022
4a1b9a4
use explicit state in benchmarkstate
d-uzlov Oct 29, 2022
8cbb57a
fix result restoration
d-uzlov Oct 29, 2022
7b681e9
fix aborting
d-uzlov Oct 29, 2022
55cee40
fix task selection saving
d-uzlov Oct 29, 2022
5e83d49
fix result history saving
d-uzlov Oct 29, 2022
41abe22
refactor starting benchmark
d-uzlov Oct 29, 2022
be3a49f
refactor benchmarkstate
d-uzlov Oct 29, 2022
8136d0b
fix result restoration on startup
d-uzlov Oct 29, 2022
f904b7e
refactor benchmarkstate
d-uzlov Oct 29, 2022
40e45c6
rename benchmarkstate to appstate
d-uzlov Oct 29, 2022
57659b7
move appstate to state folder
d-uzlov Oct 29, 2022
ae85106
extract appstatehelper
d-uzlov Oct 29, 2022
425dd12
refactor appstate
d-uzlov Oct 29, 2022
637a279
add documentation for appstate
d-uzlov Oct 29, 2022
9f1948c
add documentation to some classes
d-uzlov Oct 29, 2022
4b80e71
rename runMode readable field
d-uzlov Oct 29, 2022
6727432
move loadgenlogfilename to class level
d-uzlov Oct 29, 2022
ceb9837
fix fast mode cooldown duration
d-uzlov Oct 29, 2022
97e013b
fix config reading on first launch
d-uzlov Oct 30, 2022
b7207cb
adjust documentation in appstate
d-uzlov Oct 30, 2022
c551df3
Merge commit '38327317a45fd0593fb92240b14c4c0e99a46292' into 556/refa…
d-uzlov Oct 31, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions flutter/integration_test/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import 'dart:convert';

import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:mlperfbench/ui/root/main_screen.dart';
import 'package:mlperfbench/ui/root/main_screen/ready.dart';
import 'package:mlperfbench/ui/run/result_screen.dart';
import 'package:mlperfbench_common/data/extended_result.dart';
import 'package:mlperfbench/resources/result_manager.dart' as result_manager;
import 'package:mlperfbench/resources/result_manager.dart';
import 'package:mlperfbench/resources/resource_manager.dart'
as resource_manager;
import 'package:mlperfbench/main.dart' as app;
Expand All @@ -18,12 +18,12 @@ Future<void> runBenchmark(WidgetTester tester) async {
await app.main();
await tester.pumpAndSettle(const Duration(seconds: splashPauseSeconds));

var goButtonIsPresented = await waitFor(
tester, downloadTimeLimitMinutes, const Key(MainKeys.goButton));
var goButtonIsPresented = await waitFor(tester, downloadTimeLimitMinutes,
const Key(MainScreenReadyKeys.goButton));

expect(goButtonIsPresented, true,
reason: 'Problems with downloading of datasets or models');
final goButton = find.byKey(const Key(MainKeys.goButton));
final goButton = find.byKey(const Key(MainScreenReadyKeys.goButton));
await tester.tap(goButton);

var scrollButtonIsPresented = await waitFor(
Expand All @@ -36,9 +36,7 @@ Future<ExtendedResult> obtainResult() async {
final applicationDirectory =
await resource_manager.ResourceManager.getApplicationDirectory();

final rm = result_manager.ResultManager(applicationDirectory);
await rm.init();

final rm = await ResultManager.create(resultDir: applicationDirectory);
return rm.getLastResult();
}

Expand Down
1 change: 1 addition & 0 deletions flutter/lib/backend/bridge/run_result.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'package:mlperfbench_common/data/results/benchmark_result.dart';

// Contains raw data obtained from the dart_ffi_run_benchmark method,
class NativeRunResult {
final Accuracy? accuracy1;
final Accuracy? accuracy2;
Expand Down
1 change: 1 addition & 0 deletions flutter/lib/backend/bridge/run_settings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import 'package:mlperfbench/protos/backend_setting.pb.dart' as pb;

// Input parameters for the dart_ffi_run_benchmark method
class RunSettings {
static int single_stream_expected_latency_ns_max = 1000000;

Expand Down
98 changes: 37 additions & 61 deletions flutter/lib/benchmark/benchmark.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';

import 'package:collection/collection.dart';
import 'package:mlperfbench_common/data/results/benchmark_result.dart';

import 'package:mlperfbench/app_constants.dart';
import 'package:mlperfbench/backend/bridge/run_settings.dart';
Expand All @@ -11,56 +12,6 @@ import 'package:mlperfbench/resources/resource_manager.dart';
import 'info.dart';
import 'run_mode.dart';

class BenchmarkResult {
final double throughput;
final Accuracy? accuracy;
final Accuracy? accuracy2;
final String backendName;
final String acceleratorName;
final int batchSize;
final bool validity;

BenchmarkResult(
{required this.throughput,
required this.accuracy,
required this.accuracy2,
required this.backendName,
required this.acceleratorName,
required this.batchSize,
required this.validity});

static const _tagThroughput = 'throughput';
static const _tagAccuracy = 'accuracy';
static const _tagAccuracy2 = 'accuracy2';
static const _tagBackendName = 'backend_name';
static const _tagAcceleratorName = 'accelerator_name';
static const _tagBatchSize = 'batch_size';
static const _tagValidity = 'validity';

static BenchmarkResult? fromJson(Map<String, dynamic>? json) {
if (json == null) return null;
return BenchmarkResult(
throughput: json[_tagThroughput] as double,
accuracy: Accuracy.fromJson(json[_tagAccuracy] as Map<String, dynamic>),
accuracy2: Accuracy.fromJson(json[_tagAccuracy2] as Map<String, dynamic>),
backendName: json[_tagBackendName] as String,
acceleratorName: json[_tagAcceleratorName] as String,
batchSize: json[_tagBatchSize] as int,
validity: json[_tagValidity] as bool,
);
}

Map<String, dynamic> toJson() => {
_tagThroughput: throughput,
_tagAccuracy: accuracy,
_tagAccuracy2: accuracy2,
_tagBackendName: backendName,
_tagAcceleratorName: acceleratorName,
_tagBatchSize: batchSize,
_tagValidity: validity,
};
}

class Benchmark {
final pb.BenchmarkSetting benchmarkSettings;
final pb.TaskConfig taskConfig;
Expand All @@ -72,9 +23,6 @@ class Benchmark {
// which may not represent what backend actually used for computations
final String backendRequestDescription;

BenchmarkResult? performanceModeResult;
BenchmarkResult? accuracyModeResult;

Benchmark({
required this.benchmarkSettings,
required this.taskConfig,
Expand Down Expand Up @@ -141,7 +89,6 @@ class BenchmarkList {
BenchmarkList({
required pb.MLPerfConfig appConfig,
required List<pb.BenchmarkSetting> backendConfig,
required Map<String, bool> taskSelection,
}) {
for (final task in appConfig.task) {
final backendSettings = backendConfig
Expand All @@ -151,11 +98,10 @@ class BenchmarkList {
continue;
}

final enabled = taskSelection[task.id] ?? true;
benchmarks.add(Benchmark(
taskConfig: task,
benchmarkSettings: backendSettings,
isActive: enabled,
isActive: true,
));
}
}
Expand Down Expand Up @@ -195,11 +141,41 @@ class BenchmarkList {
return result.where((element) => element.path.isNotEmpty).toList();
}

Map<String, bool> get selection {
Map<String, bool> result = {};
static String serializeTaskSelection(Map<String, bool> selection) {
return jsonEncode(selection);
}

static Map<String, bool> deserializeTaskSelection(String serialized) {
if (serialized.isEmpty) {
return {};
}
try {
final json = jsonDecode(serialized) as Map<String, dynamic>;
Map<String, bool> result = {};
for (final e in json.entries) {
result[e.key] = e.value as bool;
}
return result;
} catch (e, t) {
print('task selection parse fail: $e');
print(t);
return {};
}
}

Map<String, bool> getTaskSelection() {
Map<String, bool> selection = {};
for (var item in benchmarks) {
result[item.id] = item.isActive;
selection[item.id] = item.isActive;
}
return selection;
}

void restoreSelection(Map<String, bool> selection) {
const stateForUnknown = true;

for (var task in benchmarks) {
task.isActive = selection[task.id] ?? stateForUnknown;
}
return result;
}
}
14 changes: 7 additions & 7 deletions flutter/lib/benchmark/run_mode.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,39 @@ class BenchmarkRunMode {
static const _accuracyLogSuffix = 'accuracy';

final String loadgenMode;
final String readable;
final String logSuffix;
final pb.OneDatasetConfig Function(pb.TaskConfig taskConfig) chooseDataset;

BenchmarkRunMode._({
required this.loadgenMode,
required this.readable,
required this.logSuffix,
required this.chooseDataset,
});

static BenchmarkRunMode performance = BenchmarkRunMode._(
loadgenMode: _performanceModeString,
readable: _perfLogSuffix,
logSuffix: _perfLogSuffix,
chooseDataset: (task) => task.datasets.lite,
);
static BenchmarkRunMode accuracy = BenchmarkRunMode._(
loadgenMode: _accuracyModeString,
readable: _accuracyLogSuffix,
logSuffix: _accuracyLogSuffix,
chooseDataset: (task) => task.datasets.full,
);

static BenchmarkRunMode performanceTest = BenchmarkRunMode._(
loadgenMode: _performanceModeString,
readable: _perfLogSuffix,
logSuffix: _perfLogSuffix,
chooseDataset: (task) => task.datasets.tiny,
);
static BenchmarkRunMode accuracyTest = BenchmarkRunMode._(
loadgenMode: _accuracyModeString,
readable: _accuracyLogSuffix,
logSuffix: _accuracyLogSuffix,
chooseDataset: (task) => task.datasets.tiny,
);

@override
String toString() {
return readable;
return logSuffix;
}
}
Loading