feature: obtain GraphicsAllocation from external CB event

Related-To: NEO-8179

Signed-off-by: Bartosz Dunajski <bartosz.dunajski@intel.com>
This commit is contained in:
Bartosz Dunajski
2024-05-06 15:11:38 +00:00
committed by Compute-Runtime-Automation
parent d6c16c1640
commit ce36812f8d
7 changed files with 64 additions and 15 deletions

View File

@@ -9,8 +9,10 @@
#include "shared/source/helpers/in_order_cmd_helpers.h"
#include "shared/source/memory_manager/graphics_allocation.h"
#include "shared/source/memory_manager/unified_memory_manager.h"
#include "level_zero/core/source/device/device.h"
#include "level_zero/core/source/driver/driver_handle.h"
#include "level_zero/core/source/event/event.h"
namespace L0 {
@@ -51,7 +53,16 @@ zexCounterBasedEventCreate(ze_context_handle_t hContext, ze_device_handle_t hDev
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
auto inOrderExecInfo = NEO::InOrderExecInfo::createFromExternalAllocation(*device->getNEODevice(), castToUint64(deviceAddress), hostAddress, completionValue);
NEO::SvmAllocationData *externalHostAllocData = nullptr;
bool allocFound = device->getDriverHandle()->findAllocationDataForRange(hostAddress, sizeof(uint64_t), externalHostAllocData);
if (!allocFound) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
auto allocation = externalHostAllocData->gpuAllocations.getGraphicsAllocation(device->getRootDeviceIndex());
auto inOrderExecInfo = NEO::InOrderExecInfo::createFromExternalAllocation(*device->getNEODevice(), castToUint64(deviceAddress), allocation, hostAddress, completionValue);
*phEvent = Event::create<uint64_t>(eventDescriptor, desc, device);
Event::fromHandle(*phEvent)->updateInOrderExecState(inOrderExecInfo, completionValue, 0);

View File

@@ -80,7 +80,7 @@ struct InOrderCmdListFixture : public ::Test<ModuleFixture> {
uint64_t *hostAddress = &(standaloneCbEventStorage.data()[standaloneCbEventStorage.size() - 1]);
uint64_t *deviceAddress = ptrOffset(hostAddress, 0x1000);
auto inOrderExecInfo = NEO::InOrderExecInfo::createFromExternalAllocation(*device->getNEODevice(), castToUint64(deviceAddress), hostAddress, 1);
auto inOrderExecInfo = NEO::InOrderExecInfo::createFromExternalAllocation(*device->getNEODevice(), castToUint64(deviceAddress), nullptr, hostAddress, 1);
ze_event_desc_t eventDesc = {};
eventDesc.pNext = pNext;

View File

@@ -3865,7 +3865,10 @@ HWTEST2_F(InOrderCmdListTests, givenIncorrectInputParamsWhenAskingForEventAddres
HWTEST2_F(InOrderCmdListTests, givenCorrectInputParamsWhenCreatingCbEventThenReturnSuccess, IsAtLeastSkl) {
uint64_t counterValue = 2;
uint64_t *hostAddress = &counterValue;
auto hostAddress = reinterpret_cast<uint64_t *>(allocHostMem(sizeof(uint64_t)));
*hostAddress = counterValue;
uint64_t *gpuAddress = ptrOffset(&counterValue, 64);
ze_event_desc_t eventDesc = {};
@@ -3876,6 +3879,7 @@ HWTEST2_F(InOrderCmdListTests, givenCorrectInputParamsWhenCreatingCbEventThenRet
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, zexCounterBasedEventCreate(context, device, gpuAddress, nullptr, counterValue, &eventDesc, &handle));
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, zexCounterBasedEventCreate(context, device, nullptr, hostAddress, counterValue, &eventDesc, &handle));
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, zexCounterBasedEventCreate(context, nullptr, gpuAddress, hostAddress, counterValue, &eventDesc, &handle));
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, zexCounterBasedEventCreate(context, device, gpuAddress, &counterValue, counterValue, &eventDesc, &handle));
EXPECT_EQ(ZE_RESULT_SUCCESS, zexCounterBasedEventCreate(context, device, gpuAddress, hostAddress, counterValue, &eventDesc, &handle));
@@ -3896,11 +3900,15 @@ HWTEST2_F(InOrderCmdListTests, givenCorrectInputParamsWhenCreatingCbEventThenRet
EXPECT_EQ(value, counterValue);
zeEventDestroy(handle);
context->freeMem(hostAddress);
}
HWTEST2_F(InOrderCmdListTests, givenStandaloneEventWhenCallingSynchronizeThenReturnCorrectValue, IsAtLeastSkl) {
uint64_t counterValue = 2;
uint64_t *hostAddress = &counterValue;
auto hostAddress = reinterpret_cast<uint64_t *>(allocHostMem(sizeof(uint64_t)));
*hostAddress = counterValue;
uint64_t *gpuAddress = ptrOffset(&counterValue, 64);
ze_event_desc_t eventDesc = {};
@@ -3912,11 +3920,13 @@ HWTEST2_F(InOrderCmdListTests, givenStandaloneEventWhenCallingSynchronizeThenRet
EXPECT_EQ(ZE_RESULT_NOT_READY, eventObj->hostSynchronize(1));
counterValue++;
(*hostAddress)++;
EXPECT_EQ(ZE_RESULT_SUCCESS, eventObj->hostSynchronize(1));
zeEventDestroy(handle);
context->freeMem(hostAddress);
}
HWTEST2_F(InOrderCmdListTests, givenStandaloneCbEventWhenPassingExternalInterruptIdThenAssign, IsAtLeastSkl) {
@@ -3937,7 +3947,9 @@ HWTEST2_F(InOrderCmdListTests, givenStandaloneCbEventWhenPassingExternalInterrup
HWTEST2_F(InOrderCmdListTests, givenStandaloneEventWhenCallingAppendThenSuccess, IsAtLeastXeHpCore) {
uint64_t counterValue = 2;
uint64_t *hostAddress = &counterValue;
auto hostAddress = reinterpret_cast<uint64_t *>(allocHostMem(sizeof(uint64_t)));
*hostAddress = counterValue;
uint64_t *gpuAddress = ptrOffset(&counterValue, 64);
ze_event_desc_t eventDesc = {};
@@ -3962,11 +3974,14 @@ HWTEST2_F(InOrderCmdListTests, givenStandaloneEventWhenCallingAppendThenSuccess,
zeEventDestroy(eHandle1);
zeEventDestroy(eHandle2);
zeEventDestroy(eHandle3);
context->freeMem(hostAddress);
}
HWTEST2_F(InOrderCmdListTests, givenStandaloneEventAndKernelSplitWhenCallingAppendThenSuccess, IsAtLeastXeHpCore) {
uint64_t counterValue = 2;
uint64_t *hostAddress = &counterValue;
auto hostAddress = reinterpret_cast<uint64_t *>(allocHostMem(sizeof(uint64_t)));
*hostAddress = counterValue;
uint64_t *gpuAddress = ptrOffset(&counterValue, 64);
ze_event_desc_t eventDesc = {};
@@ -3989,11 +4004,14 @@ HWTEST2_F(InOrderCmdListTests, givenStandaloneEventAndKernelSplitWhenCallingAppe
alignedFree(alignedPtr);
zeEventDestroy(eHandle1);
zeEventDestroy(eHandle2);
context->freeMem(hostAddress);
}
HWTEST2_F(InOrderCmdListTests, givenStandaloneEventAndCopyOnlyCmdListWhenCallingAppendThenSuccess, IsAtLeastXeHpCore) {
uint64_t counterValue = 2;
uint64_t *hostAddress = &counterValue;
auto hostAddress = reinterpret_cast<uint64_t *>(allocHostMem(sizeof(uint64_t)));
*hostAddress = counterValue;
uint64_t *gpuAddress = ptrOffset(&counterValue, 64);
ze_event_desc_t eventDesc = {};
@@ -4014,6 +4032,7 @@ HWTEST2_F(InOrderCmdListTests, givenStandaloneEventAndCopyOnlyCmdListWhenCalling
context->freeMem(data);
zeEventDestroy(eHandle1);
zeEventDestroy(eHandle2);
context->freeMem(hostAddress);
}
HWTEST2_F(InOrderCmdListTests, givenCounterBasedEventWhenAskingForEventAddressAndValueThenReturnCorrectValues, IsAtLeastSkl) {
@@ -4229,7 +4248,9 @@ struct MultiTileInOrderCmdListTests : public InOrderCmdListTests {
HWTEST2_F(MultiTileInOrderCmdListTests, givenStandaloneEventWhenCallingAppendThenSuccess, IsAtLeastXeHpCore) {
uint64_t counterValue = 2;
uint64_t *hostAddress = &counterValue;
auto hostAddress = reinterpret_cast<uint64_t *>(allocHostMem(sizeof(uint64_t)));
*hostAddress = counterValue;
uint64_t *gpuAddress = ptrOffset(&counterValue, 64);
ze_event_desc_t eventDesc = {};
@@ -4254,11 +4275,14 @@ HWTEST2_F(MultiTileInOrderCmdListTests, givenStandaloneEventWhenCallingAppendThe
zeEventDestroy(eHandle1);
zeEventDestroy(eHandle2);
zeEventDestroy(eHandle3);
context->freeMem(hostAddress);
}
HWTEST2_F(MultiTileInOrderCmdListTests, givenStandaloneEventAndKernelSplitWhenCallingAppendThenSuccess, IsAtLeastXeHpCore) {
uint64_t counterValue = 2;
uint64_t *hostAddress = &counterValue;
auto hostAddress = reinterpret_cast<uint64_t *>(allocHostMem(sizeof(uint64_t)));
*hostAddress = counterValue;
uint64_t *gpuAddress = ptrOffset(&counterValue, 64);
ze_event_desc_t eventDesc = {};
@@ -4281,11 +4305,14 @@ HWTEST2_F(MultiTileInOrderCmdListTests, givenStandaloneEventAndKernelSplitWhenCa
alignedFree(alignedPtr);
zeEventDestroy(eHandle1);
zeEventDestroy(eHandle2);
context->freeMem(hostAddress);
}
HWTEST2_F(MultiTileInOrderCmdListTests, givenStandaloneEventAndCopyOnlyCmdListWhenCallingAppendThenSuccess, IsAtLeastXeHpCore) {
uint64_t counterValue = 2;
uint64_t *hostAddress = &counterValue;
auto hostAddress = reinterpret_cast<uint64_t *>(allocHostMem(sizeof(uint64_t)));
*hostAddress = counterValue;
uint64_t *gpuAddress = ptrOffset(&counterValue, 64);
ze_event_desc_t eventDesc = {};
@@ -4306,6 +4333,7 @@ HWTEST2_F(MultiTileInOrderCmdListTests, givenStandaloneEventAndCopyOnlyCmdListWh
context->freeMem(data);
zeEventDestroy(eHandle1);
zeEventDestroy(eHandle2);
context->freeMem(hostAddress);
}
HWTEST2_F(MultiTileInOrderCmdListTests, givenDebugFlagSetWhenAskingForAtomicSignallingThenReturnTrue, IsAtLeastXeHpCore) {

View File

@@ -3399,7 +3399,14 @@ HWTEST_F(EventTests, givenStandaloneCbEventAndTbxModeWhenSynchronizingThenHandle
neoDevice->getExecutionEnvironment()->rootDeviceEnvironments[0]->memoryOperationsInterface = std::make_unique<NEO::MockMemoryOperations>();
uint64_t counterValue = 2;
uint64_t *hostAddress = &counterValue;
ze_host_mem_alloc_desc_t desc = {};
void *ptr = nullptr;
context->allocHostMem(&desc, sizeof(uint64_t), 1, &ptr);
uint64_t *hostAddress = static_cast<uint64_t *>(ptr);
*hostAddress = counterValue;
uint64_t *gpuAddress = ptrOffset(&counterValue, 64);
ze_event_desc_t eventDesc = {};
@@ -3414,6 +3421,7 @@ HWTEST_F(EventTests, givenStandaloneCbEventAndTbxModeWhenSynchronizingThenHandle
EXPECT_EQ(ZE_RESULT_SUCCESS, result);
zeEventDestroy(handle);
context->freeMem(hostAddress);
}
HWTEST_F(EventTests, givenInOrderEventWithHostAllocWhenHostSynchronizeIsCalledThenAllocationIsDonwloadedOnlyAfterEventWasUsedOnGpu) {

View File

@@ -27,10 +27,11 @@ std::shared_ptr<InOrderExecInfo> InOrderExecInfo::create(TagNodeBase *deviceCoun
return std::make_shared<NEO::InOrderExecInfo>(deviceCounterNode, hostCounterNode, *device.getMemoryManager(), partitionCount, device.getRootDeviceIndex(), regularCmdList, atomicDeviceSignalling);
}
std::shared_ptr<InOrderExecInfo> InOrderExecInfo::createFromExternalAllocation(NEO::Device &device, uint64_t deviceAddress, uint64_t *hostAddress, uint64_t counterValue) {
std::shared_ptr<InOrderExecInfo> InOrderExecInfo::createFromExternalAllocation(NEO::Device &device, uint64_t deviceAddress, NEO::GraphicsAllocation *hostAllocation, uint64_t *hostAddress, uint64_t counterValue) {
auto inOrderExecInfo = std::make_shared<NEO::InOrderExecInfo>(nullptr, nullptr, *device.getMemoryManager(), 1, device.getRootDeviceIndex(), false, true);
inOrderExecInfo->counterValue = counterValue;
inOrderExecInfo->externalHostAllocation = hostAllocation;
inOrderExecInfo->hostAddress = hostAddress;
inOrderExecInfo->deviceAddress = deviceAddress;
inOrderExecInfo->duplicatedHostStorage = true;

View File

@@ -49,7 +49,7 @@ class InOrderExecInfo : public NEO::NonCopyableClass {
InOrderExecInfo() = delete;
static std::shared_ptr<InOrderExecInfo> create(TagNodeBase *deviceCounterNode, TagNodeBase *hostCounterNode, NEO::Device &device, uint32_t partitionCount, bool regularCmdList);
static std::shared_ptr<InOrderExecInfo> createFromExternalAllocation(NEO::Device &device, uint64_t deviceAddress, uint64_t *hostAddress, uint64_t counterValue);
static std::shared_ptr<InOrderExecInfo> createFromExternalAllocation(NEO::Device &device, uint64_t deviceAddress, NEO::GraphicsAllocation *hostAllocation, uint64_t *hostAddress, uint64_t counterValue);
InOrderExecInfo(TagNodeBase *deviceCounterNode, TagNodeBase *hostCounterNode, NEO::MemoryManager &memoryManager, uint32_t partitionCount, uint32_t rootDeviceIndex,
bool regularCmdList, bool atomicDeviceSignalling);
@@ -92,6 +92,7 @@ class InOrderExecInfo : public NEO::NonCopyableClass {
NEO::MemoryManager &memoryManager;
NEO::TagNodeBase *deviceCounterNode = nullptr;
NEO::TagNodeBase *hostCounterNode = nullptr;
NEO::GraphicsAllocation *externalHostAllocation = nullptr;
uint64_t counterValue = 0;
uint64_t lastWaitedCounterValue = 0;

View File

@@ -59,7 +59,7 @@ HWTEST_F(CommandEncoderTests, givenDifferentInputParamsWhenCreatingStandaloneInO
uint64_t *hostAddress = &counterValue;
uint64_t gpuAddress = castToUint64(ptrOffset(&counterValue, 64));
auto inOrderExecInfo = InOrderExecInfo::createFromExternalAllocation(mockDevice, gpuAddress, hostAddress, counterValue);
auto inOrderExecInfo = InOrderExecInfo::createFromExternalAllocation(mockDevice, gpuAddress, nullptr, hostAddress, counterValue);
EXPECT_EQ(counterValue, inOrderExecInfo->getCounterValue());
EXPECT_EQ(hostAddress, inOrderExecInfo->getBaseHostAddress());