Skip to content

Commit

Permalink
Merge pull request #83 from helmholtz-analytics/features/82-cuda-awar…
Browse files Browse the repository at this point in the history
…e-mpi

Added CUDA-aware MPI checks
  • Loading branch information
Markus-Goetz authored Dec 5, 2018
2 parents cbf6d2f + 08feb59 commit 0d6596c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
19 changes: 17 additions & 2 deletions heat/core/communication.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
from mpi4py import MPI
import abc
import subprocess
import torch

from .stride_tricks import sanitize_axis

# check whether OpenMPI support CUDA-aware MPI
try:
buffer = subprocess.check_output(['mpirun', '--help'])

# OpenMPI
if buffer.startswith(b'mpirun (Open MPI)'):
buffer = subprocess.check_output(['ompi_info', '--parsable', '--all'])
CUDA_AWARE_MPI = b'mpi_built_with_cuda_support:value:true' in buffer
else:
CUDA_AWARE_MPI = False
except FileNotFoundError:
CUDA_AWARE_MPI = False


class Communication(metaclass=abc.ABCMeta):
@staticmethod
Expand Down Expand Up @@ -93,11 +107,12 @@ def chunk(self, shape, split):
def as_buffer(obj):
if isinstance(obj, tensor.tensor):
obj = obj._tensor__array

if not isinstance(obj, torch.Tensor):
return obj

return MPI.memory.fromaddress(obj.cpu().data_ptr(), obj.element_size() * torch.numel(obj))
pointer = obj.data_ptr() if CUDA_AWARE_MPI else obj.cpu().data_ptr()

return MPI.memory.fromaddress(pointer, obj.element_size() * torch.numel(obj))

def convert_tensors(self, a_callable):
def wrapped(*args, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,6 @@ def test_mpi_communicator(self):

self.assertIsInstance(chunks, tuple)
self.assertEqual(len(chunks), len(self.data.shape))

def test_cuda_aware_mpi(self):
self.assertTrue(hasattr(ht.communication, 'CUDA_AWARE_MPI'))

0 comments on commit 0d6596c

Please sign in to comment.