-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[flang][cuda] Remove the need of special compile definition for CUFInit #124965
Conversation
@llvm/pr-subscribers-flang-fir-hlfir Author: Valentin Clement (バレンタイン クレメン) (clementval) ChangesThis patch addresses post commit review comments from #124859. The extra compile definition is not necessary and goes against the effort to separate the runtimes from the flang compiler itself. The function declaration for A program compiled with cuda enabled but no cufruntime would just fail at link time as expected. Full diff: https://github.com/llvm/llvm-project/pull/124965.diff 4 Files Affected:
diff --git a/flang/CMakeLists.txt b/flang/CMakeLists.txt
index fb7ab4759ad37e..2e27bc2279ac47 100644
--- a/flang/CMakeLists.txt
+++ b/flang/CMakeLists.txt
@@ -475,7 +475,6 @@ option(FLANG_CUF_RUNTIME
"Compile CUDA Fortran runtime sources" OFF)
if (FLANG_CUF_RUNTIME)
find_package(CUDAToolkit REQUIRED)
- add_compile_definitions(FLANG_CUDA_SUPPORT=1)
endif()
add_subdirectory(include)
diff --git a/flang/include/flang/Runtime/CUDA/init.h b/flang/include/flang/Runtime/CUDA/init.h
index 24bc6838227208..d1c8fcbf7d5875 100644
--- a/flang/include/flang/Runtime/CUDA/init.h
+++ b/flang/include/flang/Runtime/CUDA/init.h
@@ -9,7 +9,6 @@
#ifndef FORTRAN_RUNTIME_CUDA_INIT_H_
#define FORTRAN_RUNTIME_CUDA_INIT_H_
-#include "common.h"
#include "flang/Runtime/entry-names.h"
extern "C" {
diff --git a/flang/lib/Optimizer/Builder/Runtime/Main.cpp b/flang/lib/Optimizer/Builder/Runtime/Main.cpp
index 5156fd54020777..973744837d378a 100644
--- a/flang/lib/Optimizer/Builder/Runtime/Main.cpp
+++ b/flang/lib/Optimizer/Builder/Runtime/Main.cpp
@@ -14,11 +14,9 @@
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
#include "flang/Optimizer/Dialect/FIROps.h"
#include "flang/Optimizer/Dialect/FIRType.h"
+#include "flang/Runtime/CUDA/init.h"
#include "flang/Runtime/main.h"
#include "flang/Runtime/stop.h"
-#ifdef FLANG_CUDA_SUPPORT
-#include "flang/Runtime/CUDA/init.h"
-#endif
using namespace Fortran::runtime;
@@ -66,13 +64,11 @@ void fir::runtime::genMain(
builder.create<fir::CallOp>(loc, startFn, args);
-#ifdef FLANG_CUDA_SUPPORT
if (initCuda) {
auto initFn = builder.createFunction(
loc, RTNAME_STRING(CUFInit), mlir::FunctionType::get(context, {}, {}));
builder.create<fir::CallOp>(loc, initFn);
}
-#endif
builder.create<fir::CallOp>(loc, qqMainFn);
builder.create<fir::CallOp>(loc, stopFn);
diff --git a/flang/test/Lower/CUDA/cuda-init.cuf b/flang/test/Lower/CUDA/cuda-init.cuf
new file mode 100644
index 00000000000000..71ec1e3f9df56d
--- /dev/null
+++ b/flang/test/Lower/CUDA/cuda-init.cuf
@@ -0,0 +1,11 @@
+! RUN: bbc -emit-fir -hlfir -fcuda %s -o - | FileCheck %s --check-prefixes=ALL,CUDA
+! RUN: bbc -emit-fir -hlfir %s -o - | FileCheck %s --check-prefixes=ALL,NOCUDA
+
+program test_init
+
+end
+
+! ALL-LABEL: func.func @main
+! ALL: fir.call @_FortranAProgramStart
+! CUDA: fir.call @_FortranACUFInit() fastmath<contract> : () -> ()
+! NOCUDA-NOT: fir.call @_FortranACUFInit() fastmath<contract> : () -> ()
|
Please allow for the reviewers that had concerns to confirm whether they have been addressed. |
Is it addressed? |
Yes. I still think it would have been cleaner to revert first. Now if (FLANG_CUF_RUNTIME)
find_package(CUDAToolkit REQUIRED)
endif() has moved from line 484 to line 476 for no reason. |
I can move it back with an NFC if you prefer it to stay at the same place. |
Up to you, I already fixed the merge conflict. |
This patch addresses post commit review comments from #124859.
The extra compile definition is not necessary and goes against the effort to separate the runtimes from the flang compiler itself. The function declaration for
CUFInit
can be accessed anyway since the header are always present. The insertion of the call is only based on the language feature options from the folding context.A program compiled with cuda enabled but no cufruntime would just fail at link time as expected.