Skip to content

Commit 2c7b674

Browse files
bcardosolopeslanza
authored andcommitted
Revert "[CIR][HIP] Use CUDA attributes for HIP global functions (llvm#1333)"
Broke CI jobs This reverts commit db307ce.
1 parent baecd94 commit 2c7b674

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

clang/lib/CIR/CodeGen/CIRGenModule.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2356,9 +2356,8 @@ cir::FuncOp CIRGenModule::GetAddrOfFunction(clang::GlobalDecl GD, mlir::Type Ty,
23562356
// As __global__ functions (kernels) always reside on device,
23572357
// when we access them from host, we must refer to the kernel handle.
23582358
// For CUDA, it's just the device stub. For HIP, it's something different.
2359-
if ((langOpts.CUDA || langOpts.HIP) && !langOpts.CUDAIsDevice &&
2360-
cast<FunctionDecl>(GD.getDecl())->hasAttr<CUDAGlobalAttr>() &&
2361-
cast<FunctionDecl>(GD.getDecl())->isThisDeclarationADefinition()) {
2359+
if (langOpts.CUDA && !langOpts.CUDAIsDevice && langOpts.HIP &&
2360+
cast<FunctionDecl>(GD.getDecl())->hasAttr<CUDAGlobalAttr>()) {
23622361
llvm_unreachable("NYI");
23632362
}
23642363

clang/test/CIR/CodeGen/CUDA/simple.cu

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
// RUN: %s -o %t.cir
1111
// RUN: FileCheck --check-prefix=CIR-DEVICE --input-file=%t.cir %s
1212

13-
// XFAIL: *
14-
1513
// Attribute for global_fn
1614
// CIR-HOST: [[Kernel:#[a-zA-Z_0-9]+]] = {{.*}}#cir.cuda_kernel_name<_Z9global_fni>{{.*}}
1715

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#include "../Inputs/cuda.h"
2+
3+
// RUN: %clang_cc1 -triple=amdgcn-amd-amdhsa -x hip -fcuda-is-device \
4+
// RUN: -fclangir -emit-cir -o - %s | FileCheck %s
5+
6+
// This shouldn't emit.
7+
__host__ void host_fn(int *a, int *b, int *c) {}
8+
9+
// CHECK-NOT: cir.func @_Z7host_fnPiS_S_
10+
11+
// This should emit as a normal C++ function.
12+
__device__ void device_fn(int* a, double b, float c) {}
13+
14+
// CIR: cir.func @_Z9device_fnPidf
Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,16 @@
11
#include "../Inputs/cuda.h"
22

3-
// RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir \
4-
// RUN: -x hip -emit-cir %s -o %t.cir
5-
// RUN: FileCheck --check-prefix=CIR-HOST --input-file=%t.cir %s
3+
// RUN: %clang_cc1 -triple=amdgcn-amd-amdhsa -x hip -fclangir \
4+
// RUN: -emit-cir %s -o %t.cir
5+
// RUN: FileCheck --check-prefix=CIR --input-file=%t.cir %s
66

7-
// RUN: %clang_cc1 -triple=amdgcn-amd-amdhsa -x hip \
8-
// RUN: -fcuda-is-device -emit-cir %s -o %t.cir
9-
// RUN: FileCheck --check-prefix=CIR-DEVICE --input-file=%t.cir %s
10-
11-
// Attribute for global_fn
12-
// CIR-HOST: [[Kernel:#[a-zA-Z_0-9]+]] = {{.*}}#cir.cuda_kernel_name<_Z9global_fnv>{{.*}}
137

8+
// This should emit as a normal C++ function.
149
__host__ void host_fn(int *a, int *b, int *c) {}
15-
// CIR-HOST: cir.func @_Z7host_fnPiS_S_
16-
// CIR-DEVICE-NOT: cir.func @_Z7host_fnPiS_S_
1710

18-
__device__ void device_fn(int *a, double b, float c) {}
19-
// CIR-HOST-NOT: cir.func @_Z9device_fnPidf
20-
// CIR-DEVICE: cir.func @_Z9device_fnPidf
11+
// CIR: cir.func @_Z7host_fnPiS_S_
2112

22-
#ifdef __AMDGPU__
23-
__global__ void global_fn() {}
24-
#else
25-
__global__ void global_fn();
26-
#endif
27-
// CIR-HOST: @_Z24__device_stub__global_fnv(){{.*}}extra([[Kernel]])
28-
// CIR-DEVICE: @_Z9global_fnv
13+
// This shouldn't emit.
14+
__device__ void device_fn(int* a, double b, float c) {}
2915

30-
// Make sure `global_fn` indeed gets emitted
31-
__host__ void x() { auto v = global_fn; }
16+
// CHECK-NOT: cir.func @_Z9device_fnPidf

0 commit comments

Comments
 (0)