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

Made hpvm a separate cmake project

parent 67fc68ec
No related branches found
No related tags found
No related merge requests found
include_directories(./include/)
cmake_minimum_required(VERSION 3.17)
project(hpvm CUDA CXX)
get_filename_component(
CUDA_TOOLKIT_ROOT_DIR "${CMAKE_CUDA_COMPILER}/../.." ABSOLUTE
) # Set CUDA_TOOLKIT_ROOT_DIR by our own, to the parent folder of cuda nvcc
# 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_PATH
include_directories(./include/)
# Generate TENSOR_RT_PREFIX into config.h
set(TENSOR_RT_PREFIX ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
......
......@@ -2,7 +2,7 @@ if(WIN32 OR CYGWIN)
set(LLVM_LINK_COMPONENTS Core Support)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_BUILD_DIR=${PROJECT_BINARY_DIR}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_BUILD_DIR=${CMAKE_BINARY_DIR}")
add_llvm_library( LLVMDFG2LLVM_CPU
MODULE
......
......@@ -2,7 +2,7 @@ if(WIN32 OR CYGWIN)
set(LLVM_LINK_COMPONENTS Core Support)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_BUILD_DIR=${PROJECT_BINARY_DIR}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_BUILD_DIR=${CMAKE_BINARY_DIR}")
add_llvm_library( LLVMDFG2LLVM_OpenCL
MODULE
......
......@@ -2,7 +2,7 @@ if(WIN32 OR CYGWIN)
set(LLVM_LINK_COMPONENTS Core Support)
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_BUILD_DIR=${PROJECT_BINARY_DIR}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DLLVM_BUILD_DIR=${CMAKE_BINARY_DIR}")
add_llvm_library( LLVMGenHPVM
MODULE
......
......@@ -10,7 +10,6 @@ foreach(entry ${entries})
(NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/parallel-libs) AND
(NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/openmp) AND
(NOT ${entry} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}/debuginfo-tests))
set(LLVM_BUILD_DIR ${PROJECT_BINARY_DIR})
get_filename_component(entry_name "${entry}" NAME)
add_llvm_external_project(${entry_name})
endif()
......
add_definitions(-DNUM_CORES=8)
SET(CMAKE_C_COMPILER ${CMAKE_BINARY_DIR}/bin/clang)
SET(CMAKE_CXX_COMPILER ${CMAKE_BINARY_DIR}/bin/clang++)
SET(CMAKE_C_COMPILER ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/clang)
SET(CMAKE_CXX_COMPILER ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/clang++)
SET(CMAKE_CXX_STANDARD 11)
# Defines ${OpenCL_INCLUDE_DIRS} and ${OpenCL_LIBRARY} if found
find_package(OpenCL REQUIRED)
......
cmake_minimum_required(VERSION 3.17)
project(hpvm-tensor-rt CUDA CXX)
set(CMAKE_CXX_STANDARD 14)
if(CMAKE_CURRENT_BINARY_DIR STREQUAL CMAKE_SOURCE_DIR) # This means we're NOT compiling in HPVM
set(INDEP_BUILD True)
message(STATUS "Compiling hpvm-tensor-rt independently")
else()
set(INDEP_BUILD False)
message(STATUS "Compiling hpvm-tensor-rt inside HPVM")
endif()
# -- Configure path configuration file
if(NOT EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/global_knobs.txt)
message(FATAL_ERROR "global_knobs.txt not found")
......@@ -15,7 +22,6 @@ configure_file(
)
# -- Default include directories
find_package(CUDNN 7 EXACT REQUIRED) # Include CUDNN_INCLUDE_PATH, then link CUDNN_LIBRARY_PATH
set(
INCLUDES
${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES}
......@@ -30,8 +36,7 @@ find_package(OpenMP REQUIRED) # Provides ${OpenMP_CXX_FLAGS}
# Configure gpu_profiler and soc_simulator, and setup all libs to link to
# Conditionally add gpu_profiler project if we're building independently
# (not building the whole hpvm)
if(NOT LLVM_BUILD_DIR) # Defined in ../CMakeLists.txt. This means we're compiling in LLVM
message(STATUS "Compiling hpvm-tensor-rt independently")
if(INDEP_BUILD)
message(STATUS "Also compiling gpu_profiler and soc_simulator")
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../gpu_profiler ${CMAKE_CURRENT_BINARY_DIR}/gpu_profiler)
add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../soc_simulator ${CMAKE_CURRENT_BINARY_DIR}/soc_simulator)
......@@ -102,33 +107,33 @@ add_executable(unit_tests dnn_sources/src/unit_tests.cc)
target_link_libraries(unit_tests tensor_runtime_online ${GPU_PROFILER_LIB} ${SOC_SIMULATOR_LIB})
# -- Compile tensor_runtime.ll if possible
if(LLVM_BUILD_DIR) # Defined in ../CMakeLists.txt. This means we're compiling in LLVM
get_filename_component(LLVM_CLANG_XX ${LLVM_BUILD_DIR}/bin/clang++ REALPATH)
# It's important that tensor_runtime.ll goes here if we're compiling with LLVM
# Some HPVM passes look for tensor_runtime.ll in this folder (which is usually build/lib)
set(TENSOR_RT_LL_PREFIX ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
add_dependencies(tensor_runtime clang)
else()
# Surely if we're compiling outside of hpvm, then we need the system-wide clang.
# Use it but check version 9 first
execute_process(COMMAND clang++ --version OUTPUT_VARIABLE clang_full_version_string ERROR_QUIET)
string(REGEX REPLACE ".*clang version ([0-9]+\\.[0-9]+).*" "\\1" CLANG_VERSION_STRING ${clang_full_version_string})
if(CLANG_VERSION_STRING VERSION_EQUAL 9)
set(LLVM_CLANG_XX clang++)
if(INDEP_BUILD)
# Surely if we're compiling outside of hpvm, then we need the system-wide clang -- a clang 9.
execute_process(COMMAND clang-9 --version OUTPUT_VARIABLE clang_stdout ERROR_QUIET)
if(clang_stdout)
set(TENSOR_RT_LL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/lib)
else()
message(WARNING "System clang++ of version 9 not found; skipping tensor_runtime.ll generation")
endif()
set(CLANG_NAME clang-9)
else()
# It's important that tensor_runtime.ll goes here if we're compiling with LLVM
# Some HPVM passes look for tensor_runtime.ll in this folder (which is usually build/lib)
set(TENSOR_RT_LL_PREFIX ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
# Per cmake documentation, if we're building in LLVM, then in add_custom_command
# the command "clang" will be auto resolved to the path to clang we're building
set(CLANG_NAME clang)
add_dependencies(tensor_runtime clang)
endif()
# If some clang-9 is found, create a tensor_runtime.ll from tensor_signatures.cc
if(LLVM_CLANG_XX)
if(CLANG_NAME)
message(STATUS "Creating tensor_runtime.ll in ${TENSOR_RT_LL_PREFIX}")
foreach(dir ${INCLUDES})
list(APPEND INCLUDE_COMPILER_STRINGS "-I${dir}")
endforeach()
add_custom_command(
TARGET tensor_runtime POST_BUILD
COMMAND ${LLVM_CLANG_XX} ${INCLUDE_COMPILER_STRINGS} -S -emit-llvm
COMMAND ${CLANG_NAME} -x c++ ${INCLUDE_COMPILER_STRINGS} -S -emit-llvm
${CMAKE_CURRENT_SOURCE_DIR}/tensor_runtime/include/tensor_signatures.cc
-o ${TENSOR_RT_LL_PREFIX}/tensor_runtime.ll
)
......
# First get approxhpvm.py which we then use to compile benchmarks.
get_filename_component(APPROXHPVM_PY ${PROJECT_BINARY_DIR}/bin/approxhpvm.py REALPATH)
get_filename_component(APPROXHPVM_PY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/approxhpvm.py REALPATH)
# Configure config.h which tells the benchmarks where's the model parameter directory.
# We can also use the one in tensor_runtime, but we're avoiding that so as to
......
# This file is very tightly coupled with main.py.in.
# Watch out and keep them in sync.
set(LLVM_PROJECT_DIR ${PROJECT_SOURCE_DIR})
set(LLVM_BUILD_DIR ${PROJECT_BINARY_DIR})
set(LIB_DIR ${PROJECT_BINARY_DIR}/lib)
set(LLVM_PROJECT_DIR ${CMAKE_SOURCE_DIR})
set(LLVM_BUILD_DIR ${CMAKE_BINARY_DIR})
set(LIB_DIR ${CMAKE_LIBRARY_OUTPUT_DIRECTORY})
# The hpvm-rt runtime
# This has to be explicitly set as hpvm-rt.bc is created in a custom_target
# and does not export its file location.
......@@ -26,8 +26,7 @@ set(
LLVMClearDFG
LLVMGenHPVM
)
find_package(CUDA REQUIRED) # Defines CUDA_TOOLKIT_ROOT_DIR
find_package(CUDNN 7 REQUIRED) # Defines CUDNN_LIBRARY_PATH
# CUDA_TOOLKIT_ROOT_DIR and CUDNN_LIBRARY_PATH has been defined globally
set(CUDNN_DIR ${CUDNN_LIBRARY_PATH})
# First resolve all `@symbol@` by configuring the file
configure_file(main.py.in ${CMAKE_CURRENT_BINARY_DIR}/main.py.conf)
......@@ -53,9 +52,9 @@ set(
clang opt llvm-link
)
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/bin/approxhpvm.py
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/main.py ${PROJECT_BINARY_DIR}/bin/approxhpvm.py
COMMAND chmod +x ${PROJECT_BINARY_DIR}/bin/approxhpvm.py
OUTPUT ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/approxhpvm.py
COMMAND cp ${CMAKE_CURRENT_BINARY_DIR}/main.py ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/approxhpvm.py
COMMAND chmod +x ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/approxhpvm.py
DEPENDS ${DEPS} ${CMAKE_CURRENT_BINARY_DIR}/main.py
)
add_custom_target(approxhpvm.py ALL DEPENDS ${PROJECT_BINARY_DIR}/bin/approxhpvm.py)
add_custom_target(approxhpvm.py ALL DEPENDS ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/approxhpvm.py)
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