1 ##===----------------------------------------------------------------------===##
3 # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 # See https://llvm.org/LICENSE.txt for license information.
5 # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 ##===----------------------------------------------------------------------===##
9 # Build a plugin for a CUDA machine if available.
11 ##===----------------------------------------------------------------------===##
12 set(LIBOMPTARGET_BUILD_CUDA_PLUGIN TRUE CACHE BOOL
13 "Whether to build CUDA plugin")
14 if (NOT LIBOMPTARGET_BUILD_CUDA_PLUGIN)
15 libomptarget_say("Not building CUDA NextGen offloading plugin: LIBOMPTARGET_BUILD_CUDA_PLUGIN is false")
19 if (NOT (CMAKE_SYSTEM_PROCESSOR MATCHES "(x86_64)|(ppc64le)|(aarch64)$" AND CMAKE_SYSTEM_NAME MATCHES "Linux"))
20 libomptarget_say("Not building CUDA NextGen offloading plugin: only support CUDA in Linux x86_64, ppc64le, or aarch64 hosts.")
24 libomptarget_say("Building CUDA NextGen offloading plugin.")
26 set(LIBOMPTARGET_DLOPEN_LIBCUDA OFF)
27 option(LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA "Build with dlopened libcuda" ${LIBOMPTARGET_DLOPEN_LIBCUDA})
29 add_llvm_library(omptarget.rtl.cuda SHARED
45 if ((OMPT_TARGET_DEFAULT) AND (LIBOMPTARGET_OMPT_SUPPORT))
46 target_link_libraries(omptarget.rtl.cuda PRIVATE OMPT)
49 if (LIBOMP_HAVE_VERSION_SCRIPT_FLAG)
50 target_link_libraries(omptarget.rtl.cuda PRIVATE
51 "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports,-z,defs")
55 if(LIBOMPTARGET_DEP_CUDA_FOUND AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA)
56 libomptarget_say("Building CUDA plugin linked against libcuda")
57 target_link_libraries(omptarget.rtl.cuda PRIVATE CUDA::cuda_driver)
59 libomptarget_say("Building CUDA plugin for dlopened libcuda")
60 target_include_directories(omptarget.rtl.cuda PRIVATE dynamic_cuda)
61 target_sources(omptarget.rtl.cuda PRIVATE dynamic_cuda/cuda.cpp)
64 # Define debug prefix. TODO: This should be automatized in the Debug.h but it
65 # requires changing the original plugins.
66 target_compile_definitions(omptarget.rtl.cuda PRIVATE TARGET_NAME="CUDA")
67 target_compile_definitions(omptarget.rtl.cuda PRIVATE DEBUG_PREFIX="TARGET CUDA RTL")
69 target_include_directories(omptarget.rtl.cuda PRIVATE ${LIBOMPTARGET_INCLUDE_DIR})
71 # Configure testing for the CUDA plugin. We will build tests if we could a
72 # functional NVIDIA GPU on the system, or if manually specifies by the user.
73 option(LIBOMPTARGET_FORCE_NVIDIA_TESTS "Build NVIDIA libomptarget tests" OFF)
74 if (LIBOMPTARGET_FOUND_NVIDIA_GPU OR LIBOMPTARGET_FORCE_NVIDIA_TESTS)
75 libomptarget_say("Enable tests using CUDA plugin")
76 set(LIBOMPTARGET_SYSTEM_TARGETS
77 "${LIBOMPTARGET_SYSTEM_TARGETS} nvptx64-nvidia-cuda nvptx64-nvidia-cuda-LTO" PARENT_SCOPE)
78 list(APPEND LIBOMPTARGET_TESTED_PLUGINS "omptarget.rtl.cuda")
79 set(LIBOMPTARGET_TESTED_PLUGINS "${LIBOMPTARGET_TESTED_PLUGINS}" PARENT_SCOPE)
81 libomptarget_say("Not generating NVIDIA tests, no supported devices detected."
82 " Use 'LIBOMPTARGET_FORCE_NVIDIA_TESTS' to override.")
85 # Install plugin under the lib destination folder.
86 install(TARGETS omptarget.rtl.cuda LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}")
87 set_target_properties(omptarget.rtl.cuda PROPERTIES
88 INSTALL_RPATH "$ORIGIN" BUILD_RPATH "$ORIGIN:${CMAKE_CURRENT_BINARY_DIR}/.."
89 CXX_VISIBILITY_PRESET protected)