[PATCH] D46471: [HIP] Add hip offload kind
This revision was automatically updated to reflect the committed changes. yaxunl marked an inline comment as done. Closed by commit rL331811: [HIP] Add hip offload kind (authored by yaxunl, committed by ). Herald added a subscriber: llvm-commits. Changed prior to commit: https://reviews.llvm.org/D46471?vs=145472=145780#toc Repository: rL LLVM https://reviews.llvm.org/D46471 Files: cfe/trunk/include/clang/Driver/Action.h cfe/trunk/lib/Driver/Action.cpp cfe/trunk/lib/Driver/Compilation.cpp cfe/trunk/lib/Driver/ToolChains/Clang.cpp Index: cfe/trunk/lib/Driver/ToolChains/Clang.cpp === --- cfe/trunk/lib/Driver/ToolChains/Clang.cpp +++ cfe/trunk/lib/Driver/ToolChains/Clang.cpp @@ -131,6 +131,10 @@ Work(*C.getSingleOffloadToolChain()); else if (JA.isDeviceOffloading(Action::OFK_Cuda)) Work(*C.getSingleOffloadToolChain()); + else if (JA.isHostOffloading(Action::OFK_HIP)) +Work(*C.getSingleOffloadToolChain()); + else if (JA.isDeviceOffloading(Action::OFK_HIP)) +Work(*C.getSingleOffloadToolChain()); if (JA.isHostOffloading(Action::OFK_OpenMP)) { auto TCs = C.getOffloadToolChains(); @@ -3105,13 +3109,14 @@ // Check number of inputs for sanity. We need at least one input. assert(Inputs.size() >= 1 && "Must have at least one input."); const InputInfo = Inputs[0]; - // CUDA compilation may have multiple inputs (source file + results of + // CUDA/HIP compilation may have multiple inputs (source file + results of // device-side compilations). OpenMP device jobs also take the host IR as a // second input. All other jobs are expected to have exactly one // input. bool IsCuda = JA.isOffloading(Action::OFK_Cuda); + bool IsHIP = JA.isOffloading(Action::OFK_HIP); bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP); - assert((IsCuda || (IsOpenMPDevice && Inputs.size() == 2) || + assert((IsCuda || IsHIP || (IsOpenMPDevice && Inputs.size() == 2) || Inputs.size() == 1) && "Unable to handle multiple inputs."); @@ -3123,10 +3128,10 @@ bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment(); bool IsIAMCU = RawTriple.isOSIAMCU(); - // Adjust IsWindowsXYZ for CUDA compilations. Even when compiling in device - // mode (i.e., getToolchain().getTriple() is NVPTX, not Windows), we need to - // pass Windows-specific flags to cc1. - if (IsCuda) { + // Adjust IsWindowsXYZ for CUDA/HIP compilations. Even when compiling in + // device mode (i.e., getToolchain().getTriple() is NVPTX/AMDGCN, not + // Windows), we need to pass Windows-specific flags to cc1. + if (IsCuda || IsHIP) { IsWindowsMSVC |= AuxTriple && AuxTriple->isWindowsMSVCEnvironment(); IsWindowsGNU |= AuxTriple && AuxTriple->isWindowsGNUEnvironment(); IsWindowsCygnus |= AuxTriple && AuxTriple->isWindowsCygwinEnvironment(); @@ -3150,18 +3155,21 @@ Args.ClaimAllArgs(options::OPT_MJ); } - if (IsCuda) { -// We have to pass the triple of the host if compiling for a CUDA device and -// vice-versa. + if (IsCuda || IsHIP) { +// We have to pass the triple of the host if compiling for a CUDA/HIP device +// and vice-versa. std::string NormalizedTriple; -if (JA.isDeviceOffloading(Action::OFK_Cuda)) +if (JA.isDeviceOffloading(Action::OFK_Cuda) || +JA.isDeviceOffloading(Action::OFK_HIP)) NormalizedTriple = C.getSingleOffloadToolChain() ->getTriple() .normalize(); else - NormalizedTriple = C.getSingleOffloadToolChain() - ->getTriple() - .normalize(); + NormalizedTriple = + (IsCuda ? C.getSingleOffloadToolChain() + : C.getSingleOffloadToolChain()) + ->getTriple() + .normalize(); CmdArgs.push_back("-aux-triple"); CmdArgs.push_back(Args.MakeArgString(NormalizedTriple)); Index: cfe/trunk/lib/Driver/Compilation.cpp === --- cfe/trunk/lib/Driver/Compilation.cpp +++ cfe/trunk/lib/Driver/Compilation.cpp @@ -196,10 +196,10 @@ if (FailingCommands.empty()) return false; - // CUDA can have the same input source code compiled multiple times so do not - // compiled again if there are already failures. It is OK to abort the CUDA - // pipeline on errors. - if (A->isOffloading(Action::OFK_Cuda)) + // CUDA/HIP can have the same input source code compiled multiple times so do + // not compiled again if there are already failures. It is OK to abort the + // CUDA pipeline on errors. + if (A->isOffloading(Action::OFK_Cuda) || A->isOffloading(Action::OFK_HIP)) return true; for (const auto : FailingCommands) Index: cfe/trunk/lib/Driver/Action.cpp === --- cfe/trunk/lib/Driver/Action.cpp +++
[PATCH] D46471: [HIP] Add hip offload kind
yaxunl marked an inline comment as done. yaxunl added inline comments. Comment at: lib/Driver/ToolChains/Clang.cpp:133-135 Work(*C.getSingleOffloadToolChain()); + if (JA.isHostOffloading(Action::OFK_HIP)) tra wrote: > CUDA and HIP are mutually exclusive, so this should probably be `else if` Will do when committing. https://reviews.llvm.org/D46471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46471: [HIP] Add hip offload kind
tra accepted this revision. tra added a comment. Small nit. LGTM otherwise. Comment at: lib/Driver/ToolChains/Clang.cpp:133-135 Work(*C.getSingleOffloadToolChain()); + if (JA.isHostOffloading(Action::OFK_HIP)) CUDA and HIP are mutually exclusive, so this should probably be `else if` https://reviews.llvm.org/D46471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46471: [HIP] Add hip offload kind
rjmccall accepted this revision. rjmccall added a comment. This revision is now accepted and ready to land. Thanks, LGTM. https://reviews.llvm.org/D46471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46471: [HIP] Add hip offload kind
yaxunl updated this revision to Diff 145472. yaxunl marked 2 inline comments as done. yaxunl added a comment. Updated comments. https://reviews.llvm.org/D46471 Files: include/clang/Driver/Action.h lib/Driver/Action.cpp lib/Driver/Compilation.cpp lib/Driver/ToolChains/Clang.cpp Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -132,6 +132,11 @@ else if (JA.isDeviceOffloading(Action::OFK_Cuda)) Work(*C.getSingleOffloadToolChain()); + if (JA.isHostOffloading(Action::OFK_HIP)) +Work(*C.getSingleOffloadToolChain()); + else if (JA.isDeviceOffloading(Action::OFK_HIP)) +Work(*C.getSingleOffloadToolChain()); + if (JA.isHostOffloading(Action::OFK_OpenMP)) { auto TCs = C.getOffloadToolChains(); for (auto II = TCs.first, IE = TCs.second; II != IE; ++II) @@ -3104,13 +3109,14 @@ // Check number of inputs for sanity. We need at least one input. assert(Inputs.size() >= 1 && "Must have at least one input."); const InputInfo = Inputs[0]; - // CUDA compilation may have multiple inputs (source file + results of + // CUDA/HIP compilation may have multiple inputs (source file + results of // device-side compilations). OpenMP device jobs also take the host IR as a // second input. All other jobs are expected to have exactly one // input. bool IsCuda = JA.isOffloading(Action::OFK_Cuda); + bool IsHIP = JA.isOffloading(Action::OFK_HIP); bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP); - assert((IsCuda || (IsOpenMPDevice && Inputs.size() == 2) || + assert((IsCuda || IsHIP || (IsOpenMPDevice && Inputs.size() == 2) || Inputs.size() == 1) && "Unable to handle multiple inputs."); @@ -3122,10 +3128,10 @@ bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment(); bool IsIAMCU = RawTriple.isOSIAMCU(); - // Adjust IsWindowsXYZ for CUDA compilations. Even when compiling in device - // mode (i.e., getToolchain().getTriple() is NVPTX, not Windows), we need to - // pass Windows-specific flags to cc1. - if (IsCuda) { + // Adjust IsWindowsXYZ for CUDA/HIP compilations. Even when compiling in + // device mode (i.e., getToolchain().getTriple() is NVPTX/AMDGCN, not + // Windows), we need to pass Windows-specific flags to cc1. + if (IsCuda || IsHIP) { IsWindowsMSVC |= AuxTriple && AuxTriple->isWindowsMSVCEnvironment(); IsWindowsGNU |= AuxTriple && AuxTriple->isWindowsGNUEnvironment(); IsWindowsCygnus |= AuxTriple && AuxTriple->isWindowsCygwinEnvironment(); @@ -3149,18 +3155,21 @@ Args.ClaimAllArgs(options::OPT_MJ); } - if (IsCuda) { -// We have to pass the triple of the host if compiling for a CUDA device and -// vice-versa. + if (IsCuda || IsHIP) { +// We have to pass the triple of the host if compiling for a CUDA/HIP device +// and vice-versa. std::string NormalizedTriple; -if (JA.isDeviceOffloading(Action::OFK_Cuda)) +if (JA.isDeviceOffloading(Action::OFK_Cuda) || +JA.isDeviceOffloading(Action::OFK_HIP)) NormalizedTriple = C.getSingleOffloadToolChain() ->getTriple() .normalize(); else - NormalizedTriple = C.getSingleOffloadToolChain() - ->getTriple() - .normalize(); + NormalizedTriple = + (IsCuda ? C.getSingleOffloadToolChain() + : C.getSingleOffloadToolChain()) + ->getTriple() + .normalize(); CmdArgs.push_back("-aux-triple"); CmdArgs.push_back(Args.MakeArgString(NormalizedTriple)); Index: lib/Driver/Compilation.cpp === --- lib/Driver/Compilation.cpp +++ lib/Driver/Compilation.cpp @@ -196,10 +196,10 @@ if (FailingCommands.empty()) return false; - // CUDA can have the same input source code compiled multiple times so do not - // compiled again if there are already failures. It is OK to abort the CUDA + // CUDA/HIP can have the same input source code compiled multiple times so do + // not compiled again if there are already failures. It is OK to abort the // pipeline on errors. - if (A->isOffloading(Action::OFK_Cuda)) + if (A->isOffloading(Action::OFK_Cuda) || A->isOffloading(Action::OFK_HIP)) return true; for (const auto : FailingCommands) Index: lib/Driver/Action.cpp === --- lib/Driver/Action.cpp +++ lib/Driver/Action.cpp @@ -96,16 +96,23 @@ return "device-cuda"; case OFK_OpenMP: return "device-openmp"; + case OFK_HIP: +return "device-hip"; // TODO: Add other programming models here. } if (!ActiveOffloadKindMask) return {}; std::string Res("host"); + assert(!((ActiveOffloadKindMask & OFK_Cuda) && +
[PATCH] D46471: [HIP] Add hip offload kind
yaxunl marked an inline comment as done. yaxunl added inline comments. Comment at: lib/Driver/Compilation.cpp:201 + // not compiled again if there are already failures. It is OK to abort the + // CUDA pipeline on errors. + if (A->isOffloading(Action::OFK_Cuda) || A->isOffloading(Action::OFK_HIP)) rjmccall wrote: > Mentioning only CUDA in the second clause makes me wonder whether it's *only* > okay to abort a CUDA pipeline, not a HIP one. That is presumably not your > intent. You could just drop "CUDA" there. The second sentence is OK for both CUDA and HIP. Will drop CUDA in the second sentence. https://reviews.llvm.org/D46471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46471: [HIP] Add hip offload kind
rjmccall added a comment. Otherwise LGTM. Comment at: lib/Driver/Compilation.cpp:201 + // not compiled again if there are already failures. It is OK to abort the + // CUDA pipeline on errors. + if (A->isOffloading(Action::OFK_Cuda) || A->isOffloading(Action::OFK_HIP)) Mentioning only CUDA in the second clause makes me wonder whether it's *only* okay to abort a CUDA pipeline, not a HIP one. That is presumably not your intent. You could just drop "CUDA" there. https://reviews.llvm.org/D46471 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D46471: [HIP] Add hip offload kind
yaxunl created this revision. yaxunl added reviewers: rjmccall, tra. There are quite differences in HIP action builder and action job creation, which justifies to define a separate offload kind. https://reviews.llvm.org/D46471 Files: include/clang/Driver/Action.h lib/Driver/Action.cpp lib/Driver/Compilation.cpp lib/Driver/ToolChains/Clang.cpp Index: lib/Driver/ToolChains/Clang.cpp === --- lib/Driver/ToolChains/Clang.cpp +++ lib/Driver/ToolChains/Clang.cpp @@ -132,6 +132,11 @@ else if (JA.isDeviceOffloading(Action::OFK_Cuda)) Work(*C.getSingleOffloadToolChain()); + if (JA.isHostOffloading(Action::OFK_HIP)) +Work(*C.getSingleOffloadToolChain()); + else if (JA.isDeviceOffloading(Action::OFK_HIP)) +Work(*C.getSingleOffloadToolChain()); + if (JA.isHostOffloading(Action::OFK_OpenMP)) { auto TCs = C.getOffloadToolChains(); for (auto II = TCs.first, IE = TCs.second; II != IE; ++II) @@ -3099,13 +3104,14 @@ // Check number of inputs for sanity. We need at least one input. assert(Inputs.size() >= 1 && "Must have at least one input."); const InputInfo = Inputs[0]; - // CUDA compilation may have multiple inputs (source file + results of + // CUDA/HIP compilation may have multiple inputs (source file + results of // device-side compilations). OpenMP device jobs also take the host IR as a // second input. All other jobs are expected to have exactly one // input. bool IsCuda = JA.isOffloading(Action::OFK_Cuda); + bool IsHIP = JA.isOffloading(Action::OFK_HIP); bool IsOpenMPDevice = JA.isDeviceOffloading(Action::OFK_OpenMP); - assert((IsCuda || (IsOpenMPDevice && Inputs.size() == 2) || + assert((IsCuda || IsHIP || (IsOpenMPDevice && Inputs.size() == 2) || Inputs.size() == 1) && "Unable to handle multiple inputs."); @@ -3117,10 +3123,10 @@ bool IsWindowsMSVC = RawTriple.isWindowsMSVCEnvironment(); bool IsIAMCU = RawTriple.isOSIAMCU(); - // Adjust IsWindowsXYZ for CUDA compilations. Even when compiling in device - // mode (i.e., getToolchain().getTriple() is NVPTX, not Windows), we need to - // pass Windows-specific flags to cc1. - if (IsCuda) { + // Adjust IsWindowsXYZ for CUDA/HIP compilations. Even when compiling in + // device mode (i.e., getToolchain().getTriple() is NVPTX/AMDGCN, not + // Windows), we need to pass Windows-specific flags to cc1. + if (IsCuda || IsHIP) { IsWindowsMSVC |= AuxTriple && AuxTriple->isWindowsMSVCEnvironment(); IsWindowsGNU |= AuxTriple && AuxTriple->isWindowsGNUEnvironment(); IsWindowsCygnus |= AuxTriple && AuxTriple->isWindowsCygwinEnvironment(); @@ -3144,18 +3150,21 @@ Args.ClaimAllArgs(options::OPT_MJ); } - if (IsCuda) { -// We have to pass the triple of the host if compiling for a CUDA device and -// vice-versa. + if (IsCuda || IsHIP) { +// We have to pass the triple of the host if compiling for a CUDA/HIP device +// and vice-versa. std::string NormalizedTriple; -if (JA.isDeviceOffloading(Action::OFK_Cuda)) +if (JA.isDeviceOffloading(Action::OFK_Cuda) || +JA.isDeviceOffloading(Action::OFK_HIP)) NormalizedTriple = C.getSingleOffloadToolChain() ->getTriple() .normalize(); else - NormalizedTriple = C.getSingleOffloadToolChain() - ->getTriple() - .normalize(); + NormalizedTriple = + (IsCuda ? C.getSingleOffloadToolChain() + : C.getSingleOffloadToolChain()) + ->getTriple() + .normalize(); CmdArgs.push_back("-aux-triple"); CmdArgs.push_back(Args.MakeArgString(NormalizedTriple)); Index: lib/Driver/Compilation.cpp === --- lib/Driver/Compilation.cpp +++ lib/Driver/Compilation.cpp @@ -196,10 +196,10 @@ if (FailingCommands.empty()) return false; - // CUDA can have the same input source code compiled multiple times so do not - // compiled again if there are already failures. It is OK to abort the CUDA - // pipeline on errors. - if (A->isOffloading(Action::OFK_Cuda)) + // CUDA/HIP can have the same input source code compiled multiple times so do + // not compiled again if there are already failures. It is OK to abort the + // CUDA pipeline on errors. + if (A->isOffloading(Action::OFK_Cuda) || A->isOffloading(Action::OFK_HIP)) return true; for (const auto : FailingCommands) Index: lib/Driver/Action.cpp === --- lib/Driver/Action.cpp +++ lib/Driver/Action.cpp @@ -96,16 +96,23 @@ return "device-cuda"; case OFK_OpenMP: return "device-openmp"; + case OFK_HIP: +return "device-hip"; // TODO: Add other programming models here. } if (!ActiveOffloadKindMask) return {};