Issue 1:
❓ Questions and Help

I have successfully built LibTorch for C++ API under Windows with CUDA 10.1.

Although CUDA seems to be enabled and configured correctly in CMake, and torch_cuda.lib is correctly inserted into the linker directives of torch.lib, I still get a message saying it is not linked with CUDA support in my test app.

try {
std::cout << torch::cuda::is_available() << std::endl;
torch::Tensor tensor = at::tensor({ -1, 1 }, at::kCUDA);
}
catch (exception& ex) {
std::cout << ex.what() << std::endl;
}

TestApp.exe
0
PyTorch is not linked with support for cuda devices (getDeviceGuardImpl at E:\develop\torch\torch\c10/core/impl/DeviceGuardImplInterface.h:216)

torch config in VS2019:

CMAKE config output :

******** Summary ********
General:
CMake version : 3.16.4
CMake command : C:/Program Files/CMake/bin/cmake.exe
System : Windows
C++ compiler : C:/Program Files (x86)/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/14.24.28314/bin/Hostx64/x64/cl.exe
C++ compiler id : MSVC
C++ compiler version : 19.24.28316.0
BLAS : MKL
CXX flags : /DWIN32 /D_WINDOWS /GR /w /EHa /MP /bigobj -openmp:experimental
Build type : Debug
Compile definitions : ONNX_ML=1;ONNX_NAMESPACE=onnx_torch;_CRT_SECURE_NO_DEPRECATE=1;WIN32_LEAN_AND_MEAN;MINIZ_DISABLE_ZIP_READER_CRC32_CHECKS
CMAKE_PREFIX_PATH : E:/develop/cudnn/v10.1;E:/develop/cuda/v10.1
CMAKE_INSTALL_PREFIX : E:/develop/torch/torch-1.5.0a-source-cuda-10.1/install/debug

TORCH_VERSION : 1.1.0
CAFFE2_VERSION : 1.1.0
BUILD_CAFFE2_MOBILE : ON
USE_STATIC_DISPATCH : OFF
BUILD_BINARY : OFF
BUILD_CUSTOM_PROTOBUF : ON
Link local protobuf : ON
BUILD_DOCS : OFF
BUILD_PYTHON : OFF
BUILD_CAFFE2_OPS : ON
BUILD_SHARED_LIBS : ON
BUILD_TEST : OFF
BUILD_JNI : OFF
INTERN_BUILD_MOBILE :
USE_ASAN : OFF
USE_CUDA : ON
CUDA static link : OFF
USE_CUDNN : ON
CUDA version : 10.1
cuDNN version : 7.6.4
CUDA root directory : E:/develop/cuda/v10.1
CUDA library : E:/develop/cuda/v10.1/lib/x64/cuda.lib
cudart library : E:/develop/cuda/v10.1/lib/x64/cudart_static.lib
cublas library : E:/develop/cuda/v10.1/lib/x64/cublas.lib
cufft library : E:/develop/cuda/v10.1/lib/x64/cufft.lib
curand library : E:/develop/cuda/v10.1/lib/x64/curand.lib
cuDNN library : E:/develop/cudnn/v10.1/lib/x64/cudnn.lib
nvrtc : E:/develop/cuda/v10.1/lib/x64/nvrtc.lib
CUDA include path : E:/develop/cuda/v10.1/include
NVCC executable : E:/develop/cuda/v10.1/bin/nvcc.exe
NVCC flags : -Xcompiler /w -w;-DONNX_NAMESPACE=onnx_torch;-gencode;arch=compute_61,code=sm_61;-Xcudafe;--diag_suppress=cc_clobber_ignored;-Xcudafe;--diag_suppress=integer_sign_change;-Xcudafe;--diag_suppress=useless_using_declaration;-Xcudafe;--diag_suppress=set_but_not_used;-Xcompiler;-MD$<$<CONFIG:Debug>:d>;--expt-relaxed-constexpr;--expt-extended-lambda;-Xcompiler /wd4819 -Xcompiler /wd4503 -Xcompiler /wd4190 -Xcompiler /wd4244 -Xcompiler /wd4251 -Xcompiler /wd4275 -Xcompiler /wd4522;-Wno-deprecated-gpu-targets;--expt-extended-lambda;-gencode;arch=compute_61,code=sm_61;-DCUDA_HAS_FP16=1 -D__CUDA_NO_HALF_OPERATORS__ -D__CUDA_NO_HALF_CONVERSIONS__ -D__CUDA_NO_HALF2_OPERATORS__
CUDA host compiler : $(VCInstallDir)Tools/MSVC/$(VCToolsVersion)/bin/Host$(Platform)/$(PlatformTarget)
USE_TENSORRT : OFF
USE_ROCM : OFF
USE_EIGEN_FOR_BLAS : ON
USE_FBGEMM : OFF
USE_FFMPEG : OFF
USE_GFLAGS : OFF
USE_GLOG : OFF
USE_LEVELDB : OFF
USE_LITE_PROTO : OFF
USE_LMDB : OFF
USE_METAL : OFF
USE_MKL : OFF
USE_MKLDNN : ON
USE_MKLDNN_CBLAS : OFF
USE_NCCL : OFF
USE_NNPACK : OFF
USE_NUMPY : OFF
USE_OBSERVERS : ON
USE_OPENCL : OFF
USE_OPENCV : OFF
USE_OPENMP : ON
USE_TBB : OFF
USE_PROF : OFF
USE_QNNPACK : OFF
USE_REDIS : OFF
USE_ROCKSDB : OFF
USE_ZMQ : OFF
USE_DISTRIBUTED : OFF
Public Dependencies : Threads::Threads;caffe2::mkldnn
Private Dependencies : cpuinfo;fp16;aten_op_header_gen;foxi_loader

CUDA info:

deviceQuery.exe Starting...

CUDA Device Query (Runtime API) version (CUDART static linking)

Detected 1 CUDA Capable device(s)

Device 0: "GeForce GTX 1080"
CUDA Driver Version / Runtime Version 10.2 / 10.1
CUDA Capability Major/Minor version number: 6.1
Total amount of global memory: 8192 MBytes (8589934592 bytes)
(20) Multiprocessors, (128) CUDA Cores/MP: 2560 CUDA Cores
GPU Max Clock rate: 1734 MHz (1.73 GHz)
Memory Clock rate: 5005 Mhz
Memory Bus Width: 256-bit
L2 Cache Size: 2097152 bytes
Maximum Texture Dimension Size (x,y,z) 1D=(131072), 2D=(131072, 65536), 3D=(16384, 16384, 16384)
Maximum Layered 1D Texture Size, (num) layers 1D=(32768), 2048 layers
Maximum Layered 2D Texture Size, (num) layers 2D=(32768, 32768), 2048 layers
Total amount of constant memory: 65536 bytes
Total amount of shared memory per block: 49152 bytes
Total number of registers available per block: 65536
Warp size: 32
Maximum number of threads per multiprocessor: 2048
Maximum number of threads per block: 1024
Max dimension size of a thread block (x,y,z): (1024, 1024, 64)
Max dimension size of a grid size (x,y,z): (2147483647, 65535, 65535)
Maximum memory pitch: 2147483647 bytes
Texture alignment: 512 bytes
Concurrent copy and kernel execution: Yes with 2 copy engine(s)
Run time limit on kernels: Yes
Integrated GPU sharing Host Memory: No
Support host page-locked memory mapping: Yes
Alignment requirement for Surfaces: Yes
Device has ECC support: Disabled
CUDA Device Driver Mode (TCC or WDDM): WDDM (Windows Display Driver Model)
Device supports Unified Addressing (UVA): Yes
Device supports Compute Preemption: Yes
Supports Cooperative Kernel Launch: No
Supports MultiDevice Co-op Kernel Launch: No
Device PCI Domain ID / Bus ID / location ID: 0 / 1 / 0
Compute Mode:
< Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) >

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.2, CUDA Runtime Version = 10.1, NumDevs = 1
Result = PASS

cc @peterjc123

Issue 2:
I compile the source libtorch [master] with windows10, vs2017, python3.8, cuda 10.1.

It can run sucessfully.

However, when I link the library

The compiler tells me the error

If I add the CPU version

The comipler does not have wrong information. But I still can not use the cuda version, since libtorch can not excute with the CUDA support

Has libtorch been decomposed into a cpu version and cuda version? I think it is a critial bug for the decomposition.

One more thing, the prebuilt version in https://pytorch.org/ is okay.