Skip to content

[flang][cuda] Move interface to __cuda_device #122771

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

Merged
merged 2 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion flang/lib/Semantics/resolve-names.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 32 additions & 0 deletions flang/module/__cuda_device.f90
Original file line number Diff line number Diff line change
@@ -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
17 changes: 1 addition & 16 deletions flang/module/cudadevice.f90
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -71,20 +72,4 @@ 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, 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
6 changes: 5 additions & 1 deletion flang/tools/f18/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ set(MODULES_WITHOUT_IMPLEMENTATION
"__ppc_intrinsics"
"mma"
"__cuda_builtins"
"__cuda_device"
"cudadevice"
"ieee_arithmetic"
"ieee_exceptions"
Expand Down Expand Up @@ -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")
Expand Down
Loading