Skip to content

Commit d91ea5f

Browse files
committed
Add -lcudart for CUDA mode
1 parent 4ef7508 commit d91ea5f

File tree

5 files changed

+36
-40
lines changed

5 files changed

+36
-40
lines changed

flang-rt/test/Driver/ctofortran.f90

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
! UNSUPPORTED: system-windows
2+
23
! RUN: split-file %s %t
3-
! RUN: chmod +x %t/runtest.sh
4-
! RUN: %t/runtest.sh %t %t/ffile.f90 %t/cfile.c %flang %libdir | FileCheck %s
4+
! RUN: %clang -c %t/cfile.c -o %t/cfile.o
5+
! RUN: %flang -L"%libdir" %deplibs %t/ffile.f90 %t/cfile.o -o %t/ctofortran
6+
! RUN: env LD_LIBRARY_PATH="$LD_LIBRARY_PATH:%libdir" %t/ctofortran | FileCheck %s
57

68
!--- ffile.f90
79
program fmain
@@ -65,24 +67,3 @@ end subroutine foo
6567
foo(desc);
6668
return;
6769
}
68-
!--- runtest.sh
69-
#!/bin/bash
70-
TMPDIR=$1
71-
FFILE=$2
72-
CFILE=$3
73-
FLANG=$4
74-
LIBDIR=$5
75-
shift 5
76-
FLAGS="$*"
77-
BINDIR=`dirname $FLANG`
78-
CCOMP=$BINDIR/clang
79-
if [ -x $CCOMP ]
80-
then
81-
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$LIBDIR
82-
$CCOMP $FLAGS -c $CFILE -o $TMPDIR/cfile.o
83-
$FLANG $FLAGS $FFILE $TMPDIR/cfile.o -o $TMPDIR/ctofortran -L"${LIBDIR}"
84-
$TMPDIR/ctofortran # should print "PASS"
85-
else
86-
# No clang compiler, just pass by default
87-
echo "PASS"
88-
fi

flang-rt/test/Driver/exec.f90

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
! Verify that flang can correctly build executables.
22

3-
! RUN: %flang -L"%libdir" %s -o %t
3+
! RUN: %flang -L"%libdir" %s %deplibs -o %t
44
! RUN: env LD_LIBRARY_PATH="$LD_LIBRARY_PATH:%libdir" %t | FileCheck %s
55
! RUN: rm -f %t
66

flang-rt/test/Runtime/no-cpp-dep.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,9 @@ a C compiler.
55
66
UNSUPPORTED: system-windows
77
8-
FIXME: This currently fails with CUDA-enabled flang-rt because it needs
9-
to link libcudart.
10-
118
RUN: %if system-aix %{ export OBJECT_MODE=64 %}
12-
RUN: %cc -std=c99 %s -I%include %libruntime -lm \
9+
RUN: %cc -std=c99 %s -I%include %libruntime -lm %deplibs \
1310
RUN: %if system-aix %{-lpthread %}
14-
RUN: rm a.out
1511
*/
1612

1713
#include "flang/Runtime/entry-names.h"

flang-rt/test/lit.cfg.py

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
# -*- Python -*-
22

3+
import shlex
34
import lit.util
45

56
from lit.llvm import llvm_config
67
from lit.llvm.subst import ToolSubst, FindTool
78

9+
def shjoin(args, sep=' '):
10+
return sep.join([shlex.quote(arg) for arg in args])
11+
812
# Configuration file for the 'lit' test runner.
913

1014
# name: The name of this test suite.
@@ -67,22 +71,36 @@
6771
command=FindTool("flang"),
6872
extra_args=isysroot_flag,
6973
unresolved="fatal",
70-
)
74+
),
75+
ToolSubst(
76+
"%clang",
77+
command=FindTool("clang"),
78+
extra_args=isysroot_flag,
79+
unresolved="fatal",
80+
),
81+
ToolSubst("%cc",
82+
command=config.cc,
83+
extra_args=isysroot_flag,
84+
unresolved="fatal"
85+
),
7186
]
87+
llvm_config.add_tool_substitutions(tools)
7288

73-
tools.append(ToolSubst("%libdir", command=config.flangrt_build_lib_dir, unresolved="fatal"))
89+
# Let tests find LLVM's standard tools (FileCheck, split-file, not, ...)
90+
llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)
91+
92+
# Library path of libflang_rt.a
93+
config.substitutions.append(("%libdir", config.flangrt_build_lib_dir))
7494

7595
# Define some variables to help us test that the flang runtime doesn't depend on
7696
# the C++ runtime libraries. For this we need a C compiler.
7797
libruntime = os.path.join(config.flangrt_build_lib_dir, "libflang_rt.a")
7898
include = os.path.join(config.flang_source_dir, "include")
79-
tools.append(
80-
ToolSubst("%cc", command=config.cc, extra_args=isysroot_flag, unresolved="fatal")
81-
)
82-
tools.append(ToolSubst("%libruntime", command=libruntime, unresolved="fatal"))
83-
tools.append(ToolSubst("%include", command=include, unresolved="fatal"))
84-
85-
# Let tests find LLVM's standard tools (FileCheck, split-file, not, ...)
86-
llvm_config.with_environment("PATH", config.llvm_tools_dir, append_path=True)
99+
config.substitutions.append(("%libruntime", libruntime))
100+
config.substitutions.append(("%include", include))
87101

88-
llvm_config.add_tool_substitutions(tools)
102+
# Additional library depedendencies the that flang driver does not add itself.
103+
deplibs = []
104+
if config.flangrt_experimental_offload_support == "CUDA":
105+
deplibs.append('-lcudart')
106+
config.substitutions.append(("%deplibs", shjoin(deplibs)))

flang-rt/test/lit.site.cfg.py.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ config.flang_source_dir = "@FLANG_SOURCE_DIR@"
77
config.flangrt_source_dir = "@FLANG_RT_SOURCE_DIR@"
88
config.flangrt_binary_test_dir = os.path.dirname(__file__)
99
config.flangrt_build_lib_dir = "@FLANG_RT_BUILD_LIB_DIR@"
10+
config.flangrt_experimental_offload_support = "@FLANG_RT_EXPERIMENTAL_OFFLOAD_SUPPORT@"
1011
config.cc = "@CMAKE_C_COMPILER@"
1112
config.osx_sysroot = path(r"@CMAKE_OSX_SYSROOT@")
1213

0 commit comments

Comments
 (0)