Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,22 @@ def test_event(self):
self.assertEqual(list(tensor), [4, 4, 4, 4])
p.join()

def _test_empty_tensor_sharing(self, dtype):
q = mp.Queue()
empty = torch.tensor([], dtype=dtype)
q.put(empty)
out = q.get(timeout=1)
self.assertEqual(out, empty)

def test_empty_tensor_sharing(self):
self._test_empty_tensor_sharing(torch.float32)
self._test_empty_tensor_sharing(torch.int64)

@unittest.skipIf(not torch.cuda.is_available(), 'CUDA not available')
def test_empty_tensor_sharing_cuda(self):
self._test_empty_tensor_sharing(torch.cuda.float32)
self._test_empty_tensor_sharing(torch.cuda.int64)

def _test_autograd_sharing(self, var):
ready = mp.Event()
master_modified = mp.Event()
Expand Down
8 changes: 8 additions & 0 deletions torch/multiprocessing/reductions.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ def rebuild_storage_cuda(cls, device, handle, size, offset, view_size):
return storage


def rebuild_storage_empty(cls):
return cls()


def reduce_storage(storage):
from . import get_sharing_strategy
if storage.is_cuda:
Expand All @@ -109,6 +113,10 @@ def reduce_storage(storage):
cache_key = metadata[1]
rebuild = rebuild_storage_filename
storage._shared_incref()
elif storage.size() == 0:
# This is special cased because Empty tensors
# (with size 0) cannot be mmapped.
return (rebuild_storage_empty, (type(storage),))
else:
fd, size = storage._share_fd_()
if sys.version_info[0] == 2:
Expand Down