vtk-m/vtkm/cont/kokkos/internal/KokkosAlloc.cxx
Sujin Philip 89e19ce7fa Don't require CUDA_LAUNCH_BLOCKING
1. The code now works without CUDA_LAUNCH_BLOCKING set by using explicit
   synchronizations where required.
2. The code has also been modified to use thread specific memory spaces,
   which for Kokkos' Cuda backend means per thread streams.
2020-11-30 13:12:39 -05:00

64 lines
1.5 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/kokkos/internal/KokkosAlloc.h>
#include <vtkm/cont/ErrorBadAllocation.h>
#include <vtkm/cont/kokkos/internal/KokkosTypes.h>
#include <sstream>
namespace vtkm
{
namespace cont
{
namespace kokkos
{
namespace internal
{
void* Allocate(std::size_t size)
{
try
{
return Kokkos::kokkos_malloc<ExecutionSpace::memory_space>(size);
}
catch (...) // the type of error thrown is not well documented
{
std::ostringstream err;
err << "Failed to allocate " << size << " bytes on Kokkos device";
throw vtkm::cont::ErrorBadAllocation(err.str());
}
}
void Free(void* ptr)
{
GetExecutionSpaceInstance().fence();
Kokkos::kokkos_free<ExecutionSpace::memory_space>(ptr);
}
void* Reallocate(void* ptr, std::size_t newSize)
{
try
{
return Kokkos::kokkos_realloc<ExecutionSpace::memory_space>(ptr, newSize);
}
catch (...)
{
std::ostringstream err;
err << "Failed to re-allocate " << newSize << " bytes on Kokkos device";
throw vtkm::cont::ErrorBadAllocation(err.str());
}
}
}
}
}
} // vtkm::cont::kokkos::internal