From c701c18bed0c6c1bfd4a1dcfa9f207ddbb74cdfc 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: Mon, 13 Jan 2025 17:28:34 -0800 Subject: [PATCH] [flang][cuda] Move interface to __cuda_device (#122771) --- flang/lib/Semantics/resolve-names.cpp | 4 +++- flang/module/__cuda_device.f90 | 32 +++++++++++++++++++++++++++ flang/module/cudadevice.f90 | 17 +------------- flang/tools/f18/CMakeLists.txt | 6 ++++- 4 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 flang/module/__cuda_device.f90 diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp index 51e7c5960dc2..c1663082f86d 100644 --- a/flang/lib/Semantics/resolve-names.cpp +++ b/flang/lib/Semantics/resolve-names.cpp @@ -4015,7 +4015,9 @@ bool SubprogramVisitor::Pre(const parser::PrefixSpec::Attributes &attrs) { *attrs == common::CUDASubprogramAttrs::Device) { const Scope &scope{currScope()}; const Scope *mod{FindModuleContaining(scope)}; - if (mod && mod->GetName().value() == "cudadevice") { + if (mod && + (mod->GetName().value() == "cudadevice" || + mod->GetName().value() == "__cuda_device")) { return false; } // Implicitly USE the cudadevice module by copying its symbols in the diff --git a/flang/module/__cuda_device.f90 b/flang/module/__cuda_device.f90 new file mode 100644 index 000000000000..81b1f5aa334b --- /dev/null +++ b/flang/module/__cuda_device.f90 @@ -0,0 +1,32 @@ +!===-- module/__cuda_device.f90 --------------------------------------------===! +! +! 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 module contains CUDA Fortran interfaces used in cudadevice.f90. + +module __cuda_device +implicit none + + ! Set PRIVATE by default to explicitly only export what is meant + ! to be exported by this MODULE. + + interface + attributes(device) function __fadd_rd(x, y) bind(c, name='__nv_fadd_rd') + real, intent(in), value :: 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, intent(in), value :: x, y + real :: __fadd_ru + end function + end interface + public :: __fadd_ru +end module diff --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90 index e06c706538fe..b07f82be6a72 100644 --- a/flang/module/cudadevice.f90 +++ b/flang/module/cudadevice.f90 @@ -9,6 +9,7 @@ ! CUDA Fortran procedures available in device subprogram module cudadevice + use __cuda_device, only: __fadd_rd, __fadd_ru implicit none ! Set PRIVATE by default to explicitly only export what is meant @@ -71,20 +72,4 @@ implicit none end interface public :: threadfence_system - interface - attributes(device) function __fadd_rd(x, y) bind(c, name='__nv_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, intent(in) :: x, y - real :: __fadd_ru - end function - end interface - public :: __fadd_ru - end module diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt index 4362fcf05376..cc2bc5b8eb5c 100644 --- a/flang/tools/f18/CMakeLists.txt +++ b/flang/tools/f18/CMakeLists.txt @@ -21,6 +21,7 @@ set(MODULES_WITHOUT_IMPLEMENTATION "__ppc_intrinsics" "mma" "__cuda_builtins" + "__cuda_device" "cudadevice" "ieee_arithmetic" "ieee_exceptions" @@ -67,9 +68,12 @@ if (NOT CMAKE_CROSSCOMPILING) elseif(${filename} STREQUAL "__ppc_intrinsics" OR ${filename} STREQUAL "mma") set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__ppc_types.mod) - elseif(${filename} STREQUAL "cudadevice") + elseif(${filename} STREQUAL "__cuda_device") set(opts -fc1 -xcuda) set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__cuda_builtins.mod) + elseif(${filename} STREQUAL "cudadevice") + set(opts -fc1 -xcuda) + set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__cuda_device.mod) else() set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_builtins.mod) if(${filename} STREQUAL "iso_fortran_env")