<h2 dir="auto"><g-emoji class="g-emoji" alias="question" fallback-src="https://github.githubassets.com/images/icons/emoji/unicode/2753.png">❓</g-emoji> Questions and Help</h2>
<p dir="auto">I have successfully built LibTorch for C++ API under Windows with CUDA 10.1.</p>
<p dir="auto">Although CUDA seems to be enabled and configured correctly in CMake, and <code class="notranslate">torch_cuda.lib</code> is correctly inserted into the linker directives of <code class="notranslate">torch.lib</code>, I still get a message saying it is not linked with CUDA support in my test app.</p>
<div class="highlight highlight-source-c++ notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="try {    
    std::cout &lt;&lt; torch::cuda::is_available() &lt;&lt; std::endl;
    torch::Tensor tensor = at::tensor({ -1, 1 }, at::kCUDA);
}
catch (exception&amp; ex) {
    std::cout &lt;&lt; ex.what() &lt;&lt; std::endl;
}"><pre class="notranslate"><span class="pl-k">try</span> {    
    std::cout &lt;&lt; <span class="pl-c1">torch::cuda::is_available</span>() &lt;&lt; std::endl;
    torch::Tensor tensor = <span class="pl-c1">at::tensor</span>({ -<span class="pl-c1">1</span>, <span class="pl-c1">1</span> }, at::<span class="pl-c1">kCUDA</span>);
}
<span class="pl-k">catch</span> (<span class="pl-c1">exception</span>&amp; ex) {
    std::cout &lt;&lt; ex.<span class="pl-c1">what</span>() &lt;&lt; std::endl;
}</pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="TestApp.exe
0
PyTorch is not linked with support for cuda devices (getDeviceGuardImpl at E:\develop\torch\torch\c10/core/impl/DeviceGuardImplInterface.h:216)"><pre class="notranslate"><code class="notranslate">TestApp.exe
0
PyTorch is not linked with support for cuda devices (getDeviceGuardImpl at E:\develop\torch\torch\c10/core/impl/DeviceGuardImplInterface.h:216)
</code></pre></div>
<p dir="auto"><code class="notranslate">torch</code> config in VS2019:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/19194484/74712816-3b2f1480-51f5-11ea-8b8d-d80fc472dc2d.png"><img src="https://user-images.githubusercontent.com/19194484/74712816-3b2f1480-51f5-11ea-8b8d-d80fc472dc2d.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">CMAKE config output :</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="******** 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$&lt;$&lt;CONFIG:Debug&gt;:d&gt;;--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"><pre class="notranslate"><code class="notranslate">******** 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$&lt;$&lt;CONFIG:Debug&gt;:d&gt;;--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
</code></pre></div>
<p dir="auto">CUDA info:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="deviceQuery.exe Starting...

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

Detected 1 CUDA Capable device(s)

Device 0: &quot;GeForce GTX 1080&quot;
  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:
     &lt; Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) &gt;

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.2, CUDA Runtime Version = 10.1, NumDevs = 1
Result = PASS"><pre class="notranslate"><code class="notranslate">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:
     &lt; Default (multiple host threads can use ::cudaSetDevice() with device simultaneously) &gt;

deviceQuery, CUDA Driver = CUDART, CUDA Driver Version = 10.2, CUDA Runtime Version = 10.1, NumDevs = 1
Result = PASS
</code></pre></div>
<p dir="auto">cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/peterjc123/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/peterjc123">@peterjc123</a></p>
<p dir="auto">I compile the source libtorch [master] with  windows10, vs2017, python3.8, cuda 10.1.<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/19385144/74637752-91746700-51a5-11ea-97e0-c7cf4700e84c.png"><img src="https://user-images.githubusercontent.com/19385144/74637752-91746700-51a5-11ea-97e0-c7cf4700e84c.png" alt="image" style="max-width: 100%;"></a><br>
It can run sucessfully.<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/19385144/74637663-5c681480-51a5-11ea-840e-ccc19fa696f5.png"><img src="https://user-images.githubusercontent.com/19385144/74637663-5c681480-51a5-11ea-840e-ccc19fa696f5.png" alt="11" style="max-width: 100%;"></a><br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/19385144/74637672-61c55f00-51a5-11ea-80ae-b24f49e78923.png"><img src="https://user-images.githubusercontent.com/19385144/74637672-61c55f00-51a5-11ea-80ae-b24f49e78923.png" alt="12" style="max-width: 100%;"></a></p>
<p dir="auto">However, when I link the library<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/19385144/74637703-7275d500-51a5-11ea-98c8-624a1ac62ace.png"><img src="https://user-images.githubusercontent.com/19385144/74637703-7275d500-51a5-11ea-98c8-624a1ac62ace.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">The compiler tells me the error<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/19385144/74637843-c2ed3280-51a5-11ea-844d-1456e55df84f.png"><img src="https://user-images.githubusercontent.com/19385144/74637843-c2ed3280-51a5-11ea-844d-1456e55df84f.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">If I add the CPU version<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/19385144/74637908-e2845b00-51a5-11ea-9fa1-39fd73d1bbc0.png"><img src="https://user-images.githubusercontent.com/19385144/74637908-e2845b00-51a5-11ea-9fa1-39fd73d1bbc0.png" alt="image" style="max-width: 100%;"></a><br>
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<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/19385144/74638262-8b32ba80-51a6-11ea-8d84-75f14b362839.png"><img src="https://user-images.githubusercontent.com/19385144/74638262-8b32ba80-51a6-11ea-8d84-75f14b362839.png" alt="13" style="max-width: 100%;"></a></p>
<p dir="auto">Has libtorch been decomposed into a cpu version and cuda version? I think it is a critial bug for the decomposition.<br>
One more thing, the prebuilt version in <a href="https://pytorch.org/" rel="nofollow">https://pytorch.org/</a> is okay.</p>