[flang-commits] [flang] [flang][cuda] Make sure CUDA attribute are imported when using module variable (PR #82844)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Mon Feb 26 08:56:40 PST 2024
https://github.com/clementval updated https://github.com/llvm/llvm-project/pull/82844
>From 7570a63c794be4d284a10a431d5db89a951cf2c7 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Fri, 23 Feb 2024 15:39:51 -0800
Subject: [PATCH 1/2] [flang][cuda] Make sure CUDA attribute are imported when
using module variable
---
flang/lib/Lower/ConvertVariable.cpp | 7 +++++--
flang/test/Lower/CUDA/cuda-mod.cuf | 5 +++++
flang/test/Lower/CUDA/cuda-module-use.cuf | 15 +++++++++++++++
3 files changed, 25 insertions(+), 2 deletions(-)
create mode 100644 flang/test/Lower/CUDA/cuda-mod.cuf
create mode 100644 flang/test/Lower/CUDA/cuda-module-use.cuf
diff --git a/flang/lib/Lower/ConvertVariable.cpp b/flang/lib/Lower/ConvertVariable.cpp
index b2279a319fe92e..a673a18cd20d91 100644
--- a/flang/lib/Lower/ConvertVariable.cpp
+++ b/flang/lib/Lower/ConvertVariable.cpp
@@ -172,9 +172,12 @@ static fir::GlobalOp declareGlobal(Fortran::lower::AbstractConverter &converter,
!Fortran::semantics::IsProcedurePointer(ultimate))
mlir::emitError(loc, "processing global declaration: symbol '")
<< toStringRef(sym.name()) << "' has unexpected details\n";
+ fir::CUDADataAttributeAttr cudaAttr =
+ Fortran::lower::translateSymbolCUDADataAttribute(
+ converter.getFirOpBuilder().getContext(), sym);
return builder.createGlobal(loc, converter.genType(var), globalName, linkage,
mlir::Attribute{}, isConstant(ultimate),
- var.isTarget());
+ var.isTarget(), cudaAttr);
}
/// Temporary helper to catch todos in initial data target lowering.
@@ -1586,7 +1589,7 @@ fir::FortranVariableFlagsAttr Fortran::lower::translateSymbolAttributes(
fir::CUDADataAttributeAttr Fortran::lower::translateSymbolCUDADataAttribute(
mlir::MLIRContext *mlirContext, const Fortran::semantics::Symbol &sym) {
std::optional<Fortran::common::CUDADataAttr> cudaAttr =
- Fortran::semantics::GetCUDADataAttr(&sym);
+ Fortran::semantics::GetCUDADataAttr(&sym.GetUltimate());
return fir::getCUDADataAttribute(mlirContext, cudaAttr);
}
diff --git a/flang/test/Lower/CUDA/cuda-mod.cuf b/flang/test/Lower/CUDA/cuda-mod.cuf
new file mode 100644
index 00000000000000..41a012fcdb0809
--- /dev/null
+++ b/flang/test/Lower/CUDA/cuda-mod.cuf
@@ -0,0 +1,5 @@
+! Simple module to test module use in
+
+module cuf_mod
+ real, device :: md
+end module
diff --git a/flang/test/Lower/CUDA/cuda-module-use.cuf b/flang/test/Lower/CUDA/cuda-module-use.cuf
new file mode 100644
index 00000000000000..43ab0f6ff8d68e
--- /dev/null
+++ b/flang/test/Lower/CUDA/cuda-module-use.cuf
@@ -0,0 +1,15 @@
+! RUN: bbc -emit-hlfir -fcuda %S/cuda-mod.cuf
+! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
+
+! Test importing module with variable with CUDA attributes.
+
+subroutine sub1()
+ use cuf_mod
+ md = 1.0
+end
+
+! CHECK-LABEL: func.func @_QPsub1()
+! CHECK: %[[ADDR:.*]] = fir.address_of(@_QMcuf_modEmd) : !fir.ref<f32>
+! CHECK: %{{.*}}:2 = hlfir.declare %[[ADDR]] {cuda_attr = #fir.cuda<device>, uniq_name = "_QMcuf_modEmd"} : (!fir.ref<f32>) -> (!fir.ref<f32>, !fir.ref<f32>)
+
+! CHECK: fir.global @_QMcuf_modEmd {cuda_attr = #fir.cuda<device>} : f32
>From 2a4fb05d86d349fe88dc479e474ff87d90507d57 Mon Sep 17 00:00:00 2001
From: Valentin Clement <clementval at gmail.com>
Date: Mon, 26 Feb 2024 08:56:20 -0800
Subject: [PATCH 2/2] Add run line to the mod
---
flang/test/Lower/CUDA/cuda-mod.cuf | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/flang/test/Lower/CUDA/cuda-mod.cuf b/flang/test/Lower/CUDA/cuda-mod.cuf
index 41a012fcdb0809..2cc6439789a279 100644
--- a/flang/test/Lower/CUDA/cuda-mod.cuf
+++ b/flang/test/Lower/CUDA/cuda-mod.cuf
@@ -1,5 +1,9 @@
+! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s
+
! Simple module to test module use in
module cuf_mod
real, device :: md
end module
+
+! CHECK: fir.global @_QMcuf_modEmd {cuda_attr = #fir.cuda<device>} : f32
More information about the flang-commits
mailing list