Skip to content

Commit ab1ee91

Browse files
authored
[flang][cuda] Remove the need of special compile definition for CUFInit (#124965)
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.
1 parent 15ab7be commit ab1ee91

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

flang/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,6 @@ option(FLANG_CUF_RUNTIME
475475
"Compile CUDA Fortran runtime sources" OFF)
476476
if (FLANG_CUF_RUNTIME)
477477
find_package(CUDAToolkit REQUIRED)
478-
add_compile_definitions(FLANG_CUDA_SUPPORT=1)
479478
endif()
480479

481480
add_subdirectory(include)

flang/include/flang/Runtime/CUDA/init.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#ifndef FORTRAN_RUNTIME_CUDA_INIT_H_
1010
#define FORTRAN_RUNTIME_CUDA_INIT_H_
1111

12-
#include "common.h"
1312
#include "flang/Runtime/entry-names.h"
1413

1514
extern "C" {

flang/lib/Optimizer/Builder/Runtime/Main.cpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@
1414
#include "flang/Optimizer/Builder/Runtime/RTBuilder.h"
1515
#include "flang/Optimizer/Dialect/FIROps.h"
1616
#include "flang/Optimizer/Dialect/FIRType.h"
17+
#include "flang/Runtime/CUDA/init.h"
1718
#include "flang/Runtime/main.h"
1819
#include "flang/Runtime/stop.h"
19-
#ifdef FLANG_CUDA_SUPPORT
20-
#include "flang/Runtime/CUDA/init.h"
21-
#endif
2220

2321
using namespace Fortran::runtime;
2422

@@ -66,13 +64,11 @@ void fir::runtime::genMain(
6664

6765
builder.create<fir::CallOp>(loc, startFn, args);
6866

69-
#ifdef FLANG_CUDA_SUPPORT
7067
if (initCuda) {
7168
auto initFn = builder.createFunction(
7269
loc, RTNAME_STRING(CUFInit), mlir::FunctionType::get(context, {}, {}));
7370
builder.create<fir::CallOp>(loc, initFn);
7471
}
75-
#endif
7672

7773
builder.create<fir::CallOp>(loc, qqMainFn);
7874
builder.create<fir::CallOp>(loc, stopFn);
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
! RUN: bbc -emit-fir -hlfir -fcuda %s -o - | FileCheck %s --check-prefixes=ALL,CUDA
2+
! RUN: bbc -emit-fir -hlfir %s -o - | FileCheck %s --check-prefixes=ALL,NOCUDA
3+
4+
program test_init
5+
6+
end
7+
8+
! ALL-LABEL: func.func @main
9+
! ALL: fir.call @_FortranAProgramStart
10+
! CUDA: fir.call @_FortranACUFInit() fastmath<contract> : () -> ()
11+
! NOCUDA-NOT: fir.call @_FortranACUFInit() fastmath<contract> : () -> ()

0 commit comments

Comments
 (0)