Commit 8f4dcd54 by Tianqi Chen

[CMAKE] Windows build instruction (#161)

parent 90554d08
......@@ -9,16 +9,26 @@ if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/build/private/local_config.cmake)
endif()
include(cmake/Utils.cmake)
if(EXISTS ${CMAKE_CURRENT_BINARY_DIR}/config.cmake)
include(${CMAKE_CURRENT_BINARY_DIR}/config.cmake)
else()
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/config.cmake)
include(${CMAKE_CURRENT_SOURCE_DIR}/config.cmake)
endif()
endif()
# include path
include_directories(BEFORE "include")
include_directories("tvm/include")
include_directories("tvm/dlpack/include")
include_directories("tvm/HalideIR/src")
set(nnvm_LINKER_LIBS "")
set(NNVM_LINKER_LIBS "")
set(NNVM_COMPILER_LINKER_LIBS "")
add_definitions(-DNNVM_EXPORTS)
# Build a shared lib (libnnvm.so) by default
option(BUILD_SHARED_NNVM "Build a shared nnvm lib" ON)
option(BUILD_SHARED_NNVM "Build a shared nnvm lib" ON)
option(BUILD_STATIC_NNVM "Build a static nnvm lib" OFF)
# compile
......@@ -33,15 +43,15 @@ if(MSVC)
endif(${flag_var} MATCHES "/MD")
endforeach(flag_var)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /EHsc")
find_library(TVM_LIB tvm
HINTS ${CMAKE_CURRENT_SOURCE_DIR}/../tvm/build/Release
HINTS ${CMAKE_CURRENT_SOURCE_DIR}/tvm/build/Release)
message(STATUS "Build with TVM libary: " ${TVM_LIB})
list(APPEND NNVM_COMPILER_LINKER_LIBS ${TVM_LIB})
else(MSVC)
include(CheckCXXCompilerFlag)
check_cxx_compiler_flag("-std=c++0x" SUPPORT_CXX0X)
check_cxx_compiler_flag("-msse2" SUPPORT_MSSE2)
check_cxx_compiler_flag("-openmp" SUPPORT_OPENMP)
set(CMAKE_C_FLAGS "-O3 -Wall -msse2 -Wno-unknown-pragmas -std=c++0x -fPIC")
if(SUPPORT_OPENMP)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
endif()
check_cxx_compiler_flag("-std=c++11" SUPPORT_CXX11)
set(CMAKE_C_FLAGS "-O3 -Wall -std=c++11 -fPIC")
set(CMAKE_CXX_FLAGS ${CMAKE_C_FLAGS})
endif(MSVC)
......@@ -57,11 +67,16 @@ mxnet_source_group("Source\\core" GLOB "src/core/*.cc")
mxnet_source_group("Source\\pass" GLOB "src/pass/*.cc")
FILE(GLOB_RECURSE SOURCE
file(GLOB_RECURSE SOURCE
src/c_api/*.cc
src/core/*.cc
src/pass/*.cc)
file(GLOB_RECURSE COMPILER_SRCS
src/compiler/*.cc
src/top/*.cc
)
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/dmlc-core/CMakeLists.txt)
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/dmlc-core/include)
elseif(DMLC_CORE_PATH)
......@@ -78,6 +93,9 @@ if(BUILD_STATIC_NNVM)
set_target_properties(nnvm_static PROPERTIES OUTPUT_NAME "nnvm")
endif()
add_library(nnvm_compiler SHARED ${COMPILER_SRCS} ${SOURCE})
target_link_libraries(nnvm_compiler ${NNVM_COMPILER_LINKER_LIBS} ${NNVM_LINKER_LIBS})
if(INSTALL_INCLUDE_DIR)
add_custom_command(TARGET nnvm POST_BUILD
COMMAND COMMAND ${CMAKE_COMMAND} -E copy_directory
......@@ -87,10 +105,10 @@ endif()
# ---[ Install lib, header and docs
if(BUILD_SHARED_NNVM)
install(TARGETS nnvm LIBRARY DESTINATION lib)
install(TARGETS nnvm LIBRARY DESTINATION lib)
endif()
if(BUILD_STATIC_NNVM)
install(TARGETS nnvm_static ARCHIVE DESTINATION lib)
install(TARGETS nnvm_static ARCHIVE DESTINATION lib)
endif()
install(DIRECTORY include DESTINATION .)
install(DIRECTORY docs DESTINATION .)
......
......@@ -34,10 +34,26 @@ The minimal building requirement is
You can edit `make/config.mk` to change the compile options, and then build by
`make`. If everything goes well, we can go to the specific language installation section.
### Building on Windows
NNVM support build via MSVC using cmake. The minimum required VS version is **Visual Studio Community 2015 Update 3**.
In order to generate the VS solution file using cmake, make sure you have a recent version of cmake added to your path.
NNVM compiler depend on tvm, please follow [TVM document](http://docs.tvmlang.org/how_to/install.html#building-on-windows)
to build the TVM windows library. You can build the TVM in the submodule folder under nnvm.
After tvm is built, we can then start to build nnvm, using the following command.
```bash
mkdir build
cd build
cmake -G "Visual Studio 14 2015 Win64" -DCMAKE_BUILD_TYPE=Release -DCMAKE_CONFIGURATION_TYPES="Release" ..
```
This will generate the VS project using the MSVC 14 64 bit generator. Open the .sln file in the build directory and build with Visual Studio.
## Python Package Installation
The python package is located at python
There are several ways to install the package:
The python package is located at python.
There are several ways to install the package, in all these cases the TVM library must be present in the python env:
1. Set the environment variable `PYTHONPATH` to tell python where to find
the library. For example, assume we cloned `nnvm` on the home directory
......
......@@ -26,7 +26,7 @@ def find_lib_path():
if hasattr(__builtin__, "NNVM_LIBRARY_NAME"):
lib_name = __builtin__.NNVM_LIBRARY_NAME
else:
lib_name = "libnnvm_compiler"
lib_name = "nnvm_compiler" if sys.platform.startswith('win32') else "libnnvm_compiler"
api_path = os.path.join(base_path, '../../lib/')
cmake_build_path = os.path.join(base_path, '../../build/Release/')
......@@ -40,11 +40,11 @@ def find_lib_path():
if sys.platform.startswith('win32'):
vs_configuration = 'Release'
if platform.architecture()[0] == '64bit':
dll_path.append(os.path.join(curr_path, '../../build', vs_configuration))
dll_path.append(os.path.join(curr_path, '../../windows/x64', vs_configuration))
dll_path.append(os.path.join(base_path, '../../build', vs_configuration))
dll_path.append(os.path.join(base_path, '../../windows/x64', vs_configuration))
else:
dll_path.append(os.path.join(curr_path, '../../build', vs_configuration))
dll_path.append(os.path.join(curr_path, '../../windows', vs_configuration))
dll_path.append(os.path.join(base_path, '../../build', vs_configuration))
dll_path.append(os.path.join(base_path, '../../windows', vs_configuration))
dll_path = [os.path.join(p, '%s.dll' % lib_name) for p in dll_path]
elif sys.platform.startswith('darwin'):
dll_path = [os.path.join(p, '%s.dylib' % lib_name) for p in dll_path]
......
import os
import sys
from setuptools import find_packages
from distutils.core import setup
def config_cython():
......@@ -29,7 +30,28 @@ def config_cython():
print("Cython is not installed, will compile without cython module")
return []
setup(
name='nnvm',
ext_modules = config_cython()
)
# We can not import `libinfo.py` in setup.py directly since __init__.py
# Will be invoked which introduces dependences
CURRENT_DIR = os.path.dirname(__file__)
libinfo_py = os.path.join(CURRENT_DIR, './nnvm/libinfo.py')
libinfo = {'__file__': libinfo_py}
exec(compile(open(libinfo_py, "rb").read(), libinfo_py, 'exec'), libinfo, libinfo)
LIB_PATH = libinfo['find_lib_path']()
_, LIB_NAME = os.path.split(LIB_PATH[0])
__version__ = libinfo['__version__']
curr_path = os.path.dirname(os.path.abspath(os.path.expanduser(__file__)))
rpath = os.path.relpath(LIB_PATH[0], curr_path)
setup(name='nnvm',
version=__version__,
description="NNVM: Open Compiler for AI Frameworks",
zip_safe=False,
install_requires=[
'numpy'
],
packages=find_packages(),
url='https://github.com/dmlc/nnvm',
include_package_data=True,
data_files=[('nnvm', [rpath])])
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment