Commit fdeffd6f authored by Jon Chesterfield's avatar Jon Chesterfield
Browse files

[libomptarget][cuda] Only run tests when sure there is cuda available

[libomptarget][cuda] Only run tests when sure there is cuda available

Prior to D95155, building the cuda plugin implied cuda was installed locally.
With that change, every machine can build a cuda plugin, but they won't all have
cuda and/or an nvptx card installed locally.

This change enables the nvptx tests when either:
- libcuda is present
- the user has forced use of the dlopen stub

The default case when there is no cuda detected will no longer attempt to
run the tests on nvptx hardware, as was the case before D95155.

Reviewed By: jdoerfert, ronlieb

Differential Revision: https://reviews.llvm.org/D95467
parent ec8f4a38
Loading
Loading
Loading
Loading
+17 −4
Original line number Diff line number Diff line
@@ -24,10 +24,15 @@ add_definitions(-DTARGET_NAME=CUDA)

include_directories(${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIRS})

option(LIBOMPTARGET_DLOPEN_LIBCUDA "Build with dlopened libcuda" OFF)
set(LIBOMPTARGET_DLOPEN_LIBCUDA OFF)
option(LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA "Build with dlopened libcuda" ${LIBOMPTARGET_DLOPEN_LIBCUDA})

if (LIBOMPTARGET_DEP_CUDA_FOUND AND LIBOMPTARGET_DEP_CUDA_DRIVER_FOUND
      AND NOT LIBOMPTARGET_DLOPEN_LIBCUDA)
set(LIBOMPTARGET_CAN_LINK_LIBCUDA FALSE)
if (LIBOMPTARGET_DEP_CUDA_FOUND AND LIBOMPTARGET_DEP_CUDA_DRIVER_FOUND)
  set(LIBOMPTARGET_CAN_LINK_LIBCUDA TRUE)
endif()

if (LIBOMPTARGET_CAN_LINK_LIBCUDA AND NOT LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA)
  libomptarget_say("Building CUDA plugin linked against libcuda")
  include_directories(${LIBOMPTARGET_DEP_CUDA_INCLUDE_DIRS})
  add_library(omptarget.rtl.cuda SHARED src/rtl.cpp)
@@ -51,4 +56,12 @@ target_link_libraries(omptarget.rtl.cuda
  "-Wl,-z,defs")

# Report to the parent scope that we are building a plugin for CUDA.
# This controls whether tests are run for the nvptx offloading target
# Run them if libcuda is available, or if the user explicitly asked for dlopen
# Otherwise this plugin is being built speculatively and there may be no cuda available
if (LIBOMPTARGET_CAN_LINK_LIBCUDA OR LIBOMPTARGET_FORCE_DLOPEN_LIBCUDA)
  libomptarget_say("Enable tests using CUDA plugin")
  set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS} nvptx64-nvidia-cuda" PARENT_SCOPE)
else()
  libomptarget_say("Disabling tests using CUDA plugin as cuda may not be available")
endif()