forked from llvm/llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CUDA][HIP] Externalize kernels in anonymous name space
kernels in anonymous name space needs to have unique name to avoid duplicate symbols. Fixes: llvm#54560 Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D123353 [CUDA][HIP] Externalize kernels with internal linkage This patch is a continuation of https://reviews.llvm.org/D123353. Not only kernels in anonymous namespace, but also template kernels with template arguments in anonymous namespace need to be externalized. To be more generic, this patch checks the linkage of a kernel assuming the kernel does not have __global__ attribute. If the linkage is internal then clang will externalize it. This patch also fixes the postfix for externalized symbol since nvptx does not allow '.' in symbol name. Reviewed by: Artem Belevich Differential Revision: https://reviews.llvm.org/D124189 Fixes: llvm#54560 Fixes: SWDEV-335985 Change-Id: I97fae99bdc8b2b3eeb57e789aedcfe3bc8610706
- Loading branch information
Showing
9 changed files
with
136 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -fcuda-is-device -cuid=abc \ | ||
// RUN: -aux-triple x86_64-unknown-linux-gnu -std=c++11 -fgpu-rdc \ | ||
// RUN: -emit-llvm -o - -x hip %s > %t.dev | ||
|
||
// RUN: %clang_cc1 -triple x86_64-gnu-linux -cuid=abc \ | ||
// RUN: -aux-triple amdgcn-amd-amdhsa -std=c++11 -fgpu-rdc \ | ||
// RUN: -emit-llvm -o - -x hip %s > %t.host | ||
|
||
// RUN: cat %t.dev %t.host | FileCheck -check-prefixes=HIP,COMMON %s | ||
|
||
// RUN: echo "GPU binary" > %t.fatbin | ||
|
||
// RUN: %clang_cc1 -triple nvptx -fcuda-is-device -cuid=abc \ | ||
// RUN: -aux-triple x86_64-unknown-linux-gnu -std=c++11 -fgpu-rdc \ | ||
// RUN: -emit-llvm -o - %s > %t.dev | ||
|
||
// RUN: %clang_cc1 -triple x86_64-gnu-linux -cuid=abc \ | ||
// RUN: -aux-triple nvptx -std=c++11 -fgpu-rdc -fcuda-include-gpubinary %t.fatbin \ | ||
// RUN: -emit-llvm -o - %s > %t.host | ||
|
||
// RUN: cat %t.dev %t.host | FileCheck -check-prefixes=CUDA,COMMON %s | ||
|
||
#include "Inputs/cuda.h" | ||
|
||
// HIP-DAG: define weak_odr {{.*}}void @[[KERN1:_ZN12_GLOBAL__N_16kernelEv\.intern\.b04fd23c98500190]]( | ||
// HIP-DAG: define weak_odr {{.*}}void @[[KERN2:_Z8tempKernIN12_GLOBAL__N_11XEEvT_\.intern\.b04fd23c98500190]]( | ||
// HIP-DAG: define weak_odr {{.*}}void @[[KERN3:_Z8tempKernIN12_GLOBAL__N_1UlvE_EEvT_\.intern\.b04fd23c98500190]]( | ||
|
||
// CUDA-DAG: define weak_odr {{.*}}void @[[KERN1:_ZN12_GLOBAL__N_16kernelEv__intern__b04fd23c98500190]]( | ||
// CUDA-DAG: define weak_odr {{.*}}void @[[KERN2:_Z8tempKernIN12_GLOBAL__N_11XEEvT___intern__b04fd23c98500190]]( | ||
// CUDA-DAG: define weak_odr {{.*}}void @[[KERN3:_Z8tempKernIN12_GLOBAL__N_1UlvE_EEvT___intern__b04fd23c98500190]]( | ||
|
||
// COMMON-DAG: @[[STR1:.*]] = {{.*}} c"[[KERN1]]\00" | ||
// COMMON-DAG: @[[STR2:.*]] = {{.*}} c"[[KERN2]]\00" | ||
// COMMON-DAG: @[[STR3:.*]] = {{.*}} c"[[KERN3]]\00" | ||
|
||
// COMMON-DAG: call i32 @__{{.*}}RegisterFunction({{.*}}@[[STR1]] | ||
// COMMON-DAG: call i32 @__{{.*}}RegisterFunction({{.*}}@[[STR2]] | ||
// COMMON-DAG: call i32 @__{{.*}}RegisterFunction({{.*}}@[[STR3]] | ||
|
||
|
||
template <typename T> | ||
__global__ void tempKern(T x) {} | ||
|
||
namespace { | ||
__global__ void kernel() {} | ||
struct X {}; | ||
X x; | ||
auto lambda = [](){}; | ||
} | ||
|
||
void test() { | ||
kernel<<<1, 1>>>(); | ||
|
||
tempKern<<<1, 1>>>(x); | ||
|
||
tempKern<<<1, 1>>>(lambda); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters