oneapi-src / level-zero

oneAPI Level Zero Specification Headers and Loader
https://spec.oneapi.com/versions/latest/elements/l0/source/index.html
MIT License
218 stars 96 forks source link

device memory allocations required to have mappings/be dereferenceable? #13

Open airlied opened 4 years ago

airlied commented 4 years ago

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 commented 4 years ago

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?

bashbaug commented 4 years ago

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?