-
Notifications
You must be signed in to change notification settings - Fork 10.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[HIP][Clang][CodeGen] Add CodeGen support for
hipstdpar
This patch adds the CodeGen changes needed for enabling HIP parallel algorithm offload on AMDGPU targets. This change relaxes restrictions on what gets emitted on the device path, when compiling in `hipstdpar` mode: 1. Unless a function is explicitly marked `__host__`, it will get emitted, whereas before only `__device__` and `__global__` functions would be emitted; 2. Unsupported builtins are ignored as opposed to being marked as an error, as the decision on their validity is deferred to the `hipstdpar` specific code selection pass; 3. We add a `hipstdpar` specific pass to the opt pipeline, independent of optimisation level: - When compiling for the host, iff the user requested it via the `--hipstdpar-interpose-alloc` flag, we add a pass which replaces canonical allocation / deallocation functions with accelerator aware equivalents. A test to validate that unannotated functions get correctly emitted is added as well. Reviewed by: yaxunl, efriedma Differential Revision: https://reviews.llvm.org/D155850
- Loading branch information
Showing
9 changed files
with
116 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ set(LLVM_LINK_COMPONENTS | |
Extensions | ||
FrontendHLSL | ||
FrontendOpenMP | ||
HIPStdPar | ||
IPO | ||
IRPrinter | ||
IRReader | ||
|
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
19 changes: 19 additions & 0 deletions
19
clang/test/CodeGenHipStdPar/unannotated-functions-get-emitted.cpp
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,19 @@ | ||
// RUN: %clang_cc1 -x hip -emit-llvm -fcuda-is-device \ | ||
// RUN: -o - %s | FileCheck --check-prefix=NO-HIPSTDPAR-DEV %s | ||
|
||
// RUN: %clang_cc1 --hipstdpar -emit-llvm -fcuda-is-device \ | ||
// RUN: -o - %s | FileCheck --check-prefix=HIPSTDPAR-DEV %s | ||
|
||
#define __device__ __attribute__((device)) | ||
|
||
// NO-HIPSTDPAR-DEV-NOT: define {{.*}} void @foo({{.*}}) | ||
// HIPSTDPAR-DEV: define {{.*}} void @foo({{.*}}) | ||
extern "C" void foo(float *a, float b) { | ||
*a = b; | ||
} | ||
|
||
// NO-HIPSTDPAR-DEV: define {{.*}} void @bar({{.*}}) | ||
// HIPSTDPAR-DEV: define {{.*}} void @bar({{.*}}) | ||
extern "C" __device__ void bar(float *a, float b) { | ||
*a = b; | ||
} |
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,10 @@ | ||
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu \ | ||
// RUN: --hipstdpar -x hip -emit-llvm -fcuda-is-device -o - %s | FileCheck %s | ||
|
||
#define __global__ __attribute__((global)) | ||
|
||
__global__ void foo(int i) { | ||
asm ("addl %2, %1; seto %b0" : "=q" (i), "+g" (i) : "r" (i)); | ||
} | ||
|
||
// CHECK: declare void @__ASM__hipstdpar_unsupported([{{.*}}]) |
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,8 @@ | ||
// RUN: %clang_cc1 -triple amdgcn-amd-amdhsa -aux-triple x86_64-unknown-linux-gnu \ | ||
// RUN: --hipstdpar -x hip -emit-llvm -fcuda-is-device -o - %s | FileCheck %s | ||
|
||
#define __global__ __attribute__((global)) | ||
|
||
__global__ void foo() { return __builtin_ia32_pause(); } | ||
|
||
// CHECK: declare void @__builtin_ia32_pause__hipstdpar_unsupported() |