How to build Torch with CUDA10

Building Torch with CUDA10 has two problems.

cmake/3.6/Modules/FindCUDA.cmake is outdated.
atomicAdd(__half address, __half val) is defined in /usr/local/cuda/include/cuda_fp16.h (duplicated).
How to build Torch with CUDA10
Install the latest CMake from github repo (the latest FindCUDA.cmake will be installed)
$ sudo apt-get purge cmake
$ git clone https://github.com/Kitware/CMake.git
$ cd CMake
$ ./bootstrap; make; sudo make install
Remove FindCUDA.cmake.
$ cd ~/torch
$ rm -fr cmake/3.6/Modules/FindCUDA

Apply the following patch to cutorch
diff --git a/lib/THC/THCAtomics.cuh b/lib/THC/THCAtomics.cuh
index 400875c…ccb7a1c 100644
— a/lib/THC/THCAtomics.cuh
+++ b/lib/THC/THCAtomics.cuh
@@ -94,6 +94,7 @@ static inline device void atomicAdd(long *address, long val) {
}

#ifdef CUDA_HALF_TENSOR
+#if !(CUDA_ARCH >= 700 || !defined(CUDA_ARCH) )
static inline device void atomicAdd(half *address, half val) {
unsigned int * address_as_ui =
(unsigned int *) ((char *)address - ((size_t)address & 2));
@@ -117,6 +118,7 @@ static inline device void atomicAdd(half *address, half val) {
} while (assumed != old);
}
#endif
+#endif
$ cd extra/cutorch
$ cat > atomic.patch

$ patch -p1 < atomic.patch
Build
$ ./clean.sh
$ export TORCH_NVCC_FLAGS="-D__CUDA_NO_HALF_OPERATORS__"
$ ./install.sh
I was successfully build Torch with CUDA10 with the above steps.

猜你喜欢

转载自blog.csdn.net/seamanj/article/details/89061880
今日推荐