Hi,
I would like to use the virtual memory management API to create a contiguous virtual address range which is accessible by the host. However, I am not sure if it is possible.
I am already able to create a device memory range which can be successfully used in kernel calls. To get a host mapping, I tried the following approaches by using the device id CU_DEVICE_CPU:
Option 1: Create host memory -> CUDA_ERROR_INVALID_DEVICE
CUmemAllocationProp prop = {};
prop.location.type = CU_MEM_LOCATION_TYPE_DEVICE;
prop.location.id = CU_DEVICE_CPU;
prop.requestedHandleTypes = CU_MEM_HANDLE_TYPE_POSIX_FILE_DESCRIPTOR;
prop.type = CU_MEM_ALLOCATION_TYPE_PINNED;
prop.win32HandleMetaData = nullptr;
CUDADRV_SAFE_CALL( cuMemCreate(&handle, size, &prop, 0) );
Option 2: Allow both host and device to access device memory -> CUDA_ERROR_INVALID_VALUE
CUmemAccessDesc desc[2];
desc[0].flags = CU_MEM_ACCESS_FLAGS_PROT_READWRITE;
desc[0].location.id = device_;
desc[0].location.type = CU_MEM_LOCATION_TYPE_DEVICE;
desc[1].flags = CU_MEM_ACCESS_FLAGS_PROT_READWRITE;
desc[1].location.id = CU_DEVICE_CPU;
desc[1].location.type = CU_MEM_LOCATION_TYPE_DEVICE;
CUDADRV_SAFE_CALL( cuMemSetAccess(ptr, size, &desc[0], 2) );
Are there any other options? Is it possible at all to get this working?