Skip to content

Commit 8e41e34

Browse files
authored
Documentation: Clarify External Memory Mapping (sysmem) extension semantics (#477)
Resolve the open questions raised in review of the ze_external_memmap_sysmem_ext extension by documenting the previously-unspecified behavior of mapping host system memory into a host allocation via zeMemAllocHost: - Alignment is the host page size, queried via OS-specific calls (no L0 query). - The returned pointer equals pSystemMemory; the virtual address is preserved on both host and device. - Any host pointer (heap, stack, or static storage) may be passed; the OS may fail the mapping if unsupported. Read-only memory requires the MEM_READ_ONLY flag. - The underlying system memory must remain valid for the allocation's lifetime. - Mapped ranges must not overlap. - zeMemGetAllocProperties reports ZE_MEMORY_TYPE_HOST_IMPORTED. - The mapping is released via zeMemFree.
1 parent fdea2c7 commit 8e41e34

2 files changed

Lines changed: 24 additions & 7 deletions

File tree

scripts/core/EXT_ExternalMemMap.rst

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,19 @@ API
2828
* ${x}_external_memmap_sysmem_ext_desc_t
2929

3030
Mapping External Memory to Host Allocation
31-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
31+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
3232

33-
Accelerator devices can map external memory as a host allocation. The ${x}_external_memmap_sysmem_ext_desc_t struct defines the system memory being mapped as part of the ${x}MemAllocHost.
34-
The user may use this extention to specify, as part of the pNext member of the ${x}_host_mem_alloc_desc_t , the system memory that needs to be mapped as part of the allocation being created with a call to ${x}MemAllocHost.
35-
For read-only system memory $(X}_HOST_MEM_ALLOC_FLAG_MEM_READ_ONLY flag should be set in ${x}_host_mem_alloc_desc_t.
33+
Accelerator devices can map existing host system memory into a host allocation. The ${x}_external_memmap_sysmem_ext_desc_t struct defines the system memory being mapped as part of the ${x}MemAllocHost call.
34+
The user may use this extension to specify, as part of the pNext member of the ${x}_host_mem_alloc_desc_t, the system memory that needs to be mapped as part of the allocation being created with a call to ${x}MemAllocHost.
35+
36+
The following rules apply when mapping external system memory:
37+
38+
* The ``pSystemMemory`` pointer and ``size`` must be aligned to the host page size. The host page size must be obtained using operating-system-specific calls; the mapped memory originates from the system allocator rather than from Level-Zero, so there is no Level-Zero query for this value.
39+
* On success, the pointer returned from ${x}MemAllocHost is identical to ``pSystemMemory``. The virtual address is preserved, so the same address is valid on both the host and the device.
40+
* Memory from the application's heap, stack, or statically-allocated (global) storage is supported. Support for memory obtained by other means is platform- and driver-dependent and is not guaranteed. If ``pSystemMemory`` points to a memory type that cannot be mapped, ${x}MemAllocHost returns ${X}_RESULT_ERROR_INVALID_ARGUMENT.
41+
* Read-only host memory can only be mapped successfully when the ${X}_HOST_MEM_ALLOC_FLAG_MEM_READ_ONLY flag is set in ${x}_host_mem_alloc_desc_t. In that case device access to the mapped memory is read-only.
42+
* The system memory referenced by ``pSystemMemory`` must remain valid for the entire lifetime of the resulting allocation. Freeing or unmapping the underlying system memory before the allocation is released results in undefined behavior.
43+
* Mapped memory ranges must not overlap. Releasing a mapping with ${x}MemFree tears down the device page-table entries for its virtual address range. Because these page tables are shared across imports, releasing a mapping that overlaps another import also tears down the overlapping device page-table entries, leaving the other allocation invalid for device access. The host system memory itself is unaffected.
44+
* After mapping, ${x}MemGetAllocProperties reports the allocation type as ${X}_MEMORY_TYPE_HOST_IMPORTED.
45+
* The mapping is released by passing the pointer to ${x}MemFree, like any other host allocation.
3646

scripts/core/externalMemMap.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
#
88
--- #--------------------------------------------------------------------------
99
type: header
10-
desc: "Intel $OneApi Level-Zero Extension APIs for Mapping External Memory as part of host llocation"
10+
desc: "Intel $OneApi Level-Zero Extension APIs for Mapping External Memory as part of host allocation"
1111
version: "1.14"
1212
--- #--------------------------------------------------------------------------
1313
type: macro
@@ -37,7 +37,14 @@ members:
3737
desc: "[in] system memory pointer to map; must be page-aligned."
3838
- type: uint64_t
3939
name: size
40-
desc: "[in] size of the system memory to map; must be page-aligned."
40+
desc: "[in] size of the system memory to map; must be a multiple of the page size."
4141
details:
4242
- "This structure may be passed to $xMemAllocHost, via the `pNext` member of $x_host_mem_alloc_desc_t to map system memory for a host allocation."
43-
- "The system memory pointer and size being mapped must be page aligned based on the supported page sizes on the device."
43+
- "The `pSystemMemory` pointer and `size` being mapped must be aligned to the host page size. The host page size must be queried using operating-system-specific calls, as the mapped memory originates from the system allocator rather than from Level-Zero; there is no Level-Zero query for this value."
44+
- "On success, the pointer returned from $xMemAllocHost is identical to `pSystemMemory`; the mapping preserves the virtual address, so the same address is valid on both the host and the device."
45+
- "Memory from the application's heap, stack, or statically-allocated (global) storage is supported. Support for memory obtained by other means is platform- and driver-dependent and is not guaranteed. If `pSystemMemory` points to a memory type that cannot be mapped, $xMemAllocHost returns $X_RESULT_ERROR_INVALID_ARGUMENT."
46+
- "Host memory that is read-only can only be mapped successfully when the $X_HOST_MEM_ALLOC_FLAG_MEM_READ_ONLY flag is set in $x_host_mem_alloc_desc_t; in that case device access to the mapped memory is read-only."
47+
- "The system memory referenced by `pSystemMemory` must remain valid for the entire lifetime of the resulting allocation. Freeing or unmapping the underlying system memory before the allocation is released results in undefined behavior."
48+
- "Mapped memory ranges must not overlap. Releasing a mapping with $xMemFree tears down the device page-table entries for its virtual address range. Because these page tables are shared across imports, releasing a mapping that overlaps another import also tears down the overlapping device page-table entries, leaving the other allocation invalid for device access. The host system memory itself is unaffected."
49+
- "After mapping, $xMemGetAllocProperties reports the allocation type as $X_MEMORY_TYPE_HOST_IMPORTED."
50+
- "The mapping is released by passing the pointer to $xMemFree, like any other host allocation."

0 commit comments

Comments
 (0)