Skip to content

Commit e739ac0

Browse files
committed
[HIP] change kernel stub name
Add .stub to kernel stub function name so that it is different from kernel name in device code. This is necessary to let debugger find correct symbol for kernel. Differential Revision: https://reviews.llvm.org/D58518 llvm-svn: 354948
1 parent c4eff21 commit e739ac0

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

clang/lib/CodeGen/CGCUDANV.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,7 @@ std::string CGNVCUDARuntime::getDeviceSideName(const Decl *D) {
218218
void CGNVCUDARuntime::emitDeviceStub(CodeGenFunction &CGF,
219219
FunctionArgList &Args) {
220220
assert(getDeviceSideName(CGF.CurFuncDecl) == CGF.CurFn->getName() ||
221+
getDeviceSideName(CGF.CurFuncDecl) + ".stub" == CGF.CurFn->getName() ||
221222
CGF.CGM.getContext().getTargetInfo().getCXXABI() !=
222223
CGF.CGM.getContext().getAuxTargetInfo()->getCXXABI());
223224

clang/lib/CodeGen/CodeGenModule.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1048,8 +1048,17 @@ StringRef CodeGenModule::getMangledName(GlobalDecl GD) {
10481048

10491049
// Keep the first result in the case of a mangling collision.
10501050
const auto *ND = cast<NamedDecl>(GD.getDecl());
1051-
auto Result =
1052-
Manglings.insert(std::make_pair(getMangledNameImpl(*this, GD, ND), GD));
1051+
std::string MangledName = getMangledNameImpl(*this, GD, ND);
1052+
1053+
// Postfix kernel stub names with .stub to differentiate them from kernel
1054+
// names in device binaries. This is to facilitate the debugger to find
1055+
// the correct symbols for kernels in the device binary.
1056+
if (auto *FD = dyn_cast<FunctionDecl>(GD.getDecl()))
1057+
if (getLangOpts().HIP && !getLangOpts().CUDAIsDevice &&
1058+
FD->hasAttr<CUDAGlobalAttr>())
1059+
MangledName = MangledName + ".stub";
1060+
1061+
auto Result = Manglings.insert(std::make_pair(MangledName, GD));
10531062
return MangledDeclNames[CanonicalGD] = Result.first->first();
10541063
}
10551064

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// RUN: echo "GPU binary would be here" > %t
2+
3+
// RUN: %clang_cc1 -triple x86_64-linux-gnu -emit-llvm %s \
4+
// RUN: -fcuda-include-gpubinary %t -o - -x hip\
5+
// RUN: | FileCheck -allow-deprecated-dag-overlap %s --check-prefixes=CHECK
6+
7+
#include "Inputs/cuda.h"
8+
9+
template<class T>
10+
__global__ void kernelfunc() {}
11+
12+
// CHECK-LABEL: define{{.*}}@_Z8hostfuncv()
13+
// CHECK: call void @[[STUB:_Z10kernelfuncIiEvv.stub]]()
14+
void hostfunc(void) { kernelfunc<int><<<1, 1>>>(); }
15+
16+
// CHECK: define{{.*}}@[[STUB]]
17+
// CHECK: call{{.*}}@hipLaunchByPtr{{.*}}@[[STUB]]
18+
19+
// CHECK-LABEL: define{{.*}}@__hip_register_globals
20+
// CHECK: call{{.*}}@__hipRegisterFunction{{.*}}@[[STUB]]

0 commit comments

Comments
 (0)