-
Notifications
You must be signed in to change notification settings - Fork 177
[CIR][CUDA] Support builtin CUDA variables #1458
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
Merged
Merged
Changes from 24 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
e440258
emit const attr for cuda
anominos 73fabd6
emitGlobal: move shouldEmitCUDAGlobalVar to first check
anominos 76901bb
tests: add constant to global-vars.cu
anominos 2617e0f
implement const
anominos a250e36
fix address space for offload_constant
anominos 8a3c8f1
Merge branch 'main' into anom/constant-var
anominos d514fc4
Merge branch 'anom/const-var' into anom/constant-var
anominos 33c353f
Fix address space values for NVPTX
anominos 92cc36e
add testcase
anominos 6e7f8ab
Merge branch 'anom/fix-nvptx-addrspace' into anom/constant-var
anominos 07ac4f5
test: enable const test in addrspace-lowering.cu
anominos 466ce1d
[CIR][CUDA] Support builtin CUDA variables
advay168 6b902e5
[CIR][CUDA] Fix formatting
advay168 57c5572
[CIR][CUDA] Defer failing test
advay168 e480ce4
[CIR][CUDA] Revert change to test
advay168 0c1c8ed
[CIR][CUDA] Fix test
advay168 3431265
Merge branch 'main' into anom/constant-var
anominos bf4c995
remove duplicated case
anominos 0a26ede
Merge branch 'main' into anom/constant-var
anominos 0776935
Merge remote-tracking branch 'aiden/anom/constant-var'
advay168 f2f98d6
Fix style
advay168 108f38e
Change naming case
advay168 19aead8
Merge remote-tracking branch 'original/main'
advay168 01b5987
Formatting
advay168 c0ed490
Change naming
advay168 d6239ef
Naming
advay168 05b644b
Merge remote-tracking branch 'original/main'
advay168 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,82 @@ | ||
| //===---- CIRGenBuiltinX86.cpp - Emit CIR for X86 builtins ----------------===// | ||
| // | ||
| // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // This contains code to emit NVPTX Builtin calls. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include "CIRGenCXXABI.h" | ||
| #include "CIRGenCall.h" | ||
| #include "CIRGenFunction.h" | ||
| #include "CIRGenModule.h" | ||
| #include "TargetInfo.h" | ||
| #include "clang/CIR/MissingFeatures.h" | ||
|
|
||
| #include "mlir/Dialect/Func/IR/FuncOps.h" | ||
| #include "mlir/IR/Value.h" | ||
| #include "clang/AST/GlobalDecl.h" | ||
| #include "clang/Basic/Builtins.h" | ||
| #include "clang/Basic/TargetBuiltins.h" | ||
| #include "clang/CIR/Dialect/IR/CIRDialect.h" | ||
| #include "clang/CIR/Dialect/IR/CIRTypes.h" | ||
| #include "llvm/Support/ErrorHandling.h" | ||
|
|
||
| using namespace clang; | ||
| using namespace clang::CIRGen; | ||
| using namespace cir; | ||
|
|
||
| mlir::Value CIRGenFunction::emitNVPTXBuiltinExpr(unsigned BuiltinID, | ||
advay168 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const CallExpr *E) { | ||
advay168 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| auto getIntrinsic = [&](const char *name) { | ||
| mlir::Type intTy = cir::IntType::get(&getMLIRContext(), 32, false); | ||
| return builder | ||
| .create<cir::LLVMIntrinsicCallOp>(getLoc(E->getExprLoc()), | ||
| builder.getStringAttr(name), intTy) | ||
| .getResult(); | ||
| }; | ||
| switch (BuiltinID) { | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_tid_x: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.tid.x"); | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_tid_y: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.tid.y"); | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_tid_z: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.tid.z"); | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_tid_w: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.tid.w"); | ||
|
|
||
| case NVPTX::BI__nvvm_read_ptx_sreg_ntid_x: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.ntid.x"); | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_ntid_y: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.ntid.y"); | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_ntid_z: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.ntid.z"); | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_ntid_w: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.ntid.w"); | ||
|
|
||
| case NVPTX::BI__nvvm_read_ptx_sreg_ctaid_x: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.ctaid.x"); | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_ctaid_y: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.ctaid.y"); | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_ctaid_z: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.ctaid.z"); | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_ctaid_w: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.ctaid.w"); | ||
|
|
||
| case NVPTX::BI__nvvm_read_ptx_sreg_nctaid_x: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.nctaid.x"); | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_nctaid_y: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.nctaid.y"); | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_nctaid_z: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.nctaid.z"); | ||
| case NVPTX::BI__nvvm_read_ptx_sreg_nctaid_w: | ||
| return getIntrinsic("nvvm.read.ptx.sreg.nctaid.w"); | ||
|
|
||
| default: | ||
| llvm_unreachable("NYI"); | ||
| } | ||
| } | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,88 @@ | ||
| // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fclangir \ | ||
| // RUN: -fcuda-is-device -emit-llvm -o - %s \ | ||
| // RUN: | FileCheck --check-prefix=LLVM %s | ||
|
|
||
| // RUN: %clang_cc1 -triple nvptx64-nvidia-cuda -fclangir \ | ||
| // RUN: -fcuda-is-device -emit-cir -o - %s \ | ||
| // RUN: | FileCheck --check-prefix=CIR %s | ||
|
|
||
| #include "__clang_cuda_builtin_vars.h" | ||
|
|
||
| // LLVM: define{{.*}} void @_Z6kernelPi(ptr %0) | ||
| __attribute__((global)) | ||
| void kernel(int *out) { | ||
| int i = 0; | ||
|
|
||
| out[i++] = threadIdx.x; | ||
| // CIR: cir.func linkonce_odr @_ZN26__cuda_builtin_threadIdx_t17__fetch_builtin_xEv() | ||
| // CIR: cir.llvm.intrinsic "nvvm.read.ptx.sreg.tid.x" | ||
| // LLVM: call {{.*}} i32 @llvm.nvvm.read.ptx.sreg.tid.x() | ||
|
|
||
| out[i++] = threadIdx.y; | ||
| // CIR: cir.func linkonce_odr @_ZN26__cuda_builtin_threadIdx_t17__fetch_builtin_yEv() | ||
| // CIR: cir.llvm.intrinsic "nvvm.read.ptx.sreg.tid.y" | ||
| // LLVM: call {{.*}} i32 @llvm.nvvm.read.ptx.sreg.tid.y() | ||
|
|
||
| out[i++] = threadIdx.z; | ||
| // CIR: cir.func linkonce_odr @_ZN26__cuda_builtin_threadIdx_t17__fetch_builtin_zEv() | ||
| // CIR: cir.llvm.intrinsic "nvvm.read.ptx.sreg.tid.z" | ||
| // LLVM: call {{.*}} i32 @llvm.nvvm.read.ptx.sreg.tid.z() | ||
|
|
||
|
|
||
| out[i++] = blockIdx.x; | ||
| // CIR: cir.func linkonce_odr @_ZN25__cuda_builtin_blockIdx_t17__fetch_builtin_xEv() | ||
| // CIR: cir.llvm.intrinsic "nvvm.read.ptx.sreg.ctaid.x" | ||
| // LLVM: call {{.*}} i32 @llvm.nvvm.read.ptx.sreg.ctaid.x() | ||
|
|
||
| out[i++] = blockIdx.y; | ||
| // CIR: cir.func linkonce_odr @_ZN25__cuda_builtin_blockIdx_t17__fetch_builtin_yEv() | ||
| // CIR: cir.llvm.intrinsic "nvvm.read.ptx.sreg.ctaid.y" | ||
| // LLVM: call {{.*}} i32 @llvm.nvvm.read.ptx.sreg.ctaid.y() | ||
|
|
||
| out[i++] = blockIdx.z; | ||
| // CIR: cir.func linkonce_odr @_ZN25__cuda_builtin_blockIdx_t17__fetch_builtin_zEv() | ||
| // CIR: cir.llvm.intrinsic "nvvm.read.ptx.sreg.ctaid.z" | ||
| // LLVM: call {{.*}} i32 @llvm.nvvm.read.ptx.sreg.ctaid.z() | ||
|
|
||
|
|
||
| out[i++] = blockDim.x; | ||
| // CIR: cir.func linkonce_odr @_ZN25__cuda_builtin_blockDim_t17__fetch_builtin_xEv() | ||
| // CIR: cir.llvm.intrinsic "nvvm.read.ptx.sreg.ntid.x" | ||
| // LLVM: call {{.*}} i32 @llvm.nvvm.read.ptx.sreg.ntid.x() | ||
|
|
||
| out[i++] = blockDim.y; | ||
| // CIR: cir.func linkonce_odr @_ZN25__cuda_builtin_blockDim_t17__fetch_builtin_yEv() | ||
| // CIR: cir.llvm.intrinsic "nvvm.read.ptx.sreg.ntid.y" | ||
| // LLVM: call {{.*}} i32 @llvm.nvvm.read.ptx.sreg.ntid.y() | ||
|
|
||
| out[i++] = blockDim.z; | ||
| // CIR: cir.func linkonce_odr @_ZN25__cuda_builtin_blockDim_t17__fetch_builtin_zEv() | ||
| // CIR: cir.llvm.intrinsic "nvvm.read.ptx.sreg.ntid.z" | ||
| // LLVM: call {{.*}} i32 @llvm.nvvm.read.ptx.sreg.ntid.z() | ||
|
|
||
|
|
||
| out[i++] = gridDim.x; | ||
| // CIR: cir.func linkonce_odr @_ZN24__cuda_builtin_gridDim_t17__fetch_builtin_xEv() | ||
| // CIR: cir.llvm.intrinsic "nvvm.read.ptx.sreg.nctaid.x" | ||
| // LLVM: call {{.*}} i32 @llvm.nvvm.read.ptx.sreg.nctaid.x() | ||
|
|
||
| out[i++] = gridDim.y; | ||
| // CIR: cir.func linkonce_odr @_ZN24__cuda_builtin_gridDim_t17__fetch_builtin_yEv() | ||
| // CIR: cir.llvm.intrinsic "nvvm.read.ptx.sreg.nctaid.y" | ||
| // LLVM: call {{.*}} i32 @llvm.nvvm.read.ptx.sreg.nctaid.y() | ||
|
|
||
| out[i++] = gridDim.z; | ||
| // CIR: cir.func linkonce_odr @_ZN24__cuda_builtin_gridDim_t17__fetch_builtin_zEv() | ||
| // CIR: cir.llvm.intrinsic "nvvm.read.ptx.sreg.nctaid.z" | ||
| // LLVM: call {{.*}} i32 @llvm.nvvm.read.ptx.sreg.nctaid.z() | ||
|
|
||
|
|
||
| out[i++] = warpSize; | ||
| // CIR: [[REGISTER:%.*]] = cir.const #cir.int<32> | ||
| // CIR: cir.store [[REGISTER]] | ||
| // LLVM: store i32 32, | ||
|
|
||
|
|
||
| // CIR: cir.return loc | ||
| // LLVM: ret void | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.