Virtual Memory Read-Only Properties Extension

Virtual Memory Read-Only Properties Extension#

API#

Virtual Memory Read-Only Properties#

‘oneAPI’ Level-Zero provides the ZE_MEMORY_ACCESS_ATTRIBUTE_READONLY attribute for virtual memory page mappings via zeVirtualMemSetAccessAttribute. However, the actual behavior when this attribute is applied varies across drivers and hardware.

This extension introduces the ze_device_readonly_memory_ext_properties_t struct, which can be chained via the pNext member of ze_device_properties_t to query the read-only capability supported by the device.

The readonlyCapability field reports one of the following values:

  • :ref:`ZE_DEVICE_READONLY_MEMORY_CAPABILITY_NONE <ze-device-readonly-memory-capability-t>`\: The read-only attribute has no effect.

  • :ref:`ZE_DEVICE_READONLY_MEMORY_CAPABILITY_HINT <ze-device-readonly-memory-capability-t>`\: The read-only attribute is forwarded to the OS as a performance hint.

  • :ref:`ZE_DEVICE_READONLY_MEMORY_CAPABILITY_ENFORCED <ze-device-readonly-memory-capability-t>`\: The read-only attribute is hardware-enforced.

The following pseudo-code demonstrates how to query the read-only memory capability:

// Query device properties with read-only memory capability extension
ze_device_readonly_memory_ext_properties_t roProps = {};
roProps.stype = ZE_STRUCTURE_TYPE_DEVICE_READONLY_MEMORY_EXT_PROPERTIES;
roProps.pNext = nullptr;

ze_device_properties_t devProps = {};
devProps.stype = ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES_1_2; // ZE_STRUCTURE_TYPE_DEVICE_PROPERTIES deprecated since 1.17
devProps.pNext = &roProps;

zeDeviceGetProperties(hDevice, &devProps);

if (roProps.readonlyCapability == ZE_DEVICE_READONLY_MEMORY_CAPABILITY_ENFORCED) {
    // Hardware enforces read-only; writes will fault
} else if (roProps.readonlyCapability == ZE_DEVICE_READONLY_MEMORY_CAPABILITY_HINT) {
    // Read-only is a hint; writes may still succeed
} else {
    // No read-only support; attribute has no effect
}