// that can be temporarily created with Caffe2 APIs. See the note on top of
// TensorImpl.h for details.
static Storage create_legacy(at::Device device, caffe2::TypeMeta data_type) {
+ auto allocator = GetAllocator(device.type());
return Storage(c10::make_intrusive<StorageImpl>(
data_type,
0,
- at::DataPtr(nullptr, device),
- GetAllocator(device.type()),
+ allocator->allocate(0), // materialize a non-default Device.
+ allocator,
true));
}
}
switch (g_cuda_memory_pool_type) {
case CudaMemoryPoolType::NONE:
- CUDA_ENFORCE(cudaMalloc(&ptr, nbytes));
+ if (nbytes != 0) {
+ CUDA_ENFORCE(cudaMalloc(&ptr, nbytes));
+ }
if (FLAGS_caffe2_gpu_memory_tracking) {
g_size_map[ptr] = nbytes;
g_cuda_device_affiliation[ptr] = CaffeCudaGetDevice();
}
return {ptr, ptr, &Delete, at::Device(CUDA, CaffeCudaGetDevice())};
case CudaMemoryPoolType::CUB:
- CUDA_ENFORCE(g_cub_allocator->DeviceAllocate(&ptr, nbytes));
+ if (nbytes != 0) {
+ CUDA_ENFORCE(g_cub_allocator->DeviceAllocate(&ptr, nbytes));
+ }
g_cuda_device_affiliation[ptr] = CaffeCudaGetDevice();
VLOG(2) << "CUB allocating pointer " << ptr << " on device "
<< CaffeCudaGetDevice();