Skip to content

Commit 8e3e993

Browse files
committed
[projmgr] MLOps: make it tolerant to missing hardware or simulator targets
1 parent e673230 commit 8e3e993

11 files changed

Lines changed: 222 additions & 126 deletions

tools/projmgr/include/ProjMgrMlops.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ class ProjMgrMlops {
131131
std::string BuildActive(const std::string& targetType, const std::string& targetSet) const;
132132
std::string GetCustomScalar(const CustomItem& custom, const std::string& key) const;
133133
std::string BuildVelaOptions(const MlopsNpuType& npu, const MlopsVelaItem& vela) const;
134+
bool ResolveMlopsPath(std::string& path, const std::string& solutionDir,
135+
bool hardwareFound, ContextItem& hardwareContext) const;
134136
void SetMlopsRunType(MlopsRunType& run, const std::string& targetType, const std::string& targetSet,
135137
const std::vector<ContextItem>& contexts, const std::string& outBaseDir, const std::string& solutionName) const;
136138
};

tools/projmgr/src/ProjMgrMlops.cpp

Lines changed: 47 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "ProjMgrMlops.h"
88

9-
#include "ProjMgrLogger.h"
109
#include "ProjMgrParser.h"
1110
#include "ProjMgrUtils.h"
1211

@@ -27,7 +26,6 @@ bool ProjMgrMlops::FindTargetType(const CsolutionItem& csolution, const string&
2726
return true;
2827
}
2928
}
30-
ProjMgrLogger::Get().Error("mlops: target-type '" + typeName + "' not found");
3129
return false;
3230
}
3331

@@ -41,7 +39,6 @@ bool ProjMgrMlops::GetTargetSetItemRef(const TargetType& targetType, const strin
4139
return true;
4240
}
4341
}
44-
ProjMgrLogger::Get().Error("mlops: simulator target with debugger 'Arm-FVP' not found");
4542
return false;
4643
}
4744
if (!targetType.targetSet.empty()) {
@@ -56,8 +53,6 @@ bool ProjMgrMlops::GetTargetSetItemRef(const TargetType& targetType, const strin
5653
}
5754
}
5855
}
59-
ProjMgrLogger::Get().Error("mlops: target-type '" + targetTypeName + "' target-set '" +
60-
(targetSetName.empty() ? "<default>" : targetSetName) + "' not found");
6156
return false;
6257
}
6358

@@ -91,6 +86,20 @@ string ProjMgrMlops::BuildVelaOptions(const MlopsNpuType& npu, const MlopsVelaIt
9186
return options;
9287
}
9388

89+
bool ProjMgrMlops::ResolveMlopsPath(string& path, const string& solutionDir,
90+
bool hardwareFound, ContextItem& hardwareContext) const {
91+
if (hardwareFound && !m_worker->ProcessSequenceRelative(hardwareContext, path, solutionDir, false)) {
92+
return false;
93+
}
94+
if (ProjMgrUtils::HasAccessSequence(path)) {
95+
path.clear();
96+
} else if (RteFsUtils::IsRelative(path)) {
97+
const auto& baseDir = hardwareFound ? hardwareContext.directories.cprj : solutionDir;
98+
RteFsUtils::NormalizePath(path, baseDir);
99+
}
100+
return true;
101+
}
102+
94103
void ProjMgrMlops::SetMlopsRunType(MlopsRunType& run, const string& targetType, const string& targetSet,
95104
const vector<ContextItem>& contexts, const string& outBaseDir, const string& solutionName) const {
96105
run.active = BuildActive(targetType, targetSet);
@@ -119,17 +128,15 @@ bool ProjMgrMlops::CollectSettings(const CsolutionItem& csolution, MlopsType& ml
119128
// get hardware set
120129
TargetType hardwareTargetType;
121130
TargetSetItem hardwareTargetSet;
122-
if (!FindTargetType(csolution, hardwareType, hardwareTargetType) ||
123-
!GetTargetSetItemRef(hardwareTargetType, hardwareType, solutionMlops.hardware.targetSet, false, hardwareTargetSet)) {
124-
return false;
131+
if (FindTargetType(csolution, hardwareType, hardwareTargetType)) {
132+
GetTargetSetItemRef(hardwareTargetType, hardwareType, solutionMlops.hardware.targetSet, false, hardwareTargetSet);
125133
}
126134

127135
// get simulator set
128136
TargetType simulatorTargetType;
129137
TargetSetItem simulatorTargetSet;
130-
if (!FindTargetType(csolution, simulatorType, simulatorTargetType) ||
131-
!GetTargetSetItemRef(simulatorTargetType, simulatorType, solutionMlops.simulator.targetSet, true, simulatorTargetSet)) {
132-
return false;
138+
if (FindTargetType(csolution, simulatorType, simulatorTargetType)) {
139+
GetTargetSetItemRef(simulatorTargetType, simulatorType, solutionMlops.simulator.targetSet, true, simulatorTargetSet);
133140
}
134141

135142
// get all context items
@@ -164,20 +171,11 @@ bool ProjMgrMlops::CollectSettings(const CsolutionItem& csolution, MlopsType& ml
164171
}
165172

166173
// check if hardware and simulator contexts were found
167-
vector<tuple<const vector<ContextItem>&, const string&, const string&>> contextRefs = {
168-
{hardwareContexts, hardwareType, hardwareTargetSet.set},
169-
{simulatorContexts, simulatorType, simulatorTargetSet.set}
170-
};
171-
for (const auto& [ref, targetType, targetSet] : contextRefs) {
172-
if (ref.empty()) {
173-
ProjMgrLogger::Get().Error("mlops: target-type '" + targetType + "' target-set '" +
174-
(targetSet.empty() ? "<default>" : targetSet) + "' project-contexts not found");
175-
return false;
176-
}
177-
}
178-
179-
auto& hardwareContext = hardwareContexts.front();
180-
auto& simulatorContext = simulatorContexts.front();
174+
bool hardwareFound = !hardwareContexts.empty();
175+
bool simulatorFound = !simulatorContexts.empty();
176+
ContextItem defaultContext;
177+
ContextItem& hardwareContext = hardwareFound ? hardwareContexts.front() : defaultContext;
178+
ContextItem& simulatorContext = simulatorFound ? simulatorContexts.front() : defaultContext;
181179

182180
// mlops description
183181
mlops.description = solutionMlops.description;
@@ -244,40 +242,41 @@ bool ProjMgrMlops::CollectSettings(const CsolutionItem& csolution, MlopsType& ml
244242
} else {
245243
// explicit vela ini
246244
mlops.vela.ini = solutionMlops.vela.ini;
247-
if (!m_worker->ProcessSequenceRelative(hardwareContext, mlops.vela.ini, csolution.directory, false)) {
245+
if (!ResolveMlopsPath(mlops.vela.ini, csolution.directory, hardwareFound, hardwareContext)) {
248246
return false;
249247
}
250-
if (RteFsUtils::IsRelative(mlops.vela.ini)) {
251-
RteFsUtils::NormalizePath(mlops.vela.ini, hardwareContext.directories.cprj);
252-
}
253248
}
254-
249+
255250
// model name and clayer
256251
if (!solutionMlops.model.clayer.empty()) {
257252
mlops.model.name = solutionMlops.model.name.empty() ? "Algorithm" : solutionMlops.model.name;
258253
mlops.model.clayer = solutionMlops.model.clayer;
259-
if (!m_worker->ProcessSequenceRelative(hardwareContext, mlops.model.clayer, csolution.directory, false)) {
254+
if (!ResolveMlopsPath(mlops.model.clayer, csolution.directory, hardwareFound, hardwareContext)) {
260255
return false;
261-
}
262-
if (RteFsUtils::IsRelative(mlops.model.clayer)) {
263-
RteFsUtils::NormalizePath(mlops.model.clayer, hardwareContext.directories.cprj);
264-
}
256+
}
265257
}
266258

267-
// set hardware and simulator run types
268-
const string outBaseDir = hardwareContext.directories.cprj + "/" + hardwareContext.directories.outBaseDir;
269-
SetMlopsRunType(mlops.hardware, hardwareType, hardwareTargetSet.set, hardwareContexts, outBaseDir, csolution.name);
270-
SetMlopsRunType(mlops.simulator, simulatorType, simulatorTargetSet.set, simulatorContexts, outBaseDir, csolution.name);
259+
if (hardwareFound) {
260+
// set hardware run types
261+
const string outBaseDir = hardwareContext.directories.cprj + "/" + hardwareContext.directories.outBaseDir;
262+
SetMlopsRunType(mlops.hardware, hardwareType, hardwareTargetSet.set, hardwareContexts, outBaseDir, csolution.name);
263+
}
271264

272-
// get debugger model and config-file
273-
mlops.simulator.model = GetCustomScalar(simulatorTargetSet.debugger.custom, "model");
274-
mlops.simulator.configFile = GetCustomScalar(simulatorTargetSet.debugger.custom, "config-file");
275-
if (!mlops.simulator.configFile.empty()) {
276-
if (!m_worker->ProcessSequenceRelative(simulatorContext, mlops.simulator.configFile, csolution.directory, false)) {
277-
return false;
278-
}
279-
if (RteFsUtils::IsRelative(mlops.simulator.configFile)) {
280-
RteFsUtils::NormalizePath(mlops.simulator.configFile, simulatorContext.directories.cprj);
265+
if (simulatorFound) {
266+
// set simulator run types
267+
const string outBaseDir = simulatorContext.directories.cprj + "/" + simulatorContext.directories.outBaseDir;
268+
SetMlopsRunType(mlops.simulator, simulatorType, simulatorTargetSet.set, simulatorContexts, outBaseDir, csolution.name);
269+
270+
// get debugger model and config-file
271+
mlops.simulator.model = GetCustomScalar(simulatorTargetSet.debugger.custom, "model");
272+
mlops.simulator.configFile = GetCustomScalar(simulatorTargetSet.debugger.custom, "config-file");
273+
if (!mlops.simulator.configFile.empty()) {
274+
if (!m_worker->ProcessSequenceRelative(simulatorContext, mlops.simulator.configFile, csolution.directory, false)) {
275+
return false;
276+
}
277+
if (RteFsUtils::IsRelative(mlops.simulator.configFile)) {
278+
RteFsUtils::NormalizePath(mlops.simulator.configFile, simulatorContext.directories.cprj);
279+
}
281280
}
282281
}
283282

tools/projmgr/test/data/MLOps/failure1.csolution.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

tools/projmgr/test/data/MLOps/failure2.csolution.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

tools/projmgr/test/data/MLOps/failure3.csolution.yml

Lines changed: 0 additions & 20 deletions
This file was deleted.

tools/projmgr/test/data/MLOps/minimal.csolution.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ solution:
2121

2222
- type: Simulator
2323
device: RteTest_ARMCM0_Dual
24-
define:
25-
- SIMULATOR
2624
variables:
2725
- AI-Layer: $SolutionDir()$/ai_layer/ai_layer.clayer.yml
2826
target-set:
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json
2+
3+
solution:
4+
compiler: AC6
5+
6+
mlops:
7+
description: hardware target not present
8+
model:
9+
clayer: $AI-Layer$
10+
hardware:
11+
target: OtherHardware
12+
13+
target-types:
14+
- type: Hardware
15+
device: RteTest_ARMCM0_Dual
16+
variables:
17+
- AI-Layer: $SolutionDir()$/ai_layer/ai_layer.clayer.yml
18+
target-set:
19+
- set:
20+
images:
21+
- project-context: core0
22+
- project-context: core1
23+
24+
- type: Simulator
25+
device: RteTest_ARMCM0_Dual
26+
variables:
27+
- AI-Layer: $SolutionDir()$/ai_layer/ai_layer.clayer.yml
28+
target-set:
29+
- set: FVP-Test
30+
debugger:
31+
name: Arm-FVP
32+
model: FVP_Corstone_SSE-320
33+
config-file: fvp/fvp_config.txt
34+
images:
35+
- project-context: core0
36+
- project-context: core1
37+
38+
projects:
39+
- project: core0/core0.cproject.yml
40+
- project: core1/core1.cproject.yml
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json
2+
3+
solution:
4+
compiler: AC6
5+
6+
mlops:
7+
description: hardware context not found
8+
vela:
9+
ini: vela/custom.ini
10+
model:
11+
clayer: ai_layer/ai_layer.clayer.yml
12+
hardware:
13+
target: Hardware
14+
15+
target-types:
16+
- type: Hardware
17+
device: RteTest_ARMCM0_Dual
18+
variables:
19+
- AI-Layer: $SolutionDir()$/ai_layer/ai_layer.clayer.yml
20+
target-set:
21+
- set:
22+
images:
23+
- project-context: coreX
24+
- project-context: coreY
25+
26+
- type: Simulator
27+
device: RteTest_ARMCM0_Dual
28+
variables:
29+
- AI-Layer: $SolutionDir()$/ai_layer/ai_layer.clayer.yml
30+
target-set:
31+
- set: FVP-Test
32+
debugger:
33+
name: Arm-FVP
34+
model: FVP_Corstone_SSE-320
35+
config-file: fvp/fvp_config.txt
36+
images:
37+
- project-context: core0
38+
- project-context: core1
39+
40+
projects:
41+
- project: core0/core0.cproject.yml
42+
- project: core1/core1.cproject.yml
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# yaml-language-server: $schema=https://raw.githubusercontent.com/Open-CMSIS-Pack/devtools/main/tools/projmgr/schemas/csolution.schema.json
2+
3+
solution:
4+
compiler: AC6
5+
6+
mlops:
7+
description: simulator target not present
8+
model:
9+
clayer: $AI-Layer$
10+
simulator:
11+
target: OtherSimulator
12+
13+
target-types:
14+
- type: Hardware
15+
device: RteTest_ARMCM0_Dual
16+
variables:
17+
- AI-Layer: $SolutionDir()$/ai_layer/ai_layer.clayer.yml
18+
target-set:
19+
- set:
20+
images:
21+
- project-context: core0
22+
- project-context: core1
23+
24+
- type: Simulator
25+
device: RteTest_ARMCM0_Dual
26+
variables:
27+
- AI-Layer: $SolutionDir()$/ai_layer/ai_layer.clayer.yml
28+
target-set:
29+
- set: FVP-Test
30+
debugger:
31+
name: Arm-FVP
32+
model: FVP_Corstone_SSE-320
33+
config-file: fvp/fvp_config.txt
34+
images:
35+
- project-context: core0
36+
- project-context: core1
37+
38+
projects:
39+
- project: core0/core0.cproject.yml
40+
- project: core1/core1.cproject.yml

0 commit comments

Comments
 (0)