[CUDA] Implement CL_MEM_USE_HOST_PTR
@@ -222,13 +222,29 @@ pocl_cuda_uninit(cl_device_id device)
cl_int pocl_cuda_alloc_mem_obj(cl_device_id device, cl_mem mem_obj)
{
+ CUresult result;
void *b = NULL;
/* if memory for this global memory is not yet allocated -> do it */
if (mem_obj->device_ptrs[device->global_mem_id].mem_ptr == NULL)
{
+ cl_mem_flags flags = mem_obj->flags;
+
// TODO: Deal with mem flags
- CUresult result = cuMemAlloc((CUdeviceptr*)&b, mem_obj->size);
+ if (flags & CL_MEM_USE_HOST_PTR)
+ {
+ result = cuMemHostRegister(mem_obj->mem_host_ptr, mem_obj->size,
+ CU_MEMHOSTREGISTER_DEVICEMAP);
+ if (result != CUDA_SUCCESS &&
+ result != CUDA_ERROR_HOST_MEMORY_ALREADY_REGISTERED)
+ CUDA_CHECK(result, "cuMemHostRegister");
+ result = cuMemHostGetDevicePointer((CUdeviceptr*)&b,
+ mem_obj->mem_host_ptr, 0);
+ CUDA_CHECK(result, "cuMemHostGetDevicePointer");
+ }
+ else
+ {
+ result = cuMemAlloc((CUdeviceptr*)&b, mem_obj->size);
if (result != CUDA_SUCCESS)
{
const char *err;
@@ -237,6 +253,7 @@ cl_int pocl_cuda_alloc_mem_obj(cl_device_id device, cl_mem mem_obj)
"-> Failed to allocate memory: %s\n", err);
return CL_MEM_OBJECT_ALLOCATION_FAILURE;
}
+ }
mem_obj->device_ptrs[device->global_mem_id].mem_ptr = b;
mem_obj->device_ptrs[device->global_mem_id].global_mem_id =
