@@ -190,8 +190,9 @@ Error asyncMemCopy(bool UseMultipleSdmaEngines, void *Dst, hsa_agent_t DstAgent,
190190#endif
191191}
192192
193- Error getTargetTripleAndFeatures (hsa_agent_t Agent,
194- SmallVector<std::string> &Targets) {
193+ Expected<StringRef>
194+ getTargetTripleAndFeatures (hsa_agent_t Agent, SmallVector<StringRef> &Targets) {
195+ StringRef SpecificTarget;
195196 auto Err = hsa_utils::iterateAgentISAs (Agent, [&](hsa_isa_t ISA) {
196197 uint32_t Length;
197198 hsa_status_t Status;
@@ -206,15 +207,18 @@ Error getTargetTripleAndFeatures(hsa_agent_t Agent,
206207
207208 llvm::StringRef TripleTarget (ISAName.begin (), Length);
208209 if (TripleTarget.consume_front (" amdgcn-amd-amdhsa" )) {
209- auto Target = TripleTarget.ltrim (' -' ).rtrim (' \0 ' ).str ();
210- if (Target.find (" generic" ) != std::string::npos)
211- Targets.push_back (Target);
212- else
213- Targets[0 ] = Target;
210+ auto Target = TripleTarget.ltrim (' -' ).rtrim (' \0 ' );
211+ Targets.push_back (Target);
212+ if (!Target.ends_with (" generic" ))
213+ SpecificTarget = Target; // Expect one (and only one) to be found
214214 }
215215 return HSA_STATUS_SUCCESS;
216216 });
217- return Err;
217+ if (Err)
218+ return Err;
219+ if (SpecificTarget.empty ())
220+ return Plugin::error (" Specific Target ISA not found" );
221+ return SpecificTarget;
218222}
219223} // namespace hsa_utils
220224
@@ -1991,11 +1995,13 @@ struct AMDGPUDeviceTy : public GenericDeviceTy, AMDGenericDeviceTy {
19911995 return Err;
19921996
19931997 // Detect if XNACK is enabled
1994- SmallVector<std::string> Targets;
1995- Targets.push_back (" " );
1996- if (auto Err = hsa_utils::getTargetTripleAndFeatures (Agent, Targets))
1997- return Err;
1998- if (Targets[0 ].find (" xnack+" ) != std::string::npos)
1998+ SmallVector<StringRef> Targets;
1999+ auto TargeTripleAndFeaturesOrError =
2000+ hsa_utils::getTargetTripleAndFeatures (Agent, Targets);
2001+ if (!TargeTripleAndFeaturesOrError)
2002+ return TargeTripleAndFeaturesOrError.takeError ();
2003+ if (static_cast <StringRef>(*TargeTripleAndFeaturesOrError)
2004+ .contains (" xnack+" ))
19992005 IsXnackEnabled = true ;
20002006
20012007 // detect if device is an APU.
@@ -3209,15 +3215,15 @@ struct AMDGPUPluginTy final : public GenericPluginTy {
32093215 if (!Processor)
32103216 return false ;
32113217
3212- SmallVector<std::string > Targets;
3213- Targets. push_back ( " " );
3214- if ( auto Err = hsa_utils::getTargetTripleAndFeatures (
3215- getKernelAgent (DeviceId), Targets) )
3216- return Err ;
3218+ SmallVector<StringRef > Targets;
3219+ auto TargetTripleAndFeaturesOrError = hsa_utils::getTargetTripleAndFeatures (
3220+ getKernelAgent (DeviceId), Targets);
3221+ if (!TargetTripleAndFeaturesOrError )
3222+ return TargetTripleAndFeaturesOrError. takeError () ;
32173223 for (auto &Target : Targets)
32183224 if (offloading::amdgpu::isImageCompatibleWithEnv (
32193225 Processor ? *Processor : " " , ElfOrErr->getPlatformFlags (),
3220- Target))
3226+ Target. str () ))
32213227 return true ;
32223228 return false ;
32233229 }
0 commit comments