@@ -27,40 +27,64 @@ bool ProjMgrMlops::FindTargetType(const CsolutionItem& csolution, const string&
2727 return true ;
2828 }
2929 }
30- ProjMgrLogger::Get ().Error (" mlops: target-type '" + typeName + " ' not found" );
3130 return false ;
3231}
3332
34- bool ProjMgrMlops::GetTargetSetItemRef (const TargetType& targetType, const string& targetTypeName ,
35- const string& targetSetName, bool simulatorDefault , TargetSetItem& targetSet) const {
36- if (targetSetName.empty ()) {
37- if (simulatorDefault ) {
38- for ( const auto & set : targetType. targetSet ) {
39- if ( set.debugger .name == " Arm-FVP" ) {
40- targetSet = set;
41- return true ;
42- }
33+ bool ProjMgrMlops::GetTargetSetItemRef (const TargetType& targetType, optional< const string> targetSetName ,
34+ bool simulator , TargetSetItem& targetSet) const {
35+ if (! targetSetName.has_value ()) {
36+ for ( const auto & set : targetType. targetSet ) {
37+ if ((simulator && set. debugger . name == " Arm-FVP " ) ||
38+ (!simulator && set.debugger .name != " Arm-FVP" ) ) {
39+ // default simulator or hardware target set
40+ targetSet = set ;
41+ return true ;
4342 }
44- ProjMgrLogger::Get ().Error (" mlops: simulator target with debugger 'Arm-FVP' not found" );
45- return false ;
46- }
47- if (!targetType.targetSet .empty ()) {
48- targetSet = targetType.targetSet .front ();
49- return true ;
5043 }
5144 } else {
5245 for (const auto & set : targetType.targetSet ) {
53- if (set.set == targetSetName) {
46+ if (set.set == targetSetName.value ()) {
47+ // specified target set
5448 targetSet = set;
5549 return true ;
5650 }
5751 }
5852 }
59- ProjMgrLogger::Get ().Error (" mlops: target-type '" + targetTypeName + " ' target-set '" +
60- (targetSetName.empty () ? " <default>" : targetSetName) + " ' not found" );
53+ // target set could not be determined
6154 return false ;
6255}
6356
57+ bool ProjMgrMlops::ResolveTargetSet (const CsolutionItem& csolution, const MlopsTargetItem target,
58+ bool simulatorDefault, string& typeName, TargetSetItem& targetSetItem) const {
59+ TargetType targetType;
60+ if (target.targetType .empty ()) {
61+ if (!csolution.targetTypes .empty ()) {
62+ // default simulator: last target-type, default hardware: first target-type
63+ typeName = simulatorDefault ? csolution.targetTypes .back ().first : csolution.targetTypes .front ().first ;
64+ targetType = simulatorDefault ? csolution.targetTypes .back ().second : csolution.targetTypes .front ().second ;
65+ }
66+ } else {
67+ typeName = target.targetType ;
68+ if (!FindTargetType (csolution, target.targetType , targetType)) {
69+ // print error if specified target type was not found
70+ ProjMgrLogger::Get ().Error (" mlops: target type '" + target.targetType + " ' not found" );
71+ return false ;
72+ }
73+ }
74+ // target set name = nullopt if target type is not specified, to differentiate from default (unnamed) target set
75+ auto targetSetName = target.targetType .empty () ? nullopt : make_optional (target.targetSet );
76+ if (!GetTargetSetItemRef (targetType, targetSetName, simulatorDefault, targetSetItem)) {
77+ if (targetSetName.has_value ()) {
78+ // print error if specified target set was not found
79+ ProjMgrLogger::Get ().Error (" mlops: " + (target.targetSet .empty () ?
80+ (" no default unnamed target set for '" + target.targetType + " '" ) :
81+ (" target set '" + target.targetType + ' @' + target.targetSet + " ' not found" )));
82+ return false ;
83+ }
84+ }
85+ return true ;
86+ }
87+
6488string ProjMgrMlops::BuildActive (const string& targetType, const string& targetSet) const {
6589 return targetSet.empty () ? targetType : targetType + " @" + targetSet;
6690}
@@ -110,41 +134,31 @@ bool ProjMgrMlops::CollectSettings(const CsolutionItem& csolution, MlopsType& ml
110134
111135 const auto & solutionMlops = csolution.mlops ;
112136
113- // hardware and simulator target types
114- const string hardwareType = !solutionMlops.hardware .targetType .empty () ? solutionMlops.hardware .targetType :
115- (!csolution.targetTypes .empty () ? csolution.targetTypes .front ().first : RteUtils::EMPTY_STRING );
116- const string simulatorType = !solutionMlops.simulator .targetType .empty () ? solutionMlops.simulator .targetType :
117- (!csolution.targetTypes .empty () ? csolution.targetTypes .back ().first : RteUtils::EMPTY_STRING );
118-
119- // get hardware set
120- TargetType hardwareTargetType;
121- TargetSetItem hardwareTargetSet;
122- if (!FindTargetType (csolution, hardwareType, hardwareTargetType) ||
123- !GetTargetSetItemRef (hardwareTargetType, hardwareType, solutionMlops.hardware .targetSet , false , hardwareTargetSet)) {
124- return false ;
125- }
126-
127- // get simulator set
128- TargetType simulatorTargetType;
129- TargetSetItem simulatorTargetSet;
130- if (!FindTargetType (csolution, simulatorType, simulatorTargetType) ||
131- !GetTargetSetItemRef (simulatorTargetType, simulatorType, solutionMlops.simulator .targetSet , true , simulatorTargetSet)) {
137+ // resolve hardware and simulator targets and get references for their items
138+ string hardwareType, simulatorType;
139+ TargetSetItem hardwareTargetSet, simulatorTargetSet;
140+ if (!ResolveTargetSet (csolution, solutionMlops.hardware , false , hardwareType, hardwareTargetSet) ||
141+ !ResolveTargetSet (csolution, solutionMlops.simulator , true , simulatorType, simulatorTargetSet)) {
142+ // throw error if target is explicit specified but target set cannot be determined
132143 return false ;
133144 }
134145
135146 // get all context items
136147 map<string, ContextItem>* contexts = nullptr ;
137148 m_worker->GetContexts (contexts);
149+ if (contexts->empty ()) {
150+ return false ;
151+ }
138152
139153 // find hardware and simulator contexts
140154 vector<ContextItem> hardwareContexts, simulatorContexts;
141155 StrSet pnames;
142156 vector<tuple<const TargetSetItem&, const string&, vector<ContextItem>&>> refs = {
143157 {hardwareTargetSet, hardwareType, hardwareContexts}, {simulatorTargetSet, simulatorType, simulatorContexts}};
144158 for (auto & [targetSet, targetType, ref] : refs) {
145- for (const auto & image : targetSet.images ) {
146- if (!image .context .empty ()) {
147- const string contextName = image .context + " +" + targetType;
159+ for (const auto & entry : targetSet.images ) {
160+ if (!entry .context .empty ()) {
161+ const string contextName = entry .context + " +" + targetType;
148162 if (contexts->find (contextName) != contexts->end ()) {
149163 // process context precedences if needed
150164 auto & context = contexts->at (contextName);
@@ -164,27 +178,35 @@ bool ProjMgrMlops::CollectSettings(const CsolutionItem& csolution, MlopsType& ml
164178 }
165179
166180 // 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 }
181+ vector<tuple<const vector<ContextItem>&, const MlopsTargetItem &>> contextRefs = {
182+ {hardwareContexts, solutionMlops. hardware },
183+ {simulatorContexts, solutionMlops. simulator }
170184 };
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" );
185+ for (const auto & [ref, t] : contextRefs) {
186+ if (!t.targetType .empty () && ref.empty ()) {
187+ // print error if context for specified target type was not found
188+ ProjMgrLogger::Get ().Error (" mlops: no project-context specified for target '" +
189+ t.targetType + (t.targetSet .empty () ? " " : ' @' + t.targetSet ) + " '" );
175190 return false ;
176191 }
177192 }
178193
179- auto & hardwareContext = hardwareContexts.front ();
180- auto & simulatorContext = simulatorContexts.front ();
194+ // get hardware and simulator context references
195+ bool hardwareFound = !hardwareContexts.empty ();
196+ bool simulatorFound = !simulatorContexts.empty ();
197+ ContextItem emptyContext;
198+ ContextItem& hardwareContext = hardwareFound ? hardwareContexts.front () : emptyContext;
199+ ContextItem& simulatorContext = simulatorFound ? simulatorContexts.front () : emptyContext;
200+
201+ // if hardware is not determined use first default context for processor type and access sequences
202+ ContextItem& context = hardwareFound ? hardwareContext : contexts->begin ()->second ;
181203
182204 // mlops description
183205 mlops.description = solutionMlops.description ;
184206
185207 // get hardware processor type ("Dcore")
186- if (hardwareContext .targetAttributes .find (" Dcore" ) != hardwareContext .targetAttributes .end ()) {
187- mlops.processor .type = hardwareContext .targetAttributes .at (" Dcore" );
208+ if (context .targetAttributes .find (" Dcore" ) != context .targetAttributes .end ()) {
209+ mlops.processor .type = context .targetAttributes .at (" Dcore" );
188210 }
189211
190212 // npu type and macs
@@ -244,40 +266,47 @@ bool ProjMgrMlops::CollectSettings(const CsolutionItem& csolution, MlopsType& ml
244266 } else {
245267 // explicit vela ini
246268 mlops.vela .ini = solutionMlops.vela .ini ;
247- if (!m_worker->ProcessSequenceRelative (hardwareContext , mlops.vela .ini , csolution.directory , false )) {
269+ if (!m_worker->ProcessSequenceRelative (context , mlops.vela .ini , csolution.directory , false )) {
248270 return false ;
249271 }
250272 if (RteFsUtils::IsRelative (mlops.vela .ini )) {
251- RteFsUtils::NormalizePath (mlops.vela .ini , hardwareContext .directories .cprj );
273+ RteFsUtils::NormalizePath (mlops.vela .ini , context .directories .cprj );
252274 }
253275 }
254-
276+
255277 // model name and clayer
256278 if (!solutionMlops.model .clayer .empty ()) {
257279 mlops.model .name = solutionMlops.model .name .empty () ? " Algorithm" : solutionMlops.model .name ;
258280 mlops.model .clayer = solutionMlops.model .clayer ;
259- if (!m_worker->ProcessSequenceRelative (hardwareContext , mlops.model .clayer , csolution.directory , false )) {
281+ if (!m_worker->ProcessSequenceRelative (context , mlops.model .clayer , csolution.directory , false )) {
260282 return false ;
261283 }
262284 if (RteFsUtils::IsRelative (mlops.model .clayer )) {
263- RteFsUtils::NormalizePath (mlops.model .clayer , hardwareContext .directories .cprj );
285+ RteFsUtils::NormalizePath (mlops.model .clayer , context .directories .cprj );
264286 }
265287 }
266288
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 );
289+ if (hardwareFound) {
290+ // set hardware run types
291+ const string outBaseDir = hardwareContext.directories .cprj + " /" + hardwareContext.directories .outBaseDir ;
292+ SetMlopsRunType (mlops.hardware , hardwareType, hardwareTargetSet.set , hardwareContexts, outBaseDir, csolution.name );
293+ }
271294
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 );
295+ if (simulatorFound) {
296+ // set simulator run types
297+ const string outBaseDir = simulatorContext.directories .cprj + " /" + simulatorContext.directories .outBaseDir ;
298+ SetMlopsRunType (mlops.simulator , simulatorType, simulatorTargetSet.set , simulatorContexts, outBaseDir, csolution.name );
299+
300+ // get debugger model and config-file
301+ mlops.simulator .model = GetCustomScalar (simulatorTargetSet.debugger .custom , " model" );
302+ mlops.simulator .configFile = GetCustomScalar (simulatorTargetSet.debugger .custom , " config-file" );
303+ if (!mlops.simulator .configFile .empty ()) {
304+ if (!m_worker->ProcessSequenceRelative (simulatorContext, mlops.simulator .configFile , csolution.directory , false )) {
305+ return false ;
306+ }
307+ if (RteFsUtils::IsRelative (mlops.simulator .configFile )) {
308+ RteFsUtils::NormalizePath (mlops.simulator .configFile , simulatorContext.directories .cprj );
309+ }
281310 }
282311 }
283312
0 commit comments