[flang-commits] [flang] Revert "[flang][cuda] Implicitly load cudadevice module in device/global subprogram" (PR #91827)
Valentin Clement バレンタイン クレメン via flang-commits
flang-commits at lists.llvm.org
Fri May 10 17:44:13 PDT 2024
https://github.com/clementval created https://github.com/llvm/llvm-project/pull/91827
Reverts llvm/llvm-project#91668
>From 0f59bd6878dd97db4210ccfd9dd193ddfe7a50c6 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?= <clementval at gmail.com>
Date: Fri, 10 May 2024 17:43:59 -0700
Subject: [PATCH] =?UTF-8?q?Revert=20"[flang][cuda]=20Implicitly=20load=20c?=
=?UTF-8?q?udadevice=20module=20in=20device/global=20subp=E2=80=A6"?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
This reverts commit f32f6d199ac36e0c45433a648691f5165893deec.
---
flang/include/flang/Semantics/semantics.h | 5 +-
flang/lib/Semantics/check-cuda.cpp | 5 --
flang/lib/Semantics/resolve-names.cpp | 13 ----
flang/lib/Semantics/semantics.cpp | 8 --
flang/module/__cuda_device_builtins.f90 | 74 -------------------
flang/module/cudadevice.f90 | 21 ------
.../Semantics/cuf-device-procedures01.cuf | 35 ---------
.../Semantics/cuf-device-procedures02.cuf | 17 -----
flang/tools/f18/CMakeLists.txt | 4 -
9 files changed, 1 insertion(+), 181 deletions(-)
delete mode 100644 flang/module/__cuda_device_builtins.f90
delete mode 100644 flang/module/cudadevice.f90
delete mode 100644 flang/test/Semantics/cuf-device-procedures01.cuf
delete mode 100644 flang/test/Semantics/cuf-device-procedures02.cuf
diff --git a/flang/include/flang/Semantics/semantics.h b/flang/include/flang/Semantics/semantics.h
index 167e613816394..e6ba71d53e92b 100644
--- a/flang/include/flang/Semantics/semantics.h
+++ b/flang/include/flang/Semantics/semantics.h
@@ -215,10 +215,8 @@ class SemanticsContext {
void UseFortranBuiltinsModule();
const Scope *GetBuiltinsScope() const { return builtinsScope_; }
- const Scope &GetCUDABuiltinsScope();
- const Scope &GetCUDADeviceScope();
-
void UsePPCBuiltinTypesModule();
+ const Scope &GetCUDABuiltinsScope();
void UsePPCBuiltinsModule();
Scope *GetPPCBuiltinTypesScope() { return ppcBuiltinTypesScope_; }
const Scope *GetPPCBuiltinsScope() const { return ppcBuiltinsScope_; }
@@ -294,7 +292,6 @@ class SemanticsContext {
const Scope *builtinsScope_{nullptr}; // module __Fortran_builtins
Scope *ppcBuiltinTypesScope_{nullptr}; // module __Fortran_PPC_types
std::optional<const Scope *> cudaBuiltinsScope_; // module __CUDA_builtins
- std::optional<const Scope *> cudaDeviceScope_; // module cudadevice
const Scope *ppcBuiltinsScope_{nullptr}; // module __ppc_intrinsics
std::list<parser::Program> modFileParseTrees_;
std::unique_ptr<CommonBlockMap> commonBlockMap_;
diff --git a/flang/lib/Semantics/check-cuda.cpp b/flang/lib/Semantics/check-cuda.cpp
index 2830d5f0be6ea..96ab902392633 100644
--- a/flang/lib/Semantics/check-cuda.cpp
+++ b/flang/lib/Semantics/check-cuda.cpp
@@ -82,11 +82,6 @@ struct DeviceExprChecker
}
}
}
- if (sym->owner().IsModule() &&
- sym->owner().parent().IsIntrinsicModules() &&
- DEREF(sym->owner().symbol()).name() == "__cuda_device_builtins") {
- return {};
- }
} else if (x.GetSpecificIntrinsic()) {
// TODO(CUDA): Check for unsupported intrinsics here
return {};
diff --git a/flang/lib/Semantics/resolve-names.cpp b/flang/lib/Semantics/resolve-names.cpp
index 7cb0c6af937cc..e2875081b732c 100644
--- a/flang/lib/Semantics/resolve-names.cpp
+++ b/flang/lib/Semantics/resolve-names.cpp
@@ -3797,19 +3797,6 @@ bool SubprogramVisitor::Pre(const parser::PrefixSpec::Attributes &attrs) {
subp->set_cudaSubprogramAttrs(attr);
}
}
- if (auto attrs{subp->cudaSubprogramAttrs()}) {
- if (*attrs == common::CUDASubprogramAttrs::Global ||
- *attrs == common::CUDASubprogramAttrs::Device) {
- // Implicitly USE the cudadevice module by copying its symbols in the
- // current scope.
- const Scope &scope{context().GetCUDADeviceScope()};
- for (auto sym : scope.GetSymbols()) {
- if (!currScope().FindSymbol(sym->name())) {
- currScope().CopySymbol(sym);
- }
- }
- }
- }
}
return false;
}
diff --git a/flang/lib/Semantics/semantics.cpp b/flang/lib/Semantics/semantics.cpp
index d51cc62d804e8..6ccd915c4dcbf 100644
--- a/flang/lib/Semantics/semantics.cpp
+++ b/flang/lib/Semantics/semantics.cpp
@@ -543,14 +543,6 @@ const Scope &SemanticsContext::GetCUDABuiltinsScope() {
return **cudaBuiltinsScope_;
}
-const Scope &SemanticsContext::GetCUDADeviceScope() {
- if (!cudaDeviceScope_) {
- cudaDeviceScope_ = GetBuiltinModule("cudadevice");
- CHECK(cudaDeviceScope_.value() != nullptr);
- }
- return **cudaDeviceScope_;
-}
-
void SemanticsContext::UsePPCBuiltinsModule() {
if (ppcBuiltinsScope_ == nullptr) {
ppcBuiltinsScope_ = GetBuiltinModule("__ppc_intrinsics");
diff --git a/flang/module/__cuda_device_builtins.f90 b/flang/module/__cuda_device_builtins.f90
deleted file mode 100644
index 738dc97242f2b..0000000000000
--- a/flang/module/__cuda_device_builtins.f90
+++ /dev/null
@@ -1,74 +0,0 @@
-!===-- module/__cuda_device_builtins.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
-!
-!===------------------------------------------------------------------------===!
-
-! CUDA Fortran procedures available in device subprogram
-
-module __CUDA_device_builtins
-
- implicit none
-
- ! Set PRIVATE by default to explicitly only export what is meant
- ! to be exported by this MODULE.
- private
-
- ! Synchronization Functions
-
- interface
- subroutine __cuda_device_builtins_syncthreads()
- end subroutine
- end interface
- public :: __cuda_device_builtins_syncthreads
-
- interface
- integer function __cuda_device_builtins_syncthreads_and(value)
- integer :: value
- end function
- end interface
- public :: __cuda_device_builtins_syncthreads_and
-
- interface
- integer function __cuda_device_builtins_syncthreads_count(value)
- integer :: value
- end function
- end interface
- public :: __cuda_device_builtins_syncthreads_count
-
- interface
- integer function __cuda_device_builtins_syncthreads_or(int_value)
- end function
- end interface
- public :: __cuda_device_builtins_syncthreads_or
-
- interface
- subroutine __cuda_device_builtins_syncwarp(mask)
- integer :: mask
- end subroutine
- end interface
- public :: __cuda_device_builtins_syncwarp
-
- ! Memory Fences
-
- interface
- subroutine __cuda_device_builtins_threadfence()
- end subroutine
- end interface
- public :: __cuda_device_builtins_threadfence
-
- interface
- subroutine __cuda_device_builtins_threadfence_block()
- end subroutine
- end interface
- public :: __cuda_device_builtins_threadfence_block
-
- interface
- subroutine __cuda_device_builtins_threadfence_system()
- end subroutine
- end interface
- public :: __cuda_device_builtins_threadfence_system
-
-end module
diff --git a/flang/module/cudadevice.f90 b/flang/module/cudadevice.f90
deleted file mode 100644
index b635d77ea4529..0000000000000
--- a/flang/module/cudadevice.f90
+++ /dev/null
@@ -1,21 +0,0 @@
-!===-- module/cudedevice.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
-!
-!===------------------------------------------------------------------------===!
-
-! CUDA Fortran procedures available in device subprogram
-
-module cudadevice
- use __cuda_device_builtins, only: &
- syncthreads => __cuda_device_builtins_syncthreads, &
- syncthreads_and => __cuda_device_builtins_syncthreads_and, &
- syncthreads_count => __cuda_device_builtins_syncthreads_count, &
- syncthreads_or => __cuda_device_builtins_syncthreads_or, &
- syncwarp => __cuda_device_builtins_syncwarp, &
- threadfence => __cuda_device_builtins_threadfence, &
- threadfence_block => __cuda_device_builtins_threadfence_block, &
- threadfence_system => __cuda_device_builtins_threadfence_system
-end module
diff --git a/flang/test/Semantics/cuf-device-procedures01.cuf b/flang/test/Semantics/cuf-device-procedures01.cuf
deleted file mode 100644
index e79423e3587a1..0000000000000
--- a/flang/test/Semantics/cuf-device-procedures01.cuf
+++ /dev/null
@@ -1,35 +0,0 @@
-! RUN: %flang_fc1 -fdebug-dump-symbols %s | FileCheck %s
-
-! Test CUDA Fortran intrinsic can pass semantic
-
-attributes(global) subroutine devsub()
- implicit none
- integer :: ret
-
- ! 3.6.4. Synchronization Functions
- call syncthreads()
- call syncwarp(1)
- call threadfence()
- call threadfence_block()
- call threadfence_system()
- ret = syncthreads_and(1)
- ret = syncthreads_count(1)
- ret = syncthreads_or(1)
-end
-
-! CHECK-LABEL: Subprogram scope: devsub
-! CHECK: syncthreads, EXTERNAL, PUBLIC (Subroutine): Use from __cuda_device_builtins_syncthreads in __cuda_device_builtins
-! CHECK: syncthreads_and, EXTERNAL, PUBLIC (Function): Use from __cuda_device_builtins_syncthreads_and in __cuda_device_builtins
-! CHECK: syncthreads_count, EXTERNAL, PUBLIC (Function): Use from __cuda_device_builtins_syncthreads_count in __cuda_device_builtins
-! CHECK: syncthreads_or, EXTERNAL, PUBLIC (Function): Use from __cuda_device_builtins_syncthreads_or in __cuda_device_builtins
-! CHECK: syncwarp, EXTERNAL, PUBLIC (Subroutine): Use from __cuda_device_builtins_syncwarp in __cuda_device_builtins
-! CHECK: threadfence, EXTERNAL, PUBLIC (Subroutine): Use from __cuda_device_builtins_threadfence in __cuda_device_builtins
-! CHECK: threadfence_block, EXTERNAL, PUBLIC (Subroutine): Use from __cuda_device_builtins_threadfence_block in __cuda_device_builtins
-! CHECK: threadfence_system, EXTERNAL, PUBLIC (Subroutine): Use from __cuda_device_builtins_threadfence_system in __cuda_device_builtins
-
-subroutine host()
- call syncthreads()
-end subroutine
-
-! CHECK-LABEL: Subprogram scope: host
-! CHECK: syncthreads, EXTERNAL: HostAssoc{{$}}
diff --git a/flang/test/Semantics/cuf-device-procedures02.cuf b/flang/test/Semantics/cuf-device-procedures02.cuf
deleted file mode 100644
index ea6a094ed5c38..0000000000000
--- a/flang/test/Semantics/cuf-device-procedures02.cuf
+++ /dev/null
@@ -1,17 +0,0 @@
-! RUN: %python %S/test_errors.py %s %flang_fc1
-
-module dev
- integer, device :: syncthreads
-
-contains
-
- attributes(device) subroutine sub1()
- syncthreads = 1 ! syncthreads not overwritten by cudadevice
- end subroutine
-
- attributes(global) subroutine sub2()
-!ERROR: 'threadfence' is use-associated from module '__cuda_device_builtins' and cannot be re-declared
- integer :: threadfence
- end subroutine
-end module
-
diff --git a/flang/tools/f18/CMakeLists.txt b/flang/tools/f18/CMakeLists.txt
index 0222654c8e5d8..64815a1f5da62 100644
--- a/flang/tools/f18/CMakeLists.txt
+++ b/flang/tools/f18/CMakeLists.txt
@@ -12,8 +12,6 @@ set(MODULES
"__ppc_intrinsics"
"mma"
"__cuda_builtins"
- "__cuda_device_builtins"
- "cudadevice"
"ieee_arithmetic"
"ieee_exceptions"
"ieee_features"
@@ -33,8 +31,6 @@ 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")
- set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__cuda_device_builtins.mod)
else()
set(depends ${FLANG_INTRINSIC_MODULES_DIR}/__fortran_builtins.mod)
if(NOT ${filename} STREQUAL "__fortran_type_info")
More information about the flang-commits
mailing list