File tree Expand file tree Collapse file tree 6 files changed +38
-8
lines changed
Expand file tree Collapse file tree 6 files changed +38
-8
lines changed Original file line number Diff line number Diff line change 44cmake_minimum_required (VERSION 3.20.0 )
55set (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.
812if (APPLE OR WIN32 OR WASM)
913 message (WARNING "libomptarget cannot be built on Windows and MacOS X!" )
Original file line number Diff line number Diff line change @@ -3,7 +3,11 @@ add_target_library(omptarget.rtl.cuda CUDA)
33
44target_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+
711if (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 )
Original file line number Diff line number Diff line change 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+
3742using namespace llvm ::offload::debug;
3843using 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);
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ endif()
1616# char into the lit command.
1717string (REPLACE " " ";" LIBOMPTARGET_LIT_ARG_LIST "${LIBOMPTARGET_LIT_ARGS} " )
1818
19- find_package (CUDAToolkit QUIET )
19+ find_package (CUDAToolkit QUIET ${OFFLOAD_MIN_CUDA_VERSION} )
2020if (CUDAToolkit_FOUND)
2121 get_filename_component (CUDA_ROOT "${CUDAToolkit_BIN_DIR} " DIRECTORY ABSOLUTE )
2222 get_filename_component (CUDA_LIBDIR "${CUDA_cudart_static_LIBRARY} " DIRECTORY )
Original file line number Diff line number Diff 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 ()
Original file line number Diff line number Diff line change @@ -20,11 +20,12 @@ for those requirements.
2020### Requirements for Building with Nvidia GPU support
2121
2222The 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
You can’t perform that action at this time.
0 commit comments