• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1set(LLVM_OPTIONAL_SOURCES
2  cuda-runtime-wrappers.cpp
3  mlir-cuda-runner.cpp
4  )
5set(LLVM_LINK_COMPONENTS
6  Core
7  Support
8)
9
10if(MLIR_CUDA_RUNNER_ENABLED)
11  if (NOT ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD))
12    message(SEND_ERROR
13      "Building the mlir cuda runner requires the NVPTX backend")
14  endif()
15
16  # Configure CUDA runner support. Using check_language first allows us to give
17  # a custom error message.
18  include(CheckLanguage)
19  check_language(CUDA)
20  if (CMAKE_CUDA_COMPILER)
21    enable_language(CUDA)
22  else()
23    message(SEND_ERROR
24      "Building the mlir cuda runner requires a working CUDA install")
25  endif()
26
27  # We need the libcuda.so library.
28  find_library(CUDA_RUNTIME_LIBRARY cuda)
29
30  add_llvm_library(cuda-runtime-wrappers SHARED
31    cuda-runtime-wrappers.cpp
32  )
33  target_include_directories(cuda-runtime-wrappers
34    PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
35    LLVMSupport
36  )
37  target_link_libraries(cuda-runtime-wrappers
38    PUBLIC
39    LLVMSupport
40    ${CUDA_RUNTIME_LIBRARY}
41  )
42
43  get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
44  get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)
45  set(LIBS
46    ${dialect_libs}
47    ${conversion_libs}
48    MLIRJitRunner
49    MLIRAnalysis
50    MLIREDSC
51    MLIRExecutionEngine
52    MLIRIR
53    MLIRParser
54    MLIRSupport
55    MLIRTargetLLVMIR
56    MLIRTargetNVVMIR
57    MLIRTransforms
58    MLIRTranslation
59    ${CUDA_RUNTIME_LIBRARY}
60  )
61
62  # Manually expand the target library, since our MLIR libraries
63  # aren't plugged into the LLVM dependency tracking. If we don't
64  # do this then we can't insert the CodeGen library after ourselves
65  llvm_expand_pseudo_components(TARGET_LIBS AllTargetsCodeGens)
66  # Prepend LLVM in front of every target, this is how the library
67  # are named with CMake
68  SET(targets_to_link)
69  FOREACH(t ${TARGET_LIBS})
70    LIST(APPEND targets_to_link "LLVM${t}")
71  ENDFOREACH(t)
72
73  add_llvm_tool(mlir-cuda-runner
74    mlir-cuda-runner.cpp
75
76    DEPENDS
77    cuda-runtime-wrappers
78    )
79  target_include_directories(mlir-cuda-runner
80    PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
81  )
82  llvm_update_compile_flags(mlir-cuda-runner)
83  target_link_libraries(mlir-cuda-runner PRIVATE ${LIBS} ${targets_to_link})
84
85endif()
86