From eeff9f4a6e0ed51ba459fd923724fb4c3dd545d7 Mon Sep 17 00:00:00 2001 From: Przemek Malon Date: Wed, 8 Jan 2025 19:53:17 +0000 Subject: [PATCH] Enable creation of bindless images backed by host USM Small patch to enable bindless images backed by host USM in the CUDA adapter. Host and Device USM pointers are usable across the host and device for all versions of CUDA that we support. There is no need to provide the `CU_MEMHOSTALLOC_DEVICEMAP` flag during allocation, or calling `cuMemHostGetDevicePointer` to retrieve a device usable address. Passing a `CU_MEMHOSTALLOC_WRITECOMBINED` flag to the host USM allocation will enhance performance in certain scenarios, however, an extension allowing this is not yet available. --- source/adapters/cuda/image.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source/adapters/cuda/image.cpp b/source/adapters/cuda/image.cpp index c11a85b293..87570e3b45 100644 --- a/source/adapters/cuda/image.cpp +++ b/source/adapters/cuda/image.cpp @@ -533,8 +533,10 @@ UR_APIEXPORT ur_result_t UR_APICALL urBindlessImagesSampledImageCreateExp( image_res_desc.resType = CU_RESOURCE_TYPE_MIPMAPPED_ARRAY; image_res_desc.res.mipmap.hMipmappedArray = (CUmipmappedArray)hImageMem; } - } else if (mem_type == CU_MEMORYTYPE_DEVICE) { - // We have a USM pointer + } else if (mem_type == CU_MEMORYTYPE_DEVICE || + mem_type == CU_MEMORYTYPE_HOST) { + // We have a USM pointer. + // Images may be created from device or host USM. if (pImageDesc->type == UR_MEM_TYPE_IMAGE1D) { image_res_desc.resType = CU_RESOURCE_TYPE_LINEAR; image_res_desc.res.linear.devPtr = (CUdeviceptr)hImageMem;