Sub-Allocation Properties Extension
Contents
Sub-Allocation Properties Extension¶
API¶
Enumerations
Structures
Sub-Allocation Properties¶
Driver implementations may choose to create a device allocation as a series of sub-allocations. For instance, an allocation created against a parent device may be allocated internally as set of N sub-allocations, with N being the number of sub-devices associated with the parent device.
The sub-allocation properties extension may be used to get the properties, i.e. base address and size, for each of those sub-allocations. The following pseudo-code demonstrates a basic use-case of this extension:
zeMemAllocDevice(context, &desc, size, alignment, device, &ptr); ze_memory_sub_allocations_exp_properties_t subAllocationDesc {}; uitn32_t numberOfSuballocations = 0; subAllocationDesc.stype = ZE_STRUCTURE_TYPE_MEMORY_SUB_ALLOCATIONS_EXP_PROPERTIES; subAllocationDesc.pCount = &numberOfSuballocations; ze_memory_allocation_properties_t memAllocProperties {}; memAllocProperties.stype = ZE_STRUCTURE_TYPE_MEMORY_ALLOCATION_PROPERTIES; memAllocProperties.pNext = &subAllocationDesc; // Get number of sub-allocations zeMemGetAllocProperties(context, ptr, &memAllocProperties, nullptr); // if more than 1 sub-allocation, then allocation has been split if (numberOfSuballocations > 1) { std::vector<ze_sub_allocation_t> subAllocationMemAllocProperties(numberOfSuballocations); subAllocationDesc.pSubAllocations = subAllocationMemAllocProperties.data(); zeMemGetAllocProperties(context, ptr, &memAllocProperties, nullptr); // retrieve the properties of each sub-allocation for (auto &subAllocationProperty : subAllocationMemAllocProperties) { void * base = subAllocationProperty.base; size_t size = subAllocationProperty.size; } } ...