Skip to content

Commit

Permalink
[HIP] Compile device code
Browse files Browse the repository at this point in the history
  • Loading branch information
koparasy committed Feb 7, 2025
1 parent 1783f4c commit 52049fc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenCall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1641,7 +1641,8 @@ static void getTrivialDefaultFunctionAttributes(
// AFAIK, neither of them support exceptions in device code.
if (langOpts.SYCLIsDevice)
llvm_unreachable("NYI");
if (langOpts.OpenCL || (langOpts.CUDA && langOpts.CUDAIsDevice)) {
if (langOpts.OpenCL ||
((langOpts.CUDA || langOpts.HIP) && langOpts.CUDAIsDevice)) {
auto noThrow = cir::NoThrowAttr::get(CGM.getBuilder().getContext());
funcAttrs.set(noThrow.getMnemonic(), noThrow);
}
Expand Down
2 changes: 1 addition & 1 deletion clang/lib/CIR/CodeGen/CIRGenModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3114,7 +3114,7 @@ void CIRGenModule::emitDeferred(unsigned recursionLimit) {
// Emit CUDA/HIP static device variables referenced by host code only. Note we
// should not clear CUDADeviceVarODRUsedByHost since it is still needed for
// further handling.
if (getLangOpts().CUDA && getLangOpts().CUDAIsDevice &&
if ((getLangOpts().CUDA || getLangOpts().HIP) && getLangOpts().CUDAIsDevice &&
!getASTContext().CUDADeviceVarODRUsedByHost.empty()) {
llvm_unreachable("NYI");
}
Expand Down
6 changes: 5 additions & 1 deletion clang/lib/CIR/CodeGen/CIRGenTypes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,11 @@ mlir::Type CIRGenTypes::convertType(QualType T) {

// For the device-side compilation, CUDA device builtin surface/texture types
// may be represented in different types.
if (astContext.getLangOpts().CUDAIsDevice) {
// NOTE: CUDAIsDevice is true when building also HIP code.
// 1. There is no SurfaceType on HIP,
// 2. There is Texture memory on HIP but accessing the memory goes through
// calls to the runtime. e.g. for a 2D: `tex2D<float>(tex, x, y);`
if (astContext.getLangOpts().CUDA && astContext.getLangOpts().CUDAIsDevice) {
if (Ty->isCUDADeviceBuiltinSurfaceType() ||
Ty->isCUDADeviceBuiltinTextureType())
llvm_unreachable("NYI");
Expand Down
4 changes: 2 additions & 2 deletions clang/test/CIR/CodeGen/HIP/simple-device.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "../Inputs/cuda.h"

// RUN: %clang_cc1 -triple=amdgcn-amd-amdhsa -fcuda-is-device \
// RUN: -x hip -fclangir -emit-cir -o - %s | FileCheck %s
// RUN: %clang_cc1 -triple=amdgcn-amd-amdhsa -x hip -fcuda-is-device \
// RUN: -fclangir -emit-cir -o - %s | FileCheck %s

// This shouldn't emit.
__host__ void host_fn(int *a, int *b, int *c) {}
Expand Down

0 comments on commit 52049fc

Please sign in to comment.