Skip to content
Snippets Groups Projects
Commit 11c39759 authored by Yifan Zhao's avatar Yifan Zhao
Browse files

Make OpenCL requirements optional

parent 6032f36b
No related branches found
No related tags found
No related merge requests found
......@@ -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/)
......
......@@ -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(
......
......@@ -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
......
......@@ -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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment