Skip to content

Commit

Permalink
[Build] Reflect Compile-Time CMake Options into libtvm.so (apache#6280)
Browse files Browse the repository at this point in the history
* Initial comit

* Address comments from @tqchen
  • Loading branch information
junrushao authored and Trevor Morris committed Aug 26, 2020
1 parent 88bf180 commit 62d37bf
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 0 deletions.
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,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)
Expand Down Expand Up @@ -384,6 +385,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)
Expand Down
40 changes: 40 additions & 0 deletions cmake/modules/Git.cmake
Original file line number Diff line number Diff line change
@@ -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()
5 changes: 5 additions & 0 deletions python/tvm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,13 @@
# 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."""

Expand All @@ -82,4 +86,5 @@ def wrapper(exctype, value, trbk):

return wrapper


sys.excepthook = tvm_wrap_excepthook(sys.excepthook)
25 changes: 25 additions & 0 deletions python/tvm/support.py
Original file line number Diff line number Diff line change
@@ -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__)
38 changes: 38 additions & 0 deletions src/support/libinfo.cc
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 62d37bf

Please sign in to comment.