Skip to content

Commit c701c18

Browse files
authored
[flang][cuda] Move interface to __cuda_device (#122771)
1 parent ba4dc5a commit c701c18

File tree

4 files changed

+41
-18
lines changed

4 files changed

+41
-18
lines changed

flang/lib/Semantics/resolve-names.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4015,7 +4015,9 @@ bool SubprogramVisitor::Pre(const parser::PrefixSpec::Attributes &attrs) {
40154015
*attrs == common::CUDASubprogramAttrs::Device) {
40164016
const Scope &scope{currScope()};
40174017
const Scope *mod{FindModuleContaining(scope)};
4018-
if (mod && mod->GetName().value() == "cudadevice") {
4018+
if (mod &&
4019+
(mod->GetName().value() == "cudadevice" ||
4020+
mod->GetName().value() == "__cuda_device")) {
40194021
return false;
40204022
}
40214023
// Implicitly USE the cudadevice module by copying its symbols in the

flang/module/__cuda_device.f90

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
!===-- module/__cuda_device.f90 --------------------------------------------===!
2+
!
3+
! Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4+
! See https://llvm.org/LICENSE.txt for license information.
5+
! SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6+
!
7+
!===------------------------------------------------------------------------===!
8+
9+
! This module contains CUDA Fortran interfaces used in cudadevice.f90.
10+
11+
module __cuda_device
12+
implicit none
13+
14+
! Set PRIVATE by default to explicitly only export what is meant
15+
! to be exported by this MODULE.
16+
17+
interface
18+
attributes(device) function __fadd_rd(x, y) bind(c, name='__nv_fadd_rd')
19+
real, intent(in), value :: x, y
20+
real :: __fadd_rd
21+
end function
22+
end interface
23+
public :: __fadd_rd
24+
25+
interface
26+
attributes(device) function __fadd_ru(x, y) bind(c, name='__nv_fadd_ru')
27+
real, intent(in), value :: x, y
28+
real :: __fadd_ru
29+
end function
30+
end interface
31+
public :: __fadd_ru
32+
end module

flang/module/cudadevice.f90

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
! CUDA Fortran procedures available in device subprogram
1010

1111
module cudadevice
12+
use __cuda_device, only: __fadd_rd, __fadd_ru
1213
implicit none
1314

1415
! Set PRIVATE by default to explicitly only export what is meant
@@ -71,20 +72,4 @@ attributes(device) subroutine threadfence_system()
7172
end interface
7273
public :: threadfence_system
7374

74-
interface
75-
attributes(device) function __fadd_rd(x, y) bind(c, name='__nv_fadd_rd')
76-
real, intent(in) :: x, y
77-
real :: __fadd_rd
78-
end function
79-
end interface
80-
public :: __fadd_rd
81-
82-
interface
83-
attributes(device) function __fadd_ru(x, y) bind(c, name='__nv_fadd_ru')
84-
real, intent(in) :: x, y
85-
real :: __fadd_ru
86-
end function
87-
end interface
88-
public :: __fadd_ru
89-
9075
end module

flang/tools/f18/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set(MODULES_WITHOUT_IMPLEMENTATION
2121
"__ppc_intrinsics"
2222
"mma"
2323
"__cuda_builtins"
24+
"__cuda_device"
2425
"cudadevice"
2526
"ieee_arithmetic"
2627
"ieee_exceptions"
@@ -67,9 +68,12 @@ if (NOT CMAKE_CROSSCOMPILING)
6768
elseif(${filename} STREQUAL "__ppc_intrinsics" OR
6869
${filename} STREQUAL "mma")
6970
set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__ppc_types.mod)
70-
elseif(${filename} STREQUAL "cudadevice")
71+
elseif(${filename} STREQUAL "__cuda_device")
7172
set(opts -fc1 -xcuda)
7273
set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__cuda_builtins.mod)
74+
elseif(${filename} STREQUAL "cudadevice")
75+
set(opts -fc1 -xcuda)
76+
set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__cuda_device.mod)
7377
else()
7478
set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_builtins.mod)
7579
if(${filename} STREQUAL "iso_fortran_env")

0 commit comments

Comments
 (0)