|
79 | 79 | #include "llvm/Option/OptSpecifier.h"
|
80 | 80 | #include "llvm/Option/OptTable.h"
|
81 | 81 | #include "llvm/Option/Option.h"
|
82 |
| -#include "llvm/SYCLLowerIR/DeviceConfigFile.hpp" |
83 | 82 | #include "llvm/Support/CommandLine.h"
|
84 | 83 | #include "llvm/Support/ErrorHandling.h"
|
85 | 84 | #include "llvm/Support/ExitCodes.h"
|
@@ -6234,101 +6233,6 @@ class OffloadingActionBuilder final {
|
6234 | 6233 | return FinalDeviceSections;
|
6235 | 6234 | }
|
6236 | 6235 |
|
6237 |
| - /// Reads device config file to find information about the SYCL targets in |
6238 |
| - /// `Targets`, and defines device traits macros accordingly. |
6239 |
| - void populateSYCLDeviceTraitsMacrosArgs( |
6240 |
| - Compilation &C, const DerivedArgList &Args, |
6241 |
| - const SmallVector<DeviceTargetInfo, 4> &Targets) const { |
6242 |
| - if (Targets.empty()) |
6243 |
| - return; |
6244 |
| - |
6245 |
| - const auto &TargetTable = DeviceConfigFile::TargetTable; |
6246 |
| - std::map<StringRef, unsigned int> AllDevicesHave; |
6247 |
| - std::map<StringRef, bool> AnyDeviceHas; |
6248 |
| - bool AnyDeviceHasAnyAspect = false; |
6249 |
| - unsigned int ValidTargets = 0; |
6250 |
| - for (const auto &[TC, BoundArch] : Targets) { |
6251 |
| - assert(TC && "Invalid SYCL Offload Toolchain"); |
6252 |
| - // Try and find the device arch, if it's empty, try to search for either |
6253 |
| - // the whole Triple or just the 'ArchName' string. |
6254 |
| - auto TargetIt = TargetTable.end(); |
6255 |
| - const llvm::Triple &TargetTriple = TC->getTriple(); |
6256 |
| - const StringRef TargetArch{BoundArch}; |
6257 |
| - if (!TargetArch.empty()) { |
6258 |
| - TargetIt = llvm::find_if(TargetTable, [&](const auto &Value) { |
6259 |
| - using namespace tools::SYCL; |
6260 |
| - StringRef Device{Value.first}; |
6261 |
| - if (Device.consume_front(gen::AmdGPU)) |
6262 |
| - return TargetArch == Device && TargetTriple.isAMDGCN(); |
6263 |
| - if (Device.consume_front(gen::NvidiaGPU)) |
6264 |
| - return TargetArch == Device && TargetTriple.isNVPTX(); |
6265 |
| - if (Device.consume_front(gen::IntelGPU)) |
6266 |
| - return TargetArch == Device && TargetTriple.isSPIRAOT(); |
6267 |
| - return TargetArch == Device && isValidSYCLTriple(TargetTriple); |
6268 |
| - }); |
6269 |
| - } else { |
6270 |
| - TargetIt = TargetTable.find(TargetTriple.str()); |
6271 |
| - if (TargetIt == TargetTable.end()) |
6272 |
| - TargetIt = TargetTable.find(TargetTriple.getArchName().str()); |
6273 |
| - } |
6274 |
| - |
6275 |
| - if (TargetIt != TargetTable.end()) { |
6276 |
| - const DeviceConfigFile::TargetInfo &Info = (*TargetIt).second; |
6277 |
| - ++ValidTargets; |
6278 |
| - const auto &AspectList = Info.aspects; |
6279 |
| - const auto &MaySupportOtherAspects = Info.maySupportOtherAspects; |
6280 |
| - if (!AnyDeviceHasAnyAspect) |
6281 |
| - AnyDeviceHasAnyAspect = MaySupportOtherAspects; |
6282 |
| - for (const auto &Aspect : AspectList) { |
6283 |
| - // If target has an entry in the config file, the set of aspects |
6284 |
| - // supported by all devices supporting the target is 'AspectList'. |
6285 |
| - // If there's no entry, such set is empty. |
6286 |
| - const auto &AspectIt = AllDevicesHave.find(Aspect); |
6287 |
| - if (AspectIt != AllDevicesHave.end()) |
6288 |
| - ++AllDevicesHave[Aspect]; |
6289 |
| - else |
6290 |
| - AllDevicesHave[Aspect] = 1; |
6291 |
| - // If target has an entry in the config file AND |
6292 |
| - // 'MaySupportOtherAspects' is false, the set of aspects supported |
6293 |
| - // by any device supporting the target is 'AspectList'. If there's |
6294 |
| - // no entry OR 'MaySupportOtherAspects' is true, such set contains |
6295 |
| - // all the aspects. |
6296 |
| - AnyDeviceHas[Aspect] = true; |
6297 |
| - } |
6298 |
| - } |
6299 |
| - } |
6300 |
| - |
6301 |
| - // If there's no entry for the target in the device config file, the set |
6302 |
| - // of aspects supported by any device supporting the target contains all |
6303 |
| - // the aspects. |
6304 |
| - if (ValidTargets == 0) |
6305 |
| - AnyDeviceHasAnyAspect = true; |
6306 |
| - |
6307 |
| - const Driver &D = C.getDriver(); |
6308 |
| - if (AnyDeviceHasAnyAspect) { |
6309 |
| - // There exists some target that supports any given aspect. |
6310 |
| - constexpr static StringRef MacroAnyDeviceAnyAspect{ |
6311 |
| - "-D__SYCL_ANY_DEVICE_HAS_ANY_ASPECT__=1"}; |
6312 |
| - D.addSYCLDeviceTraitsMacroArg(Args, MacroAnyDeviceAnyAspect); |
6313 |
| - } else { |
6314 |
| - // Some of the aspects are not supported at all by any of the targets. |
6315 |
| - // Thus, we need to define individual macros for each supported aspect. |
6316 |
| - for (const auto &[TargetKey, SupportedTarget] : AnyDeviceHas) { |
6317 |
| - assert(SupportedTarget); |
6318 |
| - const SmallString<64> MacroAnyDevice{ |
6319 |
| - {"-D__SYCL_ANY_DEVICE_HAS_", TargetKey, "__=1"}}; |
6320 |
| - D.addSYCLDeviceTraitsMacroArg(Args, MacroAnyDevice); |
6321 |
| - } |
6322 |
| - } |
6323 |
| - for (const auto &[TargetKey, SupportedTargets] : AllDevicesHave) { |
6324 |
| - if (SupportedTargets != ValidTargets) |
6325 |
| - continue; |
6326 |
| - const SmallString<64> MacroAllDevices{ |
6327 |
| - {"-D__SYCL_ALL_DEVICES_HAVE_", TargetKey, "__=1"}}; |
6328 |
| - D.addSYCLDeviceTraitsMacroArg(Args, MacroAllDevices); |
6329 |
| - } |
6330 |
| - } |
6331 |
| - |
6332 | 6236 | bool initialize() override {
|
6333 | 6237 | using namespace tools::SYCL;
|
6334 | 6238 | // Get the SYCL toolchains. If we don't get any, the action builder will
|
@@ -6563,7 +6467,17 @@ class OffloadingActionBuilder final {
|
6563 | 6467 | // Define macros associated with `any_device_has/all_devices_have`
|
6564 | 6468 | // according to the aspects defined in the DeviceConfigFile for the SYCL
|
6565 | 6469 | // targets.
|
6566 |
| - populateSYCLDeviceTraitsMacrosArgs(C, Args, SYCLTargetInfoList); |
| 6470 | + // We are using the Traits population function in multiple offloading |
| 6471 | + // models. These use different containers for the toolchain and arch |
| 6472 | + // values. Convert the list for usage with the new model expectations. |
| 6473 | + SmallVector<std::pair<const ToolChain *, StringRef>> TCAndArchs; |
| 6474 | + for (auto &TargetInfo : SYCLTargetInfoList) { |
| 6475 | + const ToolChain *TC = TargetInfo.TC; |
| 6476 | + StringRef Arch(TargetInfo.BoundArch); |
| 6477 | + std::pair<const ToolChain *, StringRef> TCAndArch(TC, Arch); |
| 6478 | + TCAndArchs.push_back(TCAndArch); |
| 6479 | + } |
| 6480 | + tools::SYCL::populateSYCLDeviceTraitsMacrosArgs(C, Args, TCAndArchs); |
6567 | 6481 |
|
6568 | 6482 | DeviceLinkerInputs.resize(SYCLTargetInfoList.size());
|
6569 | 6483 | return false;
|
@@ -8003,6 +7917,10 @@ Action *Driver::BuildOffloadingActions(Compilation &C,
|
8003 | 7917 |
|
8004 | 7918 | ++TCAndArch;
|
8005 | 7919 | }
|
| 7920 | + // For SYCL based offloading, populate the device traits macros that are |
| 7921 | + // used during compilation. |
| 7922 | + if (Kind == Action::OFK_SYCL) |
| 7923 | + tools::SYCL::populateSYCLDeviceTraitsMacrosArgs(C, Args, TCAndArchs); |
8006 | 7924 | }
|
8007 | 7925 |
|
8008 | 7926 | // HIP code in non-RDC mode will bundle the output if it invoked the linker.
|
|
0 commit comments