Skip to content

Commit

Permalink
Fix CPU only MappedMem
Browse files Browse the repository at this point in the history
  • Loading branch information
CyprienBosserelle committed Oct 16, 2024
1 parent 00f02f3 commit 9c59e3e
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/MemManagement.cu
Original file line number Diff line number Diff line change
Expand Up @@ -390,12 +390,15 @@ template <class T> void AllocateMappedMemCPU(int nx, int ny,int gpudevice, T*& z
{
//printf("> Using CUDA Host Allocated (cudaHostAlloc)\n");
}
cudaGetDeviceProperties(&deviceProp, gpudevice);

if (!deviceProp.canMapHostMemory)
if (gpudevice >= 0)
{
fprintf(stderr, "Device %d does not support mapping CPU host memory!\n", gpudevice);
bPinGenericMemory = false;
cudaGetDeviceProperties(&deviceProp, gpudevice);

if (!deviceProp.canMapHostMemory)
{
fprintf(stderr, "Device %d does not support mapping CPU host memory!\n", gpudevice);
bPinGenericMemory = false;
}
}
size_t bytes = nx * ny * sizeof(T);
if (bPinGenericMemory)
Expand All @@ -409,9 +412,10 @@ template <class T> void AllocateMappedMemCPU(int nx, int ny,int gpudevice, T*& z
// We need to ensure memory is aligned to 4K (so we will need to padd memory accordingly)
z = (T*)ALIGN_UP(a_UA, MEMORY_ALIGNMENT);


CUDA_CHECK(cudaHostRegister(z, bytes, cudaHostRegisterMapped));

if (gpudevice >= 0)
{
CUDA_CHECK(cudaHostRegister(z, bytes, cudaHostRegisterMapped));
}

}
else
Expand Down

0 comments on commit 9c59e3e

Please sign in to comment.