diff --git a/hpvm/CMakeLists.txt b/hpvm/CMakeLists.txt index fcfaf264a64d52bfe13e0023fe92ad12b7cf2016..71e6de5999ad0127da5155d93fe3403c05cb3c7f 100644 --- a/hpvm/CMakeLists.txt +++ b/hpvm/CMakeLists.txt @@ -8,7 +8,13 @@ message(STATUS "CUDA Architecture: ${CMAKE_CUDA_ARCHITECTURES}") # find_package will use the auxillary cmake/Find*.cmake we provide list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake) find_package(CUDNN 7 EXACT REQUIRED) # CUDNN_INCLUDE_PATH, CUDNN_LIBRARY_DIR and CUDNN::cudnn -find_package(OpenCL REQUIRED) # Defines ${OpenCL_INCLUDE_DIRS} and ${OpenCL_LIBRARY} +find_package(OpenCL) # Defines ${OpenCL_INCLUDE_DIRS} and ${OpenCL_LIBRARY} +if(${OpenCL_FOUND}) + set(HPVM_USE_OPENCL 1) +else() + message(WARNING "OpenCL not found. --opencl flag of hpvm-clang will be unavailable for this build.") + set(HPVM_USE_OPENCL 0) +endif() include_directories(./include/) diff --git a/hpvm/projects/hpvm-rt/CMakeLists.txt b/hpvm/projects/hpvm-rt/CMakeLists.txt index 48cf16282661862a86a254b6e40097a830cc2d43..3147d00e892f8d89b71ebbe7e04aa0fa33210534 100644 --- a/hpvm/projects/hpvm-rt/CMakeLists.txt +++ b/hpvm/projects/hpvm-rt/CMakeLists.txt @@ -8,9 +8,13 @@ SET(CMAKE_CXX_STANDARD 11) # we want ${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/hpvm-rt.dir/hpvm-rt.cpp.o # which is a LLVM Bitcode file because of the -flto below. add_llvm_library(hpvm-rt hpvm-rt.cpp DEPENDS clang) -target_compile_options(hpvm-rt PUBLIC -flto) -target_include_directories(hpvm-rt PRIVATE ${OpenCL_INCLUDE_DIRS}) -target_link_directories(hpvm-rt PUBLIC ${OpenCL_LIBRARY}) +target_compile_options(hpvm-rt PUBLIC -flto -DHPVM_USE_OPENCL=${HPVM_USE_OPENCL}) +if(${HPVM_USE_OPENCL}) + target_include_directories(hpvm-rt PRIVATE ${OpenCL_INCLUDE_DIRS}) + target_link_directories(hpvm-rt PUBLIC ${OpenCL_LIBRARY}) +else() + message(STATUS "hpvm-rt.bc is not using OpenCL.") +endif() # Move and rename hpvm-rt.cpp.o to be an actual bc code add_custom_command( diff --git a/hpvm/tools/hpvm-clang/CMakeLists.txt b/hpvm/tools/hpvm-clang/CMakeLists.txt index 217bd39328788a41d7387105b312daf0c6133bb6..3564b00d0aa480996c152c1f027fa6fc39cd144c 100644 --- a/hpvm/tools/hpvm-clang/CMakeLists.txt +++ b/hpvm/tools/hpvm-clang/CMakeLists.txt @@ -8,7 +8,7 @@ # main.py.in requires the following variables: # LLVM_PROJECT_DIR, LLVM_BUILD_DIR # TRT_PATH, TRT_INCLUDE_DIRS, TRT_LINK_DIRS, TRT_LINK_LIBS -# DIRECT_LINK_LIBS +# DIRECT_LINK_LIBS, HPVM_USE_OPENCL (defined globally) # AVAILABLE_PASSES, HPVM_RT_PATH set(LLVM_PROJECT_DIR ${CMAKE_SOURCE_DIR}) @@ -18,9 +18,14 @@ get_target_property(TRT_INCLUDE_DIRS tensor_runtime INCLUDE_DIRECTORIES) get_target_property(TRT_LINK_DIRS tensor_runtime TRT_LINK_DIRS) get_target_property(TRT_LINK_LIBS tensor_runtime TRT_LINK_LIBS) -# This is defined globally. We need to manually link to this -# because OpenCL functions are injected by HPVM Passes. -set(DIRECT_LINK_LIBS ${OpenCL_LIBRARY} "$<TARGET_FILE:tensor_runtime>") +set(DIRECT_LINK_LIBS "$<TARGET_FILE:tensor_runtime>") +if(${HPVM_USE_OPENCL}) + # We need to link to OpenCL libs when hpvm uses opencl + # because OpenCL functions may be injected by the OpenCL pass. + list(APPEND DIRECT_LINK_LIBS ${OpenCL_LIBRARY}) +else() + message(STATUS "hpvm-clang is not using OpenCL (--opencl flag not available).") +endif() # The hpvm-rt runtime # This has to be explicitly set as hpvm-rt.bc is created in a custom_target diff --git a/hpvm/tools/hpvm-clang/main.py.in b/hpvm/tools/hpvm-clang/main.py.in index d37f293789787fbe81e5369543d99de97cb989ac..e2bc5cbafa23bd64094a3198ad8466f682f6bbdc 100644 --- a/hpvm/tools/hpvm-clang/main.py.in +++ b/hpvm/tools/hpvm-clang/main.py.in @@ -14,6 +14,7 @@ TRT_INCLUDE_DIRS = "@TRT_INCLUDE_DIRS@".split(";") TRT_LINK_DIRS = [Path(s) for s in "@TRT_LINK_DIRS@".split(";")] TRT_LINK_LIBS = "@TRT_LINK_LIBS@".split(";") DIRECT_LINK_LIBS = "@DIRECT_LINK_LIBS@".split(";") +HPVM_USE_OPENCL = int("@HPVM_USE_OPENCL@") AVAILABLE_PASSES = "@AVAILABLE_PASSES@".split(";") HPVM_RT_PATH = "@HPVM_RT_PATH@" @@ -254,6 +255,8 @@ See option -b for that.""" args.is_cpp = True else: parser.error(f"Language mode {args.x} not supported yet -- only c or c++") + if not HPVM_USE_OPENCL and args.opencl: + parser.error(f"OpenCL is disabled for this build of HPVM.") return args