Revert "feature: Allow for child-parent synchronization in subgraphs"

This reverts commit 5bd47a0b7d.

Signed-off-by: Compute-Runtime-Validation <compute-runtime-validation@intel.com>
This commit is contained in:
Compute-Runtime-Validation
2025-11-29 02:04:38 +01:00
committed by Compute-Runtime-Automation
parent 6a0de67ca0
commit bf3a0f6083
6 changed files with 133 additions and 223 deletions

View File

@@ -98,16 +98,15 @@ ze_result_t ZE_APICALL zeCommandListEndGraphCaptureExp(ze_command_list_handle_t
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
if ((nullptr == phGraph) && (false == graph->wasPreallocated())) {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
cmdList->getCaptureTarget()->stopCapturing();
if (nullptr == phGraph) {
UNRECOVERABLE_IF(false == graph->wasPreallocated());
cmdList->setCaptureTarget(nullptr);
return ZE_RESULT_SUCCESS;
if (graph->wasPreallocated()) {
cmdList->setCaptureTarget(nullptr);
return ZE_RESULT_SUCCESS;
} else {
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
} else {
*phGraph = graph->toHandle();
cmdList->setCaptureTarget(nullptr);

View File

@@ -682,7 +682,6 @@ TEST_F(GraphInstantiation, GivenSourceGraphThenExecutableIsInstantiatedProperly)
Mock<CommandList> subCmdlist;
subCmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Mock<Event> signalEvents[3];
ze_event_handle_t signalEventsHandles[3]{signalEvents[0].toHandle(), signalEvents[1].toHandle(), signalEvents[2].toHandle()};
Mock<Event> waitEvents[3];
ze_event_handle_t waitEventsList[3] = {waitEvents[0].toHandle(), waitEvents[1].toHandle(), waitEvents[2].toHandle()};
ctx.cmdListsToReturn.push_back(new Mock<CommandList>());
@@ -713,21 +712,16 @@ TEST_F(GraphInstantiation, GivenSourceGraphThenExecutableIsInstantiatedProperly)
EXPECT_EQ(1U, graphCmdList->appendBarrierCalled);
EXPECT_EQ(1U, graphCmdList->appendMemoryCopyCalled);
ctx.cmdListsToReturn.push_back(new Mock<CommandList>());
ctx.cmdListsToReturn.push_back(new Mock<CommandList>());
graphCmdList = ctx.cmdListsToReturn[0];
Graph *srcSubGraph = nullptr;
srcGraph.startCapturingFrom(cmdlist, false);
cmdlist.capture<CaptureApi::zeCommandListAppendBarrier>(cmdListHandle, signalEvents[0].toHandle(), 0U, nullptr);
subCmdlist.capture<CaptureApi::zeCommandListAppendBarrier>(&subCmdlist, signalEvents[2].toHandle(), 1U, &signalEventsHandles[0]);
cmdlist.capture<CaptureApi::zeCommandListAppendBarrier>(cmdListHandle, nullptr, 1U, &signalEventsHandles[2]);
srcSubGraph = subCmdlist.getCaptureTarget();
srcGraph.stopCapturing();
srcGraph.forkTo(subCmdlist, srcSubGraph, signalEvents[0]);
srcGraph.tryJoinOnNextCommand(subCmdlist, signalEvents[2]);
ASSERT_EQ(1U, srcGraph.getSubgraphs().size());
EXPECT_TRUE(srcGraph.getSubgraphs()[0]->isSubGraph());
EXPECT_FALSE(srcGraph.getSubgraphs()[0]->empty());
EXPECT_TRUE(srcGraph.getSubgraphs()[0]->empty());
static_cast<MockGraph *>(srcSubGraph)->captureTargetDesc.hDevice = device->toHandle();
@@ -735,11 +729,11 @@ TEST_F(GraphInstantiation, GivenSourceGraphThenExecutableIsInstantiatedProperly)
execMultiGraph.instantiateFrom(srcGraph, instantiateAsMonolithic);
EXPECT_FALSE(execMultiGraph.isSubGraph());
EXPECT_EQ(3U, graphCmdList->appendBarrierCalled);
EXPECT_EQ(1U, graphCmdList->appendBarrierCalled);
EXPECT_EQ(1U, graphCmdList->appendMemoryCopyCalled);
ASSERT_EQ(1U, execMultiGraph.getSubgraphs().size());
EXPECT_TRUE(execMultiGraph.getSubgraphs()[0]->isSubGraph());
EXPECT_FALSE(execMultiGraph.getSubgraphs()[0]->empty());
EXPECT_TRUE(execMultiGraph.getSubgraphs()[0]->empty());
}
TEST_F(GraphInstantiation, GivenSourceGraphThenExecutableIsInstantiatedWithPreservedOrderOfForkAndJoinCommands) {
@@ -879,68 +873,30 @@ TEST(GraphInstantiationValidation, WhenGraphHasUnjoinedForksThenItIsNotValidForI
MockGraphCmdListWithContext cmdlist{&ctx};
auto cmdListHandle = cmdlist.toHandle();
MockGraphCmdListWithContext childCmdlist{&ctx};
MockGraphCmdListWithContext grandChildCmdlist{&ctx};
Mock<Event> forkEvent;
auto forkEventHandle = forkEvent.toHandle();
Mock<Event> joinEvent;
auto joinEventHandle = joinEvent.toHandle();
{ // correct graph (0->1->0->close)
{ // missing join
Graph srcGraph(&ctx, true);
Graph *srcGraphPtr = &srcGraph;
// lvl 0
srcGraph.startCapturingFrom(cmdlist, false);
cmdlist.setCaptureTarget(&srcGraph);
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, forkEventHandle, 0U, nullptr);
Graph *childGraph = nullptr;
srcGraph.forkTo(childCmdlist, childGraph, forkEvent);
srcGraph.stopCapturing();
EXPECT_FALSE(srcGraph.validForInstantiation());
childCmdlist.setCaptureTarget(nullptr);
}
{ // lvl 1
Graph *childGraph = nullptr;
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(childCmdlist, childGraph, &childCmdlist, joinEventHandle, 1U, &forkEventHandle);
}
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, nullptr, 1U, &joinEventHandle);
{ // correct graph
Graph srcGraph(&ctx, true);
Graph *srcGraphPtr = &srcGraph;
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, forkEventHandle, 0U, nullptr);
Graph *childGraph = nullptr;
srcGraph.forkTo(childCmdlist, childGraph, forkEvent);
srcGraph.tryJoinOnNextCommand(childCmdlist, joinEvent);
srcGraph.stopCapturing();
EXPECT_TRUE(srcGraph.validForInstantiation());
}
{ // missing join lvl (0->1 0->close)
Graph srcGraph(&ctx, true);
Graph *srcGraphPtr = &srcGraph;
// lvl 0
srcGraph.startCapturingFrom(cmdlist, false);
cmdlist.setCaptureTarget(&srcGraph);
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, forkEventHandle, 0U, nullptr);
{ // lvl 1
Graph *childGraph = nullptr;
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(childCmdlist, childGraph, &childCmdlist, joinEventHandle, 1U, &forkEventHandle);
}
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, nullptr, 0U, nullptr);
srcGraph.stopCapturing();
EXPECT_FALSE(srcGraph.validForInstantiation());
}
{ // unjoined work (false join on 1->0) (0->1+! ->0->close)
Graph srcGraph(&ctx, true);
Graph *srcGraphPtr = &srcGraph;
// lvl 0
srcGraph.startCapturingFrom(cmdlist, false);
cmdlist.setCaptureTarget(&srcGraph);
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, forkEventHandle, 0U, nullptr);
{ // lvl 1
Graph *childGraph = nullptr;
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(childCmdlist, childGraph, &childCmdlist, joinEventHandle, 1U, &forkEventHandle);
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(grandChildCmdlist, childGraph, &childCmdlist, nullptr, 0U, nullptr);
}
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, nullptr, 1U, &joinEventHandle);
srcGraph.stopCapturing();
EXPECT_FALSE(srcGraph.validForInstantiation());
}
}
TEST(GraphInstantiationValidation, WhenSubGraphsAreNotValidForInstantiationThenWholeGraphIsNotReadyForInstantiation) {
@@ -956,83 +912,45 @@ TEST(GraphInstantiationValidation, WhenSubGraphsAreNotValidForInstantiationThenW
auto forkEventHandleLvl2 = forkEventLvl2.toHandle();
Mock<Event> joinEvent;
Mock<Event> joinEventLvl2;
auto joinEventHandle = joinEvent.toHandle();
auto joinEventHandleLvl2 = joinEventLvl2.toHandle();
{ // correct graph (0->1->2->1->0->close)
{ // missing join
Graph srcGraph(&ctx, true);
Graph *srcGraphPtr = &srcGraph;
// lvl 0
srcGraph.startCapturingFrom(cmdlist, false);
cmdlist.setCaptureTarget(&srcGraph);
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, forkEventHandle, 0U, nullptr);
Graph *childGraph = nullptr;
srcGraph.forkTo(childCmdlist, childGraph, forkEvent);
{ // lvl 1
Graph *childGraph = nullptr;
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(childCmdlist, childGraph, &childCmdlist, forkEventHandleLvl2, 1U, &forkEventHandle);
{
Graph *grandChildGraph = nullptr;
// lvl 2
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(grandChildCmdlist, grandChildGraph, &childCmdlist, joinEventHandleLvl2, 1U, &forkEventHandleLvl2);
}
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(childCmdlist, childGraph, &childCmdlist, joinEventHandle, 1U, &joinEventHandleLvl2);
{
Graph *grandChildGraph = nullptr;
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(childCmdlist, childGraph, &childCmdlist, forkEventHandleLvl2, 0U, nullptr);
childGraph->forkTo(grandChildCmdlist, grandChildGraph, forkEventLvl2);
grandChildCmdlist.setCaptureTarget(nullptr);
}
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, nullptr, 1U, &joinEventHandle);
srcGraph.tryJoinOnNextCommand(childCmdlist, joinEvent);
srcGraph.stopCapturing();
EXPECT_FALSE(srcGraph.validForInstantiation());
}
{ // correct graph
Graph srcGraph(&ctx, true);
Graph *srcGraphPtr = &srcGraph;
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, forkEventHandle, 0U, nullptr);
Graph *childGraph = nullptr;
srcGraph.forkTo(childCmdlist, childGraph, forkEvent);
{
Graph *grandChildGraph = nullptr;
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(childCmdlist, childGraph, &childCmdlist, forkEventHandleLvl2, 0U, nullptr);
childGraph->forkTo(grandChildCmdlist, grandChildGraph, forkEventLvl2);
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(grandChildCmdlist, grandChildGraph, &grandChildCmdlist, joinEventHandleLvl2, 0U, nullptr);
childGraph->tryJoinOnNextCommand(grandChildCmdlist, joinEventLvl2);
}
srcGraph.tryJoinOnNextCommand(childCmdlist, joinEvent);
srcGraph.stopCapturing();
EXPECT_TRUE(srcGraph.validForInstantiation());
}
{ // missing join lvl 2->1 (0->1->2 1->0->close)
Graph srcGraph(&ctx, true);
Graph *srcGraphPtr = &srcGraph;
// lvl 0
srcGraph.startCapturingFrom(cmdlist, false);
cmdlist.setCaptureTarget(&srcGraph);
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, forkEventHandle, 0U, nullptr);
{ // lvl 1
Graph *childGraph = nullptr;
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(childCmdlist, childGraph, &childCmdlist, forkEventHandleLvl2, 1U, &forkEventHandle);
{
Graph *grandChildGraph = nullptr;
// lvl 2
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(grandChildCmdlist, grandChildGraph, &grandChildCmdlist, nullptr, 1U, &forkEventHandleLvl2);
}
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(childCmdlist, childGraph, &grandChildCmdlist, joinEventHandle, 0U, nullptr);
}
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, nullptr, 1U, &joinEventHandle);
srcGraph.stopCapturing();
EXPECT_FALSE(srcGraph.validForInstantiation());
}
{ // unjoined work (false join on 2->1) (0->1->2->2+!->1->0->close)
Graph srcGraph(&ctx, true);
Graph *srcGraphPtr = &srcGraph;
// lvl 0
srcGraph.startCapturingFrom(cmdlist, false);
cmdlist.setCaptureTarget(&srcGraph);
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, forkEventHandle, 0U, nullptr);
{ // lvl 1
Graph *childGraph = nullptr;
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(childCmdlist, childGraph, &childCmdlist, forkEventHandleLvl2, 1U, &forkEventHandle);
{
Graph *grandChildGraph = nullptr;
// lvl 2
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(grandChildCmdlist, grandChildGraph, &grandChildCmdlist, joinEventHandleLvl2, 1U, &forkEventHandleLvl2);
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(grandChildCmdlist, grandChildGraph, &grandChildCmdlist, nullptr, 0U, nullptr);
}
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(childCmdlist, childGraph, &childCmdlist, joinEventHandle, 1U, &joinEventHandleLvl2);
}
L0::captureCommand<CaptureApi::zeCommandListAppendBarrier>(cmdlist, srcGraphPtr, cmdListHandle, nullptr, 1U, &joinEventHandle);
srcGraph.stopCapturing();
EXPECT_FALSE(srcGraph.validForInstantiation());
}
}
TEST_F(GraphTestInstantiationTest, WhenInstantiatingGraphThenBakeCommandsIntoCommandlists) {
@@ -1770,6 +1688,7 @@ TEST_F(GraphTestCaptureRestrictions, GivenGraphWithUnjoinedForksWhenEndGraphCapt
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, err);
EXPECT_EQ(nullptr, retGraph);
srcSubGraph->stopCapturing();
subCmdlist.setCaptureTarget(nullptr);
srcGraph.stopCapturing();
mainCmdlist.setCaptureTarget(nullptr);

View File

@@ -46,10 +46,9 @@ TEST_F(GraphDotExporterTest, GivenEmptyGraphWhenExportToStringThenContainsDigrap
TEST_F(GraphDotExporterTest, GivenGraphWithSingleCommandWhenExportToStringThenContainsCommandNode) {
Graph testGraph{&ctx, true};
Mock<Event> event;
Mock<CommandList> cmdlist;
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
testGraph.stopCapturing();
@@ -62,7 +61,6 @@ TEST_F(GraphDotExporterTest, GivenGraphWithMultipleCommandsWhenExportToStringThe
Graph testGraph{&ctx, true};
Mock<Event> event;
Mock<CommandList> cmdlist;
testGraph.startCapturingFrom(cmdlist, false);
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
@@ -93,7 +91,7 @@ TEST_F(GraphDotExporterTest, GivenGraphWithCommandWhenWriteNodesThenGeneratesNod
Mock<Event> event;
Mock<CommandList> cmdlist;
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
testGraph.stopCapturing();
@@ -110,7 +108,7 @@ TEST_F(GraphDotExporterTest, GivenGraphWithMultipleCommandsWhenWriteEdgesThenGen
Mock<Event> event;
Mock<CommandList> cmdlist;
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
testGraph.capture<CaptureApi::zeCommandListAppendMemoryCopy>(&cmdlist, nullptr, nullptr, 0U, nullptr, 0U, nullptr);
testGraph.stopCapturing();
@@ -127,7 +125,7 @@ TEST_F(GraphDotExporterTest, GivenGraphWithSingleCommandWhenWriteEdgesThenDoesNo
Mock<Event> event;
Mock<CommandList> cmdlist;
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
testGraph.stopCapturing();
@@ -143,7 +141,7 @@ TEST_F(GraphDotExporterTest, GivenGraphWithCommandWhenGetCommandNodeLabelThenRet
Mock<Event> event;
Mock<CommandList> cmdlist;
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
testGraph.stopCapturing();
@@ -156,7 +154,7 @@ TEST_F(GraphDotExporterTest, GivenDifferentCommandTypesWhenGetCommandNodeAttribu
Mock<Event> event;
Mock<CommandList> cmdlist;
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
testGraph.capture<CaptureApi::zeCommandListAppendMemoryCopy>(&cmdlist, nullptr, nullptr, 0U, nullptr, 0U, nullptr);
testGraph.capture<CaptureApi::zeCommandListAppendSignalEvent>(&cmdlist, &event);
@@ -215,7 +213,6 @@ TEST_F(GraphDotExporterTest, GivenGraphWithSubgraphsWhenWriteSubgraphsThenGenera
mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Mock<CommandList> subCmdList;
subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(mainCmdList, false);
Graph *testGraphPtr = &testGraph;
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr);
@@ -256,7 +253,6 @@ TEST_F(GraphDotExporterTest, GivenGraphWithNestedSubgraphsWhenWriteSubgraphsThen
subCmdList2.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Graph *testGraphPtr = &testGraph;
testGraph.startCapturingFrom(mainCmdList, false);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent1, 0U, nullptr);
Graph *subGraph1 = nullptr;
@@ -302,7 +298,6 @@ TEST_F(GraphDotExporterTest, GivenGraphWithAdjacentSubgraphsWhenWriteSubgraphsTh
subCmdList2.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Graph *testGraphPtr = &testGraph;
testGraph.startCapturingFrom(mainCmdList, false);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent1, 0U, nullptr);
Graph *subGraph1 = nullptr;
@@ -348,23 +343,21 @@ TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexOnEmptyGraphThenReturnsNullopt
TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexWithInvalidSubgraphThenReturnsNullopt) {
Graph testGraph{&ctx, true};
Mock<Event> forkEvent;
auto forkEventHandle = forkEvent.toHandle();
Mock<Event> joinEvent;
auto joinEventHandle = joinEvent.toHandle();
Mock<CommandList> mainCmdList;
mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Mock<CommandList> subCmdList;
subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Graph *testGraphPtr = &testGraph;
testGraph.startCapturingFrom(mainCmdList, false);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr);
Graph *subGraph = nullptr;
captureCommand<CaptureApi::zeCommandListAppendBarrier>(subCmdList, subGraph, &mainCmdList, &joinEvent, 1U, &forkEventHandle);
testGraph.forkTo(subCmdList, subGraph, forkEvent);
ASSERT_NE(subGraph, nullptr);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, nullptr, 1U, &joinEventHandle);
testGraph.tryJoinOnNextCommand(subCmdList, joinEvent);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, nullptr, 0U, nullptr);
testGraph.stopCapturing();
const auto &subGraphs = testGraph.getSubgraphs();
@@ -377,23 +370,21 @@ TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexWithInvalidSubgraphThenReturns
TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexWithValidGraphThenReturnsCorrectIndex) {
Graph testGraph{&ctx, true};
Mock<Event> forkEvent;
auto forkEventHandle = forkEvent.toHandle();
Mock<Event> joinEvent;
auto joinEventHandle = joinEvent.toHandle();
Mock<CommandList> mainCmdList;
mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Mock<CommandList> subCmdList;
subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Graph *testGraphPtr = &testGraph;
testGraph.startCapturingFrom(mainCmdList, false);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr);
Graph *subGraph = nullptr;
captureCommand<CaptureApi::zeCommandListAppendBarrier>(subCmdList, subGraph, &subCmdList, &joinEvent, 1U, &forkEventHandle);
testGraph.forkTo(subCmdList, subGraph, forkEvent);
ASSERT_NE(subGraph, nullptr);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, nullptr, 1U, &joinEventHandle);
testGraph.tryJoinOnNextCommand(subCmdList, joinEvent);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, nullptr, 0U, nullptr);
testGraph.stopCapturing();
const auto &subGraphs = testGraph.getSubgraphs();
@@ -414,23 +405,21 @@ TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexByCommandListOnEmptyGraphThenR
TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexByCommandListWithInvalidCommandListThenReturnsNullopt) {
Graph testGraph{&ctx, true};
Mock<Event> forkEvent;
auto forkEventHandle = forkEvent.toHandle();
Mock<Event> joinEvent;
auto joinEventHandle = joinEvent.toHandle();
Mock<CommandList> mainCmdList;
mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Mock<CommandList> subCmdList;
subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Graph *testGraphPtr = &testGraph;
testGraph.startCapturingFrom(mainCmdList, false);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr);
Graph *subGraph = nullptr;
captureCommand<CaptureApi::zeCommandListAppendBarrier>(subCmdList, subGraph, &mainCmdList, &joinEvent, 1U, &forkEventHandle);
testGraph.forkTo(subCmdList, subGraph, forkEvent);
ASSERT_NE(subGraph, nullptr);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, nullptr, 1U, &joinEventHandle);
testGraph.tryJoinOnNextCommand(subCmdList, joinEvent);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, nullptr, 0U, nullptr);
testGraph.stopCapturing();
const auto &subGraphs = testGraph.getSubgraphs();
@@ -443,23 +432,21 @@ TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexByCommandListWithInvalidComman
TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexByCommandListWithValidCommandListThenReturnsCorrectIndex) {
Graph testGraph{&ctx, true};
Mock<Event> forkEvent;
auto forkEventHandle = forkEvent.toHandle();
Mock<Event> joinEvent;
auto joinEventHandle = joinEvent.toHandle();
Mock<CommandList> mainCmdList;
mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Mock<CommandList> subCmdList;
subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Graph *testGraphPtr = &testGraph;
testGraph.startCapturingFrom(mainCmdList, false);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr);
Graph *subGraph = nullptr;
captureCommand<CaptureApi::zeCommandListAppendBarrier>(subCmdList, subGraph, &subCmdList, &joinEvent, 1U, &forkEventHandle);
testGraph.forkTo(subCmdList, subGraph, forkEvent);
ASSERT_NE(subGraph, nullptr);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, nullptr, 1U, &joinEventHandle);
testGraph.tryJoinOnNextCommand(subCmdList, joinEvent);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, nullptr, 0U, nullptr);
testGraph.stopCapturing();
const auto &subGraphs = testGraph.getSubgraphs();
@@ -472,7 +459,6 @@ TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexByCommandListWithValidCommandL
TEST_F(GraphDotExporterTest, GivenGraphWithEmptySubgraphWhenWriteForkJoinEdgesThenNoEdges) {
Graph testGraph{&ctx, true};
Mock<Event> forkEvent;
auto forkEventHandle = forkEvent.toHandle();
Mock<Event> joinEvent;
Mock<CommandList> mainCmdList;
mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
@@ -480,12 +466,13 @@ TEST_F(GraphDotExporterTest, GivenGraphWithEmptySubgraphWhenWriteForkJoinEdgesTh
subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Graph *testGraphPtr = &testGraph;
testGraph.startCapturingFrom(mainCmdList, false);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr);
// fork
captureCommand<CaptureApi::zeCommandListAppendBarrier>(subCmdList, testGraphPtr, &mainCmdList, nullptr, 1U, &forkEventHandle);
Graph *subGraph = nullptr;
testGraph.forkTo(subCmdList, subGraph, forkEvent);
ASSERT_NE(subGraph, nullptr);
testGraph.tryJoinOnNextCommand(subCmdList, joinEvent);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, nullptr, 0U, nullptr);
testGraph.stopCapturing();
@@ -509,20 +496,20 @@ TEST_F(GraphDotExporterTest, GivenGraphWithNoJoinedForksWhenWriteForkJoinEdgesTh
TEST_F(GraphDotExporterTest, GivenGraphWithUnjoinedForksWhenWriteUnjoinedForkEdgesThenGeneratesUnjoinedEdges) {
Graph testGraph{&ctx, true};
Mock<Event> forkEvent;
auto forkEventHandle = forkEvent.toHandle();
Mock<CommandList> mainCmdList;
mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Mock<CommandList> subCmdList;
subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Graph *testGraphPtr = &testGraph;
testGraph.startCapturingFrom(mainCmdList, false);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr);
Graph *subGraph = nullptr;
captureCommand<CaptureApi::zeCommandListAppendMemoryCopy>(subCmdList, subGraph, &subCmdList, nullptr, nullptr, 0U, nullptr, 1U, &forkEventHandle);
testGraph.forkTo(subCmdList, subGraph, forkEvent);
ASSERT_NE(subGraph, nullptr);
captureCommand<CaptureApi::zeCommandListAppendMemoryCopy>(subCmdList, subGraph, &subCmdList, nullptr, nullptr, 0U, nullptr, 0U, nullptr);
std::ostringstream dot;
exporter.writeUnjoinedForkEdges(dot, testGraph, 0, 0);
std::string output = dot.str();
@@ -530,6 +517,38 @@ TEST_F(GraphDotExporterTest, GivenGraphWithUnjoinedForksWhenWriteUnjoinedForkEdg
EXPECT_NE(output.find("// Unjoined forks:"), std::string::npos);
EXPECT_NE(output.find("L0_S0_C0 -> L1_S0_C0 [color=red, label=\"unjoined fork\"];"), std::string::npos);
// Prevent double free with unjoined forks
Mock<Event> joinEvent;
testGraph.tryJoinOnNextCommand(subCmdList, joinEvent);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr);
testGraph.stopCapturing();
}
TEST_F(GraphDotExporterTest, GivenGraphWithEmptyUnjoinedSubgraphWhenWriteUnjoinedForkEdgesThenOutputIsEmpty) {
Graph testGraph{&ctx, true};
Mock<Event> forkEvent;
Mock<CommandList> mainCmdList;
mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Mock<CommandList> subCmdList;
subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Graph *testGraphPtr = &testGraph;
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr);
Graph *subGraph = nullptr;
testGraph.forkTo(subCmdList, subGraph, forkEvent);
ASSERT_NE(subGraph, nullptr);
std::ostringstream dot;
exporter.writeUnjoinedForkEdges(dot, testGraph, 0, 0);
std::string output = dot.str();
EXPECT_EQ(output.find("L0_S0_C0 -> L1_S0_C0 [color=red, label=\"unjoined fork\"];"), std::string::npos);
// Prevent double free with unjoined forks
Mock<Event> joinEvent;
testGraph.tryJoinOnNextCommand(subCmdList, joinEvent);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr);
testGraph.stopCapturing();
}
@@ -567,7 +586,7 @@ TEST_F(GraphDotExporterSimpleStyleTest, GivenCommandWhenGetCommandNodeAttributes
Mock<Event> event;
Mock<CommandList> cmdlist;
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
testGraph.stopCapturing();
@@ -579,7 +598,7 @@ TEST_F(GraphDotExporterSimpleStyleTest, GivenCommandWhenGetCommandNodeLabelThenL
Mock<Event> event;
Mock<CommandList> cmdlist;
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
testGraph.stopCapturing();
@@ -618,7 +637,6 @@ TEST_F(GraphDotExporterSimpleStyleTest, GivenKernelCommandWhenGetCommandNodeLabe
ASSERT_EQ(ZE_RESULT_SUCCESS, result);
ze_group_count_t launchArgs = {1, 1, 1};
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendLaunchKernel>(&cmdlist, &kernel, &launchArgs, nullptr, 0U, nullptr);
testGraph.stopCapturing();
@@ -636,7 +654,6 @@ TEST_F(GraphDotExporterSimpleStyleTest, GivenGraphWithSubgraphsWhenWriteSubgraph
subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate;
Graph *testGraphPtr = &testGraph;
testGraph.startCapturingFrom(mainCmdList, false);
captureCommand<CaptureApi::zeCommandListAppendBarrier>(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr);
Graph *subGraph = nullptr;
@@ -1355,7 +1372,7 @@ TEST_F(GraphDumpApiTest, GivenValidParametersWithNullpNextWhenZeGraphDumpContent
Mock<Event> event;
Mock<CommandList> cmdlist;
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
testGraph.stopCapturing();
@@ -1379,7 +1396,6 @@ TEST_F(GraphDumpApiTest, GivenSimpleStyleExtensionWhenZeGraphDumpContentsExpIsCa
Mock<CommandList> cmdlist;
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
testGraph.stopCapturing();
@@ -1407,7 +1423,7 @@ TEST_F(GraphDumpApiTest, GivenDetailedStyleExtensionWhenZeGraphDumpContentsExpIs
Mock<Event> event;
Mock<CommandList> cmdlist;
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
testGraph.stopCapturing();
@@ -1432,7 +1448,7 @@ TEST_F(GraphDumpApiTest, GivenInvalidStyleExtensionWhenZeGraphDumpContentsExpIsC
Mock<Event> event;
Mock<CommandList> cmdlist;
cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate;
testGraph.startCapturingFrom(cmdlist, false);
testGraph.capture<CaptureApi::zeCommandListAppendBarrier>(&cmdlist, &event, 0U, nullptr);
testGraph.stopCapturing();

View File

@@ -32,7 +32,6 @@ Graph::~Graph() {
void Graph::startCapturingFrom(L0::CommandList &captureSrc, bool isSubGraph) {
this->captureSrc = &captureSrc;
this->captureSrc->setCaptureTarget(this);
captureSrc.getDeviceHandle(&this->captureTargetDesc.hDevice);
this->captureTargetDesc.desc.stype = ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC;
this->captureTargetDesc.desc.pNext = nullptr;
@@ -44,33 +43,9 @@ void Graph::startCapturingFrom(L0::CommandList &captureSrc, bool isSubGraph) {
}
void Graph::stopCapturing() {
this->wasCapturingStopped = true;
if (nullptr == this->captureSrc) {
return;
}
this->unregisterSignallingEvents();
this->captureSrc->releaseCaptureTarget();
this->captureSrc = nullptr;
StackVec<std::pair<L0::CommandList *, ForkInfo>, 1> neverJoinedForks; // should stay empty for valid graphs
for (auto &unjFork : this->unjoinedForks) {
auto forkCmdId = unjFork.second.forkCommandId;
auto potentialJoin = this->potentialJoins.find(forkCmdId);
if (this->potentialJoins.end() == potentialJoin) {
neverJoinedForks.push_back({unjFork.first, unjFork.second});
continue; // no join-like sequences found
}
auto potentialJoinEvent = static_cast<L0::Event *>(potentialJoin->second.joinEvent);
auto potentialJoinSignalId = potentialJoin->second.forkDestiny->recordedSignals.find(potentialJoinEvent)->second;
if (false == potentialJoin->second.forkDestiny->isLastCommand(potentialJoinSignalId)) {
neverJoinedForks.push_back({unjFork.first, unjFork.second});
continue; // join-like sequence found but is succeeded by unjoined commands
}
}
this->unjoinedForks.clear();
this->unjoinedForks.insert(neverJoinedForks.begin(), neverJoinedForks.end());
for (auto &subGraph : subGraphs) {
subGraph->stopCapturing();
}
this->wasCapturingStopped = true;
}
void Graph::tryJoinOnNextCommand(L0::CommandList &childCmdList, L0::Event &joinEvent) {
@@ -84,13 +59,18 @@ void Graph::tryJoinOnNextCommand(L0::CommandList &childCmdList, L0::Event &joinE
forkJoinInfo.forkEvent = forkInfo->second.forkEvent;
forkJoinInfo.joinCommandId = static_cast<CapturedCommandId>(this->commands.size());
forkJoinInfo.joinEvent = &joinEvent;
forkJoinInfo.forkDestiny = childCmdList.getCaptureTarget();
this->potentialJoins[forkInfo->second.forkCommandId] = forkJoinInfo;
forkJoinInfo.forkDestiny = childCmdList.releaseCaptureTarget();
forkJoinInfo.forkDestiny->stopCapturing();
this->joinedForks[forkInfo->second.forkCommandId] = forkJoinInfo;
this->unjoinedForks.erase(forkInfo);
}
void Graph::forkTo(L0::CommandList &childCmdList, Graph *&child, L0::Event &forkEvent) {
UNRECOVERABLE_IF(child || childCmdList.getCaptureTarget()); // should not be capturing already
child = new Graph(this->ctx, false);
ze_context_handle_t ctx = nullptr;
childCmdList.getContextHandle(&ctx);
child = new Graph(L0::Context::fromHandle(ctx), false);
child->startCapturingFrom(childCmdList, true);
childCmdList.setCaptureTarget(child);
this->subGraphs.push_back(child);

View File

@@ -108,7 +108,7 @@ struct Graph : _ze_graph_handle_t {
}
const std::unordered_map<CapturedCommandId, ForkJoinInfo> &getJoinedForks() const {
return potentialJoins;
return joinedForks;
}
const std::unordered_map<L0::CommandList *, ForkInfo> &getUnjoinedForks() const {
@@ -116,8 +116,8 @@ struct Graph : _ze_graph_handle_t {
}
Graph *getJoinedForkTarget(CapturedCommandId cmdId) {
auto it = potentialJoins.find(cmdId);
if (potentialJoins.end() == it) {
auto it = joinedForks.find(cmdId);
if (joinedForks.end() == it) {
return nullptr;
}
return it->second.forkDestiny;
@@ -179,10 +179,6 @@ struct Graph : _ze_graph_handle_t {
return externalStorage;
}
bool isLastCommand(CapturedCommandId commandId) const {
return commandId + 1 == commands.size();
}
protected:
void unregisterSignallingEvents();
@@ -194,7 +190,7 @@ struct Graph : _ze_graph_handle_t {
std::unordered_map<L0::Event *, CapturedCommandId> recordedSignals;
std::unordered_map<L0::CommandList *, ForkInfo> unjoinedForks;
std::unordered_map<CapturedCommandId, ForkJoinInfo> potentialJoins;
std::unordered_map<CapturedCommandId, ForkJoinInfo> joinedForks;
L0::CommandList *captureSrc = nullptr;
L0::CommandList *executionTarget = nullptr;

View File

@@ -117,15 +117,15 @@ void GraphDotExporter::writeSequentialEdges(std::ostringstream &dot, const Graph
void GraphDotExporter::writeForkJoinEdges(std::ostringstream &dot, const Graph &graph, uint32_t level, uint32_t subgraphId) const {
const std::string indent(static_cast<size_t>(level + 1) * 2, ' ');
const auto &potentialJoins = graph.getJoinedForks();
const auto &joinedForks = graph.getJoinedForks();
const auto &subGraphs = graph.getSubgraphs();
if (!potentialJoins.empty()) {
if (!joinedForks.empty()) {
dot << "\n"
<< indent << "// Fork/Join edges:\n";
}
for (const auto &[forkCmdId, forkJoinInfo] : potentialJoins) {
for (const auto &[forkCmdId, forkJoinInfo] : joinedForks) {
const auto subgraphIndex = findSubgraphIndex(subGraphs, forkJoinInfo.forkDestiny);
if (subgraphIndex && !forkJoinInfo.forkDestiny->getCapturedCommands().empty()) {
const auto &subgraphCommands = forkJoinInfo.forkDestiny->getCapturedCommands();