-
Notifications
You must be signed in to change notification settings - Fork 730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[SYCL] [Driver] Add offload-arch support for SYCL offloading #15624
base: sycl
Are you sure you want to change the base?
Changes from all commits
afd6a5c
d5339a0
7828b8e
9acfa69
26dd5ec
b7a3aec
aa54427
81fa084
8e8a0ef
64ee8c0
ed5902f
4692758
c718ec9
0f16679
34002a2
d14865d
96bce40
0c72954
2fba015
01a14c2
dc5b928
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1185,12 +1185,14 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C, | |
llvm::StringMap<llvm::DenseSet<StringRef>> DerivedArchs; | ||
llvm::StringMap<StringRef> FoundNormalizedTriples; | ||
llvm::SmallVector<llvm::Triple, 4> UniqueSYCLTriplesVec; | ||
// StringSet to contain SYCL target triples. | ||
llvm::StringSet<> SYCLTriples; | ||
if (HasSYCLTargetsOption) { | ||
// At this point, we know we have a valid combination | ||
// of -fsycl*target options passed | ||
Arg *SYCLTargetsValues = SYCLTargets; | ||
if (SYCLTargetsValues) { | ||
llvm::StringSet<> SYCLTriples; | ||
|
||
if (SYCLTargetsValues->getNumValues()) { | ||
|
||
// Multiple targets are currently not supported when using | ||
|
@@ -1290,6 +1292,101 @@ void Driver::CreateOffloadingDeviceToolChains(Compilation &C, | |
Diag(clang::diag::warn_drv_empty_joined_argument) | ||
<< SYCLTargetsValues->getAsString(C.getInputArgs()); | ||
} | ||
} | ||
// If the user specified --offload-arch, deduce the offloading | ||
// target triple(s) from the set of architecture(s). | ||
// Create a toolchain for each valid triple. | ||
else if (HasValidSYCLRuntime && | ||
C.getInputArgs().hasArg(options::OPT_offload_arch_EQ) && !IsHIP && | ||
!IsCuda) { | ||
// SYCL offloading to AOT Targets with ``--offload-arch`` | ||
// is currently enabled only with ``--offload-new-driver`` option. | ||
// Emit a diagnostic if ``--offload-arch`` is invoked without | ||
// ``--offload-new driver`` option. | ||
if (!C.getInputArgs().hasFlag(options::OPT_offload_new_driver, | ||
options::OPT_no_offload_new_driver, | ||
false)) { | ||
Diag(clang::diag::err_drv_sycl_offload_arch_new_driver); | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
const ToolChain *HostTC = C.getSingleOffloadToolChain<Action::OFK_Host>(); | ||
auto AMDTriple = getHIPOffloadTargetTriple(*this, C.getInputArgs()); | ||
auto NVPTXTriple = getNVIDIAOffloadTargetTriple(*this, C.getInputArgs(), | ||
HostTC->getTriple()); | ||
|
||
// Attempt to deduce the offloading triple from the set of architectures. | ||
// We need to temporarily create these toolchains so that we can access | ||
// tools for inferring architectures. | ||
llvm::DenseSet<StringRef> Archs; | ||
if (NVPTXTriple) { | ||
auto TempTC = std::make_unique<toolchains::CudaToolChain>( | ||
*this, *NVPTXTriple, *HostTC, C.getInputArgs(), Action::OFK_None); | ||
for (StringRef Arch : | ||
getOffloadArchs(C, C.getArgs(), Action::OFK_SYCL, &*TempTC, true)) | ||
Archs.insert(Arch); | ||
} | ||
if (AMDTriple) { | ||
auto TempTC = std::make_unique<toolchains::AMDGPUOpenMPToolChain>( | ||
*this, *AMDTriple, *HostTC, C.getInputArgs()); | ||
for (StringRef Arch : | ||
getOffloadArchs(C, C.getArgs(), Action::OFK_SYCL, &*TempTC, true)) | ||
Archs.insert(Arch); | ||
} | ||
if (!AMDTriple && !NVPTXTriple) { | ||
for (StringRef Arch : | ||
getOffloadArchs(C, C.getArgs(), Action::OFK_SYCL, nullptr, true)) | ||
Archs.insert(Arch); | ||
} | ||
for (StringRef Arch : Archs) { | ||
if (NVPTXTriple && IsSYCLSupportedNVidiaGPUArch(StringToOffloadArchSYCL( | ||
getProcessorFromTargetID(*NVPTXTriple, Arch)))) { | ||
DerivedArchs[NVPTXTriple->getTriple()].insert(Arch); | ||
} else if (AMDTriple && | ||
IsSYCLSupportedAMDGPUArch(StringToOffloadArchSYCL( | ||
getProcessorFromTargetID(*AMDTriple, Arch)))) { | ||
DerivedArchs[AMDTriple->getTriple()].insert(Arch); | ||
} else if (IsSYCLSupportedIntelCPUArch(StringToOffloadArchSYCL(Arch))) { | ||
DerivedArchs[MakeSYCLDeviceTriple("spir64_x86_64").getTriple()].insert( | ||
Arch); | ||
} else if (IsSYCLSupportedIntelGPUArch(StringToOffloadArchSYCL(Arch))) { | ||
StringRef IntelGPUArch; | ||
IntelGPUArch = mapIntelGPUArchName(Arch).data(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The mapping here is different than the other arch values - perhaps add a comment explaining what it is doing. |
||
DerivedArchs[MakeSYCLDeviceTriple("spir64_gen").getTriple()].insert( | ||
IntelGPUArch); | ||
} else { | ||
Diag(clang::diag::err_drv_invalid_sycl_target) << Arch; | ||
return; | ||
} | ||
} | ||
// If the set is empty then we failed to find a native architecture. | ||
if (Archs.empty()) { | ||
Diag(clang::diag::err_drv_invalid_sycl_target) << "native"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This error doesn't make any sense to the end user: Also, please add a test for this case. |
||
return; | ||
} | ||
|
||
for (const auto &TripleAndArchs : DerivedArchs) | ||
SYCLTriples.insert(TripleAndArchs.first()); | ||
|
||
for (const auto &Val : SYCLTriples) { | ||
llvm::Triple SYCLTargetTriple(MakeSYCLDeviceTriple(Val.getKey())); | ||
std::string NormalizedName = SYCLTargetTriple.normalize(); | ||
|
||
// Make sure we don't have a duplicate triple. | ||
auto Duplicate = FoundNormalizedTriples.find(NormalizedName); | ||
if (Duplicate != FoundNormalizedTriples.end()) { | ||
Diag(clang::diag::warn_drv_sycl_offload_target_duplicate) | ||
<< Val.getKey() << Duplicate->second; | ||
continue; | ||
} | ||
|
||
// Store the current triple so that we can check for duplicates in the | ||
// following iterations. | ||
FoundNormalizedTriples[NormalizedName] = Val.getKey(); | ||
UniqueSYCLTriplesVec.push_back(SYCLTargetTriple); | ||
} | ||
|
||
addSYCLDefaultTriple(C, UniqueSYCLTriplesVec); | ||
|
||
} else { | ||
// If -fsycl is supplied without -fsycl-targets we will assume SPIR-V. | ||
// For -fsycl-device-only, we also setup the implied triple as needed. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add some additional comment about why
IsHIP
andIsCuda
is not supported here.