├── .gitignore ├── .gitmodules ├── .travis.yml ├── CMakeLists.txt ├── LICENSE.md ├── README.md ├── admin └── updateSubmodules.sh ├── clean.bat ├── clean.sh ├── cmake ├── 3.6 │ ├── CMakeLists.txt │ └── Modules │ │ ├── FindCUDA.cmake │ │ └── FindCUDA │ │ ├── make2cmake.cmake │ │ ├── parse_cubin.cmake │ │ ├── run_nvcc.cmake │ │ └── select_compute_arch.cmake └── FindTorch.cmake ├── exe └── CMakeLists.txt ├── extra └── CMakeLists.txt ├── install-deps ├── install-deps.bat ├── install-openblas.sh ├── install.bat ├── install.sh ├── pkg └── CMakeLists.txt ├── prepare_mklml.sh ├── test.bat ├── test.sh ├── travis_cuda_install.sh ├── uninstall.bat ├── update.sh └── win-files ├── README.md ├── patch ├── lua-cjson.patch ├── luaffifb.patch └── torch.patch └── test ├── ffifb_perf_ffi.lua └── ffifb_perf_purelua.lua /.gitignore: -------------------------------------------------------------------------------- 1 | build/ 2 | install/ 3 | */*/build 4 | extra/luafilesystem/lfs.so 5 | win-files/3rd/ 6 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "exe/luajit-rocks"] 2 | path = exe/luajit-rocks 3 | url = https://github.com/torch/luajit-rocks.git 4 | [submodule "exe/qtlua"] 5 | path = exe/qtlua 6 | url = https://github.com/torch/qtlua.git 7 | [submodule "pkg/dok"] 8 | path = pkg/dok 9 | url = https://github.com/torch/dok.git 10 | [submodule "pkg/gnuplot"] 11 | path = pkg/gnuplot 12 | url = https://github.com/torch/gnuplot.git 13 | [submodule "pkg/paths"] 14 | path = pkg/paths 15 | url = https://github.com/torch/paths.git 16 | [submodule "pkg/cwrap"] 17 | path = pkg/cwrap 18 | url = https://github.com/torch/cwrap.git 19 | [submodule "extra/cunn"] 20 | path = extra/cunn 21 | url = https://github.com/torch/cunn.git 22 | [submodule "extra/cutorch"] 23 | path = extra/cutorch 24 | url = https://github.com/torch/cutorch.git 25 | [submodule "extra/mkltorch"] 26 | path = extra/mkltorch 27 | url = https://github.com/MlWoo/mkltorch.git 28 | [submodule "extra/mklnn"] 29 | path = extra/mklnn 30 | url = https://github.com/xhzhao/mklnn.git 31 | [submodule "pkg/torch"] 32 | path = pkg/torch 33 | url = https://github.com/MlWoo/torch7.git 34 | [submodule "pkg/sundown"] 35 | path = pkg/sundown 36 | url = https://github.com/torch/sundown-ffi.git 37 | [submodule "pkg/qttorch"] 38 | path = pkg/qttorch 39 | url = https://github.com/torch/qttorch.git 40 | [submodule "pkg/xlua"] 41 | path = pkg/xlua 42 | url = https://github.com/torch/xlua.git 43 | [submodule "pkg/sys"] 44 | path = pkg/sys 45 | url = https://github.com/torch/sys.git 46 | [submodule "pkg/image"] 47 | path = pkg/image 48 | url = https://github.com/torch/image.git 49 | [submodule "pkg/optim"] 50 | path = pkg/optim 51 | url = https://github.com/torch/optim.git 52 | [submodule "extra/threads"] 53 | path = extra/threads 54 | url = https://github.com/torch/threads-ffi.git 55 | [submodule "extra/argcheck"] 56 | path = extra/argcheck 57 | url = https://github.com/torch/argcheck.git 58 | [submodule "extra/cudnn"] 59 | path = extra/cudnn 60 | url = https://github.com/soumith/cudnn.torch.git 61 | [submodule "exe/trepl"] 62 | path = exe/trepl 63 | url = https://github.com/torch/trepl.git 64 | [submodule "extra/nnx"] 65 | path = extra/nnx 66 | url = https://github.com/clementfarabet/lua---nnx.git 67 | [submodule "extra/nn"] 68 | path = extra/nn 69 | url = https://github.com/MlWoo/nn.git 70 | [submodule "exe/env"] 71 | path = exe/env 72 | url = https://github.com/torch/env.git 73 | [submodule "extra/graph"] 74 | path = extra/graph 75 | url = https://github.com/torch/graph 76 | [submodule "extra/nngraph"] 77 | path = extra/nngraph 78 | url = https://github.com/torch/nngraph 79 | [submodule "extra/luaffifb"] 80 | path = extra/luaffifb 81 | url = https://github.com/facebook/luaffifb 82 | [submodule "extra/luafilesystem"] 83 | path = extra/luafilesystem 84 | url = https://github.com/keplerproject/luafilesystem.git 85 | [submodule "extra/penlight"] 86 | path = extra/penlight 87 | url = https://github.com/stevedonovan/Penlight.git 88 | [submodule "extra/lua-cjson"] 89 | path = extra/lua-cjson 90 | url = https://github.com/mpx/lua-cjson 91 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: c 2 | compiler: 3 | - gcc 4 | - clang 5 | cache: 6 | directories: 7 | - $HOME/OpenBlasInstall 8 | sudo: required 9 | env: 10 | - TORCH_LUA_VERSION=LUAJIT21 11 | - TORCH_LUA_VERSION=LUA51 12 | - TORCH_LUA_VERSION=LUA52 13 | addons: 14 | apt: 15 | packages: 16 | - cmake 17 | - gfortran 18 | - gcc-multilib 19 | - gfortran-multilib 20 | - liblapack-dev 21 | - build-essential 22 | - gcc 23 | - g++ 24 | - curl 25 | - cmake 26 | - libreadline-dev 27 | - git-core 28 | - libqt4-core 29 | - libqt4-gui 30 | - libqt4-dev 31 | - libjpeg-dev 32 | - libpng-dev 33 | - ncurses-dev 34 | - imagemagick 35 | - libzmq3-dev 36 | - gfortran 37 | - unzip 38 | - gnuplot 39 | - gnuplot-x11 40 | - libfftw3-dev 41 | - sox 42 | - libsox-dev 43 | - libsox-fmt-all 44 | - libgraphicsmagick1-dev 45 | - graphicsmagick 46 | before_script: 47 | - export ROOT_TRAVIS_DIR=$(pwd) 48 | - export INSTALL_PREFIX=~/torch/install 49 | - ls $HOME/OpenBlasInstall/lib || (cd /tmp/ && git clone https://github.com/xianyi/OpenBLAS.git -b master && cd OpenBLAS && (make NO_AFFINITY=1 -j$(getconf _NPROCESSORS_ONLN) 2>/dev/null >/dev/null) && make PREFIX=$HOME/OpenBlasInstall install) 50 | - git clone https://github.com/torch/distro.git ~/torch --recursive 51 | - sudo -E $ROOT_TRAVIS_DIR/travis_cuda_install.sh 52 | script: 53 | - export PATH=/usr/local/cuda/bin/:$PATH 54 | - cd ~/torch && ./install.sh -b 55 | - source ~/torch/install/bin/torch-activate 56 | - ./test.sh 57 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | ADD_SUBDIRECTORY(exe) 3 | 4 | # If this variable is defined, a pure cmake build is done end-to-end with no luarocks 5 | IF (WITH_LUAROCKS STREQUAL OFF) 6 | 7 | # LUA_INCDIR - place where lua headers exist 8 | # LUA_LIBDIR - place where lua libraries exist 9 | # LUADIR - LUA_PATH 10 | # LIBDIR - LUA_CPATH 11 | # LUALIB - the lua library to link against 12 | 13 | IF (NOT DEFINED ${LUA_INCDIR}) 14 | SET(LUA_INCDIR ${CMAKE_INSTALL_PREFIX}/include) 15 | MESSAGE(STATUS "LUA_INCDIR: ${LUA_INCDIR}") 16 | ENDIF(NOT DEFINED ${LUA_INCDIR}) 17 | IF (NOT DEFINED ${LUA_LIBDIR}) 18 | SET(LUA_LIBDIR ${CMAKE_INSTALL_PREFIX}/lib) 19 | MESSAGE(STATUS "LUA_LIBDIR: ${LUA_LIBDIR}") 20 | ENDIF(NOT DEFINED ${LUA_LIBDIR}) 21 | IF (NOT DEFINED ${LUA_BINDIR}) 22 | SET(LUA_BINDIR ${CMAKE_INSTALL_PREFIX}/bin) 23 | MESSAGE(STATUS "LUA_BINDIR: ${LUA_BINDIR}") 24 | ENDIF(NOT DEFINED ${LUA_BINDIR}) 25 | IF (NOT DEFINED ${LUALIB}) 26 | IF (WITH_LUAJIT21 OR WITH_LUAJIT20) 27 | SET(LUALIB ${LIBRARY_OUTPUT_PATH}/libluajit.so) 28 | ELSE (WITH_LUAJIT21 OR WITH_LUAJIT20) 29 | SET(LUALIB ${LIBRARY_OUTPUT_PATH}/liblua.so) 30 | ENDIF (WITH_LUAJIT21 OR WITH_LUAJIT20) 31 | MESSAGE(STATUS "LUALIB: ${LUALIB}") 32 | ENDIF(NOT DEFINED ${LUALIB}) 33 | IF (NOT DEFINED ${LUADIR}) 34 | SET(LUADIR ${CMAKE_INSTALL_PREFIX}/${INSTALL_LUA_PATH_SUBDIR}) 35 | MESSAGE(STATUS "LUADIR: ${LUADIR}") 36 | ENDIF(NOT DEFINED ${LUADIR}) 37 | IF (NOT DEFINED ${LIBDIR}) 38 | SET(LIBDIR ${CMAKE_INSTALL_PREFIX}/${INSTALL_LUA_CPATH_SUBDIR}) 39 | MESSAGE(STATUS "LIBDIR: ${LIBDIR}") 40 | ENDIF(NOT DEFINED ${LIBDIR}) 41 | IF (NOT DEFINED ${LUA_BINDIR}) 42 | SET(LUA_BINDIR ${CMAKE_INSTALL_PREFIX}/bin) 43 | MESSAGE(STATUS "LUA_BINDIR: ${LUA_BINDIR}") 44 | ENDIF(NOT DEFINED ${LUA_BINDIR}) 45 | IF (NOT DEFINED ${SCRIPTS_DIR}) 46 | SET(SCRIPTS_DIR ${CMAKE_INSTALL_PREFIX}/bin) 47 | MESSAGE(STATUS "SCRIPTS_DIR: ${SCRIPTS_DIR}") 48 | ENDIF(NOT DEFINED ${SCRIPTS_DIR}) 49 | 50 | INCLUDE_DIRECTORIES(${LUA_INCDIR}) 51 | IF (WITH_LUAJIT21 OR WITH_LUAJIT20) 52 | INCLUDE_DIRECTORIES(${LuaJIT_SOURCE_DIR}/src ${LuaJIT_BINARY_DIR}) 53 | SET(LUA "luajit") 54 | ELSE (WITH_LUAJIT21 OR WITH_LUAJIT20) 55 | INCLUDE_DIRECTORIES(${Lua_SOURCE_DIR}/src ${Lua_BINARY_DIR}) 56 | SET(LUA "lua") 57 | ENDIF (WITH_LUAJIT21 OR WITH_LUAJIT20) 58 | 59 | # add torch defs 60 | # this is done to fake compliance with FIND_PACKAGE(Torch) 61 | SET(CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake" 62 | "${CMAKE_CURRENT_BINARY_DIR}/cmake" "${CMAKE_MODULE_PATH}") 63 | 64 | INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/pkg/torch/lib/TH") 65 | INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}/pkg/torch/lib/TH") 66 | INCLUDE_DIRECTORIES("${CMAKE_CURRENT_SOURCE_DIR}/pkg/torch/lib/luaT") 67 | INCLUDE_DIRECTORIES("${CMAKE_CURRENT_BINARY_DIR}/pkg/torch/lib/luaT") 68 | 69 | SET(Torch_INSTALL_INCLUDE_SUBDIR ${LUA_INCDIR}) 70 | SET(Torch_INSTALL_INCLUDE ${LUA_INCDIR}) 71 | SET(Torch_INSTALL_LUA_PATH_SUBDIR ${LUADIR}) 72 | SET(Torch_INSTALL_LUA_CPATH_SUBDIR ${LIBDIR}) 73 | SET(Torch_INSTALL_LIB ${LUA_LIBDIR}) 74 | SET(Torch_INSTALL_LIB_SUBDIR ${LUA_LIBDIR}) 75 | 76 | # Finally add the two directories 77 | ADD_SUBDIRECTORY(pkg) 78 | ADD_SUBDIRECTORY(extra) 79 | 80 | ENDIF (WITH_LUAROCKS STREQUAL OFF) 81 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016, Soumith Chintala, Ronan Collobert, Koray Kavukcuoglu, Clement Farabet 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of distro nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | DISCONTINUATION OF PROJECT. 2 | 3 | This project will no longer be maintained by Intel. 4 | 5 | Intel has ceased development and contributions including, but not limited to, maintenance, bug fixes, new releases, or updates, to this project. 6 | 7 | Intel no longer accepts patches to this project. 8 | 9 | If you have an ongoing need to use this project, are interested in independently developing it, or would like to maintain patches for the open source software community, please create your own fork of this project. 10 | [![Build Status](https://travis-ci.org/torch/distro.svg?branch=master)](https://travis-ci.org/torch/distro) 11 | 12 | Torch* 13 | ============ 14 | Torch is a scientific computing framework with wide support for machine learning algorithms. It is easy to use and efficient, thanks to an easy and fast scripting language, LuaJIT, and an underlying C/CUDA implementation. 15 | 16 | Intel®Software Optimization for Torch 17 | ============ 18 | This fork is dedicated to improving Torch performance when running on CPU, in particular Intel® Xeon processors (HSW, BDW, Xeon Phi) 19 | 20 | 21 | ### Requirements 22 | If you are root user, please use this command to install OpenBlas and other dependency: 23 | ```sh 24 | bash install-deps 25 | ``` 26 | 27 | If you are not root user, please use this command to install OpenBlas from source code, and this script will add OpenBLAS to LD_LIBRARY_PATH automaticly. 28 | ```sh 29 | . ./install-openblas.sh 30 | ``` 31 | 32 | ### Building 33 | Install this repo, which installs the torch distribution, with a lot of nice goodies. 34 | 35 | You can specify which compiler to compile the project, and the default compiler is gcc & g++. 36 | ```sh 37 | git clone https://github.com/intel/torch.git ~/torch 38 | cd ~/torch; bash install-deps; 39 | ./install.sh #use gcc to install torch 40 | ./install.sh icc #use icc to install torch 41 | ``` 42 | 43 | By default Torch will install LuaJIT 2.1. If you want other options, you can use the command: 44 | ```sh 45 | TORCH_LUA_VERSION=LUA51 ./install.sh 46 | TORCH_LUA_VERSION=LUA52 ./install.sh 47 | ``` 48 | 49 | 50 | ### Cleaning 51 | To remove all the temporary compilation files you can run: 52 | ```sh 53 | ./clean.sh 54 | ``` 55 | 56 | ### Test 57 | You can test that all libraries are installed properly by running: 58 | ```sh 59 | ./test.sh 60 | ``` 61 | Tested on Ubuntu 14.04, CentOS 7. 62 | 63 | ### More build options for install.sh 64 | 65 | ```sh 66 | ./install.sh [gcc] [avx512] [mklml] [noskip] 67 | ``` 68 | 69 | * icc/gcc, default gcc 70 | * avx512/off, default off, avx512 will force compilers(GCC version should be greater than 4.9.2) to use AVX512F instructions to compile the framework. 71 | * mklml/mkl, default mkl. 72 | * noskip/skip,default noskip, skip means skip the openblas checking 73 | 74 | If you want to use MKL as the default BLAS library, please activate MKL before install.sh: 75 | ```sh 76 | source /opt/intel/mkl/bin/mklvars.sh intel64 77 | ``` 78 | 79 | --- 80 | >\* Other names and trademarks may be claimed as the property of others. 81 | 82 | 83 | -------------------------------------------------------------------------------- /admin/updateSubmodules.sh: -------------------------------------------------------------------------------- 1 | git pull 2 | git submodule update 3 | # dont update luajit-rocks because of https://github.com/LuaJIT/LuaJIT/issues/325 4 | git submodule foreach bash -c 'if [ $(basename $(pwd)) != 'luajit-rocks' ]; then git pull origin master; fi' 5 | # git submodule foreach git pull origin master 6 | git add extra pkg exe 7 | git commit -m "updating packages" 8 | -------------------------------------------------------------------------------- /clean.bat: -------------------------------------------------------------------------------- 1 | @setlocal enableextensions 2 | @echo off 3 | 4 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 5 | :::: This script cleans temporary compilation file :::: 6 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 7 | 8 | 9 | set TORCH_DISTRO=%~dp0. 10 | 11 | for /d %%G in ("%TORCH_DISTRO%\win-files\3rd\wineditline-*") do rmdir /s /q "%%~G"\build 12 | cd %TORCH_DISTRO%\win-files\3rd\dlfcn-win32 && git clean -fdx 13 | 14 | cd %TORCH_DISTRO%\exe\lua-5.1.5 && del /q *.obj *.o *.lib *.dll *.exp *.exe 15 | cd %TORCH_DISTRO%\exe\lua-5.2.4 && del /q *.obj *.o *.lib *.dll *.exp *.exe 16 | cd %TORCH_DISTRO%\exe\lua-5.3.3 && del /q *.obj *.o *.lib *.dll *.exp *.exe 17 | cd %TORCH_DISTRO%\exe\luajit-2.0 && git clean -fdx 18 | cd %TORCH_DISTRO%\exe\luajit-2.1 && git clean -fdx 19 | cd %TORCH_DISTRO%\exe\luarocks && git clean -fdx 20 | 21 | cd %TORCH_DISTRO% && git submodule foreach --recursive git clean -fdx 22 | 23 | echo Cleaning is finished 24 | @endlocal 25 | -------------------------------------------------------------------------------- /clean.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | THIS_DIR=$(cd $(dirname $0); pwd) 4 | find "${THIS_DIR}/" -type d -name build -o -name install \ 5 | | grep -v '/exe/luajit-rocks/' | xargs -I {} rm -rf {} 6 | 7 | rm -rf extra/threads/CMakeFiles 8 | rm -rf extra/threads/build.luarocks 9 | rm -rf extra/threads/CMakeCache.txt 10 | rm -rf extra/threads/Makefile 11 | rm -rf extra/threads/cmake_install.cmake 12 | rm -rf extra/threads/install_manifest.txt 13 | 14 | rm -rf extra/luafilesystem/lfs.so 15 | -------------------------------------------------------------------------------- /cmake/3.6/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | 3 | # 4 | # This CMake file installs some module files from CMake 3.6 5 | # into Torch cmake install directory. 6 | # 7 | 8 | INSTALL(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/Modules/" 9 | DESTINATION "share/cmake/torch") 10 | -------------------------------------------------------------------------------- /cmake/3.6/Modules/FindCUDA.cmake: -------------------------------------------------------------------------------- 1 | #.rst: 2 | # FindCUDA 3 | # -------- 4 | # 5 | # Tools for building CUDA C files: libraries and build dependencies. 6 | # 7 | # This script locates the NVIDIA CUDA C tools. It should work on linux, 8 | # windows, and mac and should be reasonably up to date with CUDA C 9 | # releases. 10 | # 11 | # This script makes use of the standard find_package arguments of 12 | # , REQUIRED and QUIET. CUDA_FOUND will report if an 13 | # acceptable version of CUDA was found. 14 | # 15 | # The script will prompt the user to specify CUDA_TOOLKIT_ROOT_DIR if 16 | # the prefix cannot be determined by the location of nvcc in the system 17 | # path and REQUIRED is specified to find_package(). To use a different 18 | # installed version of the toolkit set the environment variable 19 | # CUDA_BIN_PATH before running cmake (e.g. 20 | # CUDA_BIN_PATH=/usr/local/cuda1.0 instead of the default 21 | # /usr/local/cuda) or set CUDA_TOOLKIT_ROOT_DIR after configuring. If 22 | # you change the value of CUDA_TOOLKIT_ROOT_DIR, various components that 23 | # depend on the path will be relocated. 24 | # 25 | # It might be necessary to set CUDA_TOOLKIT_ROOT_DIR manually on certain 26 | # platforms, or to use a cuda runtime not installed in the default 27 | # location. In newer versions of the toolkit the cuda library is 28 | # included with the graphics driver- be sure that the driver version 29 | # matches what is needed by the cuda runtime version. 30 | # 31 | # The following variables affect the behavior of the macros in the 32 | # script (in alphebetical order). Note that any of these flags can be 33 | # changed multiple times in the same directory before calling 34 | # CUDA_ADD_EXECUTABLE, CUDA_ADD_LIBRARY, CUDA_COMPILE, CUDA_COMPILE_PTX, 35 | # CUDA_COMPILE_FATBIN, CUDA_COMPILE_CUBIN or CUDA_WRAP_SRCS:: 36 | # 37 | # CUDA_64_BIT_DEVICE_CODE (Default matches host bit size) 38 | # -- Set to ON to compile for 64 bit device code, OFF for 32 bit device code. 39 | # Note that making this different from the host code when generating object 40 | # or C files from CUDA code just won't work, because size_t gets defined by 41 | # nvcc in the generated source. If you compile to PTX and then load the 42 | # file yourself, you can mix bit sizes between device and host. 43 | # 44 | # CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE (Default ON) 45 | # -- Set to ON if you want the custom build rule to be attached to the source 46 | # file in Visual Studio. Turn OFF if you add the same cuda file to multiple 47 | # targets. 48 | # 49 | # This allows the user to build the target from the CUDA file; however, bad 50 | # things can happen if the CUDA source file is added to multiple targets. 51 | # When performing parallel builds it is possible for the custom build 52 | # command to be run more than once and in parallel causing cryptic build 53 | # errors. VS runs the rules for every source file in the target, and a 54 | # source can have only one rule no matter how many projects it is added to. 55 | # When the rule is run from multiple targets race conditions can occur on 56 | # the generated file. Eventually everything will get built, but if the user 57 | # is unaware of this behavior, there may be confusion. It would be nice if 58 | # this script could detect the reuse of source files across multiple targets 59 | # and turn the option off for the user, but no good solution could be found. 60 | # 61 | # CUDA_BUILD_CUBIN (Default OFF) 62 | # -- Set to ON to enable and extra compilation pass with the -cubin option in 63 | # Device mode. The output is parsed and register, shared memory usage is 64 | # printed during build. 65 | # 66 | # CUDA_BUILD_EMULATION (Default OFF for device mode) 67 | # -- Set to ON for Emulation mode. -D_DEVICEEMU is defined for CUDA C files 68 | # when CUDA_BUILD_EMULATION is TRUE. 69 | # 70 | # CUDA_GENERATED_OUTPUT_DIR (Default CMAKE_CURRENT_BINARY_DIR) 71 | # -- Set to the path you wish to have the generated files placed. If it is 72 | # blank output files will be placed in CMAKE_CURRENT_BINARY_DIR. 73 | # Intermediate files will always be placed in 74 | # CMAKE_CURRENT_BINARY_DIR/CMakeFiles. 75 | # 76 | # CUDA_HOST_COMPILATION_CPP (Default ON) 77 | # -- Set to OFF for C compilation of host code. 78 | # 79 | # CUDA_HOST_COMPILER (Default CMAKE_C_COMPILER, $(VCInstallDir)/bin for VS) 80 | # -- Set the host compiler to be used by nvcc. Ignored if -ccbin or 81 | # --compiler-bindir is already present in the CUDA_NVCC_FLAGS or 82 | # CUDA_NVCC_FLAGS_ variables. For Visual Studio targets 83 | # $(VCInstallDir)/bin is a special value that expands out to the path when 84 | # the command is run from within VS. 85 | # 86 | # CUDA_NVCC_FLAGS 87 | # CUDA_NVCC_FLAGS_ 88 | # -- Additional NVCC command line arguments. NOTE: multiple arguments must be 89 | # semi-colon delimited (e.g. --compiler-options;-Wall) 90 | # 91 | # CUDA_PROPAGATE_HOST_FLAGS (Default ON) 92 | # -- Set to ON to propagate CMAKE_{C,CXX}_FLAGS and their configuration 93 | # dependent counterparts (e.g. CMAKE_C_FLAGS_DEBUG) automatically to the 94 | # host compiler through nvcc's -Xcompiler flag. This helps make the 95 | # generated host code match the rest of the system better. Sometimes 96 | # certain flags give nvcc problems, and this will help you turn the flag 97 | # propagation off. This does not affect the flags supplied directly to nvcc 98 | # via CUDA_NVCC_FLAGS or through the OPTION flags specified through 99 | # CUDA_ADD_LIBRARY, CUDA_ADD_EXECUTABLE, or CUDA_WRAP_SRCS. Flags used for 100 | # shared library compilation are not affected by this flag. 101 | # 102 | # CUDA_SEPARABLE_COMPILATION (Default OFF) 103 | # -- If set this will enable separable compilation for all CUDA runtime object 104 | # files. If used outside of CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY 105 | # (e.g. calling CUDA_WRAP_SRCS directly), 106 | # CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME and 107 | # CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS should be called. 108 | # 109 | # CUDA_SOURCE_PROPERTY_FORMAT 110 | # -- If this source file property is set, it can override the format specified 111 | # to CUDA_WRAP_SRCS (OBJ, PTX, CUBIN, or FATBIN). If an input source file 112 | # is not a .cu file, setting this file will cause it to be treated as a .cu 113 | # file. See documentation for set_source_files_properties on how to set 114 | # this property. 115 | # 116 | # CUDA_USE_STATIC_CUDA_RUNTIME (Default ON) 117 | # -- When enabled the static version of the CUDA runtime library will be used 118 | # in CUDA_LIBRARIES. If the version of CUDA configured doesn't support 119 | # this option, then it will be silently disabled. 120 | # 121 | # CUDA_VERBOSE_BUILD (Default OFF) 122 | # -- Set to ON to see all the commands used when building the CUDA file. When 123 | # using a Makefile generator the value defaults to VERBOSE (run make 124 | # VERBOSE=1 to see output), although setting CUDA_VERBOSE_BUILD to ON will 125 | # always print the output. 126 | # 127 | # The script creates the following macros (in alphebetical order):: 128 | # 129 | # CUDA_ADD_CUFFT_TO_TARGET( cuda_target ) 130 | # -- Adds the cufft library to the target (can be any target). Handles whether 131 | # you are in emulation mode or not. 132 | # 133 | # CUDA_ADD_CUBLAS_TO_TARGET( cuda_target ) 134 | # -- Adds the cublas library to the target (can be any target). Handles 135 | # whether you are in emulation mode or not. 136 | # 137 | # CUDA_ADD_EXECUTABLE( cuda_target file0 file1 ... 138 | # [WIN32] [MACOSX_BUNDLE] [EXCLUDE_FROM_ALL] [OPTIONS ...] ) 139 | # -- Creates an executable "cuda_target" which is made up of the files 140 | # specified. All of the non CUDA C files are compiled using the standard 141 | # build rules specified by CMAKE and the cuda files are compiled to object 142 | # files using nvcc and the host compiler. In addition CUDA_INCLUDE_DIRS is 143 | # added automatically to include_directories(). Some standard CMake target 144 | # calls can be used on the target after calling this macro 145 | # (e.g. set_target_properties and target_link_libraries), but setting 146 | # properties that adjust compilation flags will not affect code compiled by 147 | # nvcc. Such flags should be modified before calling CUDA_ADD_EXECUTABLE, 148 | # CUDA_ADD_LIBRARY or CUDA_WRAP_SRCS. 149 | # 150 | # CUDA_ADD_LIBRARY( cuda_target file0 file1 ... 151 | # [STATIC | SHARED | MODULE] [EXCLUDE_FROM_ALL] [OPTIONS ...] ) 152 | # -- Same as CUDA_ADD_EXECUTABLE except that a library is created. 153 | # 154 | # CUDA_BUILD_CLEAN_TARGET() 155 | # -- Creates a convience target that deletes all the dependency files 156 | # generated. You should make clean after running this target to ensure the 157 | # dependency files get regenerated. 158 | # 159 | # CUDA_COMPILE( generated_files file0 file1 ... [STATIC | SHARED | MODULE] 160 | # [OPTIONS ...] ) 161 | # -- Returns a list of generated files from the input source files to be used 162 | # with ADD_LIBRARY or ADD_EXECUTABLE. 163 | # 164 | # CUDA_COMPILE_PTX( generated_files file0 file1 ... [OPTIONS ...] ) 165 | # -- Returns a list of PTX files generated from the input source files. 166 | # 167 | # CUDA_COMPILE_FATBIN( generated_files file0 file1 ... [OPTIONS ...] ) 168 | # -- Returns a list of FATBIN files generated from the input source files. 169 | # 170 | # CUDA_COMPILE_CUBIN( generated_files file0 file1 ... [OPTIONS ...] ) 171 | # -- Returns a list of CUBIN files generated from the input source files. 172 | # 173 | # CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME( output_file_var 174 | # cuda_target 175 | # object_files ) 176 | # -- Compute the name of the intermediate link file used for separable 177 | # compilation. This file name is typically passed into 178 | # CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS. output_file_var is produced 179 | # based on cuda_target the list of objects files that need separable 180 | # compilation as specified by object_files. If the object_files list is 181 | # empty, then output_file_var will be empty. This function is called 182 | # automatically for CUDA_ADD_LIBRARY and CUDA_ADD_EXECUTABLE. Note that 183 | # this is a function and not a macro. 184 | # 185 | # CUDA_INCLUDE_DIRECTORIES( path0 path1 ... ) 186 | # -- Sets the directories that should be passed to nvcc 187 | # (e.g. nvcc -Ipath0 -Ipath1 ... ). These paths usually contain other .cu 188 | # files. 189 | # 190 | # 191 | # CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS( output_file_var cuda_target 192 | # nvcc_flags object_files) 193 | # -- Generates the link object required by separable compilation from the given 194 | # object files. This is called automatically for CUDA_ADD_EXECUTABLE and 195 | # CUDA_ADD_LIBRARY, but can be called manually when using CUDA_WRAP_SRCS 196 | # directly. When called from CUDA_ADD_LIBRARY or CUDA_ADD_EXECUTABLE the 197 | # nvcc_flags passed in are the same as the flags passed in via the OPTIONS 198 | # argument. The only nvcc flag added automatically is the bitness flag as 199 | # specified by CUDA_64_BIT_DEVICE_CODE. Note that this is a function 200 | # instead of a macro. 201 | # 202 | # CUDA_SELECT_NVCC_ARCH_FLAGS(out_variable [target_CUDA_architectures]) 203 | # -- Selects GPU arch flags for nvcc based on target_CUDA_architectures 204 | # target_CUDA_architectures : Auto | Common | All | LIST(ARCH_AND_PTX ...) 205 | # - "Auto" detects local machine GPU compute arch at runtime. 206 | # - "Common" and "All" cover common and entire subsets of architectures 207 | # ARCH_AND_PTX : NAME | NUM.NUM | NUM.NUM(NUM.NUM) | NUM.NUM+PTX 208 | # NAME: Fermi Kepler Maxwell Kepler+Tegra Kepler+Tesla Maxwell+Tegra Pascal 209 | # NUM: Any number. Only those pairs are currently accepted by NVCC though: 210 | # 2.0 2.1 3.0 3.2 3.5 3.7 5.0 5.2 5.3 6.0 6.2 211 | # Returns LIST of flags to be added to CUDA_NVCC_FLAGS in ${out_variable} 212 | # Additionally, sets ${out_variable}_readable to the resulting numeric list 213 | # Example: 214 | # CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS 3.0 3.5+PTX 5.2(5.0) Maxwell) 215 | # LIST(APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS}) 216 | # 217 | # More info on CUDA architectures: https://en.wikipedia.org/wiki/CUDA 218 | # Note that this is a function instead of a macro. 219 | # 220 | # CUDA_WRAP_SRCS ( cuda_target format generated_files file0 file1 ... 221 | # [STATIC | SHARED | MODULE] [OPTIONS ...] ) 222 | # -- This is where all the magic happens. CUDA_ADD_EXECUTABLE, 223 | # CUDA_ADD_LIBRARY, CUDA_COMPILE, and CUDA_COMPILE_PTX all call this 224 | # function under the hood. 225 | # 226 | # Given the list of files (file0 file1 ... fileN) this macro generates 227 | # custom commands that generate either PTX or linkable objects (use "PTX" or 228 | # "OBJ" for the format argument to switch). Files that don't end with .cu 229 | # or have the HEADER_FILE_ONLY property are ignored. 230 | # 231 | # The arguments passed in after OPTIONS are extra command line options to 232 | # give to nvcc. You can also specify per configuration options by 233 | # specifying the name of the configuration followed by the options. General 234 | # options must precede configuration specific options. Not all 235 | # configurations need to be specified, only the ones provided will be used. 236 | # 237 | # OPTIONS -DFLAG=2 "-DFLAG_OTHER=space in flag" 238 | # DEBUG -g 239 | # RELEASE --use_fast_math 240 | # RELWITHDEBINFO --use_fast_math;-g 241 | # MINSIZEREL --use_fast_math 242 | # 243 | # For certain configurations (namely VS generating object files with 244 | # CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE set to ON), no generated file will 245 | # be produced for the given cuda file. This is because when you add the 246 | # cuda file to Visual Studio it knows that this file produces an object file 247 | # and will link in the resulting object file automatically. 248 | # 249 | # This script will also generate a separate cmake script that is used at 250 | # build time to invoke nvcc. This is for several reasons. 251 | # 252 | # 1. nvcc can return negative numbers as return values which confuses 253 | # Visual Studio into thinking that the command succeeded. The script now 254 | # checks the error codes and produces errors when there was a problem. 255 | # 256 | # 2. nvcc has been known to not delete incomplete results when it 257 | # encounters problems. This confuses build systems into thinking the 258 | # target was generated when in fact an unusable file exists. The script 259 | # now deletes the output files if there was an error. 260 | # 261 | # 3. By putting all the options that affect the build into a file and then 262 | # make the build rule dependent on the file, the output files will be 263 | # regenerated when the options change. 264 | # 265 | # This script also looks at optional arguments STATIC, SHARED, or MODULE to 266 | # determine when to target the object compilation for a shared library. 267 | # BUILD_SHARED_LIBS is ignored in CUDA_WRAP_SRCS, but it is respected in 268 | # CUDA_ADD_LIBRARY. On some systems special flags are added for building 269 | # objects intended for shared libraries. A preprocessor macro, 270 | # _EXPORTS is defined when a shared library compilation is 271 | # detected. 272 | # 273 | # Flags passed into add_definitions with -D or /D are passed along to nvcc. 274 | # 275 | # 276 | # 277 | # The script defines the following variables:: 278 | # 279 | # CUDA_VERSION_MAJOR -- The major version of cuda as reported by nvcc. 280 | # CUDA_VERSION_MINOR -- The minor version. 281 | # CUDA_VERSION 282 | # CUDA_VERSION_STRING -- CUDA_VERSION_MAJOR.CUDA_VERSION_MINOR 283 | # CUDA_HAS_FP16 -- Whether a short float (float16,fp16) is supported. 284 | # 285 | # CUDA_TOOLKIT_ROOT_DIR -- Path to the CUDA Toolkit (defined if not set). 286 | # CUDA_SDK_ROOT_DIR -- Path to the CUDA SDK. Use this to find files in the 287 | # SDK. This script will not directly support finding 288 | # specific libraries or headers, as that isn't 289 | # supported by NVIDIA. If you want to change 290 | # libraries when the path changes see the 291 | # FindCUDA.cmake script for an example of how to clear 292 | # these variables. There are also examples of how to 293 | # use the CUDA_SDK_ROOT_DIR to locate headers or 294 | # libraries, if you so choose (at your own risk). 295 | # CUDA_INCLUDE_DIRS -- Include directory for cuda headers. Added automatically 296 | # for CUDA_ADD_EXECUTABLE and CUDA_ADD_LIBRARY. 297 | # CUDA_LIBRARIES -- Cuda RT library. 298 | # CUDA_CUFFT_LIBRARIES -- Device or emulation library for the Cuda FFT 299 | # implementation (alternative to: 300 | # CUDA_ADD_CUFFT_TO_TARGET macro) 301 | # CUDA_CUBLAS_LIBRARIES -- Device or emulation library for the Cuda BLAS 302 | # implementation (alterative to: 303 | # CUDA_ADD_CUBLAS_TO_TARGET macro). 304 | # CUDA_cudart_static_LIBRARY -- Statically linkable cuda runtime library. 305 | # Only available for CUDA version 5.5+ 306 | # CUDA_cupti_LIBRARY -- CUDA Profiling Tools Interface library. 307 | # Only available for CUDA version 4.0+. 308 | # CUDA_curand_LIBRARY -- CUDA Random Number Generation library. 309 | # Only available for CUDA version 3.2+. 310 | # CUDA_cusolver_LIBRARY -- CUDA Direct Solver library. 311 | # Only available for CUDA version 7.0+. 312 | # CUDA_cusparse_LIBRARY -- CUDA Sparse Matrix library. 313 | # Only available for CUDA version 3.2+. 314 | # CUDA_npp_LIBRARY -- NVIDIA Performance Primitives lib. 315 | # Only available for CUDA version 4.0+. 316 | # CUDA_nppc_LIBRARY -- NVIDIA Performance Primitives lib (core). 317 | # Only available for CUDA version 5.5+. 318 | # CUDA_nppi_LIBRARY -- NVIDIA Performance Primitives lib (image processing). 319 | # Only available for CUDA version 5.5+. 320 | # CUDA_npps_LIBRARY -- NVIDIA Performance Primitives lib (signal processing). 321 | # Only available for CUDA version 5.5+. 322 | # CUDA_nvcuvenc_LIBRARY -- CUDA Video Encoder library. 323 | # Only available for CUDA version 3.2+. 324 | # Windows only. 325 | # CUDA_nvcuvid_LIBRARY -- CUDA Video Decoder library. 326 | # Only available for CUDA version 3.2+. 327 | # Windows only. 328 | # 329 | 330 | # James Bigler, NVIDIA Corp (nvidia.com - jbigler) 331 | # Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html 332 | # 333 | # Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved. 334 | # 335 | # Copyright (c) 2007-2009 336 | # Scientific Computing and Imaging Institute, University of Utah 337 | # 338 | # This code is licensed under the MIT License. See the FindCUDA.cmake script 339 | # for the text of the license. 340 | 341 | # The MIT License 342 | # 343 | # License for the specific language governing rights and limitations under 344 | # Permission is hereby granted, free of charge, to any person obtaining a 345 | # copy of this software and associated documentation files (the "Software"), 346 | # to deal in the Software without restriction, including without limitation 347 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 348 | # and/or sell copies of the Software, and to permit persons to whom the 349 | # Software is furnished to do so, subject to the following conditions: 350 | # 351 | # The above copyright notice and this permission notice shall be included 352 | # in all copies or substantial portions of the Software. 353 | # 354 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 355 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 356 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 357 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 358 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 359 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 360 | # DEALINGS IN THE SOFTWARE. 361 | # 362 | ############################################################################### 363 | 364 | # FindCUDA.cmake 365 | 366 | # We need to have at least this version to support the VERSION_LESS argument to 'if' (2.6.2) and unset (2.6.3) 367 | cmake_policy(PUSH) 368 | cmake_minimum_required(VERSION 2.6.3) 369 | cmake_policy(POP) 370 | 371 | # This macro helps us find the location of helper files we will need the full path to 372 | macro(CUDA_FIND_HELPER_FILE _name _extension) 373 | set(_full_name "${_name}.${_extension}") 374 | # CMAKE_CURRENT_LIST_FILE contains the full path to the file currently being 375 | # processed. Using this variable, we can pull out the current path, and 376 | # provide a way to get access to the other files we need local to here. 377 | get_filename_component(CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH) 378 | set(CUDA_${_name} "${CMAKE_CURRENT_LIST_DIR}/FindCUDA/${_full_name}") 379 | if(NOT EXISTS "${CUDA_${_name}}") 380 | set(error_message "${_full_name} not found in ${CMAKE_CURRENT_LIST_DIR}/FindCUDA") 381 | if(CUDA_FIND_REQUIRED) 382 | message(FATAL_ERROR "${error_message}") 383 | else() 384 | if(NOT CUDA_FIND_QUIETLY) 385 | message(STATUS "${error_message}") 386 | endif() 387 | endif() 388 | endif() 389 | # Set this variable as internal, so the user isn't bugged with it. 390 | set(CUDA_${_name} ${CUDA_${_name}} CACHE INTERNAL "Location of ${_full_name}" FORCE) 391 | endmacro() 392 | 393 | ##################################################################### 394 | ## CUDA_INCLUDE_NVCC_DEPENDENCIES 395 | ## 396 | 397 | # So we want to try and include the dependency file if it exists. If 398 | # it doesn't exist then we need to create an empty one, so we can 399 | # include it. 400 | 401 | # If it does exist, then we need to check to see if all the files it 402 | # depends on exist. If they don't then we should clear the dependency 403 | # file and regenerate it later. This covers the case where a header 404 | # file has disappeared or moved. 405 | 406 | macro(CUDA_INCLUDE_NVCC_DEPENDENCIES dependency_file) 407 | set(CUDA_NVCC_DEPEND) 408 | set(CUDA_NVCC_DEPEND_REGENERATE FALSE) 409 | 410 | 411 | # Include the dependency file. Create it first if it doesn't exist . The 412 | # INCLUDE puts a dependency that will force CMake to rerun and bring in the 413 | # new info when it changes. DO NOT REMOVE THIS (as I did and spent a few 414 | # hours figuring out why it didn't work. 415 | if(NOT EXISTS ${dependency_file}) 416 | file(WRITE ${dependency_file} "#FindCUDA.cmake generated file. Do not edit.\n") 417 | endif() 418 | # Always include this file to force CMake to run again next 419 | # invocation and rebuild the dependencies. 420 | #message("including dependency_file = ${dependency_file}") 421 | include(${dependency_file}) 422 | 423 | # Now we need to verify the existence of all the included files 424 | # here. If they aren't there we need to just blank this variable and 425 | # make the file regenerate again. 426 | # if(DEFINED CUDA_NVCC_DEPEND) 427 | # message("CUDA_NVCC_DEPEND set") 428 | # else() 429 | # message("CUDA_NVCC_DEPEND NOT set") 430 | # endif() 431 | if(CUDA_NVCC_DEPEND) 432 | #message("CUDA_NVCC_DEPEND found") 433 | foreach(f ${CUDA_NVCC_DEPEND}) 434 | # message("searching for ${f}") 435 | if(NOT EXISTS ${f}) 436 | #message("file ${f} not found") 437 | set(CUDA_NVCC_DEPEND_REGENERATE TRUE) 438 | endif() 439 | endforeach() 440 | else() 441 | #message("CUDA_NVCC_DEPEND false") 442 | # No dependencies, so regenerate the file. 443 | set(CUDA_NVCC_DEPEND_REGENERATE TRUE) 444 | endif() 445 | 446 | #message("CUDA_NVCC_DEPEND_REGENERATE = ${CUDA_NVCC_DEPEND_REGENERATE}") 447 | # No incoming dependencies, so we need to generate them. Make the 448 | # output depend on the dependency file itself, which should cause the 449 | # rule to re-run. 450 | if(CUDA_NVCC_DEPEND_REGENERATE) 451 | set(CUDA_NVCC_DEPEND ${dependency_file}) 452 | #message("Generating an empty dependency_file: ${dependency_file}") 453 | file(WRITE ${dependency_file} "#FindCUDA.cmake generated file. Do not edit.\n") 454 | endif() 455 | 456 | endmacro() 457 | 458 | ############################################################################### 459 | ############################################################################### 460 | # Setup variables' defaults 461 | ############################################################################### 462 | ############################################################################### 463 | 464 | # Allow the user to specify if the device code is supposed to be 32 or 64 bit. 465 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 466 | set(CUDA_64_BIT_DEVICE_CODE_DEFAULT ON) 467 | else() 468 | set(CUDA_64_BIT_DEVICE_CODE_DEFAULT OFF) 469 | endif() 470 | option(CUDA_64_BIT_DEVICE_CODE "Compile device code in 64 bit mode" ${CUDA_64_BIT_DEVICE_CODE_DEFAULT}) 471 | 472 | # Attach the build rule to the source file in VS. This option 473 | option(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE "Attach the build rule to the CUDA source file. Enable only when the CUDA source file is added to at most one target." ON) 474 | 475 | # Prints out extra information about the cuda file during compilation 476 | option(CUDA_BUILD_CUBIN "Generate and parse .cubin files in Device mode." OFF) 477 | 478 | # Set whether we are using emulation or device mode. 479 | option(CUDA_BUILD_EMULATION "Build in Emulation mode" OFF) 480 | 481 | # Where to put the generated output. 482 | set(CUDA_GENERATED_OUTPUT_DIR "" CACHE PATH "Directory to put all the output files. If blank it will default to the CMAKE_CURRENT_BINARY_DIR") 483 | 484 | # Parse HOST_COMPILATION mode. 485 | option(CUDA_HOST_COMPILATION_CPP "Generated file extension" ON) 486 | 487 | # Extra user settable flags 488 | set(CUDA_NVCC_FLAGS "" CACHE STRING "Semi-colon delimit multiple arguments.") 489 | 490 | if(CMAKE_GENERATOR MATCHES "Visual Studio") 491 | set(CUDA_HOST_COMPILER "$(VCInstallDir)bin" CACHE FILEPATH "Host side compiler used by NVCC") 492 | else() 493 | if(APPLE 494 | AND "${CMAKE_C_COMPILER_ID}" MATCHES "Clang" 495 | AND "${CMAKE_C_COMPILER}" MATCHES "/cc$") 496 | # Using cc which is symlink to clang may let NVCC think it is GCC and issue 497 | # unhandled -dumpspecs option to clang. Also in case neither 498 | # CMAKE_C_COMPILER is defined (project does not use C language) nor 499 | # CUDA_HOST_COMPILER is specified manually we should skip -ccbin and let 500 | # nvcc use its own default C compiler. 501 | # Only care about this on APPLE with clang to avoid 502 | # following symlinks to things like ccache 503 | if(DEFINED CMAKE_C_COMPILER AND NOT DEFINED CUDA_HOST_COMPILER) 504 | get_filename_component(c_compiler_realpath "${CMAKE_C_COMPILER}" REALPATH) 505 | # if the real path does not end up being clang then 506 | # go back to using CMAKE_C_COMPILER 507 | if(NOT "${c_compiler_realpath}" MATCHES "/clang$") 508 | set(c_compiler_realpath "${CMAKE_C_COMPILER}") 509 | endif() 510 | else() 511 | set(c_compiler_realpath "") 512 | endif() 513 | set(CUDA_HOST_COMPILER "${c_compiler_realpath}" CACHE FILEPATH "Host side compiler used by NVCC") 514 | else() 515 | set(CUDA_HOST_COMPILER "${CMAKE_C_COMPILER}" 516 | CACHE FILEPATH "Host side compiler used by NVCC") 517 | endif() 518 | endif() 519 | 520 | # Propagate the host flags to the host compiler via -Xcompiler 521 | option(CUDA_PROPAGATE_HOST_FLAGS "Propage C/CXX_FLAGS and friends to the host compiler via -Xcompile" ON) 522 | 523 | # Enable CUDA_SEPARABLE_COMPILATION 524 | option(CUDA_SEPARABLE_COMPILATION "Compile CUDA objects with separable compilation enabled. Requires CUDA 5.0+" OFF) 525 | 526 | # Specifies whether the commands used when compiling the .cu file will be printed out. 527 | option(CUDA_VERBOSE_BUILD "Print out the commands run while compiling the CUDA source file. With the Makefile generator this defaults to VERBOSE variable specified on the command line, but can be forced on with this option." OFF) 528 | 529 | mark_as_advanced( 530 | CUDA_64_BIT_DEVICE_CODE 531 | CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE 532 | CUDA_GENERATED_OUTPUT_DIR 533 | CUDA_HOST_COMPILATION_CPP 534 | CUDA_NVCC_FLAGS 535 | CUDA_PROPAGATE_HOST_FLAGS 536 | CUDA_BUILD_CUBIN 537 | CUDA_BUILD_EMULATION 538 | CUDA_VERBOSE_BUILD 539 | CUDA_SEPARABLE_COMPILATION 540 | ) 541 | 542 | # Makefile and similar generators don't define CMAKE_CONFIGURATION_TYPES, so we 543 | # need to add another entry for the CMAKE_BUILD_TYPE. We also need to add the 544 | # standerd set of 4 build types (Debug, MinSizeRel, Release, and RelWithDebInfo) 545 | # for completeness. We need run this loop in order to accomodate the addition 546 | # of extra configuration types. Duplicate entries will be removed by 547 | # REMOVE_DUPLICATES. 548 | set(CUDA_configuration_types ${CMAKE_CONFIGURATION_TYPES} ${CMAKE_BUILD_TYPE} Debug MinSizeRel Release RelWithDebInfo) 549 | list(REMOVE_DUPLICATES CUDA_configuration_types) 550 | foreach(config ${CUDA_configuration_types}) 551 | string(TOUPPER ${config} config_upper) 552 | set(CUDA_NVCC_FLAGS_${config_upper} "" CACHE STRING "Semi-colon delimit multiple arguments.") 553 | mark_as_advanced(CUDA_NVCC_FLAGS_${config_upper}) 554 | endforeach() 555 | 556 | ############################################################################### 557 | ############################################################################### 558 | # Locate CUDA, Set Build Type, etc. 559 | ############################################################################### 560 | ############################################################################### 561 | 562 | macro(cuda_unset_include_and_libraries) 563 | unset(CUDA_TOOLKIT_INCLUDE CACHE) 564 | unset(CUDA_CUDART_LIBRARY CACHE) 565 | unset(CUDA_CUDA_LIBRARY CACHE) 566 | # Make sure you run this before you unset CUDA_VERSION. 567 | if(CUDA_VERSION VERSION_EQUAL "3.0") 568 | # This only existed in the 3.0 version of the CUDA toolkit 569 | unset(CUDA_CUDARTEMU_LIBRARY CACHE) 570 | endif() 571 | unset(CUDA_cudart_static_LIBRARY CACHE) 572 | unset(CUDA_cublas_LIBRARY CACHE) 573 | unset(CUDA_cublas_device_LIBRARY CACHE) 574 | unset(CUDA_cublasemu_LIBRARY CACHE) 575 | unset(CUDA_cufft_LIBRARY CACHE) 576 | unset(CUDA_cufftemu_LIBRARY CACHE) 577 | unset(CUDA_cupti_LIBRARY CACHE) 578 | unset(CUDA_curand_LIBRARY CACHE) 579 | unset(CUDA_cusolver_LIBRARY CACHE) 580 | unset(CUDA_cusparse_LIBRARY CACHE) 581 | unset(CUDA_npp_LIBRARY CACHE) 582 | unset(CUDA_nppc_LIBRARY CACHE) 583 | unset(CUDA_nppi_LIBRARY CACHE) 584 | unset(CUDA_npps_LIBRARY CACHE) 585 | unset(CUDA_nvcuvenc_LIBRARY CACHE) 586 | unset(CUDA_nvcuvid_LIBRARY CACHE) 587 | unset(CUDA_USE_STATIC_CUDA_RUNTIME CACHE) 588 | unset(CUDA_GPU_DETECT_OUTPUT CACHE) 589 | endmacro() 590 | 591 | # Check to see if the CUDA_TOOLKIT_ROOT_DIR and CUDA_SDK_ROOT_DIR have changed, 592 | # if they have then clear the cache variables, so that will be detected again. 593 | if(NOT "${CUDA_TOOLKIT_ROOT_DIR}" STREQUAL "${CUDA_TOOLKIT_ROOT_DIR_INTERNAL}") 594 | unset(CUDA_TOOLKIT_TARGET_DIR CACHE) 595 | unset(CUDA_NVCC_EXECUTABLE CACHE) 596 | cuda_unset_include_and_libraries() 597 | unset(CUDA_VERSION CACHE) 598 | endif() 599 | 600 | if(NOT "${CUDA_TOOLKIT_TARGET_DIR}" STREQUAL "${CUDA_TOOLKIT_TARGET_DIR_INTERNAL}") 601 | cuda_unset_include_and_libraries() 602 | endif() 603 | 604 | # 605 | # End of unset() 606 | # 607 | 608 | # 609 | # Start looking for things 610 | # 611 | 612 | # Search for the cuda distribution. 613 | if(NOT CUDA_TOOLKIT_ROOT_DIR AND NOT CMAKE_CROSSCOMPILING) 614 | # Search in the CUDA_BIN_PATH first. 615 | find_path(CUDA_TOOLKIT_ROOT_DIR 616 | NAMES nvcc nvcc.exe 617 | PATHS 618 | ENV CUDA_TOOLKIT_ROOT 619 | ENV CUDA_PATH 620 | ENV CUDA_BIN_PATH 621 | PATH_SUFFIXES bin bin64 622 | DOC "Toolkit location." 623 | NO_DEFAULT_PATH 624 | ) 625 | 626 | # Now search default paths 627 | find_path(CUDA_TOOLKIT_ROOT_DIR 628 | NAMES nvcc nvcc.exe 629 | PATHS /usr/local/bin 630 | /usr/local/cuda/bin 631 | DOC "Toolkit location." 632 | ) 633 | 634 | if (CUDA_TOOLKIT_ROOT_DIR) 635 | string(REGEX REPLACE "[/\\\\]?bin[64]*[/\\\\]?$" "" CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR}) 636 | # We need to force this back into the cache. 637 | set(CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT_DIR} CACHE PATH "Toolkit location." FORCE) 638 | set(CUDA_TOOLKIT_TARGET_DIR ${CUDA_TOOLKIT_ROOT_DIR}) 639 | endif() 640 | 641 | if (NOT EXISTS ${CUDA_TOOLKIT_ROOT_DIR}) 642 | if(CUDA_FIND_REQUIRED) 643 | message(FATAL_ERROR "Specify CUDA_TOOLKIT_ROOT_DIR") 644 | elseif(NOT CUDA_FIND_QUIETLY) 645 | message("CUDA_TOOLKIT_ROOT_DIR not found or specified") 646 | endif() 647 | endif () 648 | endif () 649 | 650 | if(CMAKE_CROSSCOMPILING) 651 | SET (CUDA_TOOLKIT_ROOT $ENV{CUDA_TOOLKIT_ROOT}) 652 | if(CMAKE_SYSTEM_PROCESSOR STREQUAL "armv7-a") 653 | # Support for NVPACK 654 | set (CUDA_TOOLKIT_TARGET_NAME "armv7-linux-androideabi") 655 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "arm") 656 | # Support for arm cross compilation 657 | set(CUDA_TOOLKIT_TARGET_NAME "armv7-linux-gnueabihf") 658 | elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "aarch64") 659 | # Support for aarch64 cross compilation 660 | if (ANDROID_ARCH_NAME STREQUAL "arm64") 661 | set(CUDA_TOOLKIT_TARGET_NAME "aarch64-linux-androideabi") 662 | else() 663 | set(CUDA_TOOLKIT_TARGET_NAME "aarch64-linux") 664 | endif (ANDROID_ARCH_NAME STREQUAL "arm64") 665 | endif() 666 | 667 | if (EXISTS "${CUDA_TOOLKIT_ROOT}/targets/${CUDA_TOOLKIT_TARGET_NAME}") 668 | set(CUDA_TOOLKIT_TARGET_DIR "${CUDA_TOOLKIT_ROOT}/targets/${CUDA_TOOLKIT_TARGET_NAME}" CACHE PATH "CUDA Toolkit target location.") 669 | SET (CUDA_TOOLKIT_ROOT_DIR ${CUDA_TOOLKIT_ROOT}) 670 | mark_as_advanced(CUDA_TOOLKIT_TARGET_DIR) 671 | endif() 672 | 673 | # add known CUDA targetr root path to the set of directories we search for programs, libraries and headers 674 | set( CMAKE_FIND_ROOT_PATH "${CUDA_TOOLKIT_TARGET_DIR};${CMAKE_FIND_ROOT_PATH}") 675 | macro( cuda_find_host_program ) 676 | find_host_program( ${ARGN} ) 677 | endmacro() 678 | else() 679 | # for non-cross-compile, find_host_program == find_program and CUDA_TOOLKIT_TARGET_DIR == CUDA_TOOLKIT_ROOT_DIR 680 | macro( cuda_find_host_program ) 681 | find_program( ${ARGN} ) 682 | endmacro() 683 | SET (CUDA_TOOLKIT_TARGET_DIR ${CUDA_TOOLKIT_ROOT_DIR}) 684 | endif() 685 | 686 | 687 | # CUDA_NVCC_EXECUTABLE 688 | cuda_find_host_program(CUDA_NVCC_EXECUTABLE 689 | NAMES nvcc 690 | PATHS "${CUDA_TOOLKIT_ROOT_DIR}" 691 | ENV CUDA_PATH 692 | ENV CUDA_BIN_PATH 693 | PATH_SUFFIXES bin bin64 694 | NO_DEFAULT_PATH 695 | ) 696 | # Search default search paths, after we search our own set of paths. 697 | cuda_find_host_program(CUDA_NVCC_EXECUTABLE nvcc) 698 | mark_as_advanced(CUDA_NVCC_EXECUTABLE) 699 | 700 | if(CUDA_NVCC_EXECUTABLE AND NOT CUDA_VERSION) 701 | # Compute the version. 702 | execute_process (COMMAND ${CUDA_NVCC_EXECUTABLE} "--version" OUTPUT_VARIABLE NVCC_OUT) 703 | string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR ${NVCC_OUT}) 704 | string(REGEX REPLACE ".*release ([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR ${NVCC_OUT}) 705 | set(CUDA_VERSION "${CUDA_VERSION_MAJOR}.${CUDA_VERSION_MINOR}" CACHE STRING "Version of CUDA as computed from nvcc.") 706 | mark_as_advanced(CUDA_VERSION) 707 | else() 708 | # Need to set these based off of the cached value 709 | string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\1" CUDA_VERSION_MAJOR "${CUDA_VERSION}") 710 | string(REGEX REPLACE "([0-9]+)\\.([0-9]+).*" "\\2" CUDA_VERSION_MINOR "${CUDA_VERSION}") 711 | endif() 712 | 713 | 714 | # Always set this convenience variable 715 | set(CUDA_VERSION_STRING "${CUDA_VERSION}") 716 | 717 | # CUDA_TOOLKIT_INCLUDE 718 | find_path(CUDA_TOOLKIT_INCLUDE 719 | device_functions.h # Header included in toolkit 720 | PATHS ${CUDA_TOOLKIT_TARGET_DIR} 721 | ENV CUDA_PATH 722 | ENV CUDA_INC_PATH 723 | PATH_SUFFIXES include 724 | NO_DEFAULT_PATH 725 | ) 726 | # Search default search paths, after we search our own set of paths. 727 | find_path(CUDA_TOOLKIT_INCLUDE device_functions.h) 728 | mark_as_advanced(CUDA_TOOLKIT_INCLUDE) 729 | 730 | if (CUDA_VERSION VERSION_GREATER "7.0" OR EXISTS "${CUDA_TOOLKIT_INCLUDE}/cuda_fp16.h") 731 | set(CUDA_HAS_FP16 TRUE) 732 | else() 733 | set(CUDA_HAS_FP16 FALSE) 734 | endif() 735 | 736 | # Set the user list of include dir to nothing to initialize it. 737 | set (CUDA_NVCC_INCLUDE_ARGS_USER "") 738 | set (CUDA_INCLUDE_DIRS ${CUDA_TOOLKIT_INCLUDE}) 739 | 740 | macro(cuda_find_library_local_first_with_path_ext _var _names _doc _path_ext ) 741 | if(CMAKE_SIZEOF_VOID_P EQUAL 8) 742 | # CUDA 3.2+ on Windows moved the library directories, so we need the new 743 | # and old paths. 744 | set(_cuda_64bit_lib_dir "${_path_ext}lib/x64" "${_path_ext}lib64" "${_path_ext}libx64" ) 745 | endif() 746 | # CUDA 3.2+ on Windows moved the library directories, so we need to new 747 | # (lib/Win32) and the old path (lib). 748 | find_library(${_var} 749 | NAMES ${_names} 750 | PATHS "${CUDA_TOOLKIT_TARGET_DIR}" 751 | ENV CUDA_PATH 752 | ENV CUDA_LIB_PATH 753 | PATH_SUFFIXES ${_cuda_64bit_lib_dir} "${_path_ext}lib/Win32" "${_path_ext}lib" "${_path_ext}libWin32" 754 | DOC ${_doc} 755 | NO_DEFAULT_PATH 756 | ) 757 | if (NOT CMAKE_CROSSCOMPILING) 758 | # Search default search paths, after we search our own set of paths. 759 | find_library(${_var} 760 | NAMES ${_names} 761 | PATHS "/usr/lib/nvidia-current" 762 | DOC ${_doc} 763 | ) 764 | endif() 765 | endmacro() 766 | 767 | macro(cuda_find_library_local_first _var _names _doc) 768 | cuda_find_library_local_first_with_path_ext( "${_var}" "${_names}" "${_doc}" "" ) 769 | endmacro() 770 | 771 | macro(find_library_local_first _var _names _doc ) 772 | cuda_find_library_local_first( "${_var}" "${_names}" "${_doc}" "" ) 773 | endmacro() 774 | 775 | 776 | # CUDA_LIBRARIES 777 | cuda_find_library_local_first(CUDA_CUDART_LIBRARY cudart "\"cudart\" library") 778 | if(CUDA_VERSION VERSION_EQUAL "3.0") 779 | # The cudartemu library only existed for the 3.0 version of CUDA. 780 | cuda_find_library_local_first(CUDA_CUDARTEMU_LIBRARY cudartemu "\"cudartemu\" library") 781 | mark_as_advanced( 782 | CUDA_CUDARTEMU_LIBRARY 783 | ) 784 | endif() 785 | 786 | if(CUDA_USE_STATIC_CUDA_RUNTIME AND NOT CUDA_VERSION VERSION_LESS "5.5") 787 | cuda_find_library_local_first(CUDA_cudart_static_LIBRARY cudart_static "static CUDA runtime library") 788 | mark_as_advanced(CUDA_cudart_static_LIBRARY) 789 | endif() 790 | 791 | 792 | if(CUDA_cudart_static_LIBRARY) 793 | # Set whether to use the static cuda runtime. 794 | option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" ON) 795 | set(CUDA_CUDART_LIBRARY_VAR CUDA_cudart_static_LIBRARY) 796 | else() 797 | option(CUDA_USE_STATIC_CUDA_RUNTIME "Use the static version of the CUDA runtime library if available" OFF) 798 | set(CUDA_CUDART_LIBRARY_VAR CUDA_CUDART_LIBRARY) 799 | endif() 800 | 801 | if(CUDA_USE_STATIC_CUDA_RUNTIME) 802 | if(UNIX) 803 | # Check for the dependent libraries. Here we look for pthreads. 804 | if (DEFINED CMAKE_THREAD_PREFER_PTHREAD) 805 | set(_cuda_cmake_thread_prefer_pthread ${CMAKE_THREAD_PREFER_PTHREAD}) 806 | endif() 807 | set(CMAKE_THREAD_PREFER_PTHREAD 1) 808 | 809 | # Many of the FindXYZ CMake comes with makes use of try_compile with int main(){return 0;} 810 | # as the source file. Unfortunately this causes a warning with -Wstrict-prototypes and 811 | # -Werror causes the try_compile to fail. We will just temporarily disable other flags 812 | # when doing the find_package command here. 813 | set(_cuda_cmake_c_flags ${CMAKE_C_FLAGS}) 814 | set(CMAKE_C_FLAGS "-fPIC") 815 | find_package(Threads REQUIRED) 816 | set(CMAKE_C_FLAGS ${_cuda_cmake_c_flags}) 817 | 818 | if (DEFINED _cuda_cmake_thread_prefer_pthread) 819 | set(CMAKE_THREAD_PREFER_PTHREAD ${_cuda_cmake_thread_prefer_pthread}) 820 | unset(_cuda_cmake_thread_prefer_pthread) 821 | else() 822 | unset(CMAKE_THREAD_PREFER_PTHREAD) 823 | endif() 824 | endif() 825 | if (NOT APPLE AND CUDA_VERSION VERSION_LESS "7.0") 826 | # Before CUDA 7.0, there was librt that has things such as, clock_gettime, shm_open, and shm_unlink. 827 | find_library(CUDA_rt_LIBRARY rt) 828 | if (NOT CUDA_rt_LIBRARY) 829 | message(WARNING "Expecting to find librt for libcudart_static, but didn't find it.") 830 | endif() 831 | endif() 832 | endif() 833 | 834 | # CUPTI library showed up in cuda toolkit 4.0 835 | if(NOT CUDA_VERSION VERSION_LESS "4.0") 836 | cuda_find_library_local_first_with_path_ext(CUDA_cupti_LIBRARY cupti "\"cupti\" library" "extras/CUPTI/") 837 | mark_as_advanced(CUDA_cupti_LIBRARY) 838 | endif() 839 | 840 | # Set the CUDA_LIBRARIES variable. This is the set of stuff to link against if you are 841 | # using the CUDA runtime. For the dynamic version of the runtime, most of the 842 | # dependencies are brough in, but for the static version there are additional libraries 843 | # and linker commands needed. 844 | # Initialize to empty 845 | set(CUDA_LIBRARIES) 846 | 847 | # If we are using emulation mode and we found the cudartemu library then use 848 | # that one instead of cudart. 849 | if(CUDA_BUILD_EMULATION AND CUDA_CUDARTEMU_LIBRARY) 850 | list(APPEND CUDA_LIBRARIES ${CUDA_CUDARTEMU_LIBRARY}) 851 | elseif(CUDA_USE_STATIC_CUDA_RUNTIME AND CUDA_cudart_static_LIBRARY) 852 | list(APPEND CUDA_LIBRARIES ${CUDA_cudart_static_LIBRARY} ${CMAKE_THREAD_LIBS_INIT} ${CMAKE_DL_LIBS}) 853 | if (CUDA_rt_LIBRARY) 854 | list(APPEND CUDA_LIBRARIES ${CUDA_rt_LIBRARY}) 855 | endif() 856 | if(APPLE) 857 | # We need to add the default path to the driver (libcuda.dylib) as an rpath, so that 858 | # the static cuda runtime can find it at runtime. 859 | list(APPEND CUDA_LIBRARIES -Wl,-rpath,/usr/local/cuda/lib) 860 | endif() 861 | else() 862 | list(APPEND CUDA_LIBRARIES ${CUDA_CUDART_LIBRARY}) 863 | endif() 864 | 865 | # 1.1 toolkit on linux doesn't appear to have a separate library on 866 | # some platforms. 867 | cuda_find_library_local_first(CUDA_CUDA_LIBRARY cuda "\"cuda\" library (older versions only).") 868 | 869 | mark_as_advanced( 870 | CUDA_CUDA_LIBRARY 871 | CUDA_CUDART_LIBRARY 872 | ) 873 | 874 | ####################### 875 | # Look for some of the toolkit helper libraries 876 | macro(FIND_CUDA_HELPER_LIBS _name) 877 | cuda_find_library_local_first(CUDA_${_name}_LIBRARY ${_name} "\"${_name}\" library") 878 | mark_as_advanced(CUDA_${_name}_LIBRARY) 879 | endmacro() 880 | 881 | ####################### 882 | # Disable emulation for v3.1 onward 883 | if(CUDA_VERSION VERSION_GREATER "3.0") 884 | if(CUDA_BUILD_EMULATION) 885 | message(FATAL_ERROR "CUDA_BUILD_EMULATION is not supported in version 3.1 and onwards. You must disable it to proceed. You have version ${CUDA_VERSION}.") 886 | endif() 887 | endif() 888 | 889 | # Search for additional CUDA toolkit libraries. 890 | if(CUDA_VERSION VERSION_LESS "3.1") 891 | # Emulation libraries aren't available in version 3.1 onward. 892 | find_cuda_helper_libs(cufftemu) 893 | find_cuda_helper_libs(cublasemu) 894 | endif() 895 | find_cuda_helper_libs(cufft) 896 | find_cuda_helper_libs(cublas) 897 | if(NOT CUDA_VERSION VERSION_LESS "3.2") 898 | # cusparse showed up in version 3.2 899 | find_cuda_helper_libs(cusparse) 900 | find_cuda_helper_libs(curand) 901 | if (WIN32) 902 | find_cuda_helper_libs(nvcuvenc) 903 | find_cuda_helper_libs(nvcuvid) 904 | endif() 905 | endif() 906 | if(CUDA_VERSION VERSION_GREATER "5.0") 907 | find_cuda_helper_libs(cublas_device) 908 | # In CUDA 5.5 NPP was splitted onto 3 separate libraries. 909 | find_cuda_helper_libs(nppc) 910 | find_cuda_helper_libs(nppi) 911 | find_cuda_helper_libs(npps) 912 | set(CUDA_npp_LIBRARY "${CUDA_nppc_LIBRARY};${CUDA_nppi_LIBRARY};${CUDA_npps_LIBRARY}") 913 | elseif(NOT CUDA_VERSION VERSION_LESS "4.0") 914 | find_cuda_helper_libs(npp) 915 | endif() 916 | if(NOT CUDA_VERSION VERSION_LESS "7.0") 917 | # cusolver showed up in version 7.0 918 | find_cuda_helper_libs(cusolver) 919 | endif() 920 | 921 | if (CUDA_BUILD_EMULATION) 922 | set(CUDA_CUFFT_LIBRARIES ${CUDA_cufftemu_LIBRARY}) 923 | set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublasemu_LIBRARY}) 924 | else() 925 | set(CUDA_CUFFT_LIBRARIES ${CUDA_cufft_LIBRARY}) 926 | set(CUDA_CUBLAS_LIBRARIES ${CUDA_cublas_LIBRARY} ${CUDA_cublas_device_LIBRARY}) 927 | endif() 928 | 929 | ######################## 930 | # Look for the SDK stuff. As of CUDA 3.0 NVSDKCUDA_ROOT has been replaced with 931 | # NVSDKCOMPUTE_ROOT with the old CUDA C contents moved into the C subdirectory 932 | find_path(CUDA_SDK_ROOT_DIR common/inc/cutil.h 933 | HINTS 934 | "$ENV{NVSDKCOMPUTE_ROOT}/C" 935 | ENV NVSDKCUDA_ROOT 936 | "[HKEY_LOCAL_MACHINE\\SOFTWARE\\NVIDIA Corporation\\Installed Products\\NVIDIA SDK 10\\Compute;InstallDir]" 937 | PATHS 938 | "/Developer/GPU\ Computing/C" 939 | ) 940 | 941 | # Keep the CUDA_SDK_ROOT_DIR first in order to be able to override the 942 | # environment variables. 943 | set(CUDA_SDK_SEARCH_PATH 944 | "${CUDA_SDK_ROOT_DIR}" 945 | "${CUDA_TOOLKIT_ROOT_DIR}/local/NVSDK0.2" 946 | "${CUDA_TOOLKIT_ROOT_DIR}/NVSDK0.2" 947 | "${CUDA_TOOLKIT_ROOT_DIR}/NV_CUDA_SDK" 948 | "$ENV{HOME}/NVIDIA_CUDA_SDK" 949 | "$ENV{HOME}/NVIDIA_CUDA_SDK_MACOSX" 950 | "/Developer/CUDA" 951 | ) 952 | 953 | # Example of how to find an include file from the CUDA_SDK_ROOT_DIR 954 | 955 | # find_path(CUDA_CUT_INCLUDE_DIR 956 | # cutil.h 957 | # PATHS ${CUDA_SDK_SEARCH_PATH} 958 | # PATH_SUFFIXES "common/inc" 959 | # DOC "Location of cutil.h" 960 | # NO_DEFAULT_PATH 961 | # ) 962 | # # Now search system paths 963 | # find_path(CUDA_CUT_INCLUDE_DIR cutil.h DOC "Location of cutil.h") 964 | 965 | # mark_as_advanced(CUDA_CUT_INCLUDE_DIR) 966 | 967 | 968 | # Example of how to find a library in the CUDA_SDK_ROOT_DIR 969 | 970 | # # cutil library is called cutil64 for 64 bit builds on windows. We don't want 971 | # # to get these confused, so we are setting the name based on the word size of 972 | # # the build. 973 | 974 | # if(CMAKE_SIZEOF_VOID_P EQUAL 8) 975 | # set(cuda_cutil_name cutil64) 976 | # else() 977 | # set(cuda_cutil_name cutil32) 978 | # endif() 979 | 980 | # find_library(CUDA_CUT_LIBRARY 981 | # NAMES cutil ${cuda_cutil_name} 982 | # PATHS ${CUDA_SDK_SEARCH_PATH} 983 | # # The new version of the sdk shows up in common/lib, but the old one is in lib 984 | # PATH_SUFFIXES "common/lib" "lib" 985 | # DOC "Location of cutil library" 986 | # NO_DEFAULT_PATH 987 | # ) 988 | # # Now search system paths 989 | # find_library(CUDA_CUT_LIBRARY NAMES cutil ${cuda_cutil_name} DOC "Location of cutil library") 990 | # mark_as_advanced(CUDA_CUT_LIBRARY) 991 | # set(CUDA_CUT_LIBRARIES ${CUDA_CUT_LIBRARY}) 992 | 993 | 994 | 995 | ############################# 996 | # Check for required components 997 | set(CUDA_FOUND TRUE) 998 | 999 | set(CUDA_TOOLKIT_ROOT_DIR_INTERNAL "${CUDA_TOOLKIT_ROOT_DIR}" CACHE INTERNAL 1000 | "This is the value of the last time CUDA_TOOLKIT_ROOT_DIR was set successfully." FORCE) 1001 | set(CUDA_TOOLKIT_TARGET_DIR_INTERNAL "${CUDA_TOOLKIT_TARGET_DIR}" CACHE INTERNAL 1002 | "This is the value of the last time CUDA_TOOLKIT_TARGET_DIR was set successfully." FORCE) 1003 | set(CUDA_SDK_ROOT_DIR_INTERNAL "${CUDA_SDK_ROOT_DIR}" CACHE INTERNAL 1004 | "This is the value of the last time CUDA_SDK_ROOT_DIR was set successfully." FORCE) 1005 | 1006 | #include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake) 1007 | include(${CMAKE_ROOT}/Modules/FindPackageHandleStandardArgs.cmake) 1008 | 1009 | find_package_handle_standard_args(CUDA 1010 | REQUIRED_VARS 1011 | CUDA_TOOLKIT_ROOT_DIR 1012 | CUDA_NVCC_EXECUTABLE 1013 | CUDA_INCLUDE_DIRS 1014 | ${CUDA_CUDART_LIBRARY_VAR} 1015 | VERSION_VAR 1016 | CUDA_VERSION 1017 | ) 1018 | 1019 | 1020 | 1021 | ############################################################################### 1022 | ############################################################################### 1023 | # Macros 1024 | ############################################################################### 1025 | ############################################################################### 1026 | 1027 | ############################################################################### 1028 | # Add include directories to pass to the nvcc command. 1029 | macro(CUDA_INCLUDE_DIRECTORIES) 1030 | foreach(dir ${ARGN}) 1031 | list(APPEND CUDA_NVCC_INCLUDE_ARGS_USER -I${dir}) 1032 | endforeach() 1033 | endmacro() 1034 | 1035 | 1036 | ############################################################################## 1037 | cuda_find_helper_file(parse_cubin cmake) 1038 | cuda_find_helper_file(make2cmake cmake) 1039 | cuda_find_helper_file(run_nvcc cmake) 1040 | include("${CMAKE_CURRENT_LIST_DIR}/FindCUDA/select_compute_arch.cmake") 1041 | 1042 | ############################################################################## 1043 | # Separate the OPTIONS out from the sources 1044 | # 1045 | macro(CUDA_GET_SOURCES_AND_OPTIONS _sources _cmake_options _options) 1046 | set( ${_sources} ) 1047 | set( ${_cmake_options} ) 1048 | set( ${_options} ) 1049 | set( _found_options FALSE ) 1050 | foreach(arg ${ARGN}) 1051 | if("x${arg}" STREQUAL "xOPTIONS") 1052 | set( _found_options TRUE ) 1053 | elseif( 1054 | "x${arg}" STREQUAL "xWIN32" OR 1055 | "x${arg}" STREQUAL "xMACOSX_BUNDLE" OR 1056 | "x${arg}" STREQUAL "xEXCLUDE_FROM_ALL" OR 1057 | "x${arg}" STREQUAL "xSTATIC" OR 1058 | "x${arg}" STREQUAL "xSHARED" OR 1059 | "x${arg}" STREQUAL "xMODULE" 1060 | ) 1061 | list(APPEND ${_cmake_options} ${arg}) 1062 | else() 1063 | if ( _found_options ) 1064 | list(APPEND ${_options} ${arg}) 1065 | else() 1066 | # Assume this is a file 1067 | list(APPEND ${_sources} ${arg}) 1068 | endif() 1069 | endif() 1070 | endforeach() 1071 | endmacro() 1072 | 1073 | ############################################################################## 1074 | # Parse the OPTIONS from ARGN and set the variables prefixed by _option_prefix 1075 | # 1076 | macro(CUDA_PARSE_NVCC_OPTIONS _option_prefix) 1077 | set( _found_config ) 1078 | foreach(arg ${ARGN}) 1079 | # Determine if we are dealing with a perconfiguration flag 1080 | foreach(config ${CUDA_configuration_types}) 1081 | string(TOUPPER ${config} config_upper) 1082 | if (arg STREQUAL "${config_upper}") 1083 | set( _found_config _${arg}) 1084 | # Set arg to nothing to keep it from being processed further 1085 | set( arg ) 1086 | endif() 1087 | endforeach() 1088 | 1089 | if ( arg ) 1090 | list(APPEND ${_option_prefix}${_found_config} "${arg}") 1091 | endif() 1092 | endforeach() 1093 | endmacro() 1094 | 1095 | ############################################################################## 1096 | # Helper to add the include directory for CUDA only once 1097 | function(CUDA_ADD_CUDA_INCLUDE_ONCE) 1098 | get_directory_property(_include_directories INCLUDE_DIRECTORIES) 1099 | set(_add TRUE) 1100 | if(_include_directories) 1101 | foreach(dir ${_include_directories}) 1102 | if("${dir}" STREQUAL "${CUDA_INCLUDE_DIRS}") 1103 | set(_add FALSE) 1104 | endif() 1105 | endforeach() 1106 | endif() 1107 | if(_add) 1108 | include_directories(${CUDA_INCLUDE_DIRS}) 1109 | endif() 1110 | endfunction() 1111 | 1112 | function(CUDA_BUILD_SHARED_LIBRARY shared_flag) 1113 | set(cmake_args ${ARGN}) 1114 | # If SHARED, MODULE, or STATIC aren't already in the list of arguments, then 1115 | # add SHARED or STATIC based on the value of BUILD_SHARED_LIBS. 1116 | list(FIND cmake_args SHARED _cuda_found_SHARED) 1117 | list(FIND cmake_args MODULE _cuda_found_MODULE) 1118 | list(FIND cmake_args STATIC _cuda_found_STATIC) 1119 | if( _cuda_found_SHARED GREATER -1 OR 1120 | _cuda_found_MODULE GREATER -1 OR 1121 | _cuda_found_STATIC GREATER -1) 1122 | set(_cuda_build_shared_libs) 1123 | else() 1124 | if (BUILD_SHARED_LIBS) 1125 | set(_cuda_build_shared_libs SHARED) 1126 | else() 1127 | set(_cuda_build_shared_libs STATIC) 1128 | endif() 1129 | endif() 1130 | set(${shared_flag} ${_cuda_build_shared_libs} PARENT_SCOPE) 1131 | endfunction() 1132 | 1133 | ############################################################################## 1134 | # Helper to avoid clashes of files with the same basename but different paths. 1135 | # This doesn't attempt to do exactly what CMake internals do, which is to only 1136 | # add this path when there is a conflict, since by the time a second collision 1137 | # in names is detected it's already too late to fix the first one. For 1138 | # consistency sake the relative path will be added to all files. 1139 | function(CUDA_COMPUTE_BUILD_PATH path build_path) 1140 | #message("CUDA_COMPUTE_BUILD_PATH([${path}] ${build_path})") 1141 | # Only deal with CMake style paths from here on out 1142 | file(TO_CMAKE_PATH "${path}" bpath) 1143 | if (IS_ABSOLUTE "${bpath}") 1144 | # Absolute paths are generally unnessary, especially if something like 1145 | # file(GLOB_RECURSE) is used to pick up the files. 1146 | 1147 | string(FIND "${bpath}" "${CMAKE_CURRENT_BINARY_DIR}" _binary_dir_pos) 1148 | if (_binary_dir_pos EQUAL 0) 1149 | file(RELATIVE_PATH bpath "${CMAKE_CURRENT_BINARY_DIR}" "${bpath}") 1150 | else() 1151 | file(RELATIVE_PATH bpath "${CMAKE_CURRENT_SOURCE_DIR}" "${bpath}") 1152 | endif() 1153 | endif() 1154 | 1155 | # This recipe is from cmLocalGenerator::CreateSafeUniqueObjectFileName in the 1156 | # CMake source. 1157 | 1158 | # Remove leading / 1159 | string(REGEX REPLACE "^[/]+" "" bpath "${bpath}") 1160 | # Avoid absolute paths by removing ':' 1161 | string(REPLACE ":" "_" bpath "${bpath}") 1162 | # Avoid relative paths that go up the tree 1163 | string(REPLACE "../" "__/" bpath "${bpath}") 1164 | # Avoid spaces 1165 | string(REPLACE " " "_" bpath "${bpath}") 1166 | 1167 | # Strip off the filename. I wait until here to do it, since removin the 1168 | # basename can make a path that looked like path/../basename turn into 1169 | # path/.. (notice the trailing slash). 1170 | get_filename_component(bpath "${bpath}" PATH) 1171 | 1172 | set(${build_path} "${bpath}" PARENT_SCOPE) 1173 | #message("${build_path} = ${bpath}") 1174 | endfunction() 1175 | 1176 | ############################################################################## 1177 | # This helper macro populates the following variables and setups up custom 1178 | # commands and targets to invoke the nvcc compiler to generate C or PTX source 1179 | # dependent upon the format parameter. The compiler is invoked once with -M 1180 | # to generate a dependency file and a second time with -cuda or -ptx to generate 1181 | # a .cpp or .ptx file. 1182 | # INPUT: 1183 | # cuda_target - Target name 1184 | # format - PTX, CUBIN, FATBIN or OBJ 1185 | # FILE1 .. FILEN - The remaining arguments are the sources to be wrapped. 1186 | # OPTIONS - Extra options to NVCC 1187 | # OUTPUT: 1188 | # generated_files - List of generated files 1189 | ############################################################################## 1190 | ############################################################################## 1191 | 1192 | macro(CUDA_WRAP_SRCS cuda_target format generated_files) 1193 | 1194 | # If CMake doesn't support separable compilation, complain 1195 | if(CUDA_SEPARABLE_COMPILATION AND CMAKE_VERSION VERSION_LESS "2.8.10.1") 1196 | message(SEND_ERROR "CUDA_SEPARABLE_COMPILATION isn't supported for CMake versions less than 2.8.10.1") 1197 | endif() 1198 | 1199 | # Set up all the command line flags here, so that they can be overridden on a per target basis. 1200 | 1201 | set(nvcc_flags "") 1202 | 1203 | # Emulation if the card isn't present. 1204 | if (CUDA_BUILD_EMULATION) 1205 | # Emulation. 1206 | set(nvcc_flags ${nvcc_flags} --device-emulation -D_DEVICEEMU -g) 1207 | else() 1208 | # Device mode. No flags necessary. 1209 | endif() 1210 | 1211 | if(CUDA_HOST_COMPILATION_CPP) 1212 | set(CUDA_C_OR_CXX CXX) 1213 | else() 1214 | if(CUDA_VERSION VERSION_LESS "3.0") 1215 | set(nvcc_flags ${nvcc_flags} --host-compilation C) 1216 | else() 1217 | message(WARNING "--host-compilation flag is deprecated in CUDA version >= 3.0. Removing --host-compilation C flag" ) 1218 | endif() 1219 | set(CUDA_C_OR_CXX C) 1220 | endif() 1221 | 1222 | set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION}) 1223 | 1224 | if(CUDA_64_BIT_DEVICE_CODE) 1225 | set(nvcc_flags ${nvcc_flags} -m64) 1226 | else() 1227 | set(nvcc_flags ${nvcc_flags} -m32) 1228 | endif() 1229 | 1230 | if(CUDA_TARGET_CPU_ARCH) 1231 | set(nvcc_flags ${nvcc_flags} "--target-cpu-architecture=${CUDA_TARGET_CPU_ARCH}") 1232 | endif() 1233 | 1234 | # This needs to be passed in at this stage, because VS needs to fill out the 1235 | # value of VCInstallDir from within VS. Note that CCBIN is only used if 1236 | # -ccbin or --compiler-bindir isn't used and CUDA_HOST_COMPILER matches 1237 | # $(VCInstallDir)/bin. 1238 | if(CMAKE_GENERATOR MATCHES "Visual Studio") 1239 | set(ccbin_flags -D "\"CCBIN:PATH=$(VCInstallDir)bin\"" ) 1240 | else() 1241 | set(ccbin_flags) 1242 | endif() 1243 | 1244 | # Figure out which configure we will use and pass that in as an argument to 1245 | # the script. We need to defer the decision until compilation time, because 1246 | # for VS projects we won't know if we are making a debug or release build 1247 | # until build time. 1248 | if(CMAKE_GENERATOR MATCHES "Visual Studio") 1249 | set( CUDA_build_configuration "$(ConfigurationName)" ) 1250 | else() 1251 | set( CUDA_build_configuration "${CMAKE_BUILD_TYPE}") 1252 | endif() 1253 | 1254 | # Initialize our list of includes with the user ones followed by the CUDA system ones. 1255 | set(CUDA_NVCC_INCLUDE_ARGS ${CUDA_NVCC_INCLUDE_ARGS_USER} "-I${CUDA_INCLUDE_DIRS}") 1256 | # Get the include directories for this directory and use them for our nvcc command. 1257 | # Remove duplicate entries which may be present since include_directories 1258 | # in CMake >= 2.8.8 does not remove them. 1259 | get_directory_property(CUDA_NVCC_INCLUDE_DIRECTORIES INCLUDE_DIRECTORIES) 1260 | list(REMOVE_DUPLICATES CUDA_NVCC_INCLUDE_DIRECTORIES) 1261 | if(CUDA_NVCC_INCLUDE_DIRECTORIES) 1262 | foreach(dir ${CUDA_NVCC_INCLUDE_DIRECTORIES}) 1263 | list(APPEND CUDA_NVCC_INCLUDE_ARGS -I${dir}) 1264 | endforeach() 1265 | endif() 1266 | 1267 | # Reset these variables 1268 | set(CUDA_WRAP_OPTION_NVCC_FLAGS) 1269 | foreach(config ${CUDA_configuration_types}) 1270 | string(TOUPPER ${config} config_upper) 1271 | set(CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper}) 1272 | endforeach() 1273 | 1274 | CUDA_GET_SOURCES_AND_OPTIONS(_cuda_wrap_sources _cuda_wrap_cmake_options _cuda_wrap_options ${ARGN}) 1275 | CUDA_PARSE_NVCC_OPTIONS(CUDA_WRAP_OPTION_NVCC_FLAGS ${_cuda_wrap_options}) 1276 | 1277 | # Figure out if we are building a shared library. BUILD_SHARED_LIBS is 1278 | # respected in CUDA_ADD_LIBRARY. 1279 | set(_cuda_build_shared_libs FALSE) 1280 | # SHARED, MODULE 1281 | list(FIND _cuda_wrap_cmake_options SHARED _cuda_found_SHARED) 1282 | list(FIND _cuda_wrap_cmake_options MODULE _cuda_found_MODULE) 1283 | if(_cuda_found_SHARED GREATER -1 OR _cuda_found_MODULE GREATER -1) 1284 | set(_cuda_build_shared_libs TRUE) 1285 | endif() 1286 | # STATIC 1287 | list(FIND _cuda_wrap_cmake_options STATIC _cuda_found_STATIC) 1288 | if(_cuda_found_STATIC GREATER -1) 1289 | set(_cuda_build_shared_libs FALSE) 1290 | endif() 1291 | 1292 | # CUDA_HOST_FLAGS 1293 | if(_cuda_build_shared_libs) 1294 | # If we are setting up code for a shared library, then we need to add extra flags for 1295 | # compiling objects for shared libraries. 1296 | set(CUDA_HOST_SHARED_FLAGS ${CMAKE_SHARED_LIBRARY_${CUDA_C_OR_CXX}_FLAGS}) 1297 | else() 1298 | set(CUDA_HOST_SHARED_FLAGS) 1299 | endif() 1300 | # Only add the CMAKE_{C,CXX}_FLAGS if we are propagating host flags. We 1301 | # always need to set the SHARED_FLAGS, though. 1302 | if(CUDA_PROPAGATE_HOST_FLAGS) 1303 | set(_cuda_host_flags "set(CMAKE_HOST_FLAGS ${CMAKE_${CUDA_C_OR_CXX}_FLAGS} ${CUDA_HOST_SHARED_FLAGS})") 1304 | else() 1305 | set(_cuda_host_flags "set(CMAKE_HOST_FLAGS ${CUDA_HOST_SHARED_FLAGS})") 1306 | endif() 1307 | 1308 | set(_cuda_nvcc_flags_config "# Build specific configuration flags") 1309 | # Loop over all the configuration types to generate appropriate flags for run_nvcc.cmake 1310 | foreach(config ${CUDA_configuration_types}) 1311 | string(TOUPPER ${config} config_upper) 1312 | # CMAKE_FLAGS are strings and not lists. By not putting quotes around CMAKE_FLAGS 1313 | # we convert the strings to lists (like we want). 1314 | 1315 | if(CUDA_PROPAGATE_HOST_FLAGS) 1316 | # nvcc chokes on -g3 in versions previous to 3.0, so replace it with -g 1317 | set(_cuda_fix_g3 FALSE) 1318 | 1319 | if(CMAKE_COMPILER_IS_GNUCC) 1320 | if (CUDA_VERSION VERSION_LESS "3.0" OR 1321 | CUDA_VERSION VERSION_EQUAL "4.1" OR 1322 | CUDA_VERSION VERSION_EQUAL "4.2" 1323 | ) 1324 | set(_cuda_fix_g3 TRUE) 1325 | endif() 1326 | endif() 1327 | if(_cuda_fix_g3) 1328 | string(REPLACE "-g3" "-g" _cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}") 1329 | else() 1330 | set(_cuda_C_FLAGS "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}") 1331 | endif() 1332 | 1333 | set(_cuda_host_flags "${_cuda_host_flags}\nset(CMAKE_HOST_FLAGS_${config_upper} ${_cuda_C_FLAGS})") 1334 | endif() 1335 | 1336 | # Note that if we ever want CUDA_NVCC_FLAGS_ to be string (instead of a list 1337 | # like it is currently), we can remove the quotes around the 1338 | # ${CUDA_NVCC_FLAGS_${config_upper}} variable like the CMAKE_HOST_FLAGS_ variable. 1339 | set(_cuda_nvcc_flags_config "${_cuda_nvcc_flags_config}\nset(CUDA_NVCC_FLAGS_${config_upper} ${CUDA_NVCC_FLAGS_${config_upper}} ;; ${CUDA_WRAP_OPTION_NVCC_FLAGS_${config_upper}})") 1340 | endforeach() 1341 | 1342 | # Process the C++11 flag. If the host sets the flag, we need to add it to nvcc and 1343 | # remove it from the host. This is because -Xcompile -std=c++ will choke nvcc (it uses 1344 | # the C preprocessor). In order to get this to work correctly, we need to use nvcc's 1345 | # specific c++11 flag. 1346 | if( "${_cuda_host_flags}" MATCHES "-std=c\\+\\+11") 1347 | # Add the c++11 flag to nvcc if it isn't already present. Note that we only look at 1348 | # the main flag instead of the configuration specific flags. 1349 | if( NOT "${CUDA_NVCC_FLAGS}" MATCHES "-std;c\\+\\+11" ) 1350 | list(APPEND nvcc_flags --std c++11) 1351 | endif() 1352 | string(REGEX REPLACE "[-]+std=c\\+\\+11" "" _cuda_host_flags "${_cuda_host_flags}") 1353 | endif() 1354 | 1355 | # Get the list of definitions from the directory property 1356 | get_directory_property(CUDA_NVCC_DEFINITIONS COMPILE_DEFINITIONS) 1357 | if(CUDA_NVCC_DEFINITIONS) 1358 | foreach(_definition ${CUDA_NVCC_DEFINITIONS}) 1359 | list(APPEND nvcc_flags "-D${_definition}") 1360 | endforeach() 1361 | endif() 1362 | 1363 | if(_cuda_build_shared_libs) 1364 | list(APPEND nvcc_flags "-D${cuda_target}_EXPORTS") 1365 | endif() 1366 | 1367 | # Reset the output variable 1368 | set(_cuda_wrap_generated_files "") 1369 | 1370 | # Iterate over the macro arguments and create custom 1371 | # commands for all the .cu files. 1372 | foreach(file ${ARGN}) 1373 | # Ignore any file marked as a HEADER_FILE_ONLY 1374 | get_source_file_property(_is_header ${file} HEADER_FILE_ONLY) 1375 | # Allow per source file overrides of the format. Also allows compiling non-.cu files. 1376 | get_source_file_property(_cuda_source_format ${file} CUDA_SOURCE_PROPERTY_FORMAT) 1377 | if((${file} MATCHES "\\.cu$" OR _cuda_source_format) AND NOT _is_header) 1378 | 1379 | if(NOT _cuda_source_format) 1380 | set(_cuda_source_format ${format}) 1381 | endif() 1382 | # If file isn't a .cu file, we need to tell nvcc to treat it as such. 1383 | if(NOT ${file} MATCHES "\\.cu$") 1384 | set(cuda_language_flag -x=cu) 1385 | else() 1386 | set(cuda_language_flag) 1387 | endif() 1388 | 1389 | if( ${_cuda_source_format} MATCHES "OBJ") 1390 | set( cuda_compile_to_external_module OFF ) 1391 | else() 1392 | set( cuda_compile_to_external_module ON ) 1393 | if( ${_cuda_source_format} MATCHES "PTX" ) 1394 | set( cuda_compile_to_external_module_type "ptx" ) 1395 | elseif( ${_cuda_source_format} MATCHES "CUBIN") 1396 | set( cuda_compile_to_external_module_type "cubin" ) 1397 | elseif( ${_cuda_source_format} MATCHES "FATBIN") 1398 | set( cuda_compile_to_external_module_type "fatbin" ) 1399 | else() 1400 | message( FATAL_ERROR "Invalid format flag passed to CUDA_WRAP_SRCS or set with CUDA_SOURCE_PROPERTY_FORMAT file property for file '${file}': '${_cuda_source_format}'. Use OBJ, PTX, CUBIN or FATBIN.") 1401 | endif() 1402 | endif() 1403 | 1404 | if(cuda_compile_to_external_module) 1405 | # Don't use any of the host compilation flags for PTX targets. 1406 | set(CUDA_HOST_FLAGS) 1407 | set(CUDA_NVCC_FLAGS_CONFIG) 1408 | else() 1409 | set(CUDA_HOST_FLAGS ${_cuda_host_flags}) 1410 | set(CUDA_NVCC_FLAGS_CONFIG ${_cuda_nvcc_flags_config}) 1411 | endif() 1412 | 1413 | # Determine output directory 1414 | cuda_compute_build_path("${file}" cuda_build_path) 1415 | set(cuda_compile_intermediate_directory "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${cuda_build_path}") 1416 | if(CUDA_GENERATED_OUTPUT_DIR) 1417 | set(cuda_compile_output_dir "${CUDA_GENERATED_OUTPUT_DIR}") 1418 | else() 1419 | if ( cuda_compile_to_external_module ) 1420 | set(cuda_compile_output_dir "${CMAKE_CURRENT_BINARY_DIR}") 1421 | else() 1422 | set(cuda_compile_output_dir "${cuda_compile_intermediate_directory}") 1423 | endif() 1424 | endif() 1425 | 1426 | # Add a custom target to generate a c or ptx file. ###################### 1427 | 1428 | get_filename_component( basename ${file} NAME ) 1429 | if( cuda_compile_to_external_module ) 1430 | set(generated_file_path "${cuda_compile_output_dir}") 1431 | set(generated_file_basename "${cuda_target}_generated_${basename}.${cuda_compile_to_external_module_type}") 1432 | set(format_flag "-${cuda_compile_to_external_module_type}") 1433 | file(MAKE_DIRECTORY "${cuda_compile_output_dir}") 1434 | else() 1435 | set(generated_file_path "${cuda_compile_output_dir}/${CMAKE_CFG_INTDIR}") 1436 | set(generated_file_basename "${cuda_target}_generated_${basename}${generated_extension}") 1437 | if(CUDA_SEPARABLE_COMPILATION) 1438 | set(format_flag "-dc") 1439 | else() 1440 | set(format_flag "-c") 1441 | endif() 1442 | endif() 1443 | 1444 | # Set all of our file names. Make sure that whatever filenames that have 1445 | # generated_file_path in them get passed in through as a command line 1446 | # argument, so that the ${CMAKE_CFG_INTDIR} gets expanded at run time 1447 | # instead of configure time. 1448 | set(generated_file "${generated_file_path}/${generated_file_basename}") 1449 | set(cmake_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.depend") 1450 | set(NVCC_generated_dependency_file "${cuda_compile_intermediate_directory}/${generated_file_basename}.NVCC-depend") 1451 | set(generated_cubin_file "${generated_file_path}/${generated_file_basename}.cubin.txt") 1452 | set(custom_target_script "${cuda_compile_intermediate_directory}/${generated_file_basename}.cmake") 1453 | 1454 | # Setup properties for obj files: 1455 | if( NOT cuda_compile_to_external_module ) 1456 | set_source_files_properties("${generated_file}" 1457 | PROPERTIES 1458 | EXTERNAL_OBJECT true # This is an object file not to be compiled, but only be linked. 1459 | ) 1460 | endif() 1461 | 1462 | # Don't add CMAKE_CURRENT_SOURCE_DIR if the path is already an absolute path. 1463 | get_filename_component(file_path "${file}" PATH) 1464 | if(IS_ABSOLUTE "${file_path}") 1465 | set(source_file "${file}") 1466 | else() 1467 | set(source_file "${CMAKE_CURRENT_SOURCE_DIR}/${file}") 1468 | endif() 1469 | 1470 | if( NOT cuda_compile_to_external_module AND CUDA_SEPARABLE_COMPILATION) 1471 | list(APPEND ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS "${generated_file}") 1472 | endif() 1473 | 1474 | # Bring in the dependencies. Creates a variable CUDA_NVCC_DEPEND ####### 1475 | cuda_include_nvcc_dependencies(${cmake_dependency_file}) 1476 | 1477 | # Convience string for output ########################################### 1478 | if(CUDA_BUILD_EMULATION) 1479 | set(cuda_build_type "Emulation") 1480 | else() 1481 | set(cuda_build_type "Device") 1482 | endif() 1483 | 1484 | # Build the NVCC made dependency file ################################### 1485 | set(build_cubin OFF) 1486 | if ( NOT CUDA_BUILD_EMULATION AND CUDA_BUILD_CUBIN ) 1487 | if ( NOT cuda_compile_to_external_module ) 1488 | set ( build_cubin ON ) 1489 | endif() 1490 | endif() 1491 | 1492 | # Configure the build script 1493 | configure_file("${CUDA_run_nvcc}" "${custom_target_script}" @ONLY) 1494 | 1495 | 1496 | # So if a user specifies the same cuda file as input more than once, you 1497 | # can have bad things happen with dependencies. Here we check an option 1498 | # to see if this is the behavior they want. 1499 | if(CUDA_ATTACH_VS_BUILD_RULE_TO_CUDA_FILE) 1500 | set(main_dep MAIN_DEPENDENCY ${source_file}) 1501 | else() 1502 | set(main_dep DEPENDS ${source_file}) 1503 | endif() 1504 | 1505 | if(CUDA_VERBOSE_BUILD) 1506 | set(verbose_output ON) 1507 | elseif(CMAKE_GENERATOR MATCHES "Makefiles") 1508 | set(verbose_output "$(VERBOSE)") 1509 | else() 1510 | set(verbose_output OFF) 1511 | endif() 1512 | 1513 | # Create up the comment string 1514 | file(RELATIVE_PATH generated_file_relative_path "${CMAKE_BINARY_DIR}" "${generated_file}") 1515 | if(cuda_compile_to_external_module) 1516 | set(cuda_build_comment_string "Building NVCC ${cuda_compile_to_external_module_type} file ${generated_file_relative_path}") 1517 | else() 1518 | set(cuda_build_comment_string "Building NVCC (${cuda_build_type}) object ${generated_file_relative_path}") 1519 | endif() 1520 | 1521 | set(_verbatim VERBATIM) 1522 | if(ccbin_flags MATCHES "\\$\\(VCInstallDir\\)") 1523 | set(_verbatim "") 1524 | endif() 1525 | 1526 | # Build the generated file and dependency file ########################## 1527 | add_custom_command( 1528 | OUTPUT ${generated_file} 1529 | # These output files depend on the source_file and the contents of cmake_dependency_file 1530 | ${main_dep} 1531 | DEPENDS ${CUDA_NVCC_DEPEND} 1532 | DEPENDS ${custom_target_script} 1533 | # Make sure the output directory exists before trying to write to it. 1534 | COMMAND ${CMAKE_COMMAND} -E make_directory "${generated_file_path}" 1535 | COMMAND ${CMAKE_COMMAND} ARGS 1536 | -D verbose:BOOL=${verbose_output} 1537 | ${ccbin_flags} 1538 | -D build_configuration:STRING=${CUDA_build_configuration} 1539 | -D "generated_file:STRING=${generated_file}" 1540 | -D "generated_cubin_file:STRING=${generated_cubin_file}" 1541 | -P "${custom_target_script}" 1542 | WORKING_DIRECTORY "${cuda_compile_intermediate_directory}" 1543 | COMMENT "${cuda_build_comment_string}" 1544 | ${_verbatim} 1545 | ) 1546 | 1547 | # Make sure the build system knows the file is generated. 1548 | set_source_files_properties(${generated_file} PROPERTIES GENERATED TRUE) 1549 | 1550 | list(APPEND _cuda_wrap_generated_files ${generated_file}) 1551 | 1552 | # Add the other files that we want cmake to clean on a cleanup ########## 1553 | list(APPEND CUDA_ADDITIONAL_CLEAN_FILES "${cmake_dependency_file}") 1554 | list(REMOVE_DUPLICATES CUDA_ADDITIONAL_CLEAN_FILES) 1555 | set(CUDA_ADDITIONAL_CLEAN_FILES ${CUDA_ADDITIONAL_CLEAN_FILES} CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.") 1556 | 1557 | endif() 1558 | endforeach() 1559 | 1560 | # Set the return parameter 1561 | set(${generated_files} ${_cuda_wrap_generated_files}) 1562 | endmacro() 1563 | 1564 | function(_cuda_get_important_host_flags important_flags flag_string) 1565 | if(CMAKE_GENERATOR MATCHES "Visual Studio") 1566 | string(REGEX MATCHALL "/M[DT][d]?" flags "${flag_string}") 1567 | list(APPEND ${important_flags} ${flags}) 1568 | else() 1569 | string(REGEX MATCHALL "-fPIC" flags "${flag_string}") 1570 | list(APPEND ${important_flags} ${flags}) 1571 | endif() 1572 | set(${important_flags} ${${important_flags}} PARENT_SCOPE) 1573 | endfunction() 1574 | 1575 | ############################################################################### 1576 | ############################################################################### 1577 | # Separable Compilation Link 1578 | ############################################################################### 1579 | ############################################################################### 1580 | 1581 | # Compute the filename to be used by CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS 1582 | function(CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME output_file_var cuda_target object_files) 1583 | if (object_files) 1584 | set(generated_extension ${CMAKE_${CUDA_C_OR_CXX}_OUTPUT_EXTENSION}) 1585 | set(output_file "${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${cuda_target}.dir/${CMAKE_CFG_INTDIR}/${cuda_target}_intermediate_link${generated_extension}") 1586 | else() 1587 | set(output_file) 1588 | endif() 1589 | 1590 | set(${output_file_var} "${output_file}" PARENT_SCOPE) 1591 | endfunction() 1592 | 1593 | # Setup the build rule for the separable compilation intermediate link file. 1594 | function(CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS output_file cuda_target options object_files) 1595 | if (object_files) 1596 | 1597 | set_source_files_properties("${output_file}" 1598 | PROPERTIES 1599 | EXTERNAL_OBJECT TRUE # This is an object file not to be compiled, but only 1600 | # be linked. 1601 | GENERATED TRUE # This file is generated during the build 1602 | ) 1603 | 1604 | # For now we are ignoring all the configuration specific flags. 1605 | set(nvcc_flags) 1606 | CUDA_PARSE_NVCC_OPTIONS(nvcc_flags ${options}) 1607 | if(CUDA_64_BIT_DEVICE_CODE) 1608 | list(APPEND nvcc_flags -m64) 1609 | else() 1610 | list(APPEND nvcc_flags -m32) 1611 | endif() 1612 | # If -ccbin, --compiler-bindir has been specified, don't do anything. Otherwise add it here. 1613 | list( FIND nvcc_flags "-ccbin" ccbin_found0 ) 1614 | list( FIND nvcc_flags "--compiler-bindir" ccbin_found1 ) 1615 | if( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 AND CUDA_HOST_COMPILER ) 1616 | # Match VERBATIM check below. 1617 | if(CUDA_HOST_COMPILER MATCHES "\\$\\(VCInstallDir\\)") 1618 | list(APPEND nvcc_flags -ccbin "\"${CUDA_HOST_COMPILER}\"") 1619 | else() 1620 | list(APPEND nvcc_flags -ccbin "${CUDA_HOST_COMPILER}") 1621 | endif() 1622 | endif() 1623 | 1624 | # Create a list of flags specified by CUDA_NVCC_FLAGS_${CONFIG} and CMAKE_${CUDA_C_OR_CXX}_FLAGS* 1625 | set(config_specific_flags) 1626 | set(flags) 1627 | foreach(config ${CUDA_configuration_types}) 1628 | string(TOUPPER ${config} config_upper) 1629 | # Add config specific flags 1630 | foreach(f ${CUDA_NVCC_FLAGS_${config_upper}}) 1631 | list(APPEND config_specific_flags $<$:${f}>) 1632 | endforeach() 1633 | set(important_host_flags) 1634 | _cuda_get_important_host_flags(important_host_flags "${CMAKE_${CUDA_C_OR_CXX}_FLAGS_${config_upper}}") 1635 | foreach(f ${important_host_flags}) 1636 | list(APPEND flags $<$:-Xcompiler> $<$:${f}>) 1637 | endforeach() 1638 | endforeach() 1639 | # Add CMAKE_${CUDA_C_OR_CXX}_FLAGS 1640 | set(important_host_flags) 1641 | _cuda_get_important_host_flags(important_host_flags "${CMAKE_${CUDA_C_OR_CXX}_FLAGS}") 1642 | foreach(f ${important_host_flags}) 1643 | list(APPEND flags -Xcompiler ${f}) 1644 | endforeach() 1645 | 1646 | # Add our general CUDA_NVCC_FLAGS with the configuration specifig flags 1647 | set(nvcc_flags ${CUDA_NVCC_FLAGS} ${config_specific_flags} ${nvcc_flags}) 1648 | 1649 | file(RELATIVE_PATH output_file_relative_path "${CMAKE_BINARY_DIR}" "${output_file}") 1650 | 1651 | # Some generators don't handle the multiple levels of custom command 1652 | # dependencies correctly (obj1 depends on file1, obj2 depends on obj1), so 1653 | # we work around that issue by compiling the intermediate link object as a 1654 | # pre-link custom command in that situation. 1655 | set(do_obj_build_rule TRUE) 1656 | if (MSVC_VERSION GREATER 1599 AND MSVC_VERSION LESS 1800) 1657 | # VS 2010 and 2012 have this problem. 1658 | set(do_obj_build_rule FALSE) 1659 | endif() 1660 | 1661 | set(_verbatim VERBATIM) 1662 | if(nvcc_flags MATCHES "\\$\\(VCInstallDir\\)") 1663 | set(_verbatim "") 1664 | endif() 1665 | 1666 | if (do_obj_build_rule) 1667 | add_custom_command( 1668 | OUTPUT ${output_file} 1669 | DEPENDS ${object_files} 1670 | COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} -dlink ${object_files} -o ${output_file} 1671 | ${flags} 1672 | COMMENT "Building NVCC intermediate link file ${output_file_relative_path}" 1673 | ${_verbatim} 1674 | ) 1675 | else() 1676 | get_filename_component(output_file_dir "${output_file}" DIRECTORY) 1677 | add_custom_command( 1678 | TARGET ${cuda_target} 1679 | PRE_LINK 1680 | COMMAND ${CMAKE_COMMAND} -E echo "Building NVCC intermediate link file ${output_file_relative_path}" 1681 | COMMAND ${CMAKE_COMMAND} -E make_directory "${output_file_dir}" 1682 | COMMAND ${CUDA_NVCC_EXECUTABLE} ${nvcc_flags} ${flags} -dlink ${object_files} -o "${output_file}" 1683 | ${_verbatim} 1684 | ) 1685 | endif() 1686 | endif() 1687 | endfunction() 1688 | 1689 | ############################################################################### 1690 | ############################################################################### 1691 | # ADD LIBRARY 1692 | ############################################################################### 1693 | ############################################################################### 1694 | macro(CUDA_ADD_LIBRARY cuda_target) 1695 | 1696 | CUDA_ADD_CUDA_INCLUDE_ONCE() 1697 | 1698 | # Separate the sources from the options 1699 | CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN}) 1700 | CUDA_BUILD_SHARED_LIBRARY(_cuda_shared_flag ${ARGN}) 1701 | # Create custom commands and targets for each file. 1702 | CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources} 1703 | ${_cmake_options} ${_cuda_shared_flag} 1704 | OPTIONS ${_options} ) 1705 | 1706 | # Compute the file name of the intermedate link file used for separable 1707 | # compilation. 1708 | CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME(link_file ${cuda_target} "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") 1709 | 1710 | # Add the library. 1711 | add_library(${cuda_target} ${_cmake_options} 1712 | ${_generated_files} 1713 | ${_sources} 1714 | ${link_file} 1715 | ) 1716 | 1717 | # Add a link phase for the separable compilation if it has been enabled. If 1718 | # it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS 1719 | # variable will have been defined. 1720 | CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") 1721 | 1722 | target_link_libraries(${cuda_target} 1723 | ${CUDA_LIBRARIES} 1724 | ) 1725 | 1726 | # We need to set the linker language based on what the expected generated file 1727 | # would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP. 1728 | set_target_properties(${cuda_target} 1729 | PROPERTIES 1730 | LINKER_LANGUAGE ${CUDA_C_OR_CXX} 1731 | ) 1732 | 1733 | endmacro() 1734 | 1735 | 1736 | ############################################################################### 1737 | ############################################################################### 1738 | # ADD EXECUTABLE 1739 | ############################################################################### 1740 | ############################################################################### 1741 | macro(CUDA_ADD_EXECUTABLE cuda_target) 1742 | 1743 | CUDA_ADD_CUDA_INCLUDE_ONCE() 1744 | 1745 | # Separate the sources from the options 1746 | CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN}) 1747 | # Create custom commands and targets for each file. 1748 | CUDA_WRAP_SRCS( ${cuda_target} OBJ _generated_files ${_sources} OPTIONS ${_options} ) 1749 | 1750 | # Compute the file name of the intermedate link file used for separable 1751 | # compilation. 1752 | CUDA_COMPUTE_SEPARABLE_COMPILATION_OBJECT_FILE_NAME(link_file ${cuda_target} "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") 1753 | 1754 | # Add the library. 1755 | add_executable(${cuda_target} ${_cmake_options} 1756 | ${_generated_files} 1757 | ${_sources} 1758 | ${link_file} 1759 | ) 1760 | 1761 | # Add a link phase for the separable compilation if it has been enabled. If 1762 | # it has been enabled then the ${cuda_target}_SEPARABLE_COMPILATION_OBJECTS 1763 | # variable will have been defined. 1764 | CUDA_LINK_SEPARABLE_COMPILATION_OBJECTS("${link_file}" ${cuda_target} "${_options}" "${${cuda_target}_SEPARABLE_COMPILATION_OBJECTS}") 1765 | 1766 | target_link_libraries(${cuda_target} 1767 | ${CUDA_LIBRARIES} 1768 | ) 1769 | 1770 | # We need to set the linker language based on what the expected generated file 1771 | # would be. CUDA_C_OR_CXX is computed based on CUDA_HOST_COMPILATION_CPP. 1772 | set_target_properties(${cuda_target} 1773 | PROPERTIES 1774 | LINKER_LANGUAGE ${CUDA_C_OR_CXX} 1775 | ) 1776 | 1777 | endmacro() 1778 | 1779 | 1780 | ############################################################################### 1781 | ############################################################################### 1782 | # (Internal) helper for manually added cuda source files with specific targets 1783 | ############################################################################### 1784 | ############################################################################### 1785 | macro(cuda_compile_base cuda_target format generated_files) 1786 | 1787 | # Separate the sources from the options 1788 | CUDA_GET_SOURCES_AND_OPTIONS(_sources _cmake_options _options ${ARGN}) 1789 | # Create custom commands and targets for each file. 1790 | CUDA_WRAP_SRCS( ${cuda_target} ${format} _generated_files ${_sources} ${_cmake_options} 1791 | OPTIONS ${_options} ) 1792 | 1793 | set( ${generated_files} ${_generated_files}) 1794 | 1795 | endmacro() 1796 | 1797 | ############################################################################### 1798 | ############################################################################### 1799 | # CUDA COMPILE 1800 | ############################################################################### 1801 | ############################################################################### 1802 | macro(CUDA_COMPILE generated_files) 1803 | cuda_compile_base(cuda_compile OBJ ${generated_files} ${ARGN}) 1804 | endmacro() 1805 | 1806 | ############################################################################### 1807 | ############################################################################### 1808 | # CUDA COMPILE PTX 1809 | ############################################################################### 1810 | ############################################################################### 1811 | macro(CUDA_COMPILE_PTX generated_files) 1812 | cuda_compile_base(cuda_compile_ptx PTX ${generated_files} ${ARGN}) 1813 | endmacro() 1814 | 1815 | ############################################################################### 1816 | ############################################################################### 1817 | # CUDA COMPILE FATBIN 1818 | ############################################################################### 1819 | ############################################################################### 1820 | macro(CUDA_COMPILE_FATBIN generated_files) 1821 | cuda_compile_base(cuda_compile_fatbin FATBIN ${generated_files} ${ARGN}) 1822 | endmacro() 1823 | 1824 | ############################################################################### 1825 | ############################################################################### 1826 | # CUDA COMPILE CUBIN 1827 | ############################################################################### 1828 | ############################################################################### 1829 | macro(CUDA_COMPILE_CUBIN generated_files) 1830 | cuda_compile_base(cuda_compile_cubin CUBIN ${generated_files} ${ARGN}) 1831 | endmacro() 1832 | 1833 | 1834 | ############################################################################### 1835 | ############################################################################### 1836 | # CUDA ADD CUFFT TO TARGET 1837 | ############################################################################### 1838 | ############################################################################### 1839 | macro(CUDA_ADD_CUFFT_TO_TARGET target) 1840 | if (CUDA_BUILD_EMULATION) 1841 | target_link_libraries(${target} ${CUDA_cufftemu_LIBRARY}) 1842 | else() 1843 | target_link_libraries(${target} ${CUDA_cufft_LIBRARY}) 1844 | endif() 1845 | endmacro() 1846 | 1847 | ############################################################################### 1848 | ############################################################################### 1849 | # CUDA ADD CUBLAS TO TARGET 1850 | ############################################################################### 1851 | ############################################################################### 1852 | macro(CUDA_ADD_CUBLAS_TO_TARGET target) 1853 | if (CUDA_BUILD_EMULATION) 1854 | target_link_libraries(${target} ${CUDA_cublasemu_LIBRARY}) 1855 | else() 1856 | target_link_libraries(${target} ${CUDA_cublas_LIBRARY} ${CUDA_cublas_device_LIBRARY}) 1857 | endif() 1858 | endmacro() 1859 | 1860 | ############################################################################### 1861 | ############################################################################### 1862 | # CUDA BUILD CLEAN TARGET 1863 | ############################################################################### 1864 | ############################################################################### 1865 | macro(CUDA_BUILD_CLEAN_TARGET) 1866 | # Call this after you add all your CUDA targets, and you will get a convience 1867 | # target. You should also make clean after running this target to get the 1868 | # build system to generate all the code again. 1869 | 1870 | set(cuda_clean_target_name clean_cuda_depends) 1871 | if (CMAKE_GENERATOR MATCHES "Visual Studio") 1872 | string(TOUPPER ${cuda_clean_target_name} cuda_clean_target_name) 1873 | endif() 1874 | add_custom_target(${cuda_clean_target_name} 1875 | COMMAND ${CMAKE_COMMAND} -E remove ${CUDA_ADDITIONAL_CLEAN_FILES}) 1876 | 1877 | # Clear out the variable, so the next time we configure it will be empty. 1878 | # This is useful so that the files won't persist in the list after targets 1879 | # have been removed. 1880 | set(CUDA_ADDITIONAL_CLEAN_FILES "" CACHE INTERNAL "List of intermediate files that are part of the cuda dependency scanning.") 1881 | endmacro() 1882 | -------------------------------------------------------------------------------- /cmake/3.6/Modules/FindCUDA/make2cmake.cmake: -------------------------------------------------------------------------------- 1 | # James Bigler, NVIDIA Corp (nvidia.com - jbigler) 2 | # Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html 3 | # 4 | # Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved. 5 | # 6 | # Copyright (c) 2007-2009 7 | # Scientific Computing and Imaging Institute, University of Utah 8 | # 9 | # This code is licensed under the MIT License. See the FindCUDA.cmake script 10 | # for the text of the license. 11 | 12 | # The MIT License 13 | # 14 | # License for the specific language governing rights and limitations under 15 | # Permission is hereby granted, free of charge, to any person obtaining a 16 | # copy of this software and associated documentation files (the "Software"), 17 | # to deal in the Software without restriction, including without limitation 18 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 19 | # and/or sell copies of the Software, and to permit persons to whom the 20 | # Software is furnished to do so, subject to the following conditions: 21 | # 22 | # The above copyright notice and this permission notice shall be included 23 | # in all copies or substantial portions of the Software. 24 | # 25 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 26 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 28 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 30 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 31 | # DEALINGS IN THE SOFTWARE. 32 | # 33 | 34 | ####################################################################### 35 | # This converts a file written in makefile syntax into one that can be included 36 | # by CMake. 37 | 38 | # Input variables 39 | # 40 | # verbose:BOOL=<> OFF: Be as quiet as possible (default) 41 | # ON : Extra output 42 | # 43 | # input_file:FILEPATH=<> Path to dependecy file in makefile format 44 | # 45 | # output_file:FILEPATH=<> Path to file with dependencies in CMake readable variable 46 | # 47 | 48 | file(READ ${input_file} depend_text) 49 | 50 | if (NOT "${depend_text}" STREQUAL "") 51 | 52 | # message("FOUND DEPENDS") 53 | 54 | string(REPLACE "\\ " " " depend_text ${depend_text}) 55 | 56 | # This works for the nvcc -M generated dependency files. 57 | string(REGEX REPLACE "^.* : " "" depend_text ${depend_text}) 58 | string(REGEX REPLACE "[ \\\\]*\n" ";" depend_text ${depend_text}) 59 | 60 | set(dependency_list "") 61 | 62 | foreach(file ${depend_text}) 63 | 64 | string(REGEX REPLACE "^ +" "" file ${file}) 65 | 66 | # OK, now if we had a UNC path, nvcc has a tendency to only output the first '/' 67 | # instead of '//'. Here we will test to see if the file exists, if it doesn't then 68 | # try to prepend another '/' to the path and test again. If it still fails remove the 69 | # path. 70 | 71 | if(NOT EXISTS "${file}") 72 | if (EXISTS "/${file}") 73 | set(file "/${file}") 74 | else() 75 | if(verbose) 76 | message(WARNING " Removing non-existent dependency file: ${file}") 77 | endif() 78 | set(file "") 79 | endif() 80 | endif() 81 | 82 | # Make sure we check to see if we have a file, before asking if it is not a directory. 83 | # if(NOT IS_DIRECTORY "") will return TRUE. 84 | if(file AND NOT IS_DIRECTORY "${file}") 85 | # If softlinks start to matter, we should change this to REALPATH. For now we need 86 | # to flatten paths, because nvcc can generate stuff like /bin/../include instead of 87 | # just /include. 88 | get_filename_component(file_absolute "${file}" ABSOLUTE) 89 | list(APPEND dependency_list "${file_absolute}") 90 | endif() 91 | 92 | endforeach() 93 | 94 | else() 95 | # message("FOUND NO DEPENDS") 96 | endif() 97 | 98 | # Remove the duplicate entries and sort them. 99 | list(REMOVE_DUPLICATES dependency_list) 100 | list(SORT dependency_list) 101 | 102 | foreach(file ${dependency_list}) 103 | set(cuda_nvcc_depend "${cuda_nvcc_depend} \"${file}\"\n") 104 | endforeach() 105 | 106 | file(WRITE ${output_file} "# Generated by: make2cmake.cmake\nSET(CUDA_NVCC_DEPEND\n ${cuda_nvcc_depend})\n\n") 107 | -------------------------------------------------------------------------------- /cmake/3.6/Modules/FindCUDA/parse_cubin.cmake: -------------------------------------------------------------------------------- 1 | # James Bigler, NVIDIA Corp (nvidia.com - jbigler) 2 | # Abe Stephens, SCI Institute -- http://www.sci.utah.edu/~abe/FindCuda.html 3 | # 4 | # Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved. 5 | # 6 | # Copyright (c) 2007-2009 7 | # Scientific Computing and Imaging Institute, University of Utah 8 | # 9 | # This code is licensed under the MIT License. See the FindCUDA.cmake script 10 | # for the text of the license. 11 | 12 | # The MIT License 13 | # 14 | # License for the specific language governing rights and limitations under 15 | # Permission is hereby granted, free of charge, to any person obtaining a 16 | # copy of this software and associated documentation files (the "Software"), 17 | # to deal in the Software without restriction, including without limitation 18 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 19 | # and/or sell copies of the Software, and to permit persons to whom the 20 | # Software is furnished to do so, subject to the following conditions: 21 | # 22 | # The above copyright notice and this permission notice shall be included 23 | # in all copies or substantial portions of the Software. 24 | # 25 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 26 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 27 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 28 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 29 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 30 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 31 | # DEALINGS IN THE SOFTWARE. 32 | # 33 | 34 | ####################################################################### 35 | # Parses a .cubin file produced by nvcc and reports statistics about the file. 36 | 37 | 38 | file(READ ${input_file} file_text) 39 | 40 | if (NOT "${file_text}" STREQUAL "") 41 | 42 | string(REPLACE ";" "\\;" file_text ${file_text}) 43 | string(REPLACE "\ncode" ";code" file_text ${file_text}) 44 | 45 | list(LENGTH file_text len) 46 | 47 | foreach(line ${file_text}) 48 | 49 | # Only look at "code { }" blocks. 50 | if(line MATCHES "^code") 51 | 52 | # Break into individual lines. 53 | string(REGEX REPLACE "\n" ";" line ${line}) 54 | 55 | foreach(entry ${line}) 56 | 57 | # Extract kernel names. 58 | if (${entry} MATCHES "[^g]name = ([^ ]+)") 59 | set(entry "${CMAKE_MATCH_1}") 60 | 61 | # Check to see if the kernel name starts with "_" 62 | set(skip FALSE) 63 | # if (${entry} MATCHES "^_") 64 | # Skip the rest of this block. 65 | # message("Skipping ${entry}") 66 | # set(skip TRUE) 67 | # else () 68 | message("Kernel: ${entry}") 69 | # endif () 70 | 71 | endif() 72 | 73 | # Skip the rest of the block if necessary 74 | if(NOT skip) 75 | 76 | # Registers 77 | if (${entry} MATCHES "reg([ ]+)=([ ]+)([^ ]+)") 78 | set(entry "${CMAKE_MATCH_3}") 79 | message("Registers: ${entry}") 80 | endif() 81 | 82 | # Local memory 83 | if (${entry} MATCHES "lmem([ ]+)=([ ]+)([^ ]+)") 84 | set(entry "${CMAKE_MATCH_3}") 85 | message("Local: ${entry}") 86 | endif() 87 | 88 | # Shared memory 89 | if (${entry} MATCHES "smem([ ]+)=([ ]+)([^ ]+)") 90 | set(entry "${CMAKE_MATCH_3}") 91 | message("Shared: ${entry}") 92 | endif() 93 | 94 | if (${entry} MATCHES "^}") 95 | message("") 96 | endif() 97 | 98 | endif() 99 | 100 | 101 | endforeach() 102 | 103 | endif() 104 | 105 | endforeach() 106 | 107 | else() 108 | # message("FOUND NO DEPENDS") 109 | endif() 110 | 111 | 112 | -------------------------------------------------------------------------------- /cmake/3.6/Modules/FindCUDA/run_nvcc.cmake: -------------------------------------------------------------------------------- 1 | # James Bigler, NVIDIA Corp (nvidia.com - jbigler) 2 | # 3 | # Copyright (c) 2008 - 2009 NVIDIA Corporation. All rights reserved. 4 | # 5 | # This code is licensed under the MIT License. See the FindCUDA.cmake script 6 | # for the text of the license. 7 | 8 | # The MIT License 9 | # 10 | # License for the specific language governing rights and limitations under 11 | # Permission is hereby granted, free of charge, to any person obtaining a 12 | # copy of this software and associated documentation files (the "Software"), 13 | # to deal in the Software without restriction, including without limitation 14 | # the rights to use, copy, modify, merge, publish, distribute, sublicense, 15 | # and/or sell copies of the Software, and to permit persons to whom the 16 | # Software is furnished to do so, subject to the following conditions: 17 | # 18 | # The above copyright notice and this permission notice shall be included 19 | # in all copies or substantial portions of the Software. 20 | # 21 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22 | # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 23 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 24 | # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 25 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 27 | # DEALINGS IN THE SOFTWARE. 28 | 29 | 30 | ########################################################################## 31 | # This file runs the nvcc commands to produce the desired output file along with 32 | # the dependency file needed by CMake to compute dependencies. In addition the 33 | # file checks the output of each command and if the command fails it deletes the 34 | # output files. 35 | 36 | # Input variables 37 | # 38 | # verbose:BOOL=<> OFF: Be as quiet as possible (default) 39 | # ON : Describe each step 40 | # 41 | # build_configuration:STRING=<> Typically one of Debug, MinSizeRel, Release, or 42 | # RelWithDebInfo, but it should match one of the 43 | # entries in CUDA_HOST_FLAGS. This is the build 44 | # configuration used when compiling the code. If 45 | # blank or unspecified Debug is assumed as this is 46 | # what CMake does. 47 | # 48 | # generated_file:STRING=<> File to generate. This argument must be passed in. 49 | # 50 | # generated_cubin_file:STRING=<> File to generate. This argument must be passed 51 | # in if build_cubin is true. 52 | 53 | if(NOT generated_file) 54 | message(FATAL_ERROR "You must specify generated_file on the command line") 55 | endif() 56 | 57 | # Set these up as variables to make reading the generated file easier 58 | set(CMAKE_COMMAND "@CMAKE_COMMAND@") # path 59 | set(source_file "@source_file@") # path 60 | set(NVCC_generated_dependency_file "@NVCC_generated_dependency_file@") # path 61 | set(cmake_dependency_file "@cmake_dependency_file@") # path 62 | set(CUDA_make2cmake "@CUDA_make2cmake@") # path 63 | set(CUDA_parse_cubin "@CUDA_parse_cubin@") # path 64 | set(build_cubin @build_cubin@) # bool 65 | set(CUDA_HOST_COMPILER "@CUDA_HOST_COMPILER@") # path 66 | # We won't actually use these variables for now, but we need to set this, in 67 | # order to force this file to be run again if it changes. 68 | set(generated_file_path "@generated_file_path@") # path 69 | set(generated_file_internal "@generated_file@") # path 70 | set(generated_cubin_file_internal "@generated_cubin_file@") # path 71 | 72 | set(CUDA_NVCC_EXECUTABLE "@CUDA_NVCC_EXECUTABLE@") # path 73 | set(CUDA_NVCC_FLAGS @CUDA_NVCC_FLAGS@ ;; @CUDA_WRAP_OPTION_NVCC_FLAGS@) # list 74 | @CUDA_NVCC_FLAGS_CONFIG@ 75 | set(nvcc_flags @nvcc_flags@) # list 76 | set(CUDA_NVCC_INCLUDE_ARGS "@CUDA_NVCC_INCLUDE_ARGS@") # list (needs to be in quotes to handle spaces properly). 77 | set(format_flag "@format_flag@") # string 78 | set(cuda_language_flag @cuda_language_flag@) # list 79 | 80 | if(build_cubin AND NOT generated_cubin_file) 81 | message(FATAL_ERROR "You must specify generated_cubin_file on the command line") 82 | endif() 83 | 84 | # This is the list of host compilation flags. It C or CXX should already have 85 | # been chosen by FindCUDA.cmake. 86 | @CUDA_HOST_FLAGS@ 87 | 88 | # Take the compiler flags and package them up to be sent to the compiler via -Xcompiler 89 | set(nvcc_host_compiler_flags "") 90 | # If we weren't given a build_configuration, use Debug. 91 | if(NOT build_configuration) 92 | set(build_configuration Debug) 93 | endif() 94 | string(TOUPPER "${build_configuration}" build_configuration) 95 | #message("CUDA_NVCC_HOST_COMPILER_FLAGS = ${CUDA_NVCC_HOST_COMPILER_FLAGS}") 96 | foreach(flag ${CMAKE_HOST_FLAGS} ${CMAKE_HOST_FLAGS_${build_configuration}}) 97 | # Extra quotes are added around each flag to help nvcc parse out flags with spaces. 98 | set(nvcc_host_compiler_flags "${nvcc_host_compiler_flags},\"${flag}\"") 99 | endforeach() 100 | if (nvcc_host_compiler_flags) 101 | set(nvcc_host_compiler_flags "-Xcompiler" ${nvcc_host_compiler_flags}) 102 | endif() 103 | #message("nvcc_host_compiler_flags = \"${nvcc_host_compiler_flags}\"") 104 | # Add the build specific configuration flags 105 | list(APPEND CUDA_NVCC_FLAGS ${CUDA_NVCC_FLAGS_${build_configuration}}) 106 | 107 | # Any -ccbin existing in CUDA_NVCC_FLAGS gets highest priority 108 | list( FIND CUDA_NVCC_FLAGS "-ccbin" ccbin_found0 ) 109 | list( FIND CUDA_NVCC_FLAGS "--compiler-bindir" ccbin_found1 ) 110 | if( ccbin_found0 LESS 0 AND ccbin_found1 LESS 0 AND CUDA_HOST_COMPILER ) 111 | if (CUDA_HOST_COMPILER STREQUAL "$(VCInstallDir)bin" AND DEFINED CCBIN) 112 | set(CCBIN -ccbin "${CCBIN}") 113 | else() 114 | set(CCBIN -ccbin "${CUDA_HOST_COMPILER}") 115 | endif() 116 | endif() 117 | 118 | # cuda_execute_process - Executes a command with optional command echo and status message. 119 | # 120 | # status - Status message to print if verbose is true 121 | # command - COMMAND argument from the usual execute_process argument structure 122 | # ARGN - Remaining arguments are the command with arguments 123 | # 124 | # CUDA_result - return value from running the command 125 | # 126 | # Make this a macro instead of a function, so that things like RESULT_VARIABLE 127 | # and other return variables are present after executing the process. 128 | macro(cuda_execute_process status command) 129 | set(_command ${command}) 130 | if(NOT "x${_command}" STREQUAL "xCOMMAND") 131 | message(FATAL_ERROR "Malformed call to cuda_execute_process. Missing COMMAND as second argument. (command = ${command})") 132 | endif() 133 | if(verbose) 134 | execute_process(COMMAND "${CMAKE_COMMAND}" -E echo -- ${status}) 135 | # Now we need to build up our command string. We are accounting for quotes 136 | # and spaces, anything else is left up to the user to fix if they want to 137 | # copy and paste a runnable command line. 138 | set(cuda_execute_process_string) 139 | foreach(arg ${ARGN}) 140 | # If there are quotes, excape them, so they come through. 141 | string(REPLACE "\"" "\\\"" arg ${arg}) 142 | # Args with spaces need quotes around them to get them to be parsed as a single argument. 143 | if(arg MATCHES " ") 144 | list(APPEND cuda_execute_process_string "\"${arg}\"") 145 | else() 146 | list(APPEND cuda_execute_process_string ${arg}) 147 | endif() 148 | endforeach() 149 | # Echo the command 150 | execute_process(COMMAND ${CMAKE_COMMAND} -E echo ${cuda_execute_process_string}) 151 | endif() 152 | # Run the command 153 | execute_process(COMMAND ${ARGN} RESULT_VARIABLE CUDA_result ) 154 | endmacro() 155 | 156 | # Delete the target file 157 | cuda_execute_process( 158 | "Removing ${generated_file}" 159 | COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}" 160 | ) 161 | 162 | # For CUDA 2.3 and below, -G -M doesn't work, so remove the -G flag 163 | # for dependency generation and hope for the best. 164 | set(depends_CUDA_NVCC_FLAGS "${CUDA_NVCC_FLAGS}") 165 | set(CUDA_VERSION @CUDA_VERSION@) 166 | if(CUDA_VERSION VERSION_LESS "3.0") 167 | cmake_policy(PUSH) 168 | # CMake policy 0007 NEW states that empty list elements are not 169 | # ignored. I'm just setting it to avoid the warning that's printed. 170 | cmake_policy(SET CMP0007 NEW) 171 | # Note that this will remove all occurances of -G. 172 | list(REMOVE_ITEM depends_CUDA_NVCC_FLAGS "-G") 173 | cmake_policy(POP) 174 | endif() 175 | 176 | # nvcc doesn't define __CUDACC__ for some reason when generating dependency files. This 177 | # can cause incorrect dependencies when #including files based on this macro which is 178 | # defined in the generating passes of nvcc invokation. We will go ahead and manually 179 | # define this for now until a future version fixes this bug. 180 | set(CUDACC_DEFINE -D__CUDACC__) 181 | 182 | # Generate the dependency file 183 | cuda_execute_process( 184 | "Generating dependency file: ${NVCC_generated_dependency_file}" 185 | COMMAND "${CUDA_NVCC_EXECUTABLE}" 186 | -M 187 | ${CUDACC_DEFINE} 188 | "${source_file}" 189 | -o "${NVCC_generated_dependency_file}" 190 | ${CCBIN} 191 | ${nvcc_flags} 192 | ${nvcc_host_compiler_flags} 193 | ${depends_CUDA_NVCC_FLAGS} 194 | -DNVCC 195 | ${CUDA_NVCC_INCLUDE_ARGS} 196 | ) 197 | 198 | if(CUDA_result) 199 | message(FATAL_ERROR "Error generating ${generated_file}") 200 | endif() 201 | 202 | # Generate the cmake readable dependency file to a temp file. Don't put the 203 | # quotes just around the filenames for the input_file and output_file variables. 204 | # CMake will pass the quotes through and not be able to find the file. 205 | cuda_execute_process( 206 | "Generating temporary cmake readable file: ${cmake_dependency_file}.tmp" 207 | COMMAND "${CMAKE_COMMAND}" 208 | -D "input_file:FILEPATH=${NVCC_generated_dependency_file}" 209 | -D "output_file:FILEPATH=${cmake_dependency_file}.tmp" 210 | -D "verbose=${verbose}" 211 | -P "${CUDA_make2cmake}" 212 | ) 213 | 214 | if(CUDA_result) 215 | message(FATAL_ERROR "Error generating ${generated_file}") 216 | endif() 217 | 218 | # Copy the file if it is different 219 | cuda_execute_process( 220 | "Copy if different ${cmake_dependency_file}.tmp to ${cmake_dependency_file}" 221 | COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${cmake_dependency_file}.tmp" "${cmake_dependency_file}" 222 | ) 223 | 224 | if(CUDA_result) 225 | message(FATAL_ERROR "Error generating ${generated_file}") 226 | endif() 227 | 228 | # Delete the temporary file 229 | cuda_execute_process( 230 | "Removing ${cmake_dependency_file}.tmp and ${NVCC_generated_dependency_file}" 231 | COMMAND "${CMAKE_COMMAND}" -E remove "${cmake_dependency_file}.tmp" "${NVCC_generated_dependency_file}" 232 | ) 233 | 234 | if(CUDA_result) 235 | message(FATAL_ERROR "Error generating ${generated_file}") 236 | endif() 237 | 238 | # Generate the code 239 | cuda_execute_process( 240 | "Generating ${generated_file}" 241 | COMMAND "${CUDA_NVCC_EXECUTABLE}" 242 | "${source_file}" 243 | ${cuda_language_flag} 244 | ${format_flag} -o "${generated_file}" 245 | ${CCBIN} 246 | ${nvcc_flags} 247 | ${nvcc_host_compiler_flags} 248 | ${CUDA_NVCC_FLAGS} 249 | -DNVCC 250 | ${CUDA_NVCC_INCLUDE_ARGS} 251 | ) 252 | 253 | if(CUDA_result) 254 | # Since nvcc can sometimes leave half done files make sure that we delete the output file. 255 | cuda_execute_process( 256 | "Removing ${generated_file}" 257 | COMMAND "${CMAKE_COMMAND}" -E remove "${generated_file}" 258 | ) 259 | message(FATAL_ERROR "Error generating file ${generated_file}") 260 | else() 261 | if(verbose) 262 | message("Generated ${generated_file} successfully.") 263 | endif() 264 | endif() 265 | 266 | # Cubin resource report commands. 267 | if( build_cubin ) 268 | # Run with -cubin to produce resource usage report. 269 | cuda_execute_process( 270 | "Generating ${generated_cubin_file}" 271 | COMMAND "${CUDA_NVCC_EXECUTABLE}" 272 | "${source_file}" 273 | ${CUDA_NVCC_FLAGS} 274 | ${nvcc_flags} 275 | ${CCBIN} 276 | ${nvcc_host_compiler_flags} 277 | -DNVCC 278 | -cubin 279 | -o "${generated_cubin_file}" 280 | ${CUDA_NVCC_INCLUDE_ARGS} 281 | ) 282 | 283 | # Execute the parser script. 284 | cuda_execute_process( 285 | "Executing the parser script" 286 | COMMAND "${CMAKE_COMMAND}" 287 | -D "input_file:STRING=${generated_cubin_file}" 288 | -P "${CUDA_parse_cubin}" 289 | ) 290 | 291 | endif() 292 | -------------------------------------------------------------------------------- /cmake/3.6/Modules/FindCUDA/select_compute_arch.cmake: -------------------------------------------------------------------------------- 1 | # Synopsis: 2 | # CUDA_SELECT_NVCC_ARCH_FLAGS(out_variable [target_CUDA_architectures]) 3 | # -- Selects GPU arch flags for nvcc based on target_CUDA_architectures 4 | # target_CUDA_architectures : Auto | Common | All | LIST(ARCH_AND_PTX ...) 5 | # - "Auto" detects local machine GPU compute arch at runtime. 6 | # - "Common" and "All" cover common and entire subsets of architectures 7 | # ARCH_AND_PTX : NAME | NUM.NUM | NUM.NUM(NUM.NUM) | NUM.NUM+PTX 8 | # NAME: Fermi Kepler Maxwell Kepler+Tegra Kepler+Tesla Maxwell+Tegra Pascal 9 | # NUM: Any number. Only those pairs are currently accepted by NVCC though: 10 | # 2.0 2.1 3.0 3.2 3.5 3.7 5.0 5.2 5.3 6.0 6.2 11 | # Returns LIST of flags to be added to CUDA_NVCC_FLAGS in ${out_variable} 12 | # Additionally, sets ${out_variable}_readable to the resulting numeric list 13 | # Example: 14 | # CUDA_SELECT_NVCC_ARCH_FLAGS(ARCH_FLAGS 3.0 3.5+PTX 5.2(5.0) Maxwell) 15 | # LIST(APPEND CUDA_NVCC_FLAGS ${ARCH_FLAGS}) 16 | # 17 | # More info on CUDA architectures: https://en.wikipedia.org/wiki/CUDA 18 | # 19 | 20 | # This list will be used for CUDA_ARCH_NAME = All option 21 | set(CUDA_KNOWN_GPU_ARCHITECTURES "Fermi" "Kepler" "Maxwell") 22 | 23 | # This list will be used for CUDA_ARCH_NAME = Common option (enabled by default) 24 | set(CUDA_COMMON_GPU_ARCHITECTURES "3.0" "3.5" "5.0") 25 | 26 | if (CUDA_VERSION VERSION_GREATER "6.5") 27 | list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Kepler+Tegra" "Kepler+Tesla" "Maxwell+Tegra") 28 | list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "5.2") 29 | endif () 30 | 31 | if (CUDA_VERSION VERSION_GREATER "7.5") 32 | list(APPEND CUDA_KNOWN_GPU_ARCHITECTURES "Pascal") 33 | list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "6.0" "6.1" "6.1+PTX") 34 | else() 35 | list(APPEND CUDA_COMMON_GPU_ARCHITECTURES "5.2+PTX") 36 | endif () 37 | 38 | 39 | 40 | ################################################################################################ 41 | # A function for automatic detection of GPUs installed (if autodetection is enabled) 42 | # Usage: 43 | # CUDA_DETECT_INSTALLED_GPUS(OUT_VARIABLE) 44 | # 45 | function(CUDA_DETECT_INSTALLED_GPUS OUT_VARIABLE) 46 | if(NOT CUDA_GPU_DETECT_OUTPUT) 47 | set(cufile ${PROJECT_BINARY_DIR}/detect_cuda_archs.cu) 48 | 49 | file(WRITE ${cufile} "" 50 | "#include \n" 51 | "int main()\n" 52 | "{\n" 53 | " int count = 0;\n" 54 | " if (cudaSuccess != cudaGetDeviceCount(&count)) return -1;\n" 55 | " if (count == 0) return -1;\n" 56 | " for (int device = 0; device < count; ++device)\n" 57 | " {\n" 58 | " cudaDeviceProp prop;\n" 59 | " if (cudaSuccess == cudaGetDeviceProperties(&prop, device))\n" 60 | " std::printf(\"%d.%d \", prop.major, prop.minor);\n" 61 | " }\n" 62 | " return 0;\n" 63 | "}\n") 64 | 65 | execute_process(COMMAND "${CUDA_NVCC_EXECUTABLE}" "--run" "${cufile}" 66 | "-ccbin" ${CMAKE_CXX_COMPILER} 67 | WORKING_DIRECTORY "${PROJECT_BINARY_DIR}/CMakeFiles/" 68 | RESULT_VARIABLE nvcc_res OUTPUT_VARIABLE nvcc_out 69 | ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) 70 | 71 | if(nvcc_res EQUAL 0) 72 | string(REPLACE "2.1" "2.1(2.0)" nvcc_out "${nvcc_out}") 73 | set(CUDA_GPU_DETECT_OUTPUT ${nvcc_out} CACHE INTERNAL "Returned GPU architetures from detect_gpus tool" FORCE) 74 | endif() 75 | endif() 76 | 77 | if(NOT CUDA_GPU_DETECT_OUTPUT) 78 | message(STATUS "Automatic GPU detection failed. Building for common architectures.") 79 | set(${OUT_VARIABLE} ${CUDA_COMMON_GPU_ARCHITECTURES} PARENT_SCOPE) 80 | else() 81 | set(${OUT_VARIABLE} ${CUDA_GPU_DETECT_OUTPUT} PARENT_SCOPE) 82 | endif() 83 | endfunction() 84 | 85 | 86 | ################################################################################################ 87 | # Function for selecting GPU arch flags for nvcc based on CUDA architectures from parameter list 88 | # Usage: 89 | # SELECT_NVCC_ARCH_FLAGS(out_variable [list of CUDA compute archs]) 90 | function(CUDA_SELECT_NVCC_ARCH_FLAGS out_variable) 91 | set(CUDA_ARCH_LIST "${ARGN}") 92 | 93 | if("X${CUDA_ARCH_LIST}" STREQUAL "X" ) 94 | set(CUDA_ARCH_LIST "Auto") 95 | endif() 96 | 97 | set(cuda_arch_bin) 98 | set(cuda_arch_ptx) 99 | 100 | if("${CUDA_ARCH_LIST}" STREQUAL "All") 101 | set(CUDA_ARCH_LIST ${CUDA_KNOWN_GPU_ARCHITECTURES}) 102 | elseif("${CUDA_ARCH_LIST}" STREQUAL "Common") 103 | set(CUDA_ARCH_LIST ${CUDA_COMMON_GPU_ARCHITECTURES}) 104 | elseif("${CUDA_ARCH_LIST}" STREQUAL "Auto") 105 | CUDA_DETECT_INSTALLED_GPUS(CUDA_ARCH_LIST) 106 | message(STATUS "Autodetected CUDA architecture(s): ${CUDA_ARCH_LIST}") 107 | endif() 108 | 109 | # Now process the list and look for names 110 | string(REGEX REPLACE "[ \t]+" ";" CUDA_ARCH_LIST "${CUDA_ARCH_LIST}") 111 | list(REMOVE_DUPLICATES CUDA_ARCH_LIST) 112 | foreach(arch_name ${CUDA_ARCH_LIST}) 113 | set(arch_bin) 114 | set(add_ptx FALSE) 115 | # Check to see if we are compiling PTX 116 | if(arch_name MATCHES "(.*)\\+PTX$") 117 | set(add_ptx TRUE) 118 | set(arch_name ${CMAKE_MATCH_1}) 119 | endif() 120 | if(arch_name MATCHES "(^[0-9]\\.[0-9](\\([0-9]\\.[0-9]\\))?)$") 121 | set(arch_bin ${CMAKE_MATCH_1}) 122 | set(arch_ptx ${arch_bin}) 123 | else() 124 | # Look for it in our list of known architectures 125 | if(${arch_name} STREQUAL "Fermi") 126 | set(arch_bin "2.0 2.1(2.0)") 127 | elseif(${arch_name} STREQUAL "Kepler+Tegra") 128 | set(arch_bin 3.2) 129 | elseif(${arch_name} STREQUAL "Kepler+Tesla") 130 | set(arch_bin 3.7) 131 | elseif(${arch_name} STREQUAL "Kepler") 132 | set(arch_bin 3.0 3.5) 133 | set(arch_ptx 3.5) 134 | elseif(${arch_name} STREQUAL "Maxwell+Tegra") 135 | set(arch_bin 5.3) 136 | elseif(${arch_name} STREQUAL "Maxwell") 137 | set(arch_bin 5.0 5.2) 138 | set(arch_ptx 5.2) 139 | elseif(${arch_name} STREQUAL "Pascal") 140 | set(arch_bin 6.0 6.1) 141 | set(arch_ptx 6.1) 142 | else() 143 | message(SEND_ERROR "Unknown CUDA Architecture Name ${arch_name} in CUDA_SELECT_NVCC_ARCH_FLAGS") 144 | endif() 145 | endif() 146 | if(NOT arch_bin) 147 | message(SEND_ERROR "arch_bin wasn't set for some reason") 148 | endif() 149 | list(APPEND cuda_arch_bin ${arch_bin}) 150 | if(add_ptx) 151 | if (NOT arch_ptx) 152 | set(arch_ptx ${arch_bin}) 153 | endif() 154 | list(APPEND cuda_arch_ptx ${arch_ptx}) 155 | endif() 156 | endforeach() 157 | 158 | # remove dots and convert to lists 159 | string(REGEX REPLACE "\\." "" cuda_arch_bin "${cuda_arch_bin}") 160 | string(REGEX REPLACE "\\." "" cuda_arch_ptx "${cuda_arch_ptx}") 161 | string(REGEX MATCHALL "[0-9()]+" cuda_arch_bin "${cuda_arch_bin}") 162 | string(REGEX MATCHALL "[0-9]+" cuda_arch_ptx "${cuda_arch_ptx}") 163 | 164 | if(cuda_arch_bin) 165 | list(REMOVE_DUPLICATES cuda_arch_bin) 166 | endif() 167 | if(cuda_arch_ptx) 168 | list(REMOVE_DUPLICATES cuda_arch_ptx) 169 | endif() 170 | 171 | set(nvcc_flags "") 172 | set(nvcc_archs_readable "") 173 | 174 | # Tell NVCC to add binaries for the specified GPUs 175 | foreach(arch ${cuda_arch_bin}) 176 | if(arch MATCHES "([0-9]+)\\(([0-9]+)\\)") 177 | # User explicitly specified ARCH for the concrete CODE 178 | list(APPEND nvcc_flags -gencode arch=compute_${CMAKE_MATCH_2},code=sm_${CMAKE_MATCH_1}) 179 | list(APPEND nvcc_archs_readable sm_${CMAKE_MATCH_1}) 180 | else() 181 | # User didn't explicitly specify ARCH for the concrete CODE, we assume ARCH=CODE 182 | list(APPEND nvcc_flags -gencode arch=compute_${arch},code=sm_${arch}) 183 | list(APPEND nvcc_archs_readable sm_${arch}) 184 | endif() 185 | endforeach() 186 | 187 | # Tell NVCC to add PTX intermediate code for the specified architectures 188 | foreach(arch ${cuda_arch_ptx}) 189 | list(APPEND nvcc_flags -gencode arch=compute_${arch},code=compute_${arch}) 190 | list(APPEND nvcc_archs_readable compute_${arch}) 191 | endforeach() 192 | 193 | string(REPLACE ";" " " nvcc_archs_readable "${nvcc_archs_readable}") 194 | set(${out_variable} ${nvcc_flags} PARENT_SCOPE) 195 | set(${out_variable}_readable ${nvcc_archs_readable} PARENT_SCOPE) 196 | endfunction() 197 | -------------------------------------------------------------------------------- /cmake/FindTorch.cmake: -------------------------------------------------------------------------------- 1 | # We are in the build tree, nothing to do 2 | # We found ourselves :) 3 | -------------------------------------------------------------------------------- /exe/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_SUBDIRECTORY(luajit-rocks) -------------------------------------------------------------------------------- /extra/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | ADD_SUBDIRECTORY(nn) 3 | ADD_SUBDIRECTORY(graph) 4 | ADD_SUBDIRECTORY(nngraph) 5 | ADD_SUBDIRECTORY(nnx) 6 | ADD_SUBDIRECTORY(threads) 7 | ADD_SUBDIRECTORY(argcheck) 8 | 9 | IF (WITH_CUDA STREQUAL ON) 10 | ADD_SUBDIRECTORY(cutorch) 11 | ADD_SUBDIRECTORY(cunn) 12 | ADD_SUBDIRECTORY(cunnx) 13 | ADD_SUBDIRECTORY(cudnn) 14 | ENDIF (WITH_CUDA STREQUAL ON) 15 | -------------------------------------------------------------------------------- /install-deps: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -e 3 | 4 | ###################################################################### 5 | # This script installs required dependencies for Torch7 6 | ###################################################################### 7 | { 8 | 9 | install_openblas() { 10 | # Get and build OpenBlas (Torch is much better with a decent Blas) 11 | # Optionally set environment variable PREFIX to control 12 | # the installation directory. 13 | 14 | 15 | local PATH=$PATH:/sbin ## improve chances of finding ldconfig 16 | # Only proceed installing OpenBLAS if either ldconfig is unavailable, or ldconfig 17 | # reports that OpenBLAS is not already installed. 18 | if ! type ldconfig >/dev/null || ! ldconfig -p | grep -q "lib\(open\)\?blas.so"; then 19 | local tempdir=$(mktemp -d) 20 | 21 | git clone https://github.com/xianyi/OpenBLAS.git "$tempdir"/OpenBLAS || { echo "Error. Cannot clone OpenBLAS." >&2 ; exit 1 ; } 22 | cd "$tempdir"/OpenBLAS || { echo "Error. Cannot create tempdir." >&2 ; exit 1 ; } 23 | if [ $(getconf _NPROCESSORS_CONF) == 1 ]; then 24 | make NO_AFFINITY=1 USE_OPENMP=0 USE_THREAD=0 25 | else 26 | make NO_AFFINITY=1 USE_OPENMP=1 27 | fi 28 | RET=$?; 29 | if [ $RET -ne 0 ]; then 30 | echo "Error. OpenBLAS could not be compiled"; 31 | exit $RET; 32 | fi 33 | if [ ! -z "$PREFIX" ]; then 34 | sudo make install PREFIX="$PREFIX" 35 | else 36 | sudo make install 37 | fi 38 | RET=$?; 39 | if [ $RET -ne 0 ]; then 40 | echo "Error. OpenBLAS could not be installed"; 41 | exit $RET; 42 | fi 43 | cd - 44 | rm -rf "$tempdir" 45 | else 46 | echo "Skipping install of OpenBLAS - it is already installed." >&2 47 | fi 48 | } 49 | 50 | install_openblas_AUR() { 51 | # build and install an OpenBLAS package for Archlinux 52 | cd /tmp && \ 53 | curl https://aur.archlinux.org/cgit/aur.git/snapshot/openblas-lapack.tar.gz | tar zxf - && \ 54 | cd openblas-lapack 55 | makepkg -csi --noconfirm 56 | RET=$?; 57 | if [ $RET -ne 0 ]; then 58 | echo "Error. OpenBLAS could not be installed"; 59 | exit $RET; 60 | fi 61 | } 62 | 63 | checkupdates_archlinux() { 64 | # checks if archlinux is up to date 65 | if [[ -n $(checkupdates) ]]; then 66 | echo "It seems that your system is not up to date." 67 | echo "It is recommended to update your system before going any further." 68 | read -p "Continue installation ? [y/N] " yn 69 | case $yn in 70 | Y|y ) echo "Continuing...";; 71 | * ) echo "Installation aborted." 72 | echo "Relaunch this script after updating your system with 'pacman -Syu'." 73 | exit 0 74 | esac 75 | fi 76 | } 77 | 78 | # Based on Platform: 79 | if [[ `uname` == 'Darwin' ]]; then 80 | # GCC? 81 | if [[ `which gcc` == '' ]]; then 82 | echo "MacOS doesn't come with GCC: please install XCode and the command line tools." 83 | exit 1 84 | fi 85 | 86 | # Install Homebrew (pkg manager): 87 | if [[ `which brew` == '' ]]; then 88 | ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 89 | fi 90 | 91 | # Install dependencies: 92 | brew update 93 | brew install git readline cmake wget 94 | brew install libjpeg imagemagick zeromq graphicsmagick openssl 95 | brew link readline --force 96 | brew cask install xquartz 97 | brew list -1 | grep -q "^gnuplot\$" && brew remove gnuplot 98 | brew install gnuplot --with-wxmac --with-cairo --with-pdflib-lite --with-x11 --without-lua 99 | brew install qt || true 100 | 101 | elif [[ "$(uname)" == 'Linux' ]]; then 102 | 103 | if [[ -r /etc/os-release ]]; then 104 | # this will get the required information without dirtying any env state 105 | DIST_VERS="$( ( . /etc/os-release &>/dev/null 106 | echo "$ID $VERSION_ID") )" 107 | DISTRO="${DIST_VERS%% *}" # get our distro name 108 | VERSION="${DIST_VERS##* }" # get our version number 109 | elif [[ -r /etc/redhat-release ]]; then 110 | DIST_VERS=( $( cat /etc/redhat-release ) ) # make the file an array 111 | DISTRO="${DIST_VERS[0],,}" # get the first element and get lcase 112 | VERSION="${DIST_VERS[2]}" # get the third element (version) 113 | elif [[ -r /etc/lsb-release ]]; then 114 | DIST_VERS="$( ( . /etc/lsb-release &>/dev/null 115 | echo "${DISTRIB_ID,,} $DISTRIB_RELEASE") )" 116 | DISTRO="${DIST_VERS%% *}" # get our distro name 117 | VERSION="${DIST_VERS##* }" # get our version number 118 | else # well, I'm out of ideas for now 119 | echo '==> Failed to determine distro and version.' 120 | exit 1 121 | fi 122 | 123 | # Detect fedora 124 | if [[ "$DISTRO" = "fedora" ]]; then 125 | distribution="fedora" 126 | fedora_major_version="$VERSION" 127 | # Detect archlinux 128 | elif [[ "$DISTRO" = "arch" ]]; then 129 | distribution="archlinux" 130 | # Detect Ubuntu 131 | elif [[ "$DISTRO" = "ubuntu" ]]; then 132 | export DEBIAN_FRONTEND=noninteractive 133 | distribution="ubuntu" 134 | ubuntu_major_version="${VERSION%%.*}" 135 | elif [[ "$DISTRO" = "linuxmint" ]]; then 136 | export DEBIAN_FRONTEND=noninteractive 137 | distribution="ubuntu" 138 | ubuntu_major_version="16" 139 | # Detect elementary OS 140 | elif [[ "$DISTRO" = "elementary" ]]; then 141 | export DEBIAN_FRONTEND=noninteractive 142 | distribution="elementary" 143 | elementary_version="${VERSION%.*}" 144 | # Detect CentOS 145 | elif [[ "$DISTRO" = "centos" ]]; then 146 | distribution="centos" 147 | centos_major_version="$VERSION" 148 | # Detect AWS 149 | elif [[ "$DISTRO" = "amzn" ]]; then 150 | distribution="amzn" 151 | amzn_major_version="$VERSION" 152 | elif [[ "$DISTRO" == "raspbian" ]]; then 153 | distribution="raspbian" 154 | debian_major_version="$VERSION" 155 | elif [[ "$DISTRO" == "opensuse" ]]; then 156 | distribution="opensuse" 157 | opensuse_major_version="$VERSION" 158 | # Detect Debian 159 | elif [[ "$DISTRO" = "debian" ]]; then 160 | distribution="debian" 161 | debian_major_version="$VERSION" 162 | elif [[ "$DISTRO" = "neon" ]]; then 163 | distribution="ubuntu" 164 | ubuntu_major_version="${VERSION%%.*}" 165 | else 166 | echo '==> Only Ubuntu, elementary OS, Fedora, Archlinux, OpenSUSE, Debian, CentOS and KDE neon distributions are supported.' 167 | exit 1 168 | fi 169 | 170 | # Install dependencies for Torch: 171 | if [[ $distribution == 'ubuntu' ]]; then 172 | if sudo apt-get update ; then 173 | echo "Updated successfully." 174 | else 175 | echo "Some portion of the update is failed" 176 | fi 177 | # python-software-properties is required for apt-add-repository 178 | sudo apt-get install -y python-software-properties 179 | echo "==> Found Ubuntu version ${ubuntu_major_version}.xx" 180 | if [[ $ubuntu_major_version -lt '12' ]]; then 181 | echo '==> Ubuntu version not supported.' 182 | exit 1 183 | elif [[ $ubuntu_major_version -lt '14' ]]; then # 12.xx 184 | sudo -E add-apt-repository -y ppa:chris-lea/zeromq 185 | elif [[ $ubuntu_major_version -lt '15' ]]; then # 14.xx 186 | sudo -E apt-get install -y software-properties-common 187 | sudo -E add-apt-repository -y ppa:jtaylor/ipython 188 | else 189 | sudo apt-get install -y software-properties-common \ 190 | libgraphicsmagick1-dev libfftw3-dev sox libsox-dev \ 191 | libsox-fmt-all 192 | fi 193 | 194 | if sudo apt-get update ; then 195 | echo "Updated successfully." 196 | else 197 | echo "Some portion of the update is failed" 198 | fi 199 | sudo apt-get install -y build-essential gcc g++ curl \ 200 | cmake libreadline-dev git-core libqt4-dev libjpeg-dev \ 201 | libpng-dev ncurses-dev imagemagick libzmq3-dev gfortran \ 202 | unzip gnuplot gnuplot-x11 ipython 203 | 204 | gcc_major_version=$(gcc --version | grep ^gcc | awk '{print $4}' | \ 205 | cut -c 1) 206 | if [[ $gcc_major_version == '5' ]]; then 207 | echo '==> Found GCC 5, installing GCC 4.9.' 208 | sudo apt-get install -y gcc-4.9 libgfortran-4.9-dev g++-4.9 209 | fi 210 | 211 | if [[ $ubuntu_major_version -lt '15' ]]; then 212 | sudo apt-get install libqt4-core libqt4-gui 213 | fi 214 | 215 | install_openblas || true 216 | 217 | elif [[ $distribution == 'raspbian' ]]; then 218 | echo "==> Found Raspbian version ${debian_major_version}.xx" 219 | if sudo apt-get update ; then 220 | echo "Updated successfully." 221 | else 222 | echo "Some portion of the update is failed" 223 | fi 224 | sudo apt-get install -y build-essential gcc g++ curl \ 225 | cmake libreadline-dev git-core libqt4-dev libjpeg-dev \ 226 | libpng-dev ncurses-dev imagemagick libzmq3-dev gfortran \ 227 | unzip gnuplot gnuplot-x11 ipython 228 | 229 | install_openblas || true 230 | 231 | elif [[ $distribution == 'opensuse' ]]; then 232 | if sudo zypper refresh ; then 233 | echo "Updated successfully." 234 | else 235 | echo "Some portion of the update failed" 236 | fi 237 | sudo zypper install -y -t pattern devel_basis 238 | if [[ $opensuse_major_version == '42.2' ]]; then 239 | sudo zypper install -y gcc curl cmake readline-devel IPython git-core \ 240 | libqt4 libjpeg62-devel libpng16-compat-devel ImageMagick unzip \ 241 | gnuplot gcc-fortran libzmq5 242 | else 243 | sudo zypper install -y gcc curl cmake readline-devel IPython git-core \ 244 | libqt4 libjpeg8-devel libpng15-compat-devel imagemagick unzip \ 245 | gnuplot gcc-fortran libzmq3 246 | fi 247 | 248 | elif [[ $distribution == 'elementary' ]]; then 249 | declare -a target_pkgs 250 | target_pkgs=( build-essential gcc g++ curl \ 251 | cmake libreadline-dev git-core libqtcore4 libqtgui4 \ 252 | libqt4-dev libjpeg-dev libpng-dev ncurses-dev \ 253 | imagemagick libzmq3-dev gfortran unzip gnuplot \ 254 | gnuplot-x11 ipython ) 255 | if sudo apt-get update ; then 256 | echo "Updated successfully." 257 | else 258 | echo "Some portion of the update is failed" 259 | fi 260 | # python-software-properties is required for apt-add-repository 261 | sudo apt-get install -y python-software-properties 262 | if [[ $elementary_version == '0.3' ]]; then 263 | echo '==> Found Ubuntu version 14.xx based elementary installation, installing dependencies' 264 | sudo apt-get install -y software-properties-common \ 265 | libgraphicsmagick1-dev libfftw3-dev sox libsox-dev \ 266 | libsox-fmt-all 267 | 268 | sudo -E add-apt-repository -y ppa:jtaylor/ipython 269 | else 270 | sudo -E add-apt-repository -y ppa:chris-lea/zeromq 271 | fi 272 | if sudo apt-get update ; then 273 | echo "Updated successfully." 274 | else 275 | echo "Some portion of the update is failed" 276 | fi 277 | sudo apt-get install -y "${target_pkgs[@]}" 278 | 279 | install_openblas || true 280 | 281 | elif [[ $distribution == 'archlinux' ]]; then 282 | echo "Archlinux installation" 283 | checkupdates_archlinux 284 | sudo pacman -S --quiet --noconfirm --needed \ 285 | cmake curl readline ncurses git \ 286 | gnuplot unzip libjpeg-turbo libpng libpng \ 287 | imagemagick graphicsmagick fftw sox zeromq \ 288 | ipython qt4 qt5-webkit-ng || exit 1 289 | pacman -Sl multilib &>/dev/null 290 | if [[ $? -ne 0 ]]; then 291 | gcc_package="gcc" 292 | else 293 | gcc_package="gcc-multilib" 294 | fi 295 | sudo pacman -S --quiet --noconfirm --needed \ 296 | ${gcc_package} gcc-fortran || exit 1 297 | # if openblas is not installed yet 298 | pacman -Qs openblas &> /dev/null 299 | if [[ $? -ne 0 ]]; then 300 | install_openblas_AUR || true 301 | else 302 | echo "OpenBLAS is already installed" 303 | fi 304 | 305 | elif [[ $distribution == 'fedora' ]]; then 306 | if [[ $fedora_major_version == '20' ]]; then 307 | sudo yum install -y cmake curl readline-devel ncurses-devel \ 308 | gcc-c++ gcc-gfortran git gnuplot unzip \ 309 | libjpeg-turbo-devel libpng-devel \ 310 | ImageMagick GraphicsMagick-devel fftw-devel \ 311 | sox-devel sox zeromq3-devel \ 312 | qt-devel qtwebkit-devel sox-plugins-freeworld \ 313 | ipython 314 | install_openblas || true 315 | elif [[ $fedora_major_version == '22' || $fedora_major_version == '23' ]]; then 316 | #using dnf - since yum has been deprecated 317 | #sox-plugins-freeworld is not yet available in repos for F22 318 | sudo dnf install -y make cmake curl readline-devel ncurses-devel \ 319 | gcc-c++ gcc-gfortran git gnuplot unzip \ 320 | libjpeg-turbo-devel libpng-devel \ 321 | ImageMagick GraphicsMagick-devel fftw-devel \ 322 | sox-devel sox qt-devel qtwebkit-devel \ 323 | python-ipython czmq czmq-devel 324 | install_openblas || true 325 | elif [[ $fedora_major_version == '24' || $fedora_major_version == '25' ]]; then 326 | sudo dnf install -y make cmake curl readline-devel ncurses-devel \ 327 | gcc-c++ gcc-gfortran git gnuplot unzip \ 328 | libjpeg-turbo-devel libpng-devel \ 329 | ImageMagick GraphicsMagick-devel fftw-devel \ 330 | sox-devel sox qt-devel qtwebkit-devel \ 331 | python-ipython czmq czmq-devel 332 | install_openblas || true 333 | else 334 | echo "Only Fedora 20-25 are supported for now, aborting." 335 | exit 1 336 | fi 337 | elif [[ $distribution == 'centos' ]]; then 338 | if [[ $centos_major_version == '7' ]]; then 339 | sudo yum install -y epel-release # a lot of things live in EPEL 340 | sudo yum install -y make cmake curl readline-devel ncurses-devel \ 341 | gcc-c++ gcc-gfortran git gnuplot unzip \ 342 | libjpeg-turbo-devel libpng-devel \ 343 | ImageMagick GraphicsMagick-devel fftw-devel \ 344 | sox-devel sox zeromq3-devel \ 345 | qt-devel qtwebkit-devel sox-plugins-freeworld 346 | sudo yum install -y python-ipython 347 | install_openblas || true 348 | else 349 | echo "Only CentOS 7 is supported for now, aborting." 350 | exit 1 351 | fi 352 | elif [[ $distribution == 'amzn' ]]; then 353 | sudo yum install -y cmake curl readline-devel ncurses-devel \ 354 | gcc-c++ gcc-gfortran git gnuplot unzip \ 355 | libjpeg-turbo-devel libpng-devel \ 356 | ImageMagick GraphicsMagick-devel fftw-devel \ 357 | libgfortran python27-pip git openssl-devel 358 | 359 | # 360 | # These libraries are missing from amzn linux 361 | # sox-devel sox sox-plugins-freeworld qt-devel qtwebkit-devel 362 | # 363 | 364 | sudo yum --enablerepo=epel install -y zeromq3-devel 365 | sudo pip install ipython 366 | 367 | install_openblas || true 368 | elif [[ $distribution == 'debian' ]]; then 369 | if [[ $debian_major_version == '8' ]] || [[ $debian_major_version == '9' ]]; then 370 | echo "==> Found Debian version ${debian_major_version}" 371 | if sudo apt-get update ; then 372 | echo "Updated successfully." 373 | else 374 | echo "Some portion of the update is failed" 375 | fi 376 | #Basic package required for Torch 377 | sudo apt-get install -y build-essential curl \ 378 | cmake libreadline-dev git-core libqt4-dev libjpeg-dev \ 379 | libpng-dev ncurses-dev imagemagick libzmq3-dev gfortran \ 380 | unzip gnuplot gnuplot-x11 ipython 381 | 382 | #require for common torch plug-ins 383 | sudo apt-get install -y libgraphicsmagick1-dev libfftw3-dev sox libsox-dev 384 | 385 | install_openblas || true 386 | else 387 | echo "Only Jessie Debian 8 and 9 is supported for now, aborting." 388 | exit 1 389 | fi 390 | fi 391 | elif [[ "$(uname)" == 'FreeBSD' ]]; then 392 | pkg install ImageMagick cmake curl fftw3 git gnuplot libjpeg-turbo \ 393 | libzmq3 ncurses openblas openssl png py27-ipython \ 394 | py27-pip qt4-corelib qt4-gui readline unzip 395 | 396 | else 397 | # Unsupported 398 | echo '==> platform not supported, aborting' 399 | exit 1 400 | fi 401 | 402 | ipython_exists=$(command -v ipython) || true 403 | if [[ $ipython_exists ]]; then { 404 | ipython_version=$(ipython --version|cut -f1 -d'.') 405 | if [[ $ipython_version -lt 2 ]]; then { 406 | echo 'WARNING: Your ipython version is too old. Type "ipython --version" to see this. Should be at least version 2' 407 | } fi 408 | } fi 409 | 410 | # Done. 411 | echo "==> Torch7's dependencies have been installed" 412 | 413 | } 414 | -------------------------------------------------------------------------------- /install-deps.bat: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 4 | :::: This script setup directories, dependencies for Torch7 :::: 5 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 6 | 7 | 8 | :::: Customizable variables :::: 9 | 10 | 11 | :: which lua version will be installed for Torch7, default to LUAJIT21 12 | :: accepted lua versions: LUAJIT21, LUAJIT20, LUA53, LUA52, LUA51 13 | REM set TORCH_LUA_VERSION=LUAJIT21 14 | 15 | :: where to install Torch7, default to install\ under distro\ 16 | REM set TORCH_INSTALL_DIR=D:\Torch 17 | 18 | :: conda environment name for Torch7, default to torch-vcversion 19 | REM set TORCH_CONDA_ENV=mytorch7 20 | 21 | :: which blas/lapack libraries will be used, default to openblas installed by conda 22 | :: [1] mkl: download from https://software.intel.com/intel-mkl, install and set following two variables 23 | REM set INTEL_MKL_DIR=D:\\Intel\\SWTools\\compilers_and_libraries\\windows\\mkl\\ 24 | REM set INTEL_COMPILER_DIR=D:\\Intel\\SWTools\\compilers_and_libraries\\windows\\compiler\\ 25 | :: [2] other: set path to the blas library and path to the laback library 26 | :: both BLAS and LAPACK should be set even if they refer to the same library 27 | :: take openblas for example: download latest release from https://github.com/xianyi/OpenBLAS/releases/latest 28 | :: use mingw cross compiler tools in cygwin, since mingw windows native gfortrain is available in cygwin but not in msys2 29 | :: compilation command in cygwin: make CC=x86_64-w64-mingw32-gcc FC=x86_64-w64-mingw32-gfortran CROSS_SUFFIX=x86_64-w64-mingw32- 30 | :: please refer to openblas's README for detailed installation instructions 31 | REM set BLAS_LIBRARIES=D:\\Libraries\\lib\libopenblas.dll.a 32 | REM set LAPACK_LIBRARIES=D:\\Libraries\\lib\libopenblas.dll.a 33 | 34 | :: where to find cudnn library 35 | REM set CUDNN_PATH=D:\NVIDIA\CUDNN\v5.1\bin\cudnn64_5.dll 36 | 37 | :: whether update dependencies if already setup, default to not update 38 | REM set TORCH_UPDATE_DEPS= 39 | 40 | :::: End of customization :::: 41 | 42 | 43 | set ECHO_PREFIX=+++++++ 44 | set TORCH_SETUP_FAIL=1 45 | 46 | :::: validate msvc version :::: 47 | 48 | if "%VisualStudioVersion%" == "" ( 49 | if not "%VS150COMNTOOLS%" == "" ( call "%VS150COMNTOOLS%..\..\VC\Auxiliary\Build\vcvarsall.bat" x64 && goto :VS_SETUP) 50 | if not "%VS140COMNTOOLS%" == "" ( call "%VS140COMNTOOLS%..\..\VC\vcvarsall.bat" x64 && goto :VS_SETUP) 51 | if not "%VS120COMNTOOLS%" == "" ( call "%VS120COMNTOOLS%..\..\VC\vcvarsall.bat" x64 && goto :VS_SETUP) 52 | if not "%VS110COMNTOOLS%" == "" ( call "%VS110COMNTOOLS%..\..\VC\vcvarsall.bat" x64 && goto :VS_SETUP) 53 | if not "%VS100COMNTOOLS%" == "" ( call "%VS100COMNTOOLS%..\..\VC\vcvarsall.bat" x64 && goto :VS_SETUP) 54 | if not "%VS90COMNTOOLS%" == "" ( call "%VS90COMNTOOLS%..\..\VC\vcvarsall.bat" x64 && goto :VS_SETUP) 55 | ) 56 | :VS_SETUP 57 | 58 | if "%VisualStudioVersion%" == "" ( 59 | echo %ECHO_PREFIX% Can not find environment variable VisualStudioVersion, msvc is not setup porperly 60 | goto :FAIL 61 | ) 62 | 63 | set TORCH_VS_VERSION=%VisualStudioVersion:.0=% 64 | 65 | if "%PreferredToolArchitecture%" == "x64" ( 66 | if "%CommandPromptType%" == "Cross" ( 67 | if "%Platform%" == "ARM" set TORCH_VS_PLATFORM=amd64_arm 68 | if "%Platform%" == "X86" set TORCH_VS_PLATFORM=amd64_x86 69 | if "%Platform%" == "x86" set TORCH_VS_PLATFORM=amd64_x86 70 | ) 71 | ) else ( 72 | if "%CommandPromptType%" == "Cross" ( 73 | if "%Platform%" == "ARM" set TORCH_VS_PLATFORM=x86_arm 74 | if "%Platform%" == "X64" set TORCH_VS_PLATFORM=x86_amd64 75 | if "%Platform%" == "x64" set TORCH_VS_PLATFORM=x86_amd64 76 | ) 77 | if "%CommandPromptType%" == "Native" ( 78 | if "%Platform%" == "X64" set TORCH_VS_PLATFORM=x64 79 | if "%Platform%" == "x64" set TORCH_VS_PLATFORM=x64 80 | ) 81 | if "%Platform%" == "" set TORCH_VS_PLATFORM=x86 82 | ) 83 | 84 | if "%TORCH_VS_PLATFORM%" == "x86" set TORCH_VS_TARGET=x86 85 | if not "%TORCH_VS_PLATFORM%" == "%TORCH_VS_PLATFORM:_x86=%" set TORCH_VS_TARGET=x86 86 | if not "%TORCH_VS_PLATFORM%" == "%TORCH_VS_PLATFORM:_arm=%" set TORCH_VS_TARGET=arm 87 | if "%TORCH_VS_TARGET%" == "" set TORCH_VS_TARGET=x64 88 | 89 | :::: validate lua version :::: 90 | 91 | :: [TODO] currently luajit lua luarocks are installed from source. they can be changed to use luajit-rocks when 92 | :: luajit-rocks is ready for windows 93 | 94 | if "%TORCH_LUA_VERSION%" == "" set TORCH_LUA_VERSION=LUAJIT21 95 | if /i "%TORCH_LUA_VERSION%" == "LUAJIT21" ( 96 | set TORCH_LUAJIT_BRANCH=v2.1 97 | set TORCH_LUA_SOURCE=luajit-2.1 98 | set TORCH_LUAROCKS_LUA=5.1 99 | ) 100 | if /i "%TORCH_LUA_VERSION%" == "LUAJIT20" ( 101 | set TORCH_LUAJIT_BRANCH=master 102 | set TORCH_LUA_SOURCE=luajit-2.0 103 | set TORCH_LUAROCKS_LUA=5.1 104 | ) 105 | if /i "%TORCH_LUA_VERSION%" == "LUA53" ( 106 | set TORCH_LUA_SOURCE=lua-5.3.3 107 | set TORCH_LUAROCKS_LUA=5.3 108 | ) 109 | if /i "%TORCH_LUA_VERSION%" == "LUA52" ( 110 | set TORCH_LUA_SOURCE=lua-5.2.4 111 | set TORCH_LUAROCKS_LUA=5.2 112 | ) 113 | if /i "%TORCH_LUA_VERSION%" == "LUA51" ( 114 | set TORCH_LUA_SOURCE=lua-5.1.5 115 | set TORCH_LUAROCKS_LUA=5.1 116 | ) 117 | if /i "%TORCH_LUA_SOURCE%" == "" ( 118 | echo %ECHO_PREFIX% Bad lua version: %TORCH_LUA_VERSION%, only support LUAJIT21, LUAJIT20, LUA53, LUA52, LUA51 119 | goto :FAIL 120 | ) 121 | 122 | :::: Setup directories :::: 123 | 124 | set TORCH_DISTRO=%~dp0. 125 | if "%TORCH_INSTALL_DIR%" == "" set TORCH_INSTALL_DIR=%TORCH_DISTRO%\install 126 | set TORCH_INSTALL_BIN=%TORCH_INSTALL_DIR%\bin 127 | set TORCH_INSTALL_LIB=%TORCH_INSTALL_DIR%\lib 128 | set TORCH_INSTALL_INC=%TORCH_INSTALL_DIR%\include 129 | set TORCH_INSTALL_ROC=%TORCH_INSTALL_DIR%\luarocks 130 | if not exist %TORCH_INSTALL_BIN% md %TORCH_INSTALL_BIN% 131 | if not exist %TORCH_INSTALL_LIB% md %TORCH_INSTALL_LIB% 132 | if not exist %TORCH_INSTALL_INC% md %TORCH_INSTALL_INC% 133 | if not "%TORCH_LUAJIT_BRANCH%" == "" if not exist %TORCH_INSTALL_BIN%\lua\jit md %TORCH_INSTALL_BIN%\lua\jit 134 | if not exist %TORCH_DISTRO%\win-files\3rd md %TORCH_DISTRO%\win-files\3rd 135 | 136 | echo %ECHO_PREFIX% Torch7 will be installed under %TORCH_INSTALL_DIR% with %TORCH_LUA_SOURCE%, vs%TORCH_VS_VERSION% %TORCH_VS_PLATFORM% 137 | echo %ECHO_PREFIX% Bin: %TORCH_INSTALL_BIN% 138 | echo %ECHO_PREFIX% Lib: %TORCH_INSTALL_LIB% 139 | echo %ECHO_PREFIX% Inc: %TORCH_INSTALL_INC% 140 | 141 | :::: Setup dependencies :::: 142 | 143 | :: has blas/lapack? 144 | if not "%INTEL_MKL_DIR%" == "" if exist %INTEL_MKL_DIR% ( set "TORCH_SETUP_HAS_MKL=1" && set "TORCH_SETUP_HAS_BLAS=1" && set "TORCH_SETUP_HAS_LAPACK=1" ) 145 | if not "%BLAS_LIBRARIES%" == "" if exist %BLAS_LIBRARIES% set TORCH_SETUP_HAS_BLAS=1 146 | if not "%LAPACK_LIBRARIES%" == "" if exist %LAPACK_LIBRARIES% set TORCH_SETUP_HAS_LAPACK=1 147 | 148 | :: has cuda? 149 | for /f "delims=" %%i in ('where nvcc') do ( 150 | set NVCC_CMD=%%i 151 | goto :AFTER_NVCC 152 | ) 153 | :AFTER_NVCC 154 | if not "%NVCC_CMD%" == "" set TORCH_SETUP_HAS_CUDA=1 155 | 156 | :: has conda? 157 | for /f "delims=" %%i in ('where conda') do ( 158 | set CONDA_CMD=%%i 159 | goto :AFTER_CONDA 160 | ) 161 | :AFTER_CONDA 162 | 163 | if "%CONDA_CMD%" == "" ( 164 | echo %ECHO_PREFIX% Can not find conda, some dependencies can not be resolved 165 | if not "%TORCH_SETUP_HAS_BLAS%" == "1" ( 166 | echo %ECHO_PREFIX% Can not install torch, please either specify the blas library or install conda 167 | goto :FAIL 168 | ) 169 | goto :NO_CONDA 170 | ) 171 | 172 | set TORCH_CONDA_INFO=%TORCH_DISTRO%\win-files\check_conda_info_for_torch.txt 173 | conda info > %TORCH_CONDA_INFO% 174 | if "%TORCH_VS_TARGET%" == "x64" set TORCH_CONDA_PLATFORM=win-64 175 | if "%TORCH_VS_TARGET%" == "arm" set TORCH_CONDA_PLATFORM=win-64 176 | if "%TORCH_VS_TARGET%" == "x86" set TORCH_CONDA_PLATFORM=win-32 177 | 178 | findstr "%TORCH_CONDA_PLATFORM%" "%TORCH_CONDA_INFO%" >nul 179 | if errorlevel 1 ( 180 | echo %ECHO_PREFIX% %TORCH_VS_TARGET% Torch7 requires %TORCH_CONDA_PLATFORM% conda, installation will continue without conda 181 | goto :NO_CONDA 182 | ) 183 | 184 | if %TORCH_VS_VERSION% GEQ 14 ( set CONDA_VS_VERSION=14&& goto :CONDA_SETUP ) 185 | if %TORCH_VS_VERSION% GEQ 10 ( set CONDA_VS_VERSION=10&& goto :CONDA_SETUP ) 186 | set CONDA_VS_VERSION=9 187 | 188 | :CONDA_SETUP 189 | 190 | if "%TORCH_CONDA_ENV%" == "" set TORCH_CONDA_ENV=torch-vc%CONDA_VS_VERSION% 191 | 192 | echo %ECHO_PREFIX% Createing conda environment '%TORCH_CONDA_ENV%' for Torch7 dependencies 193 | conda create -n %TORCH_CONDA_ENV% -c conda-forge vc=%CONDA_VS_VERSION% --yes 194 | 195 | set CONDA_DIR=%CONDA_CMD:\Scripts\conda.exe=% 196 | set TORCH_CONDA_LIBRARY=%CONDA_DIR%\envs\%TORCH_CONDA_ENV%\Library 197 | set TORCH_CONDA_LIBRARY=%TORCH_CONDA_LIBRARY:\=\\% 198 | set PATH=%TORCH_CONDA_LIBRARY%\bin;%PATH%; 199 | set NEW_PATH=%%CONDA_DIR%%\Scripts;%%CONDA_DIR%%\envs\%TORCH_CONDA_ENV%\Library\bin;%NEW_PATH% 200 | 201 | set TORCH_CONDA_PKGS=%TORCH_DISTRO%\win-files\check_conda_packages_for_torch.txt 202 | conda list -n %TORCH_CONDA_ENV% > %TORCH_CONDA_PKGS% 203 | 204 | :: has cmake? 205 | :: cmake should be installed before qt since its on qt5 while qtlua is on qt4 206 | for /f "delims=" %%i in ('where cmake') do ( 207 | set CMAKE_CMD=%%i 208 | goto :AFTER_CMAKE 209 | ) 210 | if "%CMAKE_CMD%" == "" ( 211 | echo %ECHO_PREFIX% Installing cmake by conda 212 | conda install -n %TORCH_CONDA_ENV% -c conda-forge cmake --yes 213 | ) 214 | :AFTER_CMAKE 215 | 216 | :: need openblas? 217 | findstr "openblas" "%TORCH_CONDA_PKGS%" >nul 218 | if not errorlevel 1 ( set "TORCH_SETUP_HAS_BLAS=1" && set "TORCH_SETUP_HAS_LAPACK=1" ) 219 | 220 | if not "%TORCH_SETUP_HAS_BLAS%" == "1" goto :CONDA_INSTALL_OPENBLAS 221 | if not "%TORCH_SETUP_HAS_LAPACK%" == "1" goto :CONDA_INSTALL_OPENBLAS 222 | goto :AFTER_OPENBLAS 223 | 224 | :CONDA_INSTALL_OPENBLAS 225 | echo %ECHO_PREFIX% Installing openblas by conda, since there is no blas library specified 226 | if not "%TORCH_VS_TARGET%" == "x86" conda install -n %TORCH_CONDA_ENV% -c ukoethe openblas --yes || goto :Fail 227 | if "%TORCH_VS_TARGET%" == "x86" conda install -n %TORCH_CONDA_ENV% -c omnia openblas --yes || goto :Fail 228 | 229 | :AFTER_OPENBLAS 230 | if not "%TORCH_VS_TARGET%" == "x86" ( 231 | if "%BLAS_LIBRARIES%" == "" set BLAS_LIBRARIES=%TORCH_CONDA_LIBRARY%\\lib\\libopenblas.lib 232 | if "%LAPACK_LIBRARIES%" == "" set LAPACK_LIBRARIES=%TORCH_CONDA_LIBRARY%\\lib\\libopenblas.lib 233 | ) 234 | if "%TORCH_VS_TARGET%" == "x86" ( 235 | if "%BLAS_LIBRARIES%" == "" set BLAS_LIBRARIES=%TORCH_CONDA_LIBRARY%\\lib\\libopenblaspy.dll.a 236 | if "%LAPACK_LIBRARIES%" == "" set LAPACK_LIBRARIES=%TORCH_CONDA_LIBRARY%\\lib\\libopenblaspy.dll.a 237 | ) 238 | 239 | :: other dependencies 240 | findstr "jpeg" "%TORCH_CONDA_PKGS%" >nul 241 | if errorlevel 1 set TORCH_DEPENDENCIES=%TORCH_DEPENDENCIES% jpeg 242 | findstr "libpng" "%TORCH_CONDA_PKGS%" >nul 243 | if errorlevel 1 set TORCH_DEPENDENCIES=%TORCH_DEPENDENCIES% libpng 244 | findstr "zlib" "%TORCH_CONDA_PKGS%" >nul 245 | if errorlevel 1 set TORCH_DEPENDENCIES=%TORCH_DEPENDENCIES% zlib 246 | findstr "libxml2" "%TORCH_CONDA_PKGS%" >nul 247 | if errorlevel 1 set TORCH_DEPENDENCIES=%TORCH_DEPENDENCIES% libxml2 248 | findstr "qt" "%TORCH_CONDA_PKGS%" >nul 249 | if errorlevel 1 set TORCH_DEPENDENCIES=%TORCH_DEPENDENCIES% qt=4.8.7 250 | 251 | if not "%TORCH_DEPENDENCIES%" == "" ( 252 | echo %ECHO_PREFIX% Installing %TORCH_DEPENDENCIES% by conda for Torch7 253 | conda install -n %TORCH_CONDA_ENV% -c conda-forge %TORCH_DEPENDENCIES% vc=%CONDA_VS_VERSION% --yes 254 | ) 255 | 256 | :NO_CONDA 257 | if exist "%TORCH_CONDA_INFO%" del /q %TORCH_CONDA_INFO% 258 | if exist "%TORCH_CONDA_PKGS%" del /q %TORCH_CONDA_PKGS% 259 | 260 | :::: git clone luarocks :::: 261 | 262 | echo %ECHO_PREFIX% Git clone luarocks for its tools 263 | cd %TORCH_DISTRO%\exe\ 264 | if not exist luarocks\.git git clone https://github.com/keplerproject/luarocks.git luarocks 265 | set PATH=%TORCH_DISTRO%\exe\luarocks\win32\tools\;%PATH%; 266 | 267 | :::: install lua :::: 268 | 269 | echo %ECHO_PREFIX% Installing %TORCH_LUA_SOURCE% 270 | cd %TORCH_DISTRO%\exe\ 271 | if not "%TORCH_LUAJIT_BRANCH%" == "" ( 272 | if not exist %TORCH_LUA_SOURCE%\.git git clone -b %TORCH_LUAJIT_BRANCH% http://luajit.org/git/luajit-2.0.git %TORCH_LUA_SOURCE% || goto :Fail 273 | cd %TORCH_LUA_SOURCE% && ( if "%TORCH_UPDATE_DEPS%" == "1" git pull ) & cd src 274 | ) else ( 275 | wget -nc https://www.lua.org/ftp/%TORCH_LUA_SOURCE%.tar.gz --no-check-certificate || goto :Fail 276 | 7z x %TORCH_LUA_SOURCE%.tar.gz -y >NUL && 7z x %TORCH_LUA_SOURCE%.tar -y >NUL && cd %TORCH_LUA_SOURCE%\src 277 | ) 278 | if not "%TORCH_LUAJIT_BRANCH%"=="" ( 279 | call msvcbuild.bat || goto :FAIL 280 | copy /y jit\* %TORCH_INSTALL_BIN%\lua\jit\ 281 | copy /y luajit.h %TORCH_INSTALL_INC%\luajit.h 282 | set LUAJIT_CMD=%TORCH_INSTALL_DIR%\luajit.cmd 283 | ) else ( 284 | del /q *.obj *.o *.lib *.dll *.exp *.exe 285 | cl /nologo /c /O2 /W3 /D_CRT_SECURE_NO_DEPRECATE /MD /DLUA_BUILD_AS_DLL *.c || goto :FAIL 286 | ren lua.obj lua.o || goto :FAIL 287 | ren luac.obj luac.o || goto :FAIL 288 | link /nologo /DLL /IMPLIB:%TORCH_LUA_VERSION%.lib /OUT:%TORCH_LUA_VERSION%.dll *.obj || goto :FAIL 289 | link /nologo /OUT:lua.exe lua.o %TORCH_LUA_VERSION%.lib || goto :FAIL 290 | lib /nologo /OUT:%TORCH_LUA_VERSION%-static.lib *.obj || goto :FAIL 291 | link /nologo /OUT:luac.exe luac.o %TORCH_LUA_VERSION%-static.lib || goto :FAIL 292 | copy /y lua.hpp %TORCH_INSTALL_INC%\lua.hpp 293 | set LUA_CMD=%TORCH_INSTALL_DIR%\lua.cmd 294 | set LUAC_CMD=%TORCH_INSTALL_DIR%\luac.cmd 295 | ) 296 | copy /y *.exe %TORCH_INSTALL_BIN%\ 297 | copy /y *.dll %TORCH_INSTALL_BIN%\ 298 | copy /y *.lib %TORCH_INSTALL_LIB%\ 299 | for %%g in (lua.h,luaconf.h,lualib.h,lauxlib.h) do copy /y %%g %TORCH_INSTALL_INC%\%%g 300 | 301 | :::: install luarocks :::: 302 | 303 | echo %ECHO_PREFIX% Installing luarocks 304 | cd %TORCH_DISTRO%\exe\ 305 | if not exist luarocks\.git git clone https://github.com/keplerproject/luarocks.git luarocks 306 | cd luarocks && ( if "%TORCH_UPDATE_DEPS%" == "1" git pull ) & call install.bat /F /Q /P %TORCH_INSTALL_ROC% /SELFCONTAINED /FORCECONFIG /NOREG /NOADMIN /LUA %TORCH_INSTALL_DIR% || goto :FAIL 307 | for /f %%a in ('dir %TORCH_INSTALL_ROC%\config*.lua /b') do set LUAROCKS_CONFIG=%%a 308 | set LUAROCKS_CONFIG=%TORCH_INSTALL_ROC%\%LUAROCKS_CONFIG% 309 | echo rocks_servers = { >> %LUAROCKS_CONFIG% 310 | echo [[https://raw.githubusercontent.com/torch/rocks/master]], >> %LUAROCKS_CONFIG% 311 | echo [[https://raw.githubusercontent.com/rocks-moonscript-org/moonrocks-mirror/master]] >> %LUAROCKS_CONFIG% 312 | echo } >> %LUAROCKS_CONFIG% 313 | 314 | set LUAROCKS_CMD=%TORCH_INSTALL_DIR%\luarocks.cmd 315 | 316 | :::: install wineditline :::: 317 | 318 | echo %ECHO_PREFIX% Installing wineditline for trepl package 319 | cd %TORCH_DISTRO%\win-files\3rd\ 320 | wget -nc https://sourceforge.net/projects/mingweditline/files/wineditline-2.201.zip/download --no-check-certificate -O wineditline.zip 321 | 7z x wineditline.zip -y >NUL 322 | cd wineditline* 323 | cmake -E make_directory build && cd build && cmake .. -G "NMake Makefiles" -DLIB_SUFFIX="64" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=..\ && nmake install 324 | 325 | :::: install dlfcn-win32 :::: 326 | 327 | echo %ECHO_PREFIX% Installing dlfcn-win32 for thread package 328 | cd %TORCH_DISTRO%\win-files\3rd\ 329 | if not exist dlfcn-win32\.git git clone https://github.com/dlfcn-win32/dlfcn-win32.git 330 | cd dlfcn-win32 && ( if "%TORCH_UPDATE_DEPS%" == "1" git pull ) 331 | cmake -E make_directory build && cd build && cmake .. -G "NMake Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=..\ && nmake install 332 | set WIN_DLFCN_INCDIR=%TORCH_DISTRO:\=\\%\\win-files\\3rd\\dlfcn-win32\\include 333 | set WIN_DLFCN_LIBDIR=%TORCH_DISTRO:\=\\%\\win-files\\3rd\\dlfcn-win32\\lib 334 | copy /y %TORCH_DISTRO%\win-files\3rd\dlfcn-win32\bin\*.dll %TORCH_INSTALL_BIN%\ 335 | 336 | :::: download graphviz :::: 337 | 338 | echo %ECHO_PREFIX% Downloading graphviz for graph package 339 | cd %TORCH_DISTRO%\win-files\3rd\ 340 | wget -nc https://github.com/mahkoCosmo/GraphViz_x64/raw/master/graphviz-2.38_x64.tar.gz --no-check-certificate -O graphviz-2.38_x64.tar.gz 341 | 7z x graphviz-2.38_x64.tar.gz -y && 7z x graphviz-2.38_x64.tar -ographviz-2.38_x64 -y >NUL 342 | if not exist %TORCH_INSTALL_BIN%\graphviz md %TORCH_INSTALL_BIN%\graphviz 343 | copy /y %TORCH_DISTRO%\win-files\3rd\graphviz-2.38_x64\bin\ %TORCH_INSTALL_BIN%\graphviz\ 344 | 345 | set NEW_PATH=%NEW_PATH%;%%TORCH_INSTALL_DIR%%\bin\graphviz 346 | 347 | :::: create cmd utils :::: 348 | 349 | if not "%LUAJIT_CMD%" == "" ( 350 | echo %ECHO_PREFIX% Creating torch-activate.cmd luajit.cmd luarocks.cmd cmake.cmd 351 | ) else ( 352 | echo %ECHO_PREFIX% Creating torch-activate.cmd lua.cmd luac.cmd luarocks.cmd cmake.cmd 353 | ) 354 | 355 | set NEW_PATH=%%TORCH_INSTALL_DIR%%;%%TORCH_INSTALL_DIR%%\bin;%%TORCH_INSTALL_DIR%%\luarocks;%%TORCH_INSTALL_DIR%%\luarocks\tools;%%TORCH_INSTALL_DIR%%\luarocks\systree\bin;%NEW_PATH%;%%PATH%%;; 356 | set NEW_LUA_PATH=%%TORCH_INSTALL_DIR%%\luarocks\lua\?.lua;%%TORCH_INSTALL_DIR%%\luarocks\lua\?\init.lua;%%TORCH_INSTALL_DIR%%\luarocks\systree\share\lua\%TORCH_LUAROCKS_LUA%\?.lua;%%TORCH_INSTALL_DIR%%\luarocks\systree\share\lua\%TORCH_LUAROCKS_LUA%\?\init.lua;; 357 | set NEW_LUA_CPATH=%%TORCH_INSTALL_DIR%%\luarocks\systree\lib\lua\%TORCH_LUAROCKS_LUA%\?.dll;; 358 | 359 | set TORCHACTIVATE_CMD=%TORCH_INSTALL_DIR%\torch-activate.cmd 360 | if exist %TORCHACTIVATE_CMD% del %TORCHACTIVATE_CMD% 361 | echo @echo off>> %TORCHACTIVATE_CMD% 362 | echo set CONDA_DIR=%CONDA_DIR%>> %TORCHACTIVATE_CMD% 363 | echo set TORCH_INSTALL_DIR=%%~dp0.>> %TORCHACTIVATE_CMD% 364 | echo set TORCH_CONDA_ENV=%TORCH_CONDA_ENV%>> %TORCHACTIVATE_CMD% 365 | echo set TORCH_VS_VERSION=%TORCH_VS_VERSION%>> %TORCHACTIVATE_CMD% 366 | echo set TORCH_VS_PLATFORM=%TORCH_VS_PLATFORM%>> %TORCHACTIVATE_CMD% 367 | if "%TORCH_VS_VERSION%" == "15" ( 368 | set VCVARSALL_BAT_PATH=..\..\VC\Auxiliary\Build\vcvarsall.bat 369 | ) else ( 370 | set VCVARSALL_BAT_PATH=..\..\VC\vcvarsall.bat 371 | ) 372 | echo for /f "delims=" %%%%i in ('call echo %%%%VS%TORCH_VS_VERSION%0COMNTOOLS%%%%') do call "%%%%i%VCVARSALL_BAT_PATH%" %TORCH_VS_PLATFORM%>> %TORCHACTIVATE_CMD% 373 | echo set PATH=%NEW_PATH%>> %TORCHACTIVATE_CMD% 374 | echo set LUA_PATH=%NEW_LUA_PATH%>> %TORCHACTIVATE_CMD% 375 | echo set LUA_CPATH=%NEW_LUA_CPATH%>> %TORCHACTIVATE_CMD% 376 | if not "%CUDNN_PATH%" == "" echo set CUDNN_PATH=%CUDNN_PATH%>> %TORCHACTIVATE_CMD% 377 | 378 | if not "%LUAJIT_CMD%" == "" ( 379 | if exist "%LUAJIT_CMD%" del %LUAJIT_CMD% 380 | echo @echo off>> "%LUAJIT_CMD%" 381 | echo setlocal>> "%LUAJIT_CMD%" 382 | echo set TORCH_INSTALL_DIR=%%~dp0.>> "%LUAJIT_CMD%" 383 | echo call %%TORCH_INSTALL_DIR%%\torch-activate.cmd>> "%LUAJIT_CMD%" 384 | echo %%TORCH_INSTALL_DIR%%\bin\luajit.exe %%*>> "%LUAJIT_CMD%" 385 | echo endlocal>> "%LUAJIT_CMD%" 386 | ) 387 | 388 | if not "%LUA_CMD%" == "" ( 389 | if exist "%LUA_CMD%" del %LUA_CMD% 390 | echo @echo off>> "%LUA_CMD%" 391 | echo setlocal>> "%LUA_CMD%" 392 | echo set TORCH_INSTALL_DIR=%%~dp0.>> "%LUA_CMD%" 393 | echo call %%TORCH_INSTALL_DIR%%\torch-activate.cmd>> "%LUA_CMD%" 394 | echo %%TORCH_INSTALL_DIR%%\bin\lua.exe %%*>> "%LUA_CMD%" 395 | echo endlocal>> "%LUA_CMD%" 396 | ) 397 | 398 | if not "%LUAC_CMD%" == "" ( 399 | if exist "%LUAC_CMD%" del %LUAC_CMD% 400 | echo @echo off>> "%LUAC_CMD%" 401 | echo setlocal>> "%LUAC_CMD%" 402 | echo set TORCH_INSTALL_DIR=%%~dp0.>> "%LUAC_CMD%" 403 | echo call %%TORCH_INSTALL_DIR%%\torch-activate.cmd>> "%LUAC_CMD%" 404 | echo %%TORCH_INSTALL_DIR%%\bin\luac.exe %%*>> "%LUAC_CMD%" 405 | echo endlocal>> "%LUAC_CMD%" 406 | ) 407 | 408 | if exist %LUAROCKS_CMD% del %LUAROCKS_CMD% 409 | echo @echo off>> %LUAROCKS_CMD% 410 | echo setlocal>> %LUAROCKS_CMD% 411 | echo set TORCH_INSTALL_DIR=%%~dp0.>> %LUAROCKS_CMD% 412 | echo call %%TORCH_INSTALL_DIR%%\torch-activate.cmd>> %LUAROCKS_CMD% 413 | echo call %%TORCH_INSTALL_DIR%%\luarocks\luarocks.bat %%*>> %LUAROCKS_CMD% 414 | echo endlocal>> %LUAROCKS_CMD% 415 | 416 | set CMAKE_CMD=%TORCH_INSTALL_DIR%\cmake.cmd 417 | if exist %CMAKE_CMD% del %CMAKE_CMD% 418 | echo @echo off>> %CMAKE_CMD% 419 | echo if "%%1" == ".." if not "%%2" == "-G" goto :G_NMake>> %CMAKE_CMD% 420 | echo cmake.exe %%*>> %CMAKE_CMD% 421 | echo goto :EOF>> %CMAKE_CMD% 422 | echo :G_NMake>> %CMAKE_CMD% 423 | echo shift>> %CMAKE_CMD% 424 | echo cmake.exe .. -G "NMake Makefiles" %%*>> %CMAKE_CMD% 425 | 426 | set TORCH_SETUP_FAIL=0 427 | cd %TORCH_DISTRO% 428 | echo %ECHO_PREFIX% Setup succeed! 429 | goto :END 430 | 431 | :FAIL 432 | cd %TORCH_DISTRO% 433 | echo %ECHO_PREFIX% Setup fail! 434 | 435 | :END 436 | -------------------------------------------------------------------------------- /install-openblas.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | #OpenBLAS installation from source code 3 | git clone https://github.com/xianyi/OpenBLAS.git ./OpenBLAS 4 | cd OpenBLAS 5 | make USE_OPENMP=1 6 | mkdir ~/OpenBLAS 7 | make install PREFIX=~/OpenBLAS 8 | export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:~/OpenBLAS/lib 9 | SET_LLP="export LD_LIBRARY_PATH=\$LD_LIBRARY_PATH:~/OpenBLAS/lib" 10 | echo "$SET_LLP" >> ~/.bashrc 11 | cd ../ 12 | -------------------------------------------------------------------------------- /install.bat: -------------------------------------------------------------------------------- 1 | @setlocal enableextensions 2 | @echo off 3 | 4 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 5 | :::: This script instals Torch7 on windows with msvc :::: 6 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 7 | 8 | 9 | if not "%TORCH_SETUP_FAIL%" == "0" call install-deps.bat 10 | if not "%TORCH_SETUP_FAIL%" == "0" goto :FAIL 11 | 12 | echo %ECHO_PREFIX% Updating submodules 13 | git submodule update --init --recursive 14 | 15 | set PATCH_DIR=%TORCH_DISTRO%\win-files\patch 16 | 17 | echo %ECHO_PREFIX% Installing common lua packages 18 | cd %TORCH_DISTRO%\extra\luafilesystem && call %LUAROCKS_CMD% make rockspecs\luafilesystem-1.6.3-1.rockspec || goto :FAIL 19 | cd %TORCH_DISTRO%\extra\penlight && call %LUAROCKS_CMD% make penlight-scm-1.rockspec || goto :FAIL 20 | cd %TORCH_DISTRO%\extra\lua-cjson && git apply %PATCH_DIR%\lua-cjson.patch --whitespace=fix & ( call %LUAROCKS_CMD% make lua-cjson-2.1devel-1.rockspec || goto :FAIL ) & git apply %PATCH_DIR%\lua-cjson.patch --reverse --whitespace=fix 21 | 22 | echo %ECHO_PREFIX% Installing core Torch7 packages 23 | cd %TORCH_DISTRO%\extra\luaffifb && git apply %PATCH_DIR%\luaffifb.patch --whitespace=fix & ( call %LUAROCKS_CMD% make luaffi-scm-1.rockspec || goto :FAIL ) & git apply %PATCH_DIR%\luaffifb.patch --reverse --whitespace=fix 24 | cd %TORCH_DISTRO%\pkg\sundown && call %LUAROCKS_CMD% make rocks\sundown-scm-1.rockspec || goto :FAIL 25 | cd %TORCH_DISTRO%\pkg\cwrap && call %LUAROCKS_CMD% make rocks\cwrap-scm-1.rockspec || goto :FAIL 26 | cd %TORCH_DISTRO%\pkg\paths && call %LUAROCKS_CMD% make rocks\paths-scm-1.rockspec || goto :FAIL 27 | if "%TORCH_SETUP_HAS_MKL%" == "1" ( 28 | cd %TORCH_DISTRO%\pkg\torch && git apply %PATCH_DIR%\torch.patch --whitespace=fix & ( call %LUAROCKS_CMD% make rocks\torch-scm-1.rockspec INTEL_MKL_DIR="%INTEL_MKL_DIR%" INTEL_COMPILER_DIR="%INTEL_COMPILER_DIR%" || goto :FAIL ) & git apply %PATCH_DIR%\torch.patch --reverse --whitespace=fix 29 | ) else ( 30 | cd %TORCH_DISTRO%\pkg\torch && git apply %PATCH_DIR%\torch.patch --whitespace=fix & ( call %LUAROCKS_CMD% make rocks\torch-scm-1.rockspec BLAS_LIBRARIES="%BLAS_LIBRARIES%" LAPACK_LIBRARIES="%LAPACK_LIBRARIES%" LAPACK_FOUND=TRUE || goto :FAIL ) & git apply %PATCH_DIR%\torch.patch --reverse --whitespace=fix 31 | ) 32 | cd %TORCH_DISTRO%\pkg\dok && call %LUAROCKS_CMD% make rocks\dok-scm-1.rockspec || goto :FAIL 33 | cd %TORCH_DISTRO%\exe\trepl && call %LUAROCKS_CMD% make trepl-scm-1.rockspec || goto :FAIL 34 | cd %TORCH_DISTRO%\pkg\sys && call %LUAROCKS_CMD% make sys-1.1-0.rockspec || goto :FAIL 35 | cd %TORCH_DISTRO%\pkg\xlua && call %LUAROCKS_CMD% make xlua-1.0-0.rockspec || goto :FAIL 36 | cd %TORCH_DISTRO%\extra\nn && call %LUAROCKS_CMD% make rocks\nn-scm-1.rockspec || goto :FAIL 37 | cd %TORCH_DISTRO%\extra\graph && call %LUAROCKS_CMD% make rocks\graph-scm-1.rockspec || goto :FAIL 38 | cd %TORCH_DISTRO%\extra\nngraph && call %LUAROCKS_CMD% make nngraph-scm-1.rockspec || goto :FAIL 39 | cd %TORCH_DISTRO%\pkg\image && call %LUAROCKS_CMD% make image-1.1.alpha-0.rockspec || goto :FAIL 40 | cd %TORCH_DISTRO%\pkg\optim && call %LUAROCKS_CMD% make optim-1.0.5-0.rockspec || goto :FAIL 41 | 42 | if not "%TORCH_SETUP_HAS_CUDA%" == "" if not "%TORCH_VS_TARGET%" == "x86" ( 43 | echo %ECHO_PREFIX% Found CUDA on your machine. Installing CUDA packages 44 | cd %TORCH_DISTRO%\extra\cutorch && call %LUAROCKS_CMD% make rocks\cutorch-scm-1.rockspec || goto :FAIL 45 | cd %TORCH_DISTRO%\extra\cunn && call %LUAROCKS_CMD% make rocks\cunn-scm-1.rockspec || goto :FAIL 46 | ) 47 | 48 | echo %ECHO_PREFIX% Installing optional Torch7 packages 49 | cd %TORCH_DISTRO%\pkg\gnuplot && call %LUAROCKS_CMD% make rocks\gnuplot-scm-1.rockspec 50 | cd %TORCH_DISTRO%\exe\env && call %LUAROCKS_CMD% make env-scm-1.rockspec 51 | cd %TORCH_DISTRO%\extra\nnx && call %LUAROCKS_CMD% make nnx-0.1-1.rockspec 52 | cd %TORCH_DISTRO%\exe\qtlua && call %LUAROCKS_CMD% make rocks\qtlua-scm-1.rockspec 53 | cd %TORCH_DISTRO%\pkg\qttorch && call %LUAROCKS_CMD% make rocks\qttorch-scm-1.rockspec 54 | cd %TORCH_DISTRO%\extra\threads && call %LUAROCKS_CMD% make rocks\threads-scm-1.rockspec WIN_DLFCN_INCDIR=%WIN_DLFCN_INCDIR% WIN_DLFCN_LIBDIR=%WIN_DLFCN_LIBDIR% 55 | cd %TORCH_DISTRO%\extra\argcheck && call %LUAROCKS_CMD% make rocks\argcheck-scm-1.rockspec 56 | 57 | if not "%TORCH_SETUP_HAS_CUDA%" == "" if not "%TORCH_VS_TARGET%" == "x86" ( 58 | echo %ECHO_PREFIX% Found CUDA on your machine. Installing optional CUDA packages 59 | cd %TORCH_DISTRO%\extra\cudnn && call %LUAROCKS_CMD% make cudnn-scm-1.rockspec 60 | ) 61 | 62 | echo %ECHO_PREFIX% Installation succeed! 63 | goto :END 64 | 65 | :FAIL 66 | echo %ECHO_PREFIX% Installation error! 67 | 68 | :END 69 | @endlocal 70 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | export CC= 4 | export CXX= 5 | 6 | #compiling option 7 | 8 | intel=$1 # compiler icc/gcc 9 | avx512=$2 # AVX512F on/off 10 | #omp=$3 # intel intel/gnu 11 | use_mklml=$3 # intel intel/gnu 12 | skip=$4 # skip openblas, value = noskip/skip, default is noskip 13 | if [[ $skip == 'skip' ]]; then 14 | echo "skip openblas check" 15 | else 16 | #identify user level, and check openblas.For root user, check /opt/OpenBLAS, for none root user, check ~/OpenBLAS 17 | if [ "$(ls -A /opt/OpenBLAS)" ]; then 18 | echo "OpenBLAS is installed in /opt" 19 | else 20 | if [[ $EUID -ne 0 ]]; then 21 | #none root user 22 | RTN=$(echo $LD_LIBRARY_PATH |grep -i openblas) 23 | if [ -z "$RTN" ]; then 24 | echo "OpenBLAS is not installed, or environment is not set" 25 | bash install-openblas.sh 26 | else 27 | echo "OpenBLAS installed." 28 | 29 | fi 30 | else 31 | #root user 32 | echo "ERROR: please instal OpenBLAS: bash install-deps , or apt-get install -y libopenblas-dev " 33 | fi 34 | fi 35 | fi 36 | 37 | 38 | FORCE_AVX512_v=OFF 39 | if [[ $avx512 == 'avx512' ]]; then 40 | FORCE_AVX512_v=ON 41 | else 42 | FORCE_AVX512_v=OFF 43 | fi 44 | 45 | USE_MKLML_v=OFF 46 | if [[ $use_mklml == 'mklml' ]]; then 47 | USE_MKLML_v=ON 48 | else 49 | USE_MKLML_v=OFF 50 | fi 51 | 52 | WITH_IOMP_v=ON 53 | :<&1 >>$PREFIX/install.log || exit 1 181 | (make 2>&1 >>$PREFIX/install.log || exit 1) && (make install 2>&1 >>$PREFIX/install.log || exit 1) 182 | cd .. 183 | 184 | # Check for a CUDA install (using nvcc instead of nvidia-smi for cross-platform compatibility) 185 | path_to_nvcc=$(which nvcc) 186 | if [ $? == 1 ]; then { # look for it in /usr/local 187 | if [[ -f /usr/local/cuda/bin/nvcc ]]; then { 188 | path_to_nvcc=/usr/local/cuda/bin/nvcc 189 | } 190 | elif [[ -f /opt/cuda/bin/nvcc ]]; then { # default path for arch 191 | path_to_nvcc=/opt/cuda/bin/nvcc 192 | } fi 193 | } fi 194 | 195 | # check if we are on mac and fix RPATH for local install 196 | path_to_install_name_tool=$(which install_name_tool 2>/dev/null) 197 | if [ -x "$path_to_install_name_tool" ] 198 | then 199 | if [ ${TORCH_LUA_VERSION} == "LUAJIT21" ] || [ ${TORCH_LUA_VERSION} == "LUAJIT20" ] ; then 200 | install_name_tool -id ${PREFIX}/lib/libluajit.dylib ${PREFIX}/lib/libluajit.dylib 201 | else 202 | install_name_tool -id ${PREFIX}/lib/liblua.dylib ${PREFIX}/lib/liblua.dylib 203 | fi 204 | fi 205 | 206 | if [ -x "$path_to_nvcc" ] || [ -x "$path_to_nvidiasmi" ] 207 | then 208 | echo "Found CUDA on your machine. Installing CMake 3.6 modules to get up-to-date FindCUDA" 209 | cd ${THIS_DIR}/cmake/3.6 && \ 210 | (cmake -E make_directory build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX="${PREFIX}" \ 211 | && make install) && echo "FindCuda bits of CMake 3.6 installed" || exit 1 212 | fi 213 | 214 | setup_lua_env_cmd=$($PREFIX/bin/luarocks path) 215 | eval "$setup_lua_env_cmd" 216 | 217 | echo "$CC" 218 | echo "Installing common Lua packages" 219 | cd ${THIS_DIR}/extra/luafilesystem && $PREFIX/bin/luarocks make rockspecs/luafilesystem-1.6.3-1.rockspec || exit 1 220 | cd ${THIS_DIR}/extra/penlight && $PREFIX/bin/luarocks make penlight-scm-1.rockspec || exit 1 221 | cd ${THIS_DIR}/extra/lua-cjson && $PREFIX/bin/luarocks make lua-cjson-2.1devel-1.rockspec || exit 1 222 | 223 | echo "Installing core Torch packages" 224 | cd ${THIS_DIR}/extra/luaffifb && $PREFIX/bin/luarocks make luaffi-scm-1.rockspec || exit 1 225 | cd ${THIS_DIR}/pkg/sundown && $PREFIX/bin/luarocks make rocks/sundown-scm-1.rockspec || exit 1 226 | cd ${THIS_DIR}/pkg/cwrap && $PREFIX/bin/luarocks make rocks/cwrap-scm-1.rockspec || exit 1 227 | cd ${THIS_DIR}/pkg/paths && $PREFIX/bin/luarocks make rocks/paths-scm-1.rockspec || exit 1 228 | cd ${THIS_DIR}/pkg/torch && $PREFIX/bin/luarocks make WITH_IOMP=$WITH_IOMP_v FORCE_AVX512=$FORCE_AVX512_v USE_MKLML=$USE_MKLML_v rocks/torch-scm-1.rockspec || exit 1 229 | cd ${THIS_DIR}/pkg/dok && $PREFIX/bin/luarocks make rocks/dok-scm-1.rockspec || exit 1 230 | cd ${THIS_DIR}/exe/trepl && $PREFIX/bin/luarocks make trepl-scm-1.rockspec || exit 1 231 | cd ${THIS_DIR}/pkg/sys && $PREFIX/bin/luarocks make sys-1.1-0.rockspec || exit 1 232 | cd ${THIS_DIR}/pkg/xlua && $PREFIX/bin/luarocks make xlua-1.0-0.rockspec || exit 1 233 | cd ${THIS_DIR}/extra/nn && $PREFIX/bin/luarocks make FORCE_AVX512=$FORCE_AVX512_v rocks/nn-scm-1.rockspec || exit 1 234 | cd ${THIS_DIR}/extra/mkltorch && $PREFIX/bin/luarocks make FORCE_AVX512=$FORCE_AVX512_v mkltorch-scm-1.rockspec || exit 1 235 | cd ${THIS_DIR}/extra/mklnn && $PREFIX/bin/luarocks make FORCE_AVX512=$FORCE_AVX512_v mklnn-scm-1.rockspec || exit 1 236 | cd ${THIS_DIR}/extra/graph && $PREFIX/bin/luarocks make rocks/graph-scm-1.rockspec || exit 1 237 | cd ${THIS_DIR}/extra/nngraph && $PREFIX/bin/luarocks make nngraph-scm-1.rockspec || exit 1 238 | cd ${THIS_DIR}/pkg/image && $PREFIX/bin/luarocks make image-1.1.alpha-0.rockspec || exit 1 239 | cd ${THIS_DIR}/pkg/optim && $PREFIX/bin/luarocks make optim-1.0.5-0.rockspec || exit 1 240 | 241 | if [ -x "$path_to_nvcc" ] 242 | then 243 | echo "Found CUDA on your machine. Installing CUDA packages" 244 | cd ${THIS_DIR}/extra/cutorch && $PREFIX/bin/luarocks make rocks/cutorch-scm-1.rockspec || exit 1 245 | cd ${THIS_DIR}/extra/cunn && $PREFIX/bin/luarocks make rocks/cunn-scm-1.rockspec || exit 1 246 | fi 247 | 248 | # Optional packages 249 | echo "Installing optional Torch packages" 250 | cd ${THIS_DIR}/pkg/gnuplot && $PREFIX/bin/luarocks make rocks/gnuplot-scm-1.rockspec 251 | cd ${THIS_DIR}/exe/env && $PREFIX/bin/luarocks make env-scm-1.rockspec 252 | cd ${THIS_DIR}/extra/nnx && $PREFIX/bin/luarocks make nnx-0.1-1.rockspec 253 | cd ${THIS_DIR}/exe/qtlua && $PREFIX/bin/luarocks make rocks/qtlua-scm-1.rockspec 254 | cd ${THIS_DIR}/pkg/qttorch && $PREFIX/bin/luarocks make rocks/qttorch-scm-1.rockspec 255 | cd ${THIS_DIR}/extra/threads && $PREFIX/bin/luarocks make rocks/threads-scm-1.rockspec 256 | cd ${THIS_DIR}/extra/argcheck && $PREFIX/bin/luarocks make rocks/argcheck-scm-1.rockspec 257 | 258 | # Optional CUDA packages 259 | if [ -x "$path_to_nvcc" ] 260 | then 261 | echo "Found CUDA on your machine. Installing optional CUDA packages" 262 | cd ${THIS_DIR}/extra/cudnn && $PREFIX/bin/luarocks make cudnn-scm-1.rockspec 263 | fi 264 | 265 | export PATH=$OLDPATH # Restore anaconda distribution if we took it out. 266 | 267 | # Add C libs to LUA_CPATH 268 | if [[ `uname` == "Darwin" ]]; then 269 | CLIB_LUA_CPATH=$PREFIX/lib/?.dylib 270 | else 271 | CLIB_LUA_CPATH=$PREFIX/lib/?.so 272 | fi 273 | 274 | cat <$PREFIX/bin/torch-activate 275 | $setup_lua_env_cmd 276 | export PATH=$PREFIX/bin:\$PATH 277 | export LD_LIBRARY_PATH=$PREFIX/lib:\$LD_LIBRARY_PATH 278 | export DYLD_LIBRARY_PATH=$PREFIX/lib:\$DYLD_LIBRARY_PATH 279 | export LUA_CPATH='$CLIB_LUA_CPATH;'\$LUA_CPATH 280 | EOF 281 | chmod +x $PREFIX/bin/torch-activate 282 | 283 | if [[ $SKIP_RC == 1 ]]; then 284 | exit 0 285 | fi 286 | 287 | RC_FILE=0 288 | DEFAULT=yes 289 | if [[ $(echo $SHELL | grep bash) ]]; then 290 | RC_FILE=$HOME/.bashrc 291 | elif [[ $(echo $SHELL | grep zsh) ]]; then 292 | RC_FILE=$HOME/.zshrc 293 | else 294 | echo " 295 | 296 | Non-standard shell $SHELL detected. You might want to 297 | add the following lines to your shell profile: 298 | 299 | . $PREFIX/bin/torch-activate 300 | " 301 | fi 302 | 303 | if [[ $skip == 'skip' ]]; then 304 | BATCH_INSTALL=1 305 | RC_FILE= 306 | fi 307 | 308 | WRITE_PATH_TO_PROFILE=0 309 | if [[ $BATCH_INSTALL == 0 ]]; then 310 | if [ -f "$RC_FILE" ]; then 311 | echo " 312 | 313 | Do you want to automatically prepend the Torch install location 314 | to PATH and LD_LIBRARY_PATH in your $RC_FILE? (yes/no) 315 | [$DEFAULT] >>> " 316 | read input 317 | if [[ $input == "" ]]; then 318 | input=$DEFAULT 319 | fi 320 | 321 | is_yes() { 322 | yesses={y,Y,yes,Yes,YES} 323 | if [[ $yesses =~ $1 ]]; then 324 | echo 1 325 | fi 326 | } 327 | 328 | if [[ $(is_yes $input) ]]; then 329 | WRITE_PATH_TO_PROFILE=1 330 | fi 331 | fi 332 | else 333 | if [[ "$RC_FILE" ]]; then 334 | WRITE_PATH_TO_PROFILE=1 335 | fi 336 | fi 337 | 338 | WRITE_PATH_TO_PROFILE=0 339 | if [[ $WRITE_PATH_TO_PROFILE == 1 ]]; then 340 | echo " 341 | 342 | . $PREFIX/bin/torch-activate" >> "$RC_FILE" 343 | echo " 344 | 345 | . $PREFIX/bin/torch-activate" >> "$HOME"/.profile 346 | 347 | else 348 | echo " 349 | 350 | Not updating your shell profile. 351 | You might want to 352 | add the following lines to your shell profile: 353 | 354 | . $PREFIX/bin/torch-activate 355 | " 356 | fi 357 | -------------------------------------------------------------------------------- /pkg/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.8) 2 | ADD_SUBDIRECTORY(sundown) 3 | ADD_SUBDIRECTORY(cwrap) 4 | ADD_SUBDIRECTORY(paths) 5 | ADD_SUBDIRECTORY(torch) 6 | ADD_SUBDIRECTORY(dok) 7 | ADD_SUBDIRECTORY(sys) 8 | ADD_SUBDIRECTORY(xlua) 9 | ADD_SUBDIRECTORY(image) 10 | ADD_SUBDIRECTORY(optim) 11 | 12 | -------------------------------------------------------------------------------- /prepare_mklml.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # set -ex 3 | FindLibrary() 4 | { 5 | case "$1" in 6 | intel|1) 7 | LOCALMKLML=`find $DST -name libmklml_intel.so` # name of MKL SDL lib 8 | ;; 9 | *) 10 | LOCALMKLML=`find $DST -name libmklml_gnu.so` # name of MKL SDL lib 11 | ;; 12 | esac 13 | 14 | } 15 | 16 | GetVersionName() 17 | { 18 | VERSION_LINE=0 19 | if [ $1 ]; then 20 | VERSION_LINE=`grep __INTEL_MKL_BUILD_DATE $1/include/mkl_version.h 2>/dev/null | sed -e 's/.* //'` 21 | fi 22 | if [ -z $VERSION_LINE ]; then 23 | VERSION_LINE=0 24 | fi 25 | echo $VERSION_LINE # Return Version Line 26 | } 27 | 28 | # MKLML 29 | DST=`dirname $0` 30 | OMP=0 31 | VERSION_MATCH=20170908 32 | ARCHIVE_BASENAME=mklml_lnx_2018.0.1.20171007.tgz 33 | MKLML_CONTENT_DIR=`echo $ARCHIVE_BASENAME | rev | cut -d "." -f 2- | rev` 34 | GITHUB_RELEASE_TAG=v0.11 35 | MKLMLURL="https://github.com/01org/mkl-dnn/releases/download/$GITHUB_RELEASE_TAG/$ARCHIVE_BASENAME" 36 | # there are diffrent MKL lib to be used for GCC and for ICC 37 | reg='^[0-9]+$' 38 | #echo "----->" $DST 39 | VERSION_LINE=`GetVersionName $MKLMLROOT` 40 | if [[ $2 == ON ]]; then 41 | # Check if MKLMLROOT is set if positive then set one will be used.. 42 | if [ -z $MKLMLROOT ] || [ $VERSION_LINE -lt $VERSION_MATCH ]; then 43 | # ..if MKLROOT is not set then check if we have MKL downloaded in proper version 44 | VERSION_LINE=`GetVersionName $DST/$MKLML_CONTENT_DIR` 45 | if [ $VERSION_LINE -lt $VERSION_MATCH ] ; then 46 | #...If it is not then downloaded and unpacked 47 | wget --no-check-certificate -P $DST $MKLMLURL -O $DST/$ARCHIVE_BASENAME 48 | tar -xzf $DST/$ARCHIVE_BASENAME -C $DST 49 | fi 50 | 51 | FindLibrary $1 52 | #echo "----- $LOCALMKLML" 53 | MKLMLROOT=$PWD/`echo $LOCALMKLML | sed -e 's/lib.*$//'` 54 | fi 55 | # return value to calling script (Makefile,cmake) 56 | echo $MKLMLROOT $LIBRARIES $OMP 57 | 58 | else 59 | 60 | # Check what MKL lib we have in MKLROOT 61 | 62 | if [ -z `find $MKLROOT -name libmkl_rt.so -print -quit` ]; then 63 | LIBRARIES=`basename $LOCALMKL | sed -e 's/^.*lib//' | sed -e 's/\.so.*$//'` 64 | OMP=1 65 | else 66 | LIBRARIES="mkl_rt" 67 | fi 68 | echo $MKLROOT $LIBRARIES $OMP 69 | 70 | fi 71 | 72 | -------------------------------------------------------------------------------- /test.bat: -------------------------------------------------------------------------------- 1 | @setlocal enableextensions 2 | @echo off 3 | 4 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 5 | :::: This script tests if Torch7 is installed properly :::: 6 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 7 | 8 | 9 | if "%TORCH_INSTALL_DIR%" == "" goto :HELP 10 | 11 | for /f "delims=" %%i in ('where luajit.cmd') do ( 12 | set LUA=%%i 13 | goto :AFTER_LUAJIT 14 | ) 15 | 16 | :AFTER_LUAJIT 17 | if exist "%LUA%" ( 18 | set TORCH_USE_LUAJIT=1 19 | ) else ( 20 | for /f "delims=" %%i in ('where lua.cmd') do ( 21 | set LUA=%%i 22 | goto :AFTER_LUA 23 | ) 24 | ) 25 | 26 | :AFTER_LUA 27 | if not exist "%LUA%" ( 28 | echo Neither luajit nor lua found in Torch7 environment 29 | goto :FAIL 30 | ) 31 | 32 | set LUA_SAFE_PATH=%LUA:\=\\% 33 | echo Using Lua at: %LUA% 34 | 35 | :: smoke tests 36 | call %LUA% -lpaths -e "print('paths loaded succesfully')" || goto :FAIL 37 | call %LUA% -ltorch -e "print('torch loaded succesfully')" || goto :FAIL 38 | call %LUA% -lenv -e "print('env loaded succesfully')" || goto :FAIL 39 | call %LUA% -ltrepl -e "print('trepl loaded succesfully')" || goto :FAIL 40 | call %LUA% -ldok -e "print('dok loaded succesfully')" || goto :FAIL 41 | call %LUA% -limage -e "print('image loaded succesfully')" || goto :FAIL 42 | call %LUA% -lcwrap -e "print('cwrap loaded succesfully')" || goto :FAIL 43 | call %LUA% -lgnuplot -e "print('gnuplot loaded succesfully')" || goto :FAIL 44 | call %LUA% -loptim -e "print('optim loaded succesfully')" || goto :FAIL 45 | call %LUA% -lsys -e "print('sys loaded succesfully')" || goto :FAIL 46 | for /f "delims=" %%i in ('where basename') do set BASENAME=%%i 47 | if "%BASENAME%" == "" ( 48 | call %LUA% -lxlua -e "print('xlua loaded succesfully')" || goto :FAIL 49 | ) else ( 50 | call %LUA% -lxlua -e "print('x$(basename %LUA_SAFE_PATH%) loaded succesfully')" || goto :FAIL 51 | ) 52 | call %LUA% -largcheck -e "print('argcheck loaded succesfully')" || goto :FAIL 53 | call %LUA% -lgraph -e "print('graph loaded succesfully')" || goto :FAIL 54 | call %LUA% -lnn -e "print('nn loaded succesfully')" || goto :FAIL 55 | call %LUA% -lnngraph -e "print('nngraph loaded succesfully')" || goto :FAIL 56 | call %LUA% -lnnx -e "print('nnx loaded succesfully')" || goto :FAIL 57 | call %LUA% -lthreads -e "print('threads loaded succesfully')" || goto :FAIL 58 | 59 | call th -ltorch -e "torch.test()" 60 | call th -lnn -e "nn.test()" 61 | 62 | if "%TORCH_USE_LUAJIT%" == "1" ( 63 | call %LUA% -lsundown -e "print('sundown loaded succesfully')" 64 | ) 65 | 66 | call %LUA% -lcutorch -e "" 67 | if "%ERRORLEVEL%" == "0" ( 68 | call %LUA% -lcutorch -e "print('cutorch loaded succesfully')" 69 | call %LUA% -lcunn -e "print('cunn loaded succesfully')" 70 | if "%TORCH_USE_LUAJIT%" == "1" %LUA% -lcudnn -e "print('cudnn loaded succesfully')" 71 | call th -lcutorch -e "cutorch.test()" 72 | call th -lcunn -e "nn.testcuda()" 73 | ) else ( 74 | echo "CUDA not found" 75 | ) 76 | 77 | echo Test succeed 78 | goto :END 79 | 80 | :HELP 81 | echo Please run torch-activate.cmd before run test.bat so that test knows where to find Torch7. 82 | goto :END 83 | 84 | :FAIL 85 | echo Test fail 86 | 87 | :END 88 | @endlocal 89 | -------------------------------------------------------------------------------- /test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -e 3 | 4 | LUA=$(which luajit lua | head -n 1) 5 | 6 | if [ ! -x "$LUA" ] 7 | then 8 | echo "Neither luajit nor lua found in path" 9 | exit 1 10 | fi 11 | 12 | echo "Using Lua at:" 13 | echo "$LUA" 14 | 15 | #smoke tests 16 | $LUA -lpaths -e "print('paths loaded succesfully')" 17 | $LUA -ltorch -e "print('torch loaded succesfully')" 18 | $LUA -lenv -e "print('env loaded succesfully')" 19 | $LUA -ltrepl -e "print('trepl loaded succesfully')" 20 | $LUA -ldok -e "print('dok loaded succesfully')" 21 | $LUA -limage -e "print('image loaded succesfully')" 22 | $LUA -lcwrap -e "print('cwrap loaded succesfully')" 23 | $LUA -lgnuplot -e "print('gnuplot loaded succesfully')" 24 | $LUA -loptim -e "print('optim loaded succesfully')" 25 | $LUA -lsys -e "print('sys loaded succesfully')" 26 | $LUA -lxlua -e "print('x$(basename $LUA) loaded succesfully')" 27 | $LUA -largcheck -e "print('argcheck loaded succesfully')" 28 | $LUA -lgraph -e "print('graph loaded succesfully')" 29 | $LUA -lnn -e "print('nn loaded succesfully')" 30 | $LUA -lmkltorch -e "print('mkltorch loaded succesfully')" 31 | $LUA -lmklnn -e "print('mklnn loaded succesfully')" 32 | $LUA -lnngraph -e "print('nngraph loaded succesfully')" 33 | $LUA -lnnx -e "print('nnx loaded succesfully')" 34 | $LUA -lthreads -e "print('threads loaded succesfully')" 35 | 36 | th -ltorch -e "torch.test()" 37 | th -lnn -e "nn.test()" 38 | th -lmklnn -e "mklnn.test()" 39 | 40 | if [ $(basename $LUA) = "luajit" ] 41 | then 42 | $LUA -lsundown -e "print('sundown loaded succesfully')" 43 | fi 44 | 45 | if `$LUA -lcutorch -e ""` 46 | then 47 | $LUA -lcutorch -e "print('cutorch loaded succesfully')" 48 | $LUA -lcunn -e "print('cunn loaded succesfully')" 49 | if [ $(basename $LUA) = "luajit" ]; 50 | then 51 | $LUA -lcudnn -e "print('cudnn loaded succesfully')" 52 | fi 53 | th -lcutorch -e "cutorch.test()" 54 | th -lcunn -e "nn.testcuda()" 55 | else 56 | echo "CUDA not found" 57 | fi 58 | -------------------------------------------------------------------------------- /travis_cuda_install.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | if [[ `uname` == 'Linux' ]]; then 4 | CUDA_VERSION=6-5 5 | CUDA_URL=http://developer.download.nvidia.com/compute/cuda/repos/ubuntu1204/x86_64/cuda-repo-ubuntu1204_6.5-14_amd64.deb 6 | CUDA_FILE=/tmp/cuda_install.deb 7 | 8 | curl $CUDA_URL -o $CUDA_FILE 9 | dpkg -i $CUDA_FILE 10 | rm -f $CUDA_FILE 11 | apt-get -y update 12 | apt-get -y install \ 13 | cuda-core-${CUDA_VERSION} \ 14 | cuda-cublas-${CUDA_VERSION} \ 15 | cuda-cublas-dev-${CUDA_VERSION} \ 16 | cuda-cudart-${CUDA_VERSION} \ 17 | cuda-cudart-dev-${CUDA_VERSION} \ 18 | cuda-curand-${CUDA_VERSION} \ 19 | cuda-curand-dev-${CUDA_VERSION} \ 20 | cuda-cusparse-${CUDA_VERSION} \ 21 | cuda-cusparse-dev-${CUDA_VERSION} 22 | ln -s /usr/local/cuda-6.5 /usr/local/cuda 23 | fi 24 | -------------------------------------------------------------------------------- /uninstall.bat: -------------------------------------------------------------------------------- 1 | @setlocal enableextensions 2 | @echo off 3 | 4 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 5 | :::: This script [1] cleans temporary compilation file :::: 6 | :::: [2] deletes Torch7 installation directory :::: 7 | :::: [3] deletes Torch7 conda environment :::: 8 | :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: 9 | 10 | 11 | if "%TORCH_INSTALL_DIR%" == "" goto :HELP 12 | 13 | set ECHO_PREFIX=+++++++ 14 | 15 | echo %ECHO_PREFIX% cleaning temporary compilation files 16 | call clean.bat 17 | 18 | echo %ECHO_PREFIX% deleting Torch7 installation directory 19 | rmdir /s /q %TORCH_INSTALL_DIR% 20 | 21 | echo %ECHO_PREFIX% deleting Torch7 conda environment (even if env is removed, packages will stil be kept in conda/pkgs) 22 | conda env remove -n %TORCH_CONDA_ENV% --yes 23 | 24 | echo %ECHO_PREFIX% Torch7 has been uninstalled 25 | goto :END 26 | 27 | :HELP 28 | echo Please run torch-activate.cmd before run uninstall.bat so that uninstall knows where to find Torch7. 29 | 30 | :END 31 | @endlocal 32 | -------------------------------------------------------------------------------- /update.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | git fetch 4 | git reset --hard origin/master 5 | # Submodule update is done inside install.sh 6 | ./install.sh -s 7 | -------------------------------------------------------------------------------- /win-files/README.md: -------------------------------------------------------------------------------- 1 | Self-contained Torch installation for windows 2 | ============ 3 | 4 | ## Prerequisites 5 | 6 | #### Must have 7 | - MSVC, anyone of the following choices is sufficient 8 | - [Visual C++ Build Tools](http://landinghub.visualstudio.com/visual-cpp-build-tools) 9 | - [Visual Studio Express](https://www.visualstudio.com/vs/visual-studio-express/) 10 | - [Visual Studio Community](https://www.visualstudio.com/vs/community/) 11 | - [Git](https://git-scm.com/download/win) 12 | - [CMake](https://cmake.org/download/#latest) 13 | - [Conda](http://conda.pydata.org/docs/download.html), manage dependencies like openblas, jpeg, qt, etc 14 | 15 | #### If use CUDA 16 | 17 | - [CUDA Toolkit](https://developer.nvidia.com/cuda-toolkit) 18 | - [CUDNN](https://developer.nvidia.com/cudnn), if use dnn 19 | 20 | #### Optional 21 | 22 | - [MKL](https://software.intel.com/intel-mkl), better performance blas/lapack library 23 | - [Gnuplot](https://sourceforge.net/projects/gnuplot/files/latest), required by gnuplot package for plotting 24 | - [GraphicsMagick](https://sourceforge.net/projects/graphicsmagick/files/latest), optional for image package 25 | 26 | ## Install 27 | Open "Windows Command Prompt" and run: 28 | ```bat 29 | install.bat 30 | ``` 31 | By default x64 Torch will be installed under install\ with LuaJIT 2.1 and openlblas from conda environment 'torch-vcversion'. 32 | Run install.bat in a specific "VS\* \* Tools Command Prompt" to compile for a different target. Please choose x64 conda 33 | for x64 Torch and x86 conda for x86 Torch. X86 Torch does not contain cuda packages and has 2G memory limitation. 34 | There are a few customizable environment variables listed on top of install-deps.bat. There is no need to run 35 | install-deps.bat before run install.bat, it sets variables in global and it will be called directly by install.bat. 36 | **Do not** use lua instead of luajit because currently lua version Torch will use luaffifb for ffi which has bugs on windows 37 | and has poor performance. 38 | 39 | It is easy to intall multiple Torch by customizing TORCH\_INSTALL\_DIR, TORCH\_LUA\_VERSION, and by making sure 40 | clean.bat is run before running install.bat. 41 | 42 | ## Use 43 | In order to use Torch in a Self-contained way, a few helper cmd will be installed under the installation directory: 44 | - torch-activate.cmd: setup Torch environment including TORCH\_INSTALL\_DIR, TORCH\_CONDA\_ENV, TORCH\_VS\_VERSION, TORCH\_VS\_PLATFORM, PATH, LUA\_PATH, LUA\_CPATH, CUDNN\_PATH, 45 | - luajit.cmd: a wrapper of luajit.exe with Torch environment 46 | - luarocks.cmd: a wrapper of luarocks.bat with Torch environment 47 | - cmake.cmd: a wrapper of cmake.exe which helps package installation with MSVC 48 | 49 | #### Use luajit.cmd and luarocks.cmd directly 50 | ```bat 51 | path_to_Torch\luajit -ltorch -e "torch.test()" 52 | ``` 53 | The installation will remember which MSVC to use for what platform, so luarocks install can be run in a general "Windows 54 | Command Prompt". 55 | ```bat 56 | path_to_Torch\luarocks install rnn 57 | ``` 58 | It will automatically install not installed dependencies. 59 | 60 | #### Run torch-activate.cmd, then use availabe Torch executables 61 | ```bat 62 | path_to_Torch\torch-activate 63 | th 64 | qlua 65 | ``` 66 | Trepl on windows should work similarly as on linux or macos. qlua should be used to run qt related lua codes. 67 | 68 | ## Clean or Uninstall 69 | To remove all the temporary compilation files: 70 | ```bat 71 | clean.bat 72 | ``` 73 | 74 | To remove the installation: 75 | ```bat 76 | path_to_Torch\torch-activate 77 | uninstall.bat 78 | ``` 79 | torch-activate.cmd is called before uninstall.bat so that uninstall knows which Torch7 to uninstall. 80 | In addition to clean.bat, this will remove the directory pointed to by TORCH\_INSTALL\_DIR and TORCH\_CONDA\_ENV from conda. 81 | 82 | ## Test 83 | You can test that all libraries are installed properly by running: 84 | ```bat 85 | path_to_Torch\torch-activate 86 | test.bat 87 | ``` 88 | torch-activate.cmd is called before test.bat so that test knows which Torch7 to test. 89 | 90 | Tested x64 Torch7 on Windows 10 x64, Visual Studio Community 2015, Anaconda4, Cuda Toolkit8.0, MKL2017 91 | -------------------------------------------------------------------------------- /win-files/patch/lua-cjson.patch: -------------------------------------------------------------------------------- 1 | diff --git a/fpconv.h b/fpconv.h 2 | index 7b0d0ee..f674e41 100644 3 | --- a/fpconv.h 4 | +++ b/fpconv.h 5 | @@ -4,6 +4,10 @@ 6 | * 7 | * Longest double printed with %.14g is 21 characters long: 8 | * -1.7976931348623e+308 */ 9 | +#ifdef _MSC_VER 10 | +#define inline __inline 11 | +#define snprintf _snprintf 12 | +#endif 13 | # define FPCONV_G_FMT_BUFSIZE 32 14 | 15 | #ifdef USE_INTERNAL_FPCONV 16 | diff --git a/lua-cjson-2.1devel-1.rockspec b/lua-cjson-2.1devel-1.rockspec 17 | index 154e333..0f7652e 100644 18 | --- a/lua-cjson-2.1devel-1.rockspec 19 | +++ b/lua-cjson-2.1devel-1.rockspec 20 | @@ -47,6 +47,7 @@ build = { 21 | -- Override default build options (per platform) 22 | platforms = { 23 | win32 = { modules = { cjson = { defines = { 24 | + "strncasecmp=_strnicmp", 25 | "DISABLE_INVALID_NUMBERS" 26 | } } } } 27 | }, 28 | diff --git a/strbuf.c b/strbuf.c 29 | index ac779e4..c3272f0 100644 30 | --- a/strbuf.c 31 | +++ b/strbuf.c 32 | @@ -94,8 +94,8 @@ void strbuf_set_increment(strbuf_t *s, int increment) 33 | static inline void debug_stats(strbuf_t *s) 34 | { 35 | if (s->debug) { 36 | - fprintf(stderr, "strbuf(%lx) reallocs: %d, length: %d, size: %d\n", 37 | - (long)s, s->reallocs, s->length, s->size); 38 | + fprintf(stderr, "strbuf(%p) reallocs: %d, length: %d, size: %d\n", 39 | + s, s->reallocs, s->length, s->size); 40 | } 41 | } 42 | 43 | @@ -168,8 +168,8 @@ void strbuf_resize(strbuf_t *s, int len) 44 | newsize = calculate_new_size(s, len); 45 | 46 | if (s->debug > 1) { 47 | - fprintf(stderr, "strbuf(%lx) resize: %d => %d\n", 48 | - (long)s, s->size, newsize); 49 | + fprintf(stderr, "strbuf(%p) resize: %d => %d\n", 50 | + s, s->size, newsize); 51 | } 52 | 53 | s->size = newsize; 54 | diff --git a/strbuf.h b/strbuf.h 55 | index d861108..b135560 100644 56 | --- a/strbuf.h 57 | +++ b/strbuf.h 58 | @@ -24,6 +24,9 @@ 59 | 60 | #include 61 | #include 62 | +#ifdef _MSC_VER 63 | +#define inline __inline 64 | +#endif 65 | 66 | /* Size: Total bytes allocated to *buf 67 | * Length: String length, excluding optional NULL terminator. 68 | -------------------------------------------------------------------------------- /win-files/patch/luaffifb.patch: -------------------------------------------------------------------------------- 1 | diff --git a/ffi.h b/ffi.h 2 | index dabdc9b..d457fd7 100644 3 | --- a/ffi.h 4 | +++ b/ffi.h 5 | @@ -42,8 +42,10 @@ extern "C" { 6 | #include 7 | #endif 8 | 9 | +#ifndef _MSC_VER 10 | #include 11 | #define HAVE_COMPLEX 12 | +#endif 13 | #define HAVE_LONG_DOUBLE 14 | 15 | #ifndef NDEBUG 16 | diff --git a/test.c b/test.c 17 | index 20f5d13..c9acb27 100644 18 | --- a/test.c 19 | +++ b/test.c 20 | @@ -19,8 +19,12 @@ 21 | #include 22 | #endif 23 | 24 | +#ifndef _MSC_VER 25 | #include 26 | #define HAVE_COMPLEX 27 | +#else 28 | +#include 29 | +#endif 30 | 31 | #ifdef __cplusplus 32 | # define EXTERN_C extern "C" 33 | @@ -718,3 +722,9 @@ void test_call_pppppiiifii(void* p1, void* p2, void* p3, void* p4, void* p5, int 34 | sprintf(buf, "%p %p %p %p %p %d %d %d %0.1f %d %d", p1, p2, p3, p4, p5, i1, i2, i3, f4, i5, i6); 35 | } 36 | 37 | +#ifdef _MSC_VER 38 | +int luaopen_ffi_libtest(lua_State* L) 39 | +{ 40 | + return 1; 41 | +} 42 | +#endif 43 | diff --git a/test.lua b/test.lua 44 | index 8a9b718..af05ea7 100644 45 | --- a/test.lua 46 | +++ b/test.lua 47 | @@ -7,6 +7,15 @@ 48 | -- of patent rights can be found in the PATENTS file in the same directory. 49 | -- 50 | io.stdout:setvbuf('no') 51 | + 52 | +local is_luajit = false 53 | +if type(jit) == 'table' then 54 | + is_luajit = string.find(jit.version, 'LuaJIT') 55 | + if is_luajit then 56 | + package.preload['ffi'] = nil -- enable run test in luajit 57 | + end 58 | +end 59 | + 60 | local ffi = require 'ffi' 61 | local dlls = {} 62 | 63 | @@ -322,17 +331,29 @@ local types = { 64 | e32 = 'enum e32', 65 | } 66 | 67 | +-- different compilers may printf(%p) in different format, 68 | +-- for example 000000003A0A9848, 0x3a0a9848 69 | +-- tostring(cdata) may return address with '0x' prefix 70 | +local addrbuf = ffi.new('char[256]') 71 | +local function unifyaddr(ttype, addr) 72 | + if ttype == 'void*' then 73 | + dlls.__cdecl.print_p(addrbuf, tonumber(addr, 16)) 74 | + return ffi.string(addrbuf) 75 | + end 76 | + return addr 77 | +end 78 | + 79 | local buf = ffi.new('char[256]') 80 | 81 | local function checkbuf(type, ret, msg) 82 | - local str = tostring(test_values[type]):gsub('^cdata%b<>: ', '') 83 | + local str = unifyaddr(type, tostring(test_values[type]):gsub('^cdata%b<>: ', '')) 84 | check(ffi.string(buf), str, msg) 85 | check(ret, #str, msg) 86 | end 87 | 88 | local function checkalign(type, v, ret) 89 | --print(v) 90 | - local str = tostring(test_values[type]):gsub('^cdata%b<>: ', '') 91 | + local str = unifyaddr(type, tostring(test_values[type]):gsub('^cdata%b<>: ', '')) 92 | check(ffi.string(buf), ('size %d offset %d align %d value %s'):format(ffi.sizeof(v), ffi.offsetof(v, 'v'), ffi.alignof(v, 'v'), str)) 93 | check(ret, #str) 94 | end 95 | @@ -593,9 +614,13 @@ for convention,c in pairs(dlls) do 96 | 97 | check(c.call_fptr({function(a) return 3*a end}, 5), 15) 98 | 99 | + if is_luajit then 100 | + print('luajit+ffifb failure : pcall error test') 101 | + else 102 | local suc, err = pcall(c.call_s, function(s) error(ffi.string(s), 0) end, 'my error') 103 | check(suc, false) 104 | check(err, 'my error') 105 | + end 106 | 107 | check(ffi.errno(), c.get_errno()) 108 | c.set_errno(3) 109 | @@ -628,7 +653,7 @@ for convention,c in pairs(dlls) do 110 | first = false 111 | end 112 | 113 | -local c = ffi.C 114 | +local c = ffi.os=='Windows' and ffi.load('msvcrt') or ffi.C 115 | 116 | assert(c.sprintf(buf, "%g", 5.3) == 3 and ffi.string(buf) == '5.3') 117 | assert(c.sprintf(buf, "%d", false) == 1 and ffi.string(buf) == '0') 118 | @@ -927,31 +952,40 @@ void test_call_pppppiifiii(void* p1, void* p2, void* p3, void* p4, void* p5, int 119 | void test_call_pppppiiifii(void* p1, void* p2, void* p3, void* p4, void* p5, int i1, int i2, int i3, float i4, int i5, int i6); 120 | ]] 121 | 122 | -ffi.C.test_call_echo("input") 123 | -assert(ffi.C.buf == "input") 124 | +local ffiC = ffi.os=='Windows' and dlls.__cdecl or ffi.C 125 | +ffiC.test_call_echo("input") 126 | +assert(ffiC.buf == "input") 127 | 128 | local function ptr(x) return ffi.new('void*', x) end 129 | +local prefix = "" 130 | +for i=1,5 do prefix = prefix .. unifyaddr('void*', tostring(i)) .. " " end 131 | 132 | -ffi.C.test_call_pppppii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7) 133 | -assert(ffi.C.buf == "0x1 0x2 0x3 0x4 0x5 6 7") 134 | +ffiC.test_call_pppppii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7) 135 | +assert(ffiC.buf == prefix .. "6 7") 136 | 137 | -ffi.C.test_call_pppppiiiiii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7, 8, 9, 10, 11) 138 | -assert(ffi.C.buf == "0x1 0x2 0x3 0x4 0x5 6 7 8 9 10 11") 139 | +ffiC.test_call_pppppiiiiii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7, 8, 9, 10, 11) 140 | +assert(ffiC.buf == prefix .. "6 7 8 9 10 11") 141 | 142 | -ffi.C.test_call_pppppffffff(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6.5, 7.5, 8.5, 9.5, 10.5, 11.5) 143 | -assert(ffi.C.buf == "0x1 0x2 0x3 0x4 0x5 6.5 7.5 8.5 9.5 10.5 11.5") 144 | +if is_luajit then 145 | + print("luajit+ffifb failure : function call with float parameters test") 146 | +else 147 | +ffiC.test_call_pppppffffff(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6.5, 7.5, 8.5, 9.5, 10.5, 11.5) 148 | +assert(ffiC.buf == prefix .. "6.5 7.5 8.5 9.5 10.5 11.5") 149 | 150 | -ffi.C.test_call_pppppiifiii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7, 8.5, 9, 10, 11) 151 | -assert(ffi.C.buf == "0x1 0x2 0x3 0x4 0x5 6 7 8.5 9 10 11") 152 | +ffiC.test_call_pppppiifiii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7, 8.5, 9, 10, 11) 153 | +assert(ffiC.buf == prefix .. "6 7 8.5 9 10 11") 154 | 155 | -ffi.C.test_call_pppppiiifii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7, 8, 9.5, 10, 11) 156 | -assert(ffi.C.buf == "0x1 0x2 0x3 0x4 0x5 6 7 8 9.5 10 11") 157 | +ffiC.test_call_pppppiiifii(ptr(1), ptr(2), ptr(3), ptr(4), ptr(5), 6, 7, 8, 9.5, 10, 11) 158 | +assert(ffiC.buf == prefix .. "6 7 8 9.5 10 11") 159 | +end 160 | 161 | -local sum = ffi.C.add_dc(ffi.new('complex', 1, 2), ffi.new('complex', 3, 5)) 162 | +if not ffiC.is_msvc then 163 | +local sum = ffiC.add_dc(ffi.new('complex', 1, 2), ffi.new('complex', 3, 5)) 164 | assert(ffi.istype('complex', sum)) 165 | 166 | -sum = ffi.C.add_fc(ffi.new('complex float', 1, 2), ffi.new('complex float', 3, 5)) 167 | +sum = ffiC.add_fc(ffi.new('complex float', 1, 2), ffi.new('complex float', 3, 5)) 168 | assert(ffi.istype('complex float', sum)) 169 | +end 170 | 171 | ffi.cdef [[ 172 | struct Arrays { 173 | @@ -988,6 +1022,9 @@ assert(ffi.string(buf, 0) == '') 174 | assert(ffi.string(buf, ffi.new('long long', 2)) == 'aa') 175 | assert(ffi.string(buf, ffi.new('int', 2)) == 'aa') 176 | 177 | +if is_luajit then 178 | + print("luajit+ffifb failure : tmpfile test") 179 | +else 180 | -- Test io.tmpfile() 181 | ffi.cdef [[ 182 | int fprintf ( FILE * stream, const char * format, ... ); 183 | @@ -999,5 +1036,6 @@ f:seek("set", 0) 184 | local str = f:read('*l') 185 | assert(str == 'test: foo', str) 186 | f:close() 187 | +end 188 | 189 | print('Test PASSED') 190 | -------------------------------------------------------------------------------- /win-files/patch/torch.patch: -------------------------------------------------------------------------------- 1 | diff --git a/rocks/torch-scm-1.rockspec b/rocks/torch-scm-1.rockspec 2 | index 2228726..451f1aa 100644 3 | --- a/rocks/torch-scm-1.rockspec 4 | +++ b/rocks/torch-scm-1.rockspec 5 | @@ -27,7 +27,7 @@ cmake -E make_directory build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release 6 | platforms = { 7 | windows = { 8 | build_command = [[ 9 | -cmake -E make_directory build && cd build && cmake .. -DCMAKE_BUILD_TYPE=Release -DLUA=$(LUA) -DLUALIB=$(LUALIB) -DLUA_BINDIR="$(LUA_BINDIR)" -DLUA_INCDIR="$(LUA_INCDIR)" -DLUA_LIBDIR="$(LUA_LIBDIR)" -DLUADIR="$(LUADIR)" -DLIBDIR="$(LIBDIR)" -DCMAKE_INSTALL_PREFIX="$(PREFIX)" && $(MAKE) 10 | +cmake -E make_directory build && cd build && cmake .. -DINTEL_MKL_DIR="$(INTEL_MKL_DIR)" -DINTEL_COMPILER_DIR="$(INTEL_COMPILER_DIR)" -DBLAS_LIBRARIES="$(BLAS_LIBRARIES)" -DLAPACK_LIBRARIES="$(LAPACK_LIBRARIES)" -DLAPACK_FOUND=$(LAPACK_FOUND) -DCMAKE_BUILD_TYPE=Release -DLUA=$(LUA) -DLUALIB=$(LUALIB) -DLUA_BINDIR="$(LUA_BINDIR)" -DLUA_INCDIR="$(LUA_INCDIR)" -DLUA_LIBDIR="$(LUA_LIBDIR)" -DLUADIR="$(LUADIR)" -DLIBDIR="$(LIBDIR)" -DCMAKE_INSTALL_PREFIX="$(PREFIX)" && $(MAKE) 11 | ]] 12 | } 13 | }, 14 | -------------------------------------------------------------------------------- /win-files/test/ffifb_perf_ffi.lua: -------------------------------------------------------------------------------- 1 | -- code from http://luajit.org/ext_ffi.html 2 | 3 | require 'torch' 4 | 5 | local t = torch.Timer() 6 | t:reset() 7 | 8 | local ffi = require("ffi") 9 | ffi.cdef[[ 10 | typedef struct { uint8_t red, green, blue, alpha; } rgba_pixel; 11 | ]] 12 | 13 | local function image_ramp_green(n) 14 | local img = ffi.new("rgba_pixel[?]", n) 15 | local f = 255/(n-1) 16 | for i=0,n-1 do 17 | img[i].green = i*f 18 | img[i].alpha = 255 19 | end 20 | return img 21 | end 22 | 23 | local function image_to_grey(img, n) 24 | for i=0,n-1 do 25 | local y = 0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue 26 | img[i].red = y; img[i].green = y; img[i].blue = y 27 | end 28 | end 29 | 30 | local N = 400*400 31 | local img = image_ramp_green(N) 32 | for i=1,1000 do 33 | image_to_grey(img, N) 34 | end 35 | 36 | t:stop() 37 | print(t:time().real) 38 | -------------------------------------------------------------------------------- /win-files/test/ffifb_perf_purelua.lua: -------------------------------------------------------------------------------- 1 | -- code from http://luajit.org/ext_ffi.html 2 | 3 | require 'torch' 4 | 5 | local t = torch.Timer() 6 | t:reset() 7 | 8 | local floor = math.floor 9 | 10 | local function image_ramp_green(n) 11 | local img = {} 12 | local f = 255/(n-1) 13 | for i=1,n do 14 | img[i] = { red = 0, green = floor((i-1)*f), blue = 0, alpha = 255 } 15 | end 16 | return img 17 | end 18 | 19 | local function image_to_grey(img, n) 20 | for i=1,n do 21 | local y = floor(0.3*img[i].red + 0.59*img[i].green + 0.11*img[i].blue) 22 | img[i].red = y; img[i].green = y; img[i].blue = y 23 | end 24 | end 25 | 26 | local N = 400*400 27 | local img = image_ramp_green(N) 28 | for i=1,1000 do 29 | image_to_grey(img, N) 30 | end 31 | 32 | t:stop() 33 | print(t:time().real) 34 | --------------------------------------------------------------------------------