[Build] Add cmake options into libinfo (#6286)
authorJunru Shao <junrushao1994@gmail.com>
Mon, 17 Aug 2020 14:18:24 +0000 (07:18 -0700)
committerGitHub <noreply@github.com>
Mon, 17 Aug 2020 14:18:24 +0000 (07:18 -0700)
* [Build] Add cmake options into libinfo

* Address comments from @tqchen

* Add LLVM version to libinfo

CMakeLists.txt
cmake/modules/Git.cmake
cmake/modules/LibInfo.cmake [new file with mode: 0644]
cmake/util/FindLLVM.cmake
python/tvm/support.py
src/support/libinfo.cc

index 451336e..90174d5 100644 (file)
@@ -321,6 +321,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)
@@ -333,6 +334,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})
 
@@ -368,15 +371,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)
index 7372148..d6612d9 100644 (file)
 # 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}")
diff --git a/cmake/modules/LibInfo.cmake b/cmake/modules/LibInfo.cmake
new file mode 100644 (file)
index 0000000..7f9cea8
--- /dev/null
@@ -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()
index 297c8d4..25937e2 100644 (file)
@@ -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})
@@ -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})
@@ -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})
index d867faa..e0d688a 100644 (file)
@@ -19,7 +19,14 @@ import tvm._ffi
 
 
 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__)
index 9942174..94bc9d1 100644 (file)
 #include <tvm/runtime/object.h>
 #include <tvm/runtime/registry.h>
 
-#ifndef TVM_GIT_COMMIT_HASH
-#define TVM_GIT_COMMIT_HASH "NOT-FOUND"
+#ifndef TVM_INFO_GIT_COMMIT_HASH
+#define TVM_INFO_GIT_COMMIT_HASH "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_LLVM_VERSION
+#define TVM_INFO_LLVM_VERSION "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_CUDA
+#define TVM_INFO_USE_CUDA "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_OPENCL
+#define TVM_INFO_USE_OPENCL "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_VULKAN
+#define TVM_INFO_USE_VULKAN "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_METAL
+#define TVM_INFO_USE_METAL "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_ROCM
+#define TVM_INFO_USE_ROCM "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_ROCM_PATH
+#define TVM_INFO_ROCM_PATH "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_HEXAGON_DEVICE
+#define TVM_INFO_USE_HEXAGON_DEVICE "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_HEXAGON_SDK
+#define TVM_INFO_USE_HEXAGON_SDK "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_RPC
+#define TVM_INFO_USE_RPC "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_THREADS
+#define TVM_INFO_USE_THREADS "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_LLVM
+#define TVM_INFO_USE_LLVM "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_STACKVM_RUNTIME
+#define TVM_INFO_USE_STACKVM_RUNTIME "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_GRAPH_RUNTIME
+#define TVM_INFO_USE_GRAPH_RUNTIME "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_GRAPH_RUNTIME_DEBUG
+#define TVM_INFO_USE_GRAPH_RUNTIME_DEBUG "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_OPENMP
+#define TVM_INFO_USE_OPENMP "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_RELAY_DEBUG
+#define TVM_INFO_USE_RELAY_DEBUG "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_RTTI
+#define TVM_INFO_USE_RTTI "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_MSVC_MT
+#define TVM_INFO_USE_MSVC_MT "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_MICRO
+#define TVM_INFO_USE_MICRO "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_INSTALL_DEV
+#define TVM_INFO_INSTALL_DEV "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_HIDE_PRIVATE_SYMBOLS
+#define TVM_INFO_HIDE_PRIVATE_SYMBOLS "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_TF_TVMDSOOP
+#define TVM_INFO_USE_TF_TVMDSOOP "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_FALLBACK_STL_MAP
+#define TVM_INFO_USE_FALLBACK_STL_MAP "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_BLAS
+#define TVM_INFO_USE_BLAS "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_MKL
+#define TVM_INFO_USE_MKL "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_MKLDNN
+#define TVM_INFO_USE_MKLDNN "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_DNNL_CODEGEN
+#define TVM_INFO_USE_DNNL_CODEGEN "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_CUDNN
+#define TVM_INFO_USE_CUDNN "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_CUBLAS
+#define TVM_INFO_USE_CUBLAS "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_THRUST
+#define TVM_INFO_USE_THRUST "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_MIOPEN
+#define TVM_INFO_USE_MIOPEN "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_ROCBLAS
+#define TVM_INFO_USE_ROCBLAS "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_SORT
+#define TVM_INFO_USE_SORT "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_NNPACK
+#define TVM_INFO_USE_NNPACK "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_RANDOM
+#define TVM_INFO_USE_RANDOM "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_MICRO_STANDALONE_RUNTIME
+#define TVM_INFO_USE_MICRO_STANDALONE_RUNTIME "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_CPP_RPC
+#define TVM_INFO_USE_CPP_RPC "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_TFLITE
+#define TVM_INFO_USE_TFLITE "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_TENSORFLOW_PATH
+#define TVM_INFO_USE_TENSORFLOW_PATH "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_COREML
+#define TVM_INFO_USE_COREML "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_TARGET_ONNX
+#define TVM_INFO_USE_TARGET_ONNX "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_ARM_COMPUTE_LIB
+#define TVM_INFO_USE_ARM_COMPUTE_LIB "NOT-FOUND"
+#endif
+
+#ifndef TVM_INFO_USE_ARM_COMPUTE_LIB_GRAPH_RUNTIME
+#define TVM_INFO_USE_ARM_COMPUTE_LIB_GRAPH_RUNTIME "NOT-FOUND"
 #endif
 
 namespace tvm {
 
-Map<String, String> GetLibInfo() {
+/*!
+ * \brief Get a dictionary containing compile-time info, including cmake flags and git commit hash
+ * \return The compile-time info
+ */
+TVM_DLL Map<String, String> GetLibInfo() {
   Map<String, String> result = {
-      {"GIT_COMMIT_HASH", TVM_GIT_COMMIT_HASH},
+      {"GIT_COMMIT_HASH", TVM_INFO_GIT_COMMIT_HASH},
+      {"USE_CUDA", TVM_INFO_USE_CUDA},
+      {"USE_OPENCL", TVM_INFO_USE_OPENCL},
+      {"USE_VULKAN", TVM_INFO_USE_VULKAN},
+      {"USE_METAL", TVM_INFO_USE_METAL},
+      {"USE_ROCM", TVM_INFO_USE_ROCM},
+      {"ROCM_PATH", TVM_INFO_ROCM_PATH},
+      {"USE_HEXAGON_DEVICE", TVM_INFO_USE_HEXAGON_DEVICE},
+      {"USE_HEXAGON_SDK", TVM_INFO_USE_HEXAGON_SDK},
+      {"USE_RPC", TVM_INFO_USE_RPC},
+      {"USE_THREADS", TVM_INFO_USE_THREADS},
+      {"USE_LLVM", TVM_INFO_USE_LLVM},
+      {"LLVM_VERSION", TVM_INFO_LLVM_VERSION},
+      {"USE_STACKVM_RUNTIME", TVM_INFO_USE_STACKVM_RUNTIME},
+      {"USE_GRAPH_RUNTIME", TVM_INFO_USE_GRAPH_RUNTIME},
+      {"USE_GRAPH_RUNTIME_DEBUG", TVM_INFO_USE_GRAPH_RUNTIME_DEBUG},
+      {"USE_OPENMP", TVM_INFO_USE_OPENMP},
+      {"USE_RELAY_DEBUG", TVM_INFO_USE_RELAY_DEBUG},
+      {"USE_RTTI", TVM_INFO_USE_RTTI},
+      {"USE_MSVC_MT", TVM_INFO_USE_MSVC_MT},
+      {"USE_MICRO", TVM_INFO_USE_MICRO},
+      {"INSTALL_DEV", TVM_INFO_INSTALL_DEV},
+      {"HIDE_PRIVATE_SYMBOLS", TVM_INFO_HIDE_PRIVATE_SYMBOLS},
+      {"USE_TF_TVMDSOOP", TVM_INFO_USE_TF_TVMDSOOP},
+      {"USE_FALLBACK_STL_MAP", TVM_INFO_USE_FALLBACK_STL_MAP},
+      {"USE_BLAS", TVM_INFO_USE_BLAS},
+      {"USE_MKL", TVM_INFO_USE_MKL},
+      {"USE_MKLDNN", TVM_INFO_USE_MKLDNN},
+      {"USE_DNNL_CODEGEN", TVM_INFO_USE_DNNL_CODEGEN},
+      {"USE_CUDNN", TVM_INFO_USE_CUDNN},
+      {"USE_CUBLAS", TVM_INFO_USE_CUBLAS},
+      {"USE_THRUST", TVM_INFO_USE_THRUST},
+      {"USE_MIOPEN", TVM_INFO_USE_MIOPEN},
+      {"USE_ROCBLAS", TVM_INFO_USE_ROCBLAS},
+      {"USE_SORT", TVM_INFO_USE_SORT},
+      {"USE_NNPACK", TVM_INFO_USE_NNPACK},
+      {"USE_RANDOM", TVM_INFO_USE_RANDOM},
+      {"USE_MICRO_STANDALONE_RUNTIME", TVM_INFO_USE_MICRO_STANDALONE_RUNTIME},
+      {"USE_CPP_RPC", TVM_INFO_USE_CPP_RPC},
+      {"USE_TFLITE", TVM_INFO_USE_TFLITE},
+      {"USE_TENSORFLOW_PATH", TVM_INFO_USE_TENSORFLOW_PATH},
+      {"USE_COREML", TVM_INFO_USE_COREML},
+      {"USE_TARGET_ONNX", TVM_INFO_USE_TARGET_ONNX},
+      {"USE_ARM_COMPUTE_LIB", TVM_INFO_USE_ARM_COMPUTE_LIB},
+      {"USE_ARM_COMPUTE_LIB_GRAPH_RUNTIME", TVM_INFO_USE_ARM_COMPUTE_LIB_GRAPH_RUNTIME},
   };
   return result;
 }