This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-tvm.git
The following commit(s) were added to refs/heads/master by this push:
new a4ebb16 [Build] Reflect Compile-Time CMake Options into libtvm.so
(#6280)
a4ebb16 is described below
commit a4ebb16ed76bfea4ce4eed7be7ea73d4a01027e2
Author: Junru Shao <[email protected]>
AuthorDate: Sat Aug 15 07:05:40 2020 -0700
[Build] Reflect Compile-Time CMake Options into libtvm.so (#6280)
* Initial comit
* Address comments from @tqchen
---
CMakeLists.txt | 10 ++++++++++
cmake/modules/Git.cmake | 40 ++++++++++++++++++++++++++++++++++++++++
python/tvm/__init__.py | 5 +++++
python/tvm/support.py | 25 +++++++++++++++++++++++++
src/support/libinfo.cc | 38 ++++++++++++++++++++++++++++++++++++++
5 files changed, 118 insertions(+)
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 0565cfd..451336e 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -320,6 +320,7 @@ include(cmake/modules/contrib/TF_TVMDSOOP.cmake)
include(cmake/modules/contrib/CoreML.cmake)
include(cmake/modules/contrib/ONNX.cmake)
include(cmake/modules/contrib/ArmComputeLib.cmake)
+include(cmake/modules/Git.cmake)
include(CheckCXXCompilerFlag)
if(NOT MSVC)
@@ -367,6 +368,15 @@ 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)
diff --git a/cmake/modules/Git.cmake b/cmake/modules/Git.cmake
new file mode 100644
index 0000000..7372148
--- /dev/null
+++ b/cmake/modules/Git.cmake
@@ -0,0 +1,40 @@
+# 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
+# - GIT_FOUND - true if the command line client was found
+# - GIT_EXECUTABLE - path to git command line client
+# - TVM_GIT_COMMIT_HASH
+find_package(Git QUIET)
+if (${GIT_FOUND})
+ message(STATUS "Git found: ${GIT_EXECUTABLE}")
+ execute_process(COMMAND ${GIT_EXECUTABLE} rev-parse HEAD
+ WORKING_DIRECTORY "${PROJECT_SOURCE_DIR}"
+ OUTPUT_VARIABLE TVM_GIT_COMMIT_HASH
+ RESULT_VARIABLE _TVM_GIT_RESULT
+ ERROR_VARIABLE _TVM_GIT_ERROR
+ OUTPUT_STRIP_TRAILING_WHITESPACE
+ ERROR_STRIP_TRAILING_WHITESPACE)
+ if (${_TVM_GIT_RESULT} EQUAL 0)
+ message(STATUS "Found TVM_GIT_COMMIT_HASH=${TVM_GIT_COMMIT_HASH}")
+ else()
+ message(STATUS "Not a git repo")
+ set(TVM_GIT_COMMIT_HASH "NOT-FOUND")
+ endif()
+else()
+ message(WARNING "Git not found")
+ set(TVM_GIT_COMMIT_HASH "NOT-FOUND")
+endif()
diff --git a/python/tvm/__init__.py b/python/tvm/__init__.py
index 2474ae8..19a69bf 100644
--- a/python/tvm/__init__.py
+++ b/python/tvm/__init__.py
@@ -66,9 +66,13 @@ from . import hybrid
# others
from . import arith
+# support infra
+from . import support
+
# Contrib initializers
from .contrib import rocm as _rocm, nvcc as _nvcc, sdaccel as _sdaccel
+
def tvm_wrap_excepthook(exception_hook):
"""Wrap given excepthook with TVM additional work."""
@@ -82,4 +86,5 @@ def tvm_wrap_excepthook(exception_hook):
return wrapper
+
sys.excepthook = tvm_wrap_excepthook(sys.excepthook)
diff --git a/python/tvm/support.py b/python/tvm/support.py
new file mode 100644
index 0000000..d867faa
--- /dev/null
+++ b/python/tvm/support.py
@@ -0,0 +1,25 @@
+# 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.
+"""Support infra of TVM."""
+import tvm._ffi
+
+
+def libinfo():
+ return GetLibInfo()
+
+
+tvm._ffi._init_api("support", __name__)
diff --git a/src/support/libinfo.cc b/src/support/libinfo.cc
new file mode 100644
index 0000000..9942174
--- /dev/null
+++ b/src/support/libinfo.cc
@@ -0,0 +1,38 @@
+/*
+ * 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.
+ */
+#include <tvm/node/container.h>
+#include <tvm/runtime/object.h>
+#include <tvm/runtime/registry.h>
+
+#ifndef TVM_GIT_COMMIT_HASH
+#define TVM_GIT_COMMIT_HASH "NOT-FOUND"
+#endif
+
+namespace tvm {
+
+Map<String, String> GetLibInfo() {
+ Map<String, String> result = {
+ {"GIT_COMMIT_HASH", TVM_GIT_COMMIT_HASH},
+ };
+ return result;
+}
+
+TVM_REGISTER_GLOBAL("support.GetLibInfo").set_body_typed(GetLibInfo);
+
+} // namespace tvm