Skip to content

Commit 27d0421

Browse files
Add feature to estimate number of event packets
Related-To: NEO-7469 Signed-off-by: Zbigniew Zdanowicz <[email protected]>
1 parent 23bb199 commit 27d0421

32 files changed

+544
-75
lines changed

level_zero/core/source/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ if(SUPPORT_XEHP_AND_LATER)
9999
list(APPEND L0_RUNTIME_SOURCES
100100
${CMAKE_CURRENT_SOURCE_DIR}/cmdlist/cmdlist_hw_xehp_and_later.inl
101101
${CMAKE_CURRENT_SOURCE_DIR}/cmdqueue/cmdqueue_xe_hp_core_and_later.inl
102+
${CMAKE_CURRENT_SOURCE_DIR}/hw_helpers/l0_hw_helper_xehp_and_later.inl
102103
)
103104
endif()
104105

level_zero/core/source/cmdlist/cmdlist_hw.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendEventReset(ze_event_hand
390390
}
391391

392392
if (event->isEventTimestampFlagSet()) {
393-
packetsToReset = EventPacketsCount::eventPackets;
393+
packetsToReset = event->getMaxPacketsCount();
394394
}
395395
event->resetPackets();
396396
event->resetCompletion();

level_zero/core/source/context/context_imp.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,11 @@ ze_result_t ContextImp::openEventPoolIpcHandle(const ze_ipc_event_pool_handle_t
577577
auto device = Device::fromHandle(this->devices.begin()->second);
578578
auto neoDevice = device->getNEODevice();
579579
NEO::osHandle osHandle = static_cast<NEO::osHandle>(handle);
580-
auto &hwHelper = device->getHwHelper();
581-
const uint32_t eventAlignment = static_cast<uint32_t>(hwHelper.getTimestampPacketAllocatorAlignment());
582-
uint32_t eventSize = static_cast<uint32_t>(alignUp(EventPacketsCount::eventPackets * hwHelper.getSingleTimestampPacketSize(), eventAlignment));
583-
size_t alignedSize = alignUp<size_t>(numEvents * eventSize, MemoryConstants::pageSize64k);
580+
581+
eventPool->initializeSizeParameters(this->numDevices, this->deviceHandles.data(), *this->driverHandle, device->getHwInfo());
582+
584583
NEO::AllocationProperties unifiedMemoryProperties{rootDeviceIndex,
585-
alignedSize,
584+
eventPool->getEventPoolSize(),
586585
NEO::AllocationType::BUFFER_HOST_MEMORY,
587586
systemMemoryBitfield};
588587

@@ -605,8 +604,6 @@ ze_result_t ContextImp::openEventPoolIpcHandle(const ze_ipc_event_pool_handle_t
605604
eventPool->eventPoolPtr = reinterpret_cast<void *>(alloc->getUnderlyingBuffer());
606605
eventPool->devices.push_back(device);
607606
eventPool->isImportedIpcPool = true;
608-
eventPool->setEventSize(eventSize);
609-
eventPool->setEventAlignment(eventAlignment);
610607

611608
for (auto currDeviceIndex : this->rootDeviceIndices) {
612609
if (currDeviceIndex == rootDeviceIndex) {

level_zero/core/source/context/context_imp.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,20 @@ struct ContextImp : Context {
149149
bool isShareableMemory(const void *exportDesc, bool exportableMemory, NEO::Device *neoDevice) override;
150150
void *getMemHandlePtr(ze_device_handle_t hDevice, uint64_t handle, ze_ipc_memory_flags_t flags) override;
151151

152+
void initDeviceHandles(uint32_t numDevices, ze_device_handle_t *deviceHandles) {
153+
this->numDevices = numDevices;
154+
if (numDevices > 0) {
155+
this->deviceHandles.assign(deviceHandles, deviceHandles + numDevices);
156+
}
157+
}
158+
152159
protected:
153160
bool isAllocationSuitableForCompression(const StructuresLookupTable &structuresLookupTable, Device &device, size_t allocSize);
154161

155162
std::map<uint32_t, ze_device_handle_t> devices;
163+
std::vector<ze_device_handle_t> deviceHandles;
156164
DriverHandleImp *driverHandle = nullptr;
165+
uint32_t numDevices = 0;
157166
};
158167

159168
} // namespace L0

level_zero/core/source/device/device.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ struct Device : _ze_device_handle_t {
136136
virtual NEO::GraphicsAllocation *obtainReusableAllocation(size_t requiredSize, NEO::AllocationType type) = 0;
137137
virtual void storeReusableAllocation(NEO::GraphicsAllocation &alloc) = 0;
138138
virtual ze_result_t getFabricVertex(ze_fabric_vertex_handle_t *phVertex) = 0;
139+
virtual uint32_t getEventMaxPacketCount() const = 0;
139140

140141
protected:
141142
NEO::Device *neoDevice = nullptr;

level_zero/core/source/device/device_imp.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1515,4 +1515,14 @@ ze_result_t DeviceImp::getFabricVertex(ze_fabric_vertex_handle_t *phVertex) {
15151515
return ZE_RESULT_SUCCESS;
15161516
}
15171517

1518+
uint32_t DeviceImp::getEventMaxPacketCount() const {
1519+
const auto &hardwareInfo = this->getHwInfo();
1520+
auto &l0HwHelper = L0HwHelper::get(hardwareInfo.platform.eRenderCoreFamily);
1521+
1522+
uint32_t basePackets = l0HwHelper.getEventBaseMaxPacketCount(hardwareInfo);
1523+
if (this->isImplicitScalingCapable()) {
1524+
basePackets *= static_cast<uint32_t>(neoDevice->getDeviceBitfield().count());
1525+
}
1526+
return basePackets;
1527+
}
15181528
} // namespace L0

level_zero/core/source/device/device_imp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ struct DeviceImp : public Device {
141141

142142
ze_result_t queryDeviceLuid(ze_device_luid_ext_properties_t *deviceLuidProperties);
143143
ze_result_t setDeviceLuid(ze_device_luid_ext_properties_t *deviceLuidProperties);
144+
uint32_t getEventMaxPacketCount() const override;
144145

145146
protected:
146147
void adjustCommandQueueDesc(uint32_t &ordinal, uint32_t &index);

level_zero/core/source/driver/driver_handle.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ struct DriverHandle : _ze_driver_handle_t {
6666
uint32_t rootDeviceIndex,
6767
uintptr_t *gpuAddress) = 0;
6868
virtual ze_result_t fabricVertexGetExp(uint32_t *pCount, ze_fabric_vertex_handle_t *phDevices) = 0;
69+
virtual uint32_t getEventMaxPacketCount(uint32_t numDevices, ze_device_handle_t *deviceHandles) const = 0;
6970

7071
static DriverHandle *fromHandle(ze_driver_handle_t handle) { return static_cast<DriverHandle *>(handle); }
7172
inline ze_driver_handle_t toHandle() { return this; }

level_zero/core/source/driver/driver_handle_imp.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ ze_result_t DriverHandleImp::createContext(const ze_context_desc_t *desc,
5858
}
5959

6060
*phContext = context->toHandle();
61-
61+
context->initDeviceHandles(numDevices, phDevices);
6262
if (numDevices == 0) {
6363
for (auto device : this->devices) {
6464
auto neoDevice = device->getNEODevice();
@@ -704,4 +704,22 @@ ze_result_t DriverHandleImp::fabricEdgeGetExp(ze_fabric_vertex_handle_t hVertexA
704704
return ZE_RESULT_SUCCESS;
705705
}
706706

707+
uint32_t DriverHandleImp::getEventMaxPacketCount(uint32_t numDevices, ze_device_handle_t *deviceHandles) const {
708+
uint32_t maxCount = 0;
709+
710+
if (numDevices == 0) {
711+
for (auto device : this->devices) {
712+
auto deviceMaxCount = device->getEventMaxPacketCount();
713+
maxCount = std::max(maxCount, deviceMaxCount);
714+
}
715+
} else {
716+
for (uint32_t i = 0; i < numDevices; i++) {
717+
auto deviceMaxCount = Device::fromHandle(deviceHandles[i])->getEventMaxPacketCount();
718+
maxCount = std::max(maxCount, deviceMaxCount);
719+
}
720+
}
721+
722+
return maxCount;
723+
}
724+
707725
} // namespace L0

level_zero/core/source/driver/driver_handle_imp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct DriverHandleImp : public DriverHandle {
8282
Device *device);
8383
ze_result_t fabricEdgeGetExp(ze_fabric_vertex_handle_t hVertexA, ze_fabric_vertex_handle_t hVertexB,
8484
uint32_t *pCount, ze_fabric_edge_handle_t *phEdges);
85+
uint32_t getEventMaxPacketCount(uint32_t numDevices, ze_device_handle_t *deviceHandles) const override;
8586

8687
std::unique_ptr<HostPointerManager> hostPointerManager;
8788
// Experimental functions

0 commit comments

Comments
 (0)