Commit a507e784 authored by Robert Maynard's avatar Robert Maynard Committed by Kitware Robot

Merge topic 'fix_logic_error_in_enable_cuda_managed_memory'

90bb23de CudaAllocator::Initialize correctly uses managed memory when possible
Acked-by: Kitware Robot's avatarKitware Robot <kwrobot@kitware.com>
Acked-by: Haocheng LIU's avatarHaocheng LIU <haocheng.liu@kitware.com>
Merge-request: !1486
parents 376ef07f 90bb23de
......@@ -254,7 +254,6 @@ void CudaAllocator::Initialize()
{
#if CUDART_VERSION >= 8000
std::call_once(IsInitialized, []() {
bool managedMemorySupported = true;
int numDevices;
VTKM_CUDA_CALL(cudaGetDeviceCount(&numDevices));
......@@ -264,18 +263,16 @@ void CudaAllocator::Initialize()
}
// Check all devices, use the feature set supported by all
bool managed = true;
bool managedMemorySupported = true;
cudaDeviceProp prop;
for (int i = 0; i < numDevices && managed; ++i)
for (int i = 0; i < numDevices && managedMemorySupported; ++i)
{
VTKM_CUDA_CALL(cudaGetDeviceProperties(&prop, i));
// We check for concurrentManagedAccess, as devices with only the
// managedAccess property have extra synchronization requirements.
managed = managed && prop.concurrentManagedAccess;
managedMemorySupported = managedMemorySupported && prop.concurrentManagedAccess;
}
managedMemorySupported = managed;
// Check if users want to disable managed memory
#pragma warning(push)
// getenv is not thread safe on windows but since it's inside a call_once block so
......@@ -283,11 +280,12 @@ void CudaAllocator::Initialize()
#pragma warning(disable : 4996)
const char* buf = std::getenv(NO_VTKM_MANAGED_MEMORY);
#pragma warning(pop)
if (buf != nullptr)
{
ManagedMemoryEnabled = (std::string(buf) != "1");
if (managedMemorySupported && buf != nullptr)
{ //only makes sense to disable managed memory if the hardware supports it
//in the first place
managedMemorySupported = (std::string(buf) != "1");
}
ManagedMemoryEnabled = ManagedMemoryEnabled && managedMemorySupported;
ManagedMemoryEnabled = managedMemorySupported;
});
#endif
}
......
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