Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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
41 changes: 29 additions & 12 deletions flutter/lib/benchmark/benchmark.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,20 +151,37 @@ class BenchmarkSet {

void applyOptions() {
for (Benchmark benchmark in benchmarks) {
benchmark.isActive = true;
for (String optionId in benchmark.taskConfig.requiredOption) {
final index = optionMap[optionId];
final optionSet =
(index != null && index >= 0 && index < optionSets.length)
? optionSets[index]
: null;
if (!(optionSet?.getOption(optionId) ?? false)) {
benchmark.isActive = false;
break;
}
if (!areOptionsMet(benchmark)) {
benchmark.isActive = false;
}
}
}

/// Activate all benchmarks whose required options are met,
/// deactivate the rest.
void setAllActive(bool active) {
for (Benchmark benchmark in benchmarks) {
benchmark.isActive = active && areOptionsMet(benchmark);
}
}

/// Whether all required options are met for a benchmark.
bool areOptionsMet(Benchmark benchmark) {
for (String optionId in benchmark.taskConfig.requiredOption) {
final index = optionMap[optionId];
final optionSet =
(index != null && index >= 0 && index < optionSets.length)
? optionSets[index]
: null;
if (!(optionSet?.getOption(optionId) ?? false)) {
return false;
}
}
return true;
}

/// Whether any benchmark in the set is active.
bool get hasActiveBenchmarks => benchmarks.any((b) => b.isActive);
}

class BenchmarkOptionSet {
Expand Down Expand Up @@ -269,7 +286,7 @@ class BenchmarkStore {
continue;
}

final enabled = taskSelection[task.id] ?? true;
final enabled = taskSelection[task.id] ?? false;
allBenchmarks.add(Benchmark(
taskConfig: task,
benchmarkSettings: backendSettings,
Expand Down
17 changes: 17 additions & 0 deletions flutter/lib/benchmark/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@
await state.resourceManager.initSystemPaths();
state.configManager = ConfigManager(
state.resourceManager.applicationDirectory, state.resourceManager);
// Clear persisted task selection so all tasks start unchecked
store.taskSelection = '';
try {
await state.setTaskConfig(name: store.chosenConfigurationName);
state.deferredLoadResources();
Expand Down Expand Up @@ -347,6 +349,20 @@
notifyListeners();
}

void toggleBenchmarkSetAll(BenchmarkSet benchmarkSet, bool isActive) {

Check warning on line 352 in flutter/lib/benchmark/state.dart

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Undefined class 'BenchmarkSet'.

See more on https://sonarcloud.io/project/issues?id=mlcommons_mobile_app_open&issues=AZ2KcQMM4gbmiIyOySsQ&open=AZ2KcQMM4gbmiIyOySsQ&pullRequest=1124
benchmarkSet.setAllActive(isActive);
saveTaskSelection();
notifyListeners();
}

void resetAllBenchmarks() {
for (var b in _benchmarkStore.allBenchmarks) {
b.isActive = false;
}
saveTaskSelection();
notifyListeners();
}

void benchmarkSetDelegate(Benchmark benchmark, String delegate) {
benchmark.benchmarkSettings.delegateSelected = delegate;
notifyListeners();
Expand All @@ -357,6 +373,7 @@
benchmarkSet.optionSets[benchmarkSet.optionMap[option]!]
.setOptionTo(option, value);
benchmarkSet.applyOptions();
saveTaskSelection();
notifyListeners();
}

Expand Down
8 changes: 8 additions & 0 deletions flutter/lib/ui/home/benchmark_config_section.dart
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,14 @@
builder: (context, snapshot) => _setDownloadStatus(
l10n, benchmarkSet, snapshot.data!, context),
),
// Master toggle for the entire set
Switch(

Check warning on line 156 in flutter/lib/ui/home/benchmark_config_section.dart

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

The method 'Switch' isn't defined for the type 'BenchmarkConfigSection'.

See more on https://sonarcloud.io/project/issues?id=mlcommons_mobile_app_open&issues=AZ2KcQIu4gbmiIyOySsP&open=AZ2KcQIu4gbmiIyOySsP&pullRequest=1124
activeColor: AppColors.primary,

Check warning on line 157 in flutter/lib/ui/home/benchmark_config_section.dart

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Undefined name 'AppColors'.

See more on https://sonarcloud.io/project/issues?id=mlcommons_mobile_app_open&issues=AZ2KcQIu4gbmiIyOySsO&open=AZ2KcQIu4gbmiIyOySsO&pullRequest=1124
value: benchmarkSet.hasActiveBenchmarks,
onChanged: (flag) {
state.toggleBenchmarkSetAll(benchmarkSet, flag);
},
),
Padding(
padding: const EdgeInsets.only(right: 8),
child: Column(
Expand Down
1 change: 1 addition & 0 deletions flutter/lib/ui/settings/settings_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ class _SettingsScreen extends State<SettingsScreen> {
.toList(),
onChanged: (value) => setState(() {
store.selectedBenchmarkRunMode = value!;
state.resetAllBenchmarks();
})),
);
}
Expand Down
10 changes: 5 additions & 5 deletions flutter/unit_test/benchmark/benchmark_store_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ void main() {
expect(store.allBenchmarks.first.benchmarkSettings, backendSettings1);
expect(
store.allBenchmarks.first.isActive,
true,
reason: 'benchmarks must be enabled by default',
false,
reason: 'benchmarks must be disabled by default',
);
});

Expand Down Expand Up @@ -99,7 +99,7 @@ void main() {
final store = BenchmarkStore(
appConfig: pb.MLPerfConfig(task: [task1]),
backendConfig: [backendSettings1],
taskSelection: {},
taskSelection: {task1.id: true},
);

final modes = [BenchmarkRunModeEnum.accuracyOnly.accuracyRunMode];
Expand Down Expand Up @@ -136,7 +136,7 @@ void main() {
final store = BenchmarkStore(
appConfig: pb.MLPerfConfig(task: [task1]),
backendConfig: [backendSettings1],
taskSelection: {},
taskSelection: {task1.id: true},
);

final modes = [BenchmarkRunModeEnum.performanceOnly.performanceRunMode];
Expand Down Expand Up @@ -167,7 +167,7 @@ void main() {
final store = BenchmarkStore(
appConfig: pb.MLPerfConfig(task: [task1]),
backendConfig: [backendSettings1],
taskSelection: {},
taskSelection: {task1.id: true},
);

final modes = [
Expand Down
Loading