Updates will be applied on October 27th between 12pm - 12:45pm EDT (UTC-0400). Gitlab may be slow during the maintenance window.

Commit fab26344 authored by Sujin Philip's avatar Sujin Philip Committed by Kitware Robot
Browse files

Merge topic 'fix-ManagedMemory-issue'

b530a5ce

 Fix issue with Managed Memory for 0 size arrays
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: default avatarRobert Maynard <robert.maynard@kitware.com>
Merge-request: !1033
parents a6ec3ab0 b530a5ce
...@@ -33,6 +33,10 @@ static bool IsInitialized = false; ...@@ -33,6 +33,10 @@ static bool IsInitialized = false;
// True if all devices support concurrent pagable managed memory. // True if all devices support concurrent pagable managed memory.
static bool ManagedMemorySupported = false; static bool ManagedMemorySupported = false;
// Avoid overhead of cudaMemAdvise and cudaMemPrefetchAsync for small buffers.
// This value should be > 0 or else these functions will error out.
static std::size_t Threshold = 1 << 20;
} }
namespace vtkm namespace vtkm
...@@ -94,6 +98,12 @@ bool CudaAllocator::IsManagedPointer(const void* ptr) ...@@ -94,6 +98,12 @@ bool CudaAllocator::IsManagedPointer(const void* ptr)
void* CudaAllocator::Allocate(std::size_t numBytes) void* CudaAllocator::Allocate(std::size_t numBytes)
{ {
CudaAllocator::Initialize(); CudaAllocator::Initialize();
// When numBytes is zero cudaMallocManaged returns an error and the behavior
// of cudaMalloc is not documented. Just return nullptr.
if (numBytes == 0)
{
return nullptr;
}
void* ptr = nullptr; void* ptr = nullptr;
if (ManagedMemorySupported) if (ManagedMemorySupported)
...@@ -115,7 +125,7 @@ void CudaAllocator::Free(void* ptr) ...@@ -115,7 +125,7 @@ void CudaAllocator::Free(void* ptr)
void CudaAllocator::PrepareForControl(const void* ptr, std::size_t numBytes) void CudaAllocator::PrepareForControl(const void* ptr, std::size_t numBytes)
{ {
if (IsManagedPointer(ptr)) if (IsManagedPointer(ptr) && numBytes >= Threshold)
{ {
#if CUDART_VERSION >= 8000 #if CUDART_VERSION >= 8000
// TODO these hints need to be benchmarked and adjusted once we start // TODO these hints need to be benchmarked and adjusted once we start
...@@ -128,7 +138,7 @@ void CudaAllocator::PrepareForControl(const void* ptr, std::size_t numBytes) ...@@ -128,7 +138,7 @@ void CudaAllocator::PrepareForControl(const void* ptr, std::size_t numBytes)
void CudaAllocator::PrepareForInput(const void* ptr, std::size_t numBytes) void CudaAllocator::PrepareForInput(const void* ptr, std::size_t numBytes)
{ {
if (IsManagedPointer(ptr)) if (IsManagedPointer(ptr) && numBytes >= Threshold)
{ {
#if CUDART_VERSION >= 8000 #if CUDART_VERSION >= 8000
int dev; int dev;
...@@ -143,7 +153,7 @@ void CudaAllocator::PrepareForInput(const void* ptr, std::size_t numBytes) ...@@ -143,7 +153,7 @@ void CudaAllocator::PrepareForInput(const void* ptr, std::size_t numBytes)
void CudaAllocator::PrepareForOutput(const void* ptr, std::size_t numBytes) void CudaAllocator::PrepareForOutput(const void* ptr, std::size_t numBytes)
{ {
if (IsManagedPointer(ptr)) if (IsManagedPointer(ptr) && numBytes >= Threshold)
{ {
#if CUDART_VERSION >= 8000 #if CUDART_VERSION >= 8000
int dev; int dev;
...@@ -158,7 +168,7 @@ void CudaAllocator::PrepareForOutput(const void* ptr, std::size_t numBytes) ...@@ -158,7 +168,7 @@ void CudaAllocator::PrepareForOutput(const void* ptr, std::size_t numBytes)
void CudaAllocator::PrepareForInPlace(const void* ptr, std::size_t numBytes) void CudaAllocator::PrepareForInPlace(const void* ptr, std::size_t numBytes)
{ {
if (IsManagedPointer(ptr)) if (IsManagedPointer(ptr) && numBytes >= Threshold)
{ {
#if CUDART_VERSION >= 8000 #if CUDART_VERSION >= 8000
int dev; int dev;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment