vtk-m/vtkm/cont/DIYMemoryManagement.cxx
Vicente Adolfo Bolea Sanchez 1e27495809 diy,mpi: Enable GPU AWARE MPI buffers
This commit adds the flag VTKm_ENABLE_GPU_MPI which when enable it
will use GPU AWARE MPI.

- This will only work with GPUs and MPI implementation that supports GPU
  AWARE MPI calls.
- Enabling VTKm_ENABLE_GPU_MPI without MPI/GPU support might results in
  errors when running VTK-m with DIY/MPI.
- Only the following tests can run with this feature if enabled:
  - UnitTestSerializationDataSet
  - UnitTestSerializationArrayHandle
2023-05-30 12:13:03 -04:00

79 lines
2.2 KiB
C++

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
//
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//============================================================================
#include <vtkm/cont/DIYMemoryManagement.h>
#include <vtkm/cont/DeviceAdapterList.h>
#include <vtkm/cont/DeviceAdapterTag.h>
#include <vtkm/cont/RuntimeDeviceInformation.h>
#include <vtkm/cont/serial/DeviceAdapterSerial.h>
#ifdef VTKM_ENABLE_GPU_MPI
#include <vtkm/cont/kokkos/DeviceAdapterKokkos.h>
#endif
namespace
{
thread_local vtkm::cont::DeviceAdapterId DIYCurrentDeviceAdaptor =
vtkm::cont::DeviceAdapterTagSerial();
vtkm::cont::internal::DeviceAdapterMemoryManagerBase& GetMemoryManager(
vtkm::cont::DeviceAdapterId device)
{
return vtkm::cont::RuntimeDeviceInformation().GetMemoryManager(device);
}
vtkmdiy::MemoryManagement GetDIYMemoryManagement(vtkm::cont::DeviceAdapterId device)
{
return vtkmdiy::MemoryManagement(
[device](int, size_t n) {
return static_cast<char*>(GetMemoryManager(device).AllocateRawPointer(n));
},
[device](const char* p) { GetMemoryManager(device).DeleteRawPointer(const_cast<char*>(p)); },
[device](char* dest, const char* src, size_t count) {
GetMemoryManager(device).CopyDeviceToDeviceRawPointer(src, dest, count);
});
}
}
namespace vtkm
{
namespace cont
{
vtkm::cont::DeviceAdapterId GetDIYDeviceAdapter()
{
return DIYCurrentDeviceAdaptor;
}
void DIYMasterExchange(vtkmdiy::Master& master, bool remote)
{
#ifdef VTKM_ENABLE_GPU_MPI
try
{
DIYCurrentDeviceAdaptor = vtkm::cont::DeviceAdapterTagKokkos();
master.exchange(remote, GetDIYMemoryManagement(vtkm::cont::DeviceAdapterTagKokkos()));
DIYCurrentDeviceAdaptor = vtkm::cont::DeviceAdapterTagSerial();
}
catch (...)
{
DIYCurrentDeviceAdaptor = vtkm::cont::DeviceAdapterTagSerial();
throw;
}
#else
DIYCurrentDeviceAdaptor = vtkm::cont::DeviceAdapterTagSerial();
master.exchange(remote);
#endif
}
}
}