From 6dc8676a09077f716059bd0e087a2ef1bd816711 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Fri, 10 Jan 2025 13:40:03 -0800 Subject: [PATCH 1/3] [flang][cuda] Add bind(c) interfaces for __fadd_rd and __fadd_ru --- flang/module/cudadevice.f90 | 14 ++++++++++++++ flang/test/Lower/CUDA/cuda-intrinsic.cuf | 17 +++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 flang/test/Lower/CUDA/cuda-intrinsic.cuf diff --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90 index 1402bd4e15041..74825c36f7a95 100644 --- a/flang/module/cudadevice.f90 +++ b/flang/module/cudadevice.f90 @@ -71,4 +71,18 @@ attributes(device) subroutine threadfence_system() end interface public :: threadfence_system + interface + attributes(device) function __fadd_rd(x, y) bind(c, name='__nv_fadd_rd') + real :: x, y, __fadd_rd + end function + end interface + public :: __fadd_rd + + interface + attributes(device) function __fadd_ru(x, y) bind(c, name='__nv_fadd_ru') + real :: x, y, __fadd_ru + end function + end interface + public :: __fadd_ru + end module diff --git a/flang/test/Lower/CUDA/cuda-intrinsic.cuf b/flang/test/Lower/CUDA/cuda-intrinsic.cuf new file mode 100644 index 0000000000000..9723afc532387 --- /dev/null +++ b/flang/test/Lower/CUDA/cuda-intrinsic.cuf @@ -0,0 +1,17 @@ +! RUN: bbc -emit-hlfir -fcuda %s -o - | FileCheck %s + +module mod1 + type int + real :: inf, sup + end type int +contains + attributes(global) subroutine fadd(c, a, b) + type (int) :: c, a, b + c%inf = __fadd_rd(a%inf, b%inf) + c%sup = __fadd_ru(a%sup, b%sup) + end subroutine +end + +! CHECK-LABEL: func.func @_QMmod1Pfadd +! CHECK: fir.call @__nv_fadd_rd +! CHECK: fir.call @__nv_fadd_ru From ad5a13f1096d3e82053cc778ece73ea0b9ac79a0 Mon Sep 17 00:00:00 2001 From: Valentin Clement Date: Fri, 10 Jan 2025 14:20:24 -0800 Subject: [PATCH 2/3] Add intent(in) --- flang/module/cudadevice.f90 | 6 ++++-- mlir/lib/Target/LLVM/NVVM/Target.cpp | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90 index 74825c36f7a95..e06c706538fe6 100644 --- a/flang/module/cudadevice.f90 +++ b/flang/module/cudadevice.f90 @@ -73,14 +73,16 @@ attributes(device) subroutine threadfence_system() interface attributes(device) function __fadd_rd(x, y) bind(c, name='__nv_fadd_rd') - real :: x, y, __fadd_rd + real, intent(in) :: x, y + real :: __fadd_rd end function end interface public :: __fadd_rd interface attributes(device) function __fadd_ru(x, y) bind(c, name='__nv_fadd_ru') - real :: x, y, __fadd_ru + real, intent(in) :: x, y + real :: __fadd_ru end function end interface public :: __fadd_ru diff --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp index 86ff848d6c6c2..8576421ced50e 100644 --- a/mlir/lib/Target/LLVM/NVVM/Target.cpp +++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp @@ -323,6 +323,7 @@ NVPTXSerializer::compileToBinary(const std::string &ptxCode) { std::optional ptxFile = createTemp(basename, "ptx"); if (!ptxFile) return std::nullopt; + ptx.releaseFile(); std::optional logFile = createTemp(basename, "log"); if (!logFile) return std::nullopt; From 34f06591cf900d3c6fc43b50e78d7cc9417ff910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Valentin=20Clement=20=28=E3=83=90=E3=83=AC=E3=83=B3?= =?UTF-8?q?=E3=82=BF=E3=82=A4=E3=83=B3=20=E3=82=AF=E3=83=AC=E3=83=A1?= =?UTF-8?q?=E3=83=B3=29?= Date: Fri, 10 Jan 2025 16:44:18 -0800 Subject: [PATCH 3/3] Remove debug --- mlir/lib/Target/LLVM/NVVM/Target.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/mlir/lib/Target/LLVM/NVVM/Target.cpp b/mlir/lib/Target/LLVM/NVVM/Target.cpp index 8576421ced50e..86ff848d6c6c2 100644 --- a/mlir/lib/Target/LLVM/NVVM/Target.cpp +++ b/mlir/lib/Target/LLVM/NVVM/Target.cpp @@ -323,7 +323,6 @@ NVPTXSerializer::compileToBinary(const std::string &ptxCode) { std::optional ptxFile = createTemp(basename, "ptx"); if (!ptxFile) return std::nullopt; - ptx.releaseFile(); std::optional logFile = createTemp(basename, "log"); if (!logFile) return std::nullopt;