Skip to content

Commit 18bed37

Browse files
authored
[offload][OpenMP] Require CUDA 11.8 (llvm#191100)
1 parent cf53623 commit 18bed37

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

offload/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
cmake_minimum_required(VERSION 3.20.0)
55
set(LLVM_SUBPROJECT_TITLE "liboffload")
66

7+
# The minimum versions required for dependencies.
8+
set(OFFLOAD_MIN_CUDA_VERSION 11.8.0)
9+
set(OFFLOAD_MIN_CUDA_VERSION_CODE 11080)
10+
711
# Check that the library can actually be built.
812
if(APPLE OR WIN32 OR WASM)
913
message(WARNING "libomptarget cannot be built on Windows and MacOS X!")

offload/plugins-nextgen/cuda/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ add_target_library(omptarget.rtl.cuda CUDA)
33

44
target_sources(omptarget.rtl.cuda PRIVATE src/rtl.cpp)
55

6-
find_package(CUDAToolkit QUIET)
6+
# Define the minimum CUDA version required by offload.
7+
target_compile_definitions(omptarget.rtl.cuda PRIVATE OFFLOAD_MIN_CUDA_VERSION=${OFFLOAD_MIN_CUDA_VERSION_CODE})
8+
9+
find_package(CUDAToolkit QUIET ${OFFLOAD_MIN_CUDA_VERSION})
10+
711
if(CUDAToolkit_FOUND AND NOT "cuda" IN_LIST LIBOMPTARGET_DLOPEN_PLUGINS)
812
message(STATUS "Building CUDA plugin linked against libcuda")
913
target_link_libraries(omptarget.rtl.cuda PRIVATE CUDA::cuda_driver)

offload/plugins-nextgen/cuda/src/rtl.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@
3434
#include "llvm/Support/FileSystem.h"
3535
#include "llvm/Support/Program.h"
3636

37+
// This macro should be defined by the build system.
38+
#ifndef OFFLOAD_MIN_CUDA_VERSION
39+
#error "Missing OFFLOAD_MIN_CUDA_VERSION macro"
40+
#endif
41+
3742
using namespace llvm::offload::debug;
3843
using namespace error;
3944

@@ -1594,6 +1599,22 @@ struct CUDAPluginTy final : public GenericPluginTy {
15941599
if (auto Err = Plugin::check(Res, "error in cuInit: %s"))
15951600
return std::move(Err);
15961601

1602+
// Get the latest CUDA version supported by the driver.
1603+
int Version;
1604+
Res = cuDriverGetVersion(&Version);
1605+
if (auto Err = Plugin::check(Res, "error in cuDriverGetVersion: %s"))
1606+
return std::move(Err);
1607+
1608+
// Verify that the driver supports the minimum CUDA version required.
1609+
constexpr int MinVersion = OFFLOAD_MIN_CUDA_VERSION;
1610+
if (Version < MinVersion) {
1611+
ODBG(OLDT_Init) << "Minimum CUDA version not supported by the driver.";
1612+
return Plugin::error(
1613+
ErrorCode::UNSUPPORTED,
1614+
"CUDA driver does not support minimum CUDA version %d (%d detected)",
1615+
MinVersion, Version);
1616+
}
1617+
15971618
// Get the number of devices.
15981619
int NumDevices;
15991620
Res = cuDeviceGetCount(&NumDevices);

offload/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ endif()
1616
# char into the lit command.
1717
string(REPLACE " " ";" LIBOMPTARGET_LIT_ARG_LIST "${LIBOMPTARGET_LIT_ARGS}")
1818

19-
find_package(CUDAToolkit QUIET)
19+
find_package(CUDAToolkit QUIET ${OFFLOAD_MIN_CUDA_VERSION})
2020
if(CUDAToolkit_FOUND)
2121
get_filename_component(CUDA_ROOT "${CUDAToolkit_BIN_DIR}" DIRECTORY ABSOLUTE)
2222
get_filename_component(CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY}" DIRECTORY)

offload/unittests/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ function(add_offload_test_device_code test_filename test_name)
2626

2727
# Try to build with support for NVPTX devices.
2828
if("cuda" IN_LIST LIBOMPTARGET_PLUGINS_TO_BUILD)
29-
find_package(CUDAToolkit QUIET)
29+
find_package(CUDAToolkit QUIET ${OFFLOAD_MIN_CUDA_VERSION})
3030
if(CUDAToolkit_FOUND)
3131
get_filename_component(cuda_path "${CUDAToolkit_BIN_DIR}" DIRECTORY ABSOLUTE)
3232
endif()

openmp/docs/Building.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ for those requirements.
2020
### Requirements for Building with Nvidia GPU support
2121

2222
The CUDA SDK is required on the machine that will build and execute the
23-
offloading application. Normally this is only required at runtime by dynamically
24-
opening the CUDA driver API. This can be disabled in the build by omitting
25-
`cuda` from the [`LIBOMPTARGET_DLOPEN_PLUGINS`](LIBOMPTARGET_DLOPEN_PLUGINS)
26-
list which is present by default. With this setting we will instead find the
27-
CUDA library at LLVM build time and link against it directly.
23+
offloading application. The CUDA driver must support CUDA 11.8.0 or later.
24+
Normally this is only required at runtime when the CUDA driver API is
25+
dynamically opened. This can be disabled in the build by omitting `cuda` from
26+
the [`LIBOMPTARGET_DLOPEN_PLUGINS`](LIBOMPTARGET_DLOPEN_PLUGINS) list which is
27+
present by default. With this setting we will instead find the CUDA library at
28+
LLVM build time and link against it directly.
2829

2930

3031
### Requirements for Building with AMD GPU support

0 commit comments

Comments
 (0)