level-zero icon indicating copy to clipboard operation
level-zero copied to clipboard

device memory allocations required to have mappings/be dereferenceable?

Open airlied opened this issue 5 years ago • 2 comments

Looking at the device memory allocation API,

__ze_api_export ze_result_t __zecall zeDriverAllocDeviceMem( ze_driver_handle_t hDriver, ///< [in] handle of the driver instance const ze_device_mem_alloc_desc_t* device_desc, ///< [in] pointer to device mem alloc descriptor size_t size, ///< [in] size in bytes to allocate size_t alignment, ///< [in] minimum alignment in bytes for the allocation ze_device_handle_t hDevice, ///< [in] handle of the device void** pptr ///< [out] pointer to device allocation );

It looks like it always passes back a (void *). Is this expected to be a mapped pointer accessible from the CPU?

There are GPUs out there (maybe not yet from Intel) that have limited access to the VRAM from the CPU, by forcing that *pptr is a mapped address for all allocation this will limit the amount of mapped accessible objects you can have.

This why Vulkan has VkDeviceMemory objects, and Map/Unmap APIs.

airlied avatar May 05 '20 04:05 airlied

Okay it says device allocated ptrs should not be accessed by the host. The spec should state clearly what happens if someone tries, undefined behaviour resulting in program termination?

airlied avatar May 06 '20 00:05 airlied

Hi @airlied!

Thanks for the question. You're right that for device memory allocations, the pointer must be in the same virtual address space as the host application, but it does NOT need to be host-accessible so there is no requirement that the allocation be "mapped". This is different than host or shared allocations, where the pointer does need to be host-accessible.

This is documented in the programming guide, in the text and the summary table. Additionally, the API description says: "In general, a device allocation may only be accessed by the device that owns it."

I guess "may not" could be strengthened to "must" in these places? Would that be clearer, or are there other clarifications you would suggest?

bashbaug avatar May 08 '20 15:05 bashbaug