Skip to content

Commit

Permalink
[Build] Add cmake options into libinfo (apache#6286)
Browse files Browse the repository at this point in the history
* [Build] Add cmake options into libinfo

* Address comments from @tqchen

* Add LLVM version to libinfo
  • Loading branch information
junrushao authored and Trevor Morris committed Aug 26, 2020
1 parent 8bb15a4 commit 8d47cac
Show file tree
Hide file tree
Showing 6 changed files with 322 additions and 15 deletions.
12 changes: 3 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,7 @@ include(cmake/modules/contrib/CoreML.cmake)
include(cmake/modules/contrib/ONNX.cmake)
include(cmake/modules/contrib/ArmComputeLib.cmake)
include(cmake/modules/Git.cmake)
include(cmake/modules/LibInfo.cmake)

include(CheckCXXCompilerFlag)
if(NOT MSVC)
Expand All @@ -349,6 +350,8 @@ else()
set(CMAKE_CUDA_STANDARD 14)
endif()

add_lib_info(${CMAKE_CURRENT_LIST_DIR}/src/support/libinfo.cc)

add_library(tvm SHARED ${COMPILER_SRCS} ${RUNTIME_SRCS})
add_library(tvm_runtime SHARED ${RUNTIME_SRCS})
add_library(tvm_runtime_static STATIC ${RUNTIME_SRCS})
Expand Down Expand Up @@ -385,15 +388,6 @@ if(BUILD_FOR_HEXAGON)
PUBLIC "${USE_HEXAGON_SDK}/incs/stddef")
endif()

if (${GIT_FOUND})
set_property(
SOURCE ${CMAKE_CURRENT_LIST_DIR}/src/support/libinfo.cc
APPEND
PROPERTY COMPILE_DEFINITIONS
TVM_GIT_COMMIT_HASH="${TVM_GIT_COMMIT_HASH}"
)
endif()

if(USE_THREADS AND NOT BUILD_FOR_HEXAGON)
message(STATUS "Build with thread support...")
set(CMAKE_THREAD_PREFER_PTHREAD TRUE)
Expand Down
3 changes: 2 additions & 1 deletion cmake/modules/Git.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,11 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# This script provides
# - GIT_FOUND - true if the command line client was found
# - GIT_EXECUTABLE - path to git command line client
# - TVM_GIT_COMMIT_HASH
# - TVM_GIT_COMMIT_HASH - The git commit hash found, or "NOT-FOUND" if anything went wrong
find_package(Git QUIET)
if (${GIT_FOUND})
message(STATUS "Git found: ${GIT_EXECUTABLE}")
Expand Down
78 changes: 78 additions & 0 deletions cmake/modules/LibInfo.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.

# This script provides
# - add_lib_info - A function to add definition flags to a specific file

function(add_lib_info src_file)
if (NOT DEFINED TVM_INFO_LLVM_VERSION)
set(TVM_INFO_LLVM_VERSION "NOT-FOUND")
else()
string(STRIP ${TVM_INFO_LLVM_VERSION} TVM_INFO_LLVM_VERSION)
endif()
set_property(
SOURCE ${src_file}
APPEND
PROPERTY COMPILE_DEFINITIONS
TVM_INFO_GIT_COMMIT_HASH="${TVM_GIT_COMMIT_HASH}"
TVM_INFO_USE_CUDA="${USE_CUDA}"
TVM_INFO_USE_OPENCL="${USE_OPENCL}"
TVM_INFO_USE_VULKAN="${USE_VULKAN}"
TVM_INFO_USE_METAL="${USE_METAL}"
TVM_INFO_USE_ROCM="${USE_ROCM}"
TVM_INFO_ROCM_PATH="${ROCM_PATH}"
TVM_INFO_USE_HEXAGON_DEVICE="${USE_HEXAGON_DEVICE}"
TVM_INFO_USE_HEXAGON_SDK="${USE_HEXAGON_SDK}"
TVM_INFO_USE_RPC="${USE_RPC}"
TVM_INFO_USE_THREADS="${USE_THREADS}"
TVM_INFO_USE_LLVM="${USE_LLVM}"
TVM_INFO_LLVM_VERSION="${TVM_INFO_LLVM_VERSION}"
TVM_INFO_USE_STACKVM_RUNTIME="${USE_STACKVM_RUNTIME}"
TVM_INFO_USE_GRAPH_RUNTIME="${USE_GRAPH_RUNTIME}"
TVM_INFO_USE_GRAPH_RUNTIME_DEBUG="${USE_GRAPH_RUNTIME_DEBUG}"
TVM_INFO_USE_OPENMP="${USE_OPENMP}"
TVM_INFO_USE_RELAY_DEBUG="${USE_RELAY_DEBUG}"
TVM_INFO_USE_RTTI="${USE_RTTI}"
TVM_INFO_USE_MSVC_MT="${USE_MSVC_MT}"
TVM_INFO_USE_MICRO="${USE_MICRO}"
TVM_INFO_INSTALL_DEV="${INSTALL_DEV}"
TVM_INFO_HIDE_PRIVATE_SYMBOLS="${HIDE_PRIVATE_SYMBOLS}"
TVM_INFO_USE_TF_TVMDSOOP="${USE_TF_TVMDSOOP}"
TVM_INFO_USE_FALLBACK_STL_MAP="${USE_FALLBACK_STL_MAP}"
TVM_INFO_USE_BLAS="${USE_BLAS}"
TVM_INFO_USE_MKL="${USE_MKL}"
TVM_INFO_USE_MKLDNN="${USE_MKLDNN}"
TVM_INFO_USE_DNNL_CODEGEN="${USE_DNNL_CODEGEN}"
TVM_INFO_USE_CUDNN="${USE_CUDNN}"
TVM_INFO_USE_CUBLAS="${USE_CUBLAS}"
TVM_INFO_USE_THRUST="${USE_THRUST}"
TVM_INFO_USE_MIOPEN="${USE_MIOPEN}"
TVM_INFO_USE_ROCBLAS="${USE_ROCBLAS}"
TVM_INFO_USE_SORT="${USE_SORT}"
TVM_INFO_USE_NNPACK="${USE_NNPACK}"
TVM_INFO_USE_RANDOM="${USE_RANDOM}"
TVM_INFO_USE_MICRO_STANDALONE_RUNTIME="${USE_MICRO_STANDALONE_RUNTIME}"
TVM_INFO_USE_CPP_RPC="${USE_CPP_RPC}"
TVM_INFO_USE_TFLITE="${USE_TFLITE}"
TVM_INFO_USE_TENSORFLOW_PATH="${USE_TENSORFLOW_PATH}"
TVM_INFO_USE_COREML="${USE_COREML}"
TVM_INFO_USE_TARGET_ONNX="${USE_TARGET_ONNX}"
TVM_INFO_USE_ARM_COMPUTE_LIB="${USE_ARM_COMPUTE_LIB}"
TVM_INFO_USE_ARM_COMPUTE_LIB_GRAPH_RUNTIME="${USE_ARM_COMPUTE_LIB_GRAPH_RUNTIME}"
)

endfunction()
3 changes: 3 additions & 0 deletions cmake/util/FindLLVM.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
# - LLVM_LIBS
# - LLVM_DEFINITIONS
# - TVM_LLVM_VERSION
# - TVM_INFO_LLVM_VERSION
#
macro(find_llvm use_llvm)
set(LLVM_CONFIG ${use_llvm})
Expand All @@ -53,6 +54,7 @@ macro(find_llvm use_llvm)
message(STATUS "Link with static LLVM libraries")
endif()
set(TVM_LLVM_VERSION ${LLVM_VERSION_MAJOR}${LLVM_VERSION_MINOR})
set(TVM_INFO_LLVM_VERSION "${LLVM_VERSION_MAJOR}.${LLVM_VERSION_MINOR}.${LLVM_VERSION_PATCH}")
elseif(NOT LLVM_CONFIG STREQUAL "OFF")
# use llvm config
message(STATUS "Use llvm-config=" ${LLVM_CONFIG})
Expand Down Expand Up @@ -82,6 +84,7 @@ macro(find_llvm use_llvm)
message(FATAL_ERROR "Fatal error executing: ${use_llvm} --version")
endif()
# llvm version
set(TVM_INFO_LLVM_VERSION ${__llvm_version})
string(REGEX REPLACE "^([^.]+)\.([^.])+\.[^.]+.*$" "\\1\\2" TVM_LLVM_VERSION ${__llvm_version})
# definitions
string(REGEX MATCHALL "(^| )-D[A-Za-z0-9_]*" LLVM_DEFINITIONS ${__llvm_cxxflags})
Expand Down
9 changes: 8 additions & 1 deletion python/tvm/support.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@


def libinfo():
return GetLibInfo()
"""Returns a dictionary containing compile-time info, including cmake flags and git commit hash
Returns
-------
info: Dict[str, str]
The dictionary of compile-time info.
"""
return {k: v for k, v in GetLibInfo().items()} # pylint: disable=unnecessary-comprehension


tvm._ffi._init_api("support", __name__)

0 comments on commit 8d47cac

Please sign in to comment.