Repository: pytorch
Issue: I can't set gpu is 1 it always use gpu 0
Labels: needs reproduction,module: cpp,module: cuda,low priority,triaged

  here is my code
  torch::Device deviceInfo(torch::kCUDA, 1);
  module->to(deviceInfo);

  but i got this error
terminate called after throwing an instance of 'c10::Error'
  what():  CUDA out of memory. Tried to allocate 240.00 MiB (GPU 0; 10.92 GiB total capacity; 74.36 MiB already allocated; 147.50 MiB free; 11.64 MiB cached) (malloc at ../c10/cuda/CUDACachingAllocator.cpp:267)
frame #0: c10::Error::Error(c10::SourceLocation, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) + 0x6a (0x7ff1cbc4201a in /home/training/pytorch/torch/lib/libc10.so)
frame #1: <unknown function> + 0x2009c (0x7ff1c32fd09c in /home/training/pytorch/torch/lib/libc10_cuda.so)
frame #2: <unknown function> + 0x20db3 (0x7ff1c32fddb3 in /home/training/pytorch/torch/lib/libc10_cuda.so)
frame #3: at::native::empty_cuda(c10::ArrayRef<long>, c10::TensorOptions const&, c10::optional<c10::MemoryFormat>) + 0x282 (0x7ff1ce9fe2b2 in /home/training/pytorch/torch/lib/libtorch.so)
frame #4: <unknown function> + 0x584a765 (0x7ff1d16a0765 in /home/training/pytorch/torch/lib/libtorch.so)
frame #5: at::native::to(at::Tensor const&, c10::Device, c10::ScalarType, bool, bool) + 0x8b9 (0x7ff1cf382889 in /home/training/pytorch/torch/lib/libtorch.so)
frame #6: at::TypeDefault::to(at::Tensor const&, c10::Device, c10::ScalarType, bool, bool) + 0x25 (0x7ff1cf6c7535 in /home/training/pytorch/torch/lib/libtorch.so)
frame #7: <unknown function> + 0x54aca6e (0x7ff1d1302a6e in /home/training/pytorch/torch/lib/libtorch.so)
frame #8: torch::jit::load(std::unique_ptr<caffe2::serialize::ReadAdapterInterface, std::default_delete<caffe2::serialize::ReadAdapterInterface> >, c10::optional<c10::Device>, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&) + 0x222 (0x7ff1d1304052 in /home/training/pytorch/torch/lib/libtorch.so)
frame #9: torch::jit::load(std::istream&, c10::optional<c10::Device>, std::unordered_map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > >, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > > >&) + 0x75 (0x7ff1d13041f5 in /home/training/pytorch/torch/lib/libtorch.so)
frame #10: TorchNet::loadModelEncode(char const*, unsigned char*) + 0x169 (0x40cbe9 in ./vehicleFeature)
frame #11: TorchNet::LoadModel(PES_Params_Config) + 0x5e (0x40cdfe in ./vehicleFeature)
frame #12: TorchOperation::LoadModel(PES_Params_Config) + 0x48 (0x418e98 in ./vehicleFeature)
frame #13: VehicleFeature::VehicleFeature(char const*, int) + 0xc2 (0x4192d2 in ./vehicleFeature)
frame #14: test() + 0x217 (0x41a217 in ./vehicleFeature)
frame #15: main + 0x9 (0x4098c9 in ./vehicleFeature)
frame #16: __libc_start_main + 0xf0 (0x7ff1ca45c830 in /lib/x86_64-linux-gnu/libc.so.6)
frame #17: _start + 0x29 (0x409929 in ./vehicleFeature)

Aborted (core dumped)





cc @yf225