Repository: pytorch
Issue: GPU version of minimal example for libtorch fails with "no kernel image is available..."
Labels: module: cuda,triaged

## 🐛 Bug

The following GPU version of the minimal example for `libtorch` crashes on `torch::relu` with the error "CUDA error: no kernel image is available for execution on the device".

	#include <torch/torch.h>
	#include <iostream>

	int main() {
	  torch::Device device(torch::kCUDA);
	  torch::Tensor tensor = torch::rand({2, 3}).to(device);
	  tensor = torch::relu(tensor);
	  std::cout << tensor << std::endl;
	}

## To Reproduce
Contents of `CMakeLists.txt`:

	cmake_minimum_required(VERSION 3.0 FATAL_ERROR)
	project(example-app)

	find_package(Torch REQUIRED)
	set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${TORCH_CXX_FLAGS}")

	add_executable(example-app example-app.cpp)
	target_link_libraries(example-app "${TORCH_LIBRARIES}")
	set_property(TARGET example-app PROPERTY CXX_STANDARD 14)

Steps to reproduce:

	mkdir build
	cd build
	cmake -DCMAKE_PREFIX_PATH=/absolute/path/to/libtorch ..
	make
	./example-app

Error message:

	terminate called after throwing an instance of 'c10::Error'
	  what():  CUDA error: no kernel image is available for execution on the device (launch_kernel at /pytorch/aten/src/ATen/native/cuda/Loops.cuh:102)
	frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0x6a (0x7fa2edaacc4a in /home/dbergh/sdk/libtorch/lib/libc10.so)
	frame #1: void at::native::gpu_kernel_impl<__nv_hdl_wrapper_t<false, false, __nv_dl_tag<void (*)(at::TensorIterator&, float, float), &(void at::native::threshold_kernel_impl<float>(at::TensorIterator&, float, float)), 1u>, float (float, float), float, float> >(at::TensorIterator&, __nv_hdl_wrapper_t<false, false, __nv_dl_tag<void (*)(at::TensorIterator&, float, float), &(void at::native::threshold_kernel_impl<float>(at::TensorIterator&, float, float)), 1u>, float (float, float), float, float> const&) + 0xca6 (0x7fa2f0604d56 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #2: void at::native::gpu_kernel<__nv_hdl_wrapper_t<false, false, __nv_dl_tag<void (*)(at::TensorIterator&, float, float), &(void at::native::threshold_kernel_impl<float>(at::TensorIterator&, float, float)), 1u>, float (float, float), float, float> >(at::TensorIterator&, __nv_hdl_wrapper_t<false, false, __nv_dl_tag<void (*)(at::TensorIterator&, float, float), &(void at::native::threshold_kernel_impl<float>(at::TensorIterator&, float, float)), 1u>, float (float, float), float, float> const&) + 0x17b (0x7fa2f0605b2b in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #3: void at::native::gpu_kernel_with_scalars<__nv_hdl_wrapper_t<false, false, __nv_dl_tag<void (*)(at::TensorIterator&, float, float), &(void at::native::threshold_kernel_impl<float>(at::TensorIterator&, float, float)), 1u>, float (float, float), float, float> >(at::TensorIterator&, __nv_hdl_wrapper_t<false, false, __nv_dl_tag<void (*)(at::TensorIterator&, float, float), &(void at::native::threshold_kernel_impl<float>(at::TensorIterator&, float, float)), 1u>, float (float, float), float, float> const&) + 0x51b (0x7fa2f061b65b in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #4: <unknown function> + 0x28f8fde (0x7fa2f05bffde in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #5: <unknown function> + 0x28f9d54 (0x7fa2f05c0d54 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #6: <unknown function> + 0x3add796 (0x7fa2f17a4796 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #7: <unknown function> + 0x3ad1aa8 (0x7fa2f1798aa8 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #8: at::native::threshold(at::Tensor const&, c10::Scalar, c10::Scalar) + 0x49 (0x7fa2f1798e49 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #9: <unknown function> + 0x414ab21 (0x7fa2f1e11b21 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #10: <unknown function> + 0x4013979 (0x7fa2f1cda979 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #11: at::native::relu(at::Tensor const&) + 0x2b0 (0x7fa2f179ab50 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #12: <unknown function> + 0x642fe45 (0x7fa2f40f6e45 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #13: <unknown function> + 0x4012601 (0x7fa2f1cd9601 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #14: <unknown function> + 0x2a063a6 (0x7fa2f06cd3a6 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #15: <unknown function> + 0x5afd3c2 (0x7fa2f37c43c2 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #16: <unknown function> + 0x4012601 (0x7fa2f1cd9601 in /home/dbergh/sdk/libtorch/lib/libtorch.so)
	frame #17: at::Tensor c10::KernelFunction::callUnboxed<at::Tensor, at::Tensor const&>(at::Tensor const&) const + 0x97 (0x55cc0be33c6f in ./example-app)
	frame #18: c10::impl::OperatorEntry::callUnboxed<at::Tensor, at::Tensor const&>(c10::TensorTypeId, at::Tensor const&) const::{lambda(c10::DispatchTable const&)#1}::operator()(c10::DispatchTable const&) const + 0x61 (0x55cc0be32479 in ./example-app)
	frame #19: std::result_of<c10::impl::OperatorEntry::callUnboxed<at::Tensor, at::Tensor const&>(c10::TensorTypeId, at::Tensor const&) const::{lambda(c10::DispatchTable const&)#1} (c10::DispatchTable const&)>::type c10::LeftRight<c10::DispatchTable>::read<c10::impl::OperatorEntry::callUnboxed<at::Tensor, at::Tensor const&>(c10::TensorTypeId, at::Tensor const&) const::{lambda(c10::DispatchTable const&)#1}>(c10::impl::OperatorEntry::callUnboxed<at::Tensor, at::Tensor const&>(c10::TensorTypeId, at::Tensor const&) const::{lambda(c10::DispatchTable const&)#1}&&) const + 0x125 (0x55cc0be33f29 in ./example-app)
	frame #20: at::Tensor c10::impl::OperatorEntry::callUnboxed<at::Tensor, at::Tensor const&>(c10::TensorTypeId, at::Tensor const&) const + 0x53 (0x55cc0be324eb in ./example-app)
	frame #21: at::Tensor c10::Dispatcher::callUnboxed<at::Tensor, at::Tensor const&>(c10::OperatorHandle const&, c10::TensorTypeId, at::Tensor const&) const + 0x6e (0x55cc0be2fcd2 in ./example-app)
	frame #22: <unknown function> + 0x1e22e (0x55cc0be2822e in ./example-app)
	frame #23: main + 0xc9 (0x55cc0be28398 in ./example-app)
	frame #24: __libc_start_main + 0xe7 (0x7fa2ecc84b97 in /lib/x86_64-linux-gnu/libc.so.6)
	frame #25: _start + 0x2a (0x55cc0be26eda in ./example-app)

	Aborted (core dumped)

## Expected behavior
Obvious

## Environment

 - PyTorch Version: 1.3.1
 - OS (e.g., Linux): Linux (Ubuntu 18.04)
 - How you installed PyTorch: https://download.pytorch.org/libtorch/cu101/libtorch-cxx11-abi-shared-with-deps-1.3.1.zip
 - CUDA/cuDNN version: 10.1.243/7.6.5.32-1
 - GPU models and configuration: GeForce GTX 780 (arch 3.5)
 
## Additional context

Output from `nvidia-smi`

	+-----------------------------------------------------------------------------+
	| NVIDIA-SMI 440.33.01    Driver Version: 440.33.01    CUDA Version: 10.2     |
	|-------------------------------+----------------------+----------------------+
	| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
	| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
	|===============================+======================+======================|
	|   0  GeForce GTX 780     On   | 00000000:01:00.0 N/A |                  N/A |
	| 37%   41C    P0    N/A /  N/A |    488MiB /  3016MiB |     N/A      Default |
	+-------------------------------+----------------------+----------------------+
		                                                                       
	+-----------------------------------------------------------------------------+
	| Processes:                                                       GPU Memory |
	|  GPU       PID   Type   Process name                             Usage      |
	|=============================================================================|
	|    0                    Not Supported                                       |
	+-----------------------------------------------------------------------------+

Output from cmake

	cmake -DCMAKE_PREFIX_PATH=/home/dbergh/sdk/libtorch ..
	-- The C compiler identification is GNU 7.4.0
	-- The CXX compiler identification is GNU 7.4.0
	-- Check for working C compiler: /usr/bin/cc
	-- Check for working C compiler: /usr/bin/cc -- works
	-- Detecting C compiler ABI info
	-- Detecting C compiler ABI info - done
	-- Detecting C compile features
	-- Detecting C compile features - done
	-- Check for working CXX compiler: /usr/bin/c++
	-- Check for working CXX compiler: /usr/bin/c++ -- works
	-- Detecting CXX compiler ABI info
	-- Detecting CXX compiler ABI info - done
	-- Detecting CXX compile features
	-- Detecting CXX compile features - done
	-- Looking for pthread.h
	-- Looking for pthread.h - found
	-- Looking for pthread_create
	-- Looking for pthread_create - not found
	-- Looking for pthread_create in pthreads
	-- Looking for pthread_create in pthreads - not found
	-- Looking for pthread_create in pthread
	-- Looking for pthread_create in pthread - found
	-- Found Threads: TRUE  
	-- Found CUDA: /usr/local/cuda (found version "10.1") 
	-- Caffe2: CUDA detected: 10.1
	-- Caffe2: CUDA nvcc is: /usr/local/cuda/bin/nvcc
	-- Caffe2: CUDA toolkit directory: /usr/local/cuda
	-- Caffe2: Header version is: 10.1
	-- Found CUDNN: /usr/lib/x86_64-linux-gnu/libcudnn.so  
	-- Found cuDNN: v7.6.5  (include: /usr/include, library: /usr/lib/x86_64-linux-gnu/libcudnn.so)
	-- Autodetected CUDA architecture(s):  3.5
	-- Added CUDA NVCC flags for: -gencode;arch=compute_35,code=sm_35
	-- Found torch: /home/dbergh/sdk/libtorch/lib/libtorch.so  
	-- Configuring done
	-- Generating done
	-- Build files have been written to: /home/dbergh/test/build


cc @ngimel