Repository navigation
[CIR][CUDA] Handle local, __device__, __shared__, and __constant__ variables #184248
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
809121a
512dd3a
42105b0
f58883b
5af50ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -433,12 +433,15 @@ CIRGenModule::getOrCreateStaticVarDecl(const VarDecl &d, | |
| mlir::Type lty = getTypes().convertTypeForMem(ty); | ||
| assert(!cir::MissingFeatures::addressSpace()); | ||
|
|
||
| if (d.hasAttr<LoaderUninitializedAttr>() || d.hasAttr<CUDASharedAttr>()) | ||
| mlir::Attribute init = nullptr; | ||
| if (d.hasAttr<LoaderUninitializedAttr>()) | ||
| errorNYI(d.getSourceRange(), | ||
| "getOrCreateStaticVarDecl: LoaderUninitializedAttr"); | ||
| assert(!cir::MissingFeatures::addressSpace()); | ||
| else if (ty.getAddressSpace() != LangAS::opencl_local && | ||
| !d.hasAttr<CUDASharedAttr>()) | ||
| init = builder.getZeroInitAttr(convertType(ty)); | ||
|
|
||
| mlir::Attribute init = builder.getZeroInitAttr(convertType(ty)); | ||
| assert(!cir::MissingFeatures::addressSpace()); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's missing here? Is it the AS argument to createVersionedGlobal()?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. createVersionedGlobal did not requrie AddressSpace as argument.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That is being added in #179082, so it will depend on the order in which these patches are merged. I don't think the assertion is needed since that's already in progress, but it's also fine to leave it. |
||
|
|
||
| cir::GlobalOp gv = builder.createVersionedGlobal( | ||
| getModule(), getLoc(d.getLocation()), name, lty, false, linkage); | ||
|
|
@@ -665,11 +668,6 @@ void CIRGenFunction::emitStaticVarDecl(const VarDecl &d, | |
|
|
||
| var.setAlignment(alignment.getAsAlign().value()); | ||
|
|
||
| // There are a lot of attributes that need to be handled here. Until | ||
|
ZakyHermawan marked this conversation as resolved.
|
||
| // we start to support them, we just report an error if there are any. | ||
| if (d.hasAttrs()) | ||
| cgm.errorNYI(d.getSourceRange(), "static var with attrs"); | ||
|
|
||
| if (cgm.getCodeGenOpts().KeepPersistentStorageVariables) | ||
| cgm.errorNYI(d.getSourceRange(), "static var keep persistent storage"); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #include "Inputs/cuda.h" | ||
|
|
||
| // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fclangir \ | ||
| // RUN: -fcuda-is-device -emit-cir -target-sdk-version=12.3 \ | ||
| // RUN: -I%S/Inputs/ %s -o %t.cir | ||
| // RUN: FileCheck --check-prefix=CIR-DEVICE --input-file=%t.cir %s | ||
|
|
||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir \ | ||
| // RUN: -x cuda -emit-cir -target-sdk-version=12.3 \ | ||
| // RUN: -I%S/Inputs/ %s -o %t.cir | ||
| // RUN: FileCheck --check-prefix=CIR-HOST --input-file=%t.cir %s | ||
|
|
||
| // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fclangir \ | ||
| // RUN: -fcuda-is-device -emit-llvm -target-sdk-version=12.3 \ | ||
| // RUN: -I%S/Inputs/ %s -o %t.ll | ||
| // RUN: FileCheck --check-prefix=LLVM-DEVICE --input-file=%t.ll %s | ||
|
|
||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir \ | ||
| // RUN: -x cuda -emit-llvm -target-sdk-version=12.3 \ | ||
| // RUN: -I%S/Inputs/ %s -o %t.ll | ||
| // RUN: FileCheck --check-prefix=LLVM-HOST --input-file=%t.ll %s | ||
|
|
||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu \ | ||
| // RUN: -x cuda -emit-llvm -target-sdk-version=12.3 \ | ||
| // RUN: -I%S/Inputs/ %s -o %t.ll | ||
| // RUN: FileCheck --check-prefix=OGCG-HOST --input-file=%t.ll %s | ||
|
|
||
| // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda \ | ||
| // RUN: -fcuda-is-device -emit-llvm -target-sdk-version=12.3 \ | ||
| // RUN: -I%S/Inputs/ %s -o %t.ll | ||
| // RUN: FileCheck --check-prefix=OGCG-DEVICE --input-file=%t.ll %s | ||
|
|
||
| __global__ void fn() { | ||
| int i = 0; | ||
| __shared__ int j; | ||
| j = i; | ||
| } | ||
|
|
||
| // CIR-DEVICE: cir.global "private" internal dso_local @_ZZ2fnvE1j : !s32i | ||
| // CIR-DEVICE: cir.func {{.*}}@_Z2fnv() {{.*}} { | ||
| // CIR-DEVICE: %[[I:.*]] = cir.alloca !s32i, !cir.ptr<!s32i>, ["i", init] | ||
| // CIR-DEVICE: %[[ZERO:.*]] = cir.const #cir.int<0> : !s32i | ||
| // CIR-DEVICE: cir.store {{.*}}%[[ZERO]], %[[I]] : !s32i, !cir.ptr<!s32i> | ||
| // CIR-DEVICE: %[[J:.*]] = cir.get_global @_ZZ2fnvE1j : !cir.ptr<!s32i> | ||
| // CIR-DEVICE: %[[VAL:.*]] = cir.load {{.*}}%[[I]] : !cir.ptr<!s32i>, !s32i | ||
| // CIR-DEVICE: cir.store {{.*}}%[[VAL]], %[[J]] : !s32i, !cir.ptr<!s32i> | ||
| // CIR-DEVICE: cir.return | ||
|
|
||
| // CIR-HOST: cir.func private dso_local @__cudaPopCallConfiguration | ||
| // CIR-HOST: cir.func private dso_local @cudaLaunchKernel | ||
| // CIR-HOST: cir.func {{.*}}@_Z17__device_stub__fnv() | ||
|
|
||
| // LLVM-DEVICE: @_ZZ2fnvE1j = internal global i32 undef, align 4 | ||
| // LLVM-DEVICE: define dso_local void @_Z2fnv() | ||
| // LLVM-DEVICE: %[[ALLOCA:.*]] = alloca i32, i64 1, align 4 | ||
| // LLVM-DEVICE: store i32 0, ptr %[[ALLOCA]], align 4 | ||
| // LLVM-DEVICE: %[[VAL:.*]] = load i32, ptr %[[ALLOCA]], align 4 | ||
| // LLVM-DEVICE: store i32 %[[VAL]], ptr @_ZZ2fnvE1j, align 4 | ||
| // LLVM-DEVICE: ret void | ||
|
|
||
| // LLVM-HOST: %struct.dim3 = type { i32, i32, i32 } | ||
| // LLVM-HOST: declare {{.*}}i32 @__cudaPopCallConfiguration(ptr, ptr, ptr, ptr) | ||
| // LLVM-HOST: declare {{.*}}i32 @cudaLaunchKernel(ptr, %struct.dim3, %struct.dim3, ptr, i64, ptr) | ||
| // LLVM-HOST: define dso_local void @_Z17__device_stub__fnv() | ||
|
|
||
| // OGCG-HOST: define dso_local void @_Z17__device_stub__fnv() | ||
| // OGCG-HOST: entry: | ||
| // OGCG-HOST: call i32 @__cudaPopCallConfiguration | ||
| // OGCG-HOST: call {{.*}}i32 @cudaLaunchKernel | ||
|
|
||
| // OGCG-DEVICE: @_ZZ2fnvE1j = internal addrspace(3) global i32 undef, align 4 | ||
| // OGCG-DEVICE: define dso_local ptx_kernel void @_Z2fnv() | ||
| // OGCG-DEVICE: entry: | ||
| // OGCG-DEVICE: %[[I:.*]] = alloca i32, align 4 | ||
| // OGCG-DEVICE: store i32 0, ptr %[[I]], align 4 | ||
| // OGCG-DEVICE: %[[VAL:.*]] = load i32, ptr %[[I]], align 4 | ||
| // OGCG-DEVICE: store i32 %[[VAL]], ptr addrspacecast (ptr addrspace(3) @_ZZ2fnvE1j to ptr), align 4 | ||
| // OGCG-DEVICE: ret void |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| #include "Inputs/cuda.h" | ||
|
|
||
| // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fclangir \ | ||
| // RUN: -fcuda-is-device -emit-cir -target-sdk-version=12.3 \ | ||
| // RUN: -I%S/Inputs/ %s -o %t.cir | ||
| // RUN: FileCheck --check-prefix=CIR-DEVICE --input-file=%t.cir %s | ||
|
|
||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir \ | ||
| // RUN: -x cuda -emit-cir -target-sdk-version=12.3 \ | ||
| // RUN: -I%S/Inputs/ %s -o %t.cir | ||
| // RUN: FileCheck --check-prefix=CIR-HOST --input-file=%t.cir %s | ||
|
|
||
| // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fclangir \ | ||
| // RUN: -fcuda-is-device -emit-llvm -target-sdk-version=12.3 \ | ||
| // RUN: -I%S/Inputs/ %s -o %t.ll | ||
| // RUN: FileCheck --check-prefix=LLVM-DEVICE --input-file=%t.ll %s | ||
|
|
||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu -fclangir \ | ||
| // RUN: -x cuda -emit-llvm -target-sdk-version=12.3 \ | ||
| // RUN: -I%S/Inputs/ %s -o %t.ll | ||
| // RUN: FileCheck --check-prefix=LLVM-HOST --input-file=%t.ll %s | ||
|
|
||
| // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda \ | ||
| // RUN: -fcuda-is-device -emit-llvm -target-sdk-version=12.3 \ | ||
| // RUN: -I%S/Inputs/ %s -o %t.ll | ||
| // RUN: FileCheck --check-prefix=OGCG-DEVICE --input-file=%t.ll %s | ||
|
|
||
| // RUN: %clang_cc1 -triple x86_64-unknown-linux-gnu \ | ||
| // RUN: -x cuda -emit-llvm -target-sdk-version=12.3 \ | ||
| // RUN: -I%S/Inputs/ %s -o %t.ll | ||
| // RUN: FileCheck --check-prefix=OGCG-HOST --input-file=%t.ll %s | ||
|
|
||
| __shared__ int a; | ||
| // CIR-DEVICE: cir.global external [[SHARED:@.*]] = #cir.int<0> : !s32i {alignment = 4 : i64} | ||
| // CIR-HOST: cir.global external [[SHARED_HOST:@.*]] = #cir.int<0> : !s32i {alignment = 4 : i64} | ||
| // LLVM-DEVICE: @[[SHARED_LL:.*]] = global i32 0, align 4 | ||
| // LLVM-HOST: @[[SHARED_LH:.*]] = global i32 0, align 4 | ||
| // OGCG-DEVICE: @[[SHARED_OD:.*]] = addrspace(3) global i32 undef, align 4 | ||
| // OGCG-HOST: @[[SHARED_OH:.*]] = internal global i32 undef, align 4 | ||
|
|
||
| __device__ int b; | ||
| // CIR-DEVICE: cir.global external [[DEV:@.*]] = #cir.int<0> : !s32i {alignment = 4 : i64} | ||
| // CIR-HOST: cir.global external [[DEV_HOST:@.*]] = #cir.int<0> : !s32i {alignment = 4 : i64} | ||
| // LLVM-DEVICE: @[[DEV_LD:.*]] = global i32 0, align 4 | ||
| // LLVM-HOST: @[[DEV_LH:.*]] = global i32 0, align 4 | ||
| // OGCG-HOST: @[[DEV_OH:.*]] = internal global i32 undef, align 4 | ||
| // OGCG-DEVICE: @[[DEV_OD:.*]] = addrspace(1) externally_initialized global i32 0, align 4 |
Uh oh!
There was an error while loading. Please reload this page.