Skip to content

Commit

Permalink
making cuda optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Gysi committed Jun 10, 2020
1 parent e68f6e7 commit 094f793
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
30 changes: 20 additions & 10 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,18 +1,9 @@
cmake_minimum_required(VERSION 3.10)



project(oec-opt LANGUAGES CXX C)
include(CheckLanguage)

check_language(CUDA)
if (CMAKE_CUDA_COMPILER)
enable_language(CUDA)
else()
message(SEND_ERROR
"Building the GPU lowering of oec-opt requires CUDA")
endif()
find_library(CUDA_RUNTIME_LIBRARY cuda)
set(CMAKE_CXX_STANDARD 14 CACHE STRING "C++ standard to conform to")

# setup llvm lit
set(LLVM_LIT_ARGS "-sv" CACHE STRING "lit default options")
Expand Down Expand Up @@ -40,6 +31,25 @@ include_directories(${PROJECT_BINARY_DIR}/include)
link_directories(${LLVM_BUILD_LIBRARY_DIR})
add_definitions(${LLVM_DEFINITIONS})

set(OEC_CUDA_BACKEND_ENABLED 1 CACHE BOOL "Enable building the oec CUDA backend")
if(OEC_CUDA_BACKEND_ENABLED)
add_definitions(-DOEC_CUDA_BACKEND_ENABLED)
endif()

if (OEC_CUDA_BACKEND_ENABLED)
if (NOT ("NVPTX" IN_LIST LLVM_TARGETS_TO_BUILD))
message(SEND_ERROR "Building the oec CUDA backend requires NVPTX")
endif()

check_language(CUDA)
if (CMAKE_CUDA_COMPILER)
enable_language(CUDA)
else()
message(SEND_ERROR "Building the oec CUDA backend requires CUDA")
endif()
find_library(CUDA_RUNTIME_LIBRARY cuda)
endif()

add_subdirectory(include)
add_subdirectory(lib)
add_subdirectory(test)
Expand Down
31 changes: 14 additions & 17 deletions lib/Conversion/LoopsToCUDA/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
set(NVPTX_LIB
NVPTXCodeGen
NVPTXDesc
NVPTXInfo
)
#set(AMDGPU_LIBS
# AMDGPUCodeGen
# AMDGPUDesc
# AMDGPUInfo
#)
if(OEC_CUDA_BACKEND_ENABLED)
set(NVPTX_LIB
NVPTXCodeGen
NVPTXDesc
NVPTXInfo
)
set(NVVMIR_LIB
MLIRNVVMIR
MLIRTargetNVVMIR
)
endif()

add_mlir_dialect_library(GPUtoCUDATransforms
add_mlir_dialect_library(GPUToKernelAndRuntimeCalls
ConvertLaunchFuncToCUDACalls.cpp
ConvertKernelFuncToCubin.cpp
StencilLoopMappingPass.cpp
Expand All @@ -21,16 +22,12 @@ add_mlir_dialect_library(GPUtoCUDATransforms
Core
MC
${NVPTX_LIBS}
#${AMDGPU_LIBS}

LINK_LIBS PUBLIC
MLIRNVVMIR
MLIRTargetNVVMIR
#MLIRROCDLIR
#MLIRTargetROCDLIR
${NVVMIR_LIB}

DEPENDS
MLIRLoopsToCUDAPassIncGen
)

target_link_libraries(GPUtoCUDATransforms PUBLIC MLIRIR)
target_link_libraries(GPUToKernelAndRuntimeCalls PUBLIC MLIRIR)
2 changes: 2 additions & 0 deletions lib/Conversion/LoopsToCUDA/ConvertKernelFuncToCubin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "mlir/Transforms/Passes.h"
#include "llvm/Support/TargetSelect.h"

#ifdef OEC_CUDA_BACKEND_ENABLED
#include "cuda.h"

using namespace mlir;
Expand Down Expand Up @@ -115,3 +116,4 @@ void registerGPUToCUBINPipeline() {
});
}
} // namespace mlir
#endif
4 changes: 3 additions & 1 deletion oec-opt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS)
get_property(conversion_libs GLOBAL PROPERTY MLIR_CONVERSION_LIBS)

set(LIBS
${dialect_libs}
${conversion_libs}
MLIROptLib

Stencil
StencilToStandard
GPUtoCUDATransforms
GPUToKernelAndRuntimeCalls
${CUDA_RUNTIME_LIBRARY}
)

add_llvm_executable(oec-opt oec-opt.cpp)

llvm_update_compile_flags(oec-opt)
Expand Down
2 changes: 2 additions & 0 deletions oec-opt/oec-opt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ int main(int argc, char **argv) {
registerDialect<stencil::StencilDialect>();

// Register the stencil pipelines
#ifdef OEC_CUDA_BACKEND_ENABLED
registerGPUToCUBINPipeline();
#endif

// Register the stencil passes
createShapeInferencePass();
Expand Down

0 comments on commit 094f793

Please sign in to comment.