-
Notifications
You must be signed in to change notification settings - Fork 13.6k
[flang][cuda] Lower CUDA shared variable with cuf.shared_memory op #131399
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
Conversation
@llvm/pr-subscribers-flang-fir-hlfir Author: Valentin Clement (バレンタイン クレメン) (clementval) ChangesFull diff: https://github.com/llvm/llvm-project/pull/131399.diff 2 Files Affected:
diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index ab5e6346f8d54..05256fec67241 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -738,9 +738,11 @@ static mlir::Value createNewLocal(Fortran::lower::AbstractConverter &converter,
auto idxTy = builder.getIndexType();
for (mlir::Value sh : elidedShape)
indices.push_back(builder.createConvert(loc, idxTy, sh));
- mlir::Value alloc = builder.create<cuf::AllocOp>(
- loc, ty, nm, symNm, dataAttr, lenParams, indices);
- return alloc;
+ if (dataAttr.getValue() == cuf::DataAttribute::Shared)
+ return builder.create<cuf::SharedMemoryOp>(loc, ty, nm, symNm, lenParams,
+ indices);
+ return builder.create<cuf::AllocOp>(loc, ty, nm, symNm, dataAttr, lenParams,
+ indices);
}
// Let the builder do all the heavy lifting.
@@ -1032,12 +1034,16 @@ static void instantiateLocal(Fortran::lower::AbstractConverter &converter,
symMap);
if (Fortran::semantics::NeedCUDAAlloc(var.getSymbol())) {
auto *builder = &converter.getFirOpBuilder();
+ cuf::DataAttributeAttr dataAttr =
+ Fortran::lower::translateSymbolCUFDataAttribute(builder->getContext(),
+ var.getSymbol());
mlir::Location loc = converter.getCurrentLocation();
fir::ExtendedValue exv =
converter.getSymbolExtendedValue(var.getSymbol(), &symMap);
auto *sym = &var.getSymbol();
const Fortran::semantics::Scope &owner = sym->owner();
- if (owner.kind() != Fortran::semantics::Scope::Kind::MainProgram) {
+ if (owner.kind() != Fortran::semantics::Scope::Kind::MainProgram &&
+ dataAttr.getValue() != cuf::DataAttribute::Shared) {
converter.getFctCtx().attachCleanup([builder, loc, exv, sym]() {
cuf::DataAttributeAttr dataAttr =
Fortran::lower::translateSymbolCUFDataAttribute(
diff --git a/flang/test/Lower/CUDA/cuda-shared.cuf b/flang/test/Lower/CUDA/cuda-shared.cuf
new file mode 100644
index 0000000000000..0bacc4ec0b71e
--- /dev/null
+++ b/flang/test/Lower/CUDA/cuda-shared.cuf
@@ -0,0 +1,11 @@
+! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
+
+attributes(global) subroutine sharedmem()
+ real, shared :: s(32)
+ integer :: t
+ t = threadIdx%x
+ s(t) = t
+end subroutine
+
+! CHECK-LABEL: func.func @_QPsharedmem() attributes {cuf.proc_attr = #cuf.cuda_proc<global>}
+! CHECK: %{{.*}} = cuf.shared_memory !fir.array<32xf32> {bindc_name = "s", uniq_name = "_QFsharedmemEs"} -> !fir.ref<!fir.array<32xf32>>
|
2dc9b15
to
abadac9
Compare
abadac9
to
74b42bb
Compare
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/41/builds/5606 Here is the relevant piece of the build log for the reference
|
Use
cuf.shared_memory
operation instead ofcuf.alloc
for CUDA shared variable. These variables do not need free operations.