Commit 8e21537a by liyinqiao

Support CMake tool to install NiuTensor.

1. Offer CMakeLists.txt to compile the NiuTensor.
2. Update the manuals for CMake.
parent 6d137345
# if your visual studio's version is before 2019
# use commond "cmake -A x64 .." to build this project
# or use cmake gui to build VS (remember to select x64)
# if there's some warnings, don't worry about that.
# cmake minimum version
cmake_minimum_required(VERSION 2.8)
# project's name
project(NiuTensor)
# the prefix of the generated executable file
set(NIUTRANS_EXE "NiuTensor")
# generated file path
set(EXECUTABLE_OUTPUT_PATH ../bin)
# 0 - Linux or macOS
# 1 - Windows
set(ON_WINDOWS 0)
# 0 - Not use
# 1 - Use, if set 1, please modify the CUDA_VERSION and CUDA_TOOLKIT_ROOT_DIR below
set(USE_CUDA 0)
if (USE_CUDA)
set(CUDA_VERSION 9.0)
set(CUDA_TOOLKIT_ROOT_DIR "/usr/local/cuda")
endif()
# use CMAKE_MACOSX_RPATH for macOS
set(CMAKE_MACOSX_RPATH 1)
# open floder manage
set_property(GLOBAL PROPERTY USE_FOLDERS On)
add_definitions(-std=c++11)
# find all the .cpp .h .cu .chu files in source folder
file(GLOB_RECURSE CPP_FILES source/*.cpp)
file(GLOB_RECURSE H_FILES source/*.h)
file(GLOB_RECURSE CU_FILES source/*.cu)
file(GLOB_RECURSE CUH_FILES source/*.cuh)
function(assign_source_group)
foreach(_source IN ITEMS ${ARGN})
if (IS_ABSOLUTE "${_source}")
file(RELATIVE_PATH _source_rel "${CMAKE_CURRENT_SOURCE_DIR}" "${_source}")
else()
set(_source_rel "${_source}")
endif()
get_filename_component(_source_path "${_source_rel}" PATH)
string(REPLACE "/" "\\" _source_path_msvc "${_source_path}")
source_group("${_source_path_msvc}" FILES "${_source}")
endforeach()
endfunction(assign_source_group)
function(my_add_executable)
foreach(_source IN ITEMS ${ARGN})
assign_source_group(${_source})
endforeach()
if(USE_CUDA)
cuda_add_executable(${ARGV})
else()
add_executable(${ARGV})
endif()
endfunction(my_add_executable)
if(USE_CUDA)
set(NIUTRANS_EXE "${NIUTRANS_EXE}.GPU")
add_definitions(-DUSE_CUDA)
if(ON_WINDOWS)
find_package(CUDA ${CUDA_VERSION} REQUIRED)
add_compile_options(-Wno-dev)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /wd4819")
set(CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS} "-maxrregcount=0 -m64 --disable-warnings -use_fast_math -DUSE_CUDA")
set(CMAKE_CUDA_FLAGS ${CMAKE_CUDA_FLAGS} -arch=sm_30
-gencode=arch=compute_30,code=sm_30
-gencode=arch=compute_50,code=sm_50
-gencode=arch=compute_52,code=sm_52
-gencode=arch=compute_60,code=sm_60
-gencode=arch=compute_61,code=sm_61
-gencode=arch=compute_62,code=sm_62
-gencode=arch=compute_70,code=sm_70
-gencode=arch=compute_70,code=compute_70
)
set(CMAKE_POLICY_DEFAULT_CMP0028 NEW)
link_directories("${CUDA_TOOLKIT_ROOT_DIR}/lib/x64")
include_directories("${CUDA_TOOLKIT_ROOT_DIR}/include")
set(CUDA_LIB_PATH_ME "${CUDA_TOOLKIT_ROOT_DIR}/lib/x64/")
set(CUDA_LIBS_ME ${CUDA_LIBS_ME} "${CUDA_LIB_PATH_ME}cublas.lib")
set(CUDA_LIBS_ME ${CUDA_LIBS_ME} "${CUDA_LIB_PATH_ME}npps.lib")
set(CUDA_LIBS_ME ${CUDA_LIBS_ME} "${CUDA_LIB_PATH_ME}nppc.lib")
set(CUDA_LIBS_ME ${CUDA_LIBS_ME} "${CUDA_LIB_PATH_ME}cudadevrt.lib")
set(CUDA_LIBS_ME ${CUDA_LIBS_ME} "${CUDA_LIB_PATH_ME}curand.lib")
my_add_executable(${NIUTRANS_EXE} ${CPP_FILES} ${H_FILES} ${CU_FILES} ${CUH_FILES})
else()
find_package(CUDA ${CUDA_VERSION} REQUIRED)
set(CMAKE_CXX_FLAGS "-fPIC -msse4.2 -w -march=native -Wno-enum-compare -Wno-sign-compare -Wno-format -Wno-dev -O3 -DNDEBUG -rdynamic")
set(CUDA_NVCC_FLAGS "-Xcompiler -fPIC -maxrregcount=0 --disable-warnings -use_fast_math -DUSE_CUDA -Wno-deprecated-gpu-targets -std=c++11")
set(CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS} -arch=sm_30
-gencode=arch=compute_30,code=sm_30
-gencode=arch=compute_50,code=sm_50
-gencode=arch=compute_52,code=sm_52
-gencode=arch=compute_60,code=sm_60
-gencode=arch=compute_61,code=sm_61
-gencode=arch=compute_62,code=sm_62
-gencode=arch=compute_70,code=sm_70
-gencode=arch=compute_70,code=compute_70
)
link_directories(${CUDA_TOOLKIT_ROOT_DIR}/lib64)
include_directories(${CUDA_TOOLKIT_ROOT_DIR}/include)
set(CUDA_LIB_PATH_ME "${CUDA_TOOLKIT_ROOT_DIR}/lib64/")
set(CUDA_LIBS_ME ${CUDA_LIBS_ME} "${CUDA_LIB_PATH_ME}libcublas_static.a")
set(CUDA_LIBS_ME ${CUDA_LIBS_ME} "${CUDA_LIB_PATH_ME}libculibos.a")
set(CUDA_LIBS_ME ${CUDA_LIBS_ME} "${CUDA_LIB_PATH_ME}libnpps_static.a")
set(CUDA_LIBS_ME ${CUDA_LIBS_ME} "${CUDA_LIB_PATH_ME}libnppc_static.a")
set(CUDA_LIBS_ME ${CUDA_LIBS_ME} "${CUDA_LIB_PATH_ME}libcudadevrt.a")
set(CUDA_LIBS_ME ${CUDA_LIBS_ME} "${CUDA_LIB_PATH_ME}libcurand_static.a")
set(CUDA_LIBS_ME ${CUDA_LIBS_ME} "/usr/lib64/libdl.so.2")
my_add_executable(${NIUTRANS_EXE} ${CPP_FILES} ${H_FILES} ${CU_FILES} ${CUH_FILES})
endif()
else()
set(NIUTRANS_EXE "${NIUTRANS_EXE}.CPU")
my_add_executable(${NIUTRANS_EXE} ${CPP_FILES} ${H_FILES})
endif()
set(CUDA_LIB ${CUDA_LIBS_ME})
if(ON_WINDOWS)
add_definitions(-DWIN32) # for windows specially
if(USE_CUDA)
message(STATUS "On Windows and use cuda")
target_link_libraries(${NIUTRANS_EXE} ${CUDA_LIB})
else()
message(STATUS "On Windows and not use cuda")
target_link_libraries(${NIUTRANS_EXE} ${CUDA_LIB})
endif()
else()
if(USE_CUDA)
message(STATUS "On Linux and use cuda")
target_link_libraries(${NIUTRANS_EXE} ${CUDA_LIB} -lpthread -lcudart -lnvidia-ml)
else()
message(STATUS "On Linux and not use cuda")
target_link_libraries(${NIUTRANS_EXE} ${CUDA_LIB} -lpthread)
endif()
endif()
message(STATUS "name of executable file:" ${NIUTRANS_EXE})
\ No newline at end of file
# NiuTensor
# 通过Visual Studio手动配置NiuTensor项目
## Windows系统通过Visual Studio配置NiuTensor项目
### 注意事项
## 注意事项
* 我们仅仅测试了VS2015和CUDA9.0之后的版本,对于之前的版本并不清楚是否存在问题。
* VS2015版本可以直接使用,使用较新版本的VS(如VS2017)时,需要**安装组件“适用于桌面的 VC++ 2015.3 v14.00 (v140) 工具集”**
......@@ -15,14 +13,14 @@
> C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\v140\BuildCustomizations
> C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\BuildCustomizations
### 新建项目
## 新建项目
* 新建一个VC++空项目。
* 将菜单栏中的**解决方案平台**设置为×64(默认是X86)。
***菜单栏->项目->属性**中,将平台设置为X64。
* 将源代码(source文件夹)拷贝到项目的根目录,然后选择**菜单栏->项目->显示所有文件**,解决方案中即可以看到source文件夹,右键点击source,选择包含在项目中,即可将所有的*.h和*.cpp加入到本项目中。
### CUDA配置(无GPU设备可以跳过此步骤)
## CUDA配置(无GPU设备可以跳过此步骤)
在VS项目中使用CUDA,需要设置项目的相关属性。
以下配置选项在 **菜单栏->项目 -> 属性** 中可以找到。
......@@ -46,7 +44,7 @@
* 上述配置完成后,在**菜单栏->项目->生成自定义**中,勾选CUDA*(根据自己安装的CUDA版本自行选择)。
* 在所有的*.cu和*.cuh文件上右键,包含在项目中。
### 其他配置
## 其他配置
注:以下选项也是 **菜单栏-项目 -> 属性** 中可以找到。
......
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论