diff --git a/level_zero/api/core/ze_barrier_api_entrypoints.h b/level_zero/api/core/ze_barrier_api_entrypoints.h index 0b67bd1487..6986745f9b 100644 --- a/level_zero/api/core/ze_barrier_api_entrypoints.h +++ b/level_zero/api/core/ze_barrier_api_entrypoints.h @@ -11,6 +11,8 @@ #include "level_zero/core/source/device/device.h" #include +#include "graph_captured_apis.h" + namespace L0 { ze_result_t zeCommandListAppendBarrier( ze_command_list_handle_t hCommandList, diff --git a/level_zero/api/core/ze_cmdlist_api_entrypoints.h b/level_zero/api/core/ze_cmdlist_api_entrypoints.h index 88e09f9b15..ea3796e3f5 100644 --- a/level_zero/api/core/ze_cmdlist_api_entrypoints.h +++ b/level_zero/api/core/ze_cmdlist_api_entrypoints.h @@ -12,6 +12,8 @@ #include "level_zero/core/source/context/context.h" #include +#include "graph_captured_apis.h" + namespace L0 { ze_result_t zeCommandListCreate( ze_context_handle_t hContext, diff --git a/level_zero/api/core/ze_copy_api_entrypoints.h b/level_zero/api/core/ze_copy_api_entrypoints.h index 25365a6c32..acb170024e 100644 --- a/level_zero/api/core/ze_copy_api_entrypoints.h +++ b/level_zero/api/core/ze_copy_api_entrypoints.h @@ -13,6 +13,8 @@ #include "level_zero/core/source/cmdlist/cmdlist_memory_copy_params.h" #include +#include "graph_captured_apis.h" + namespace L0 { ze_result_t zeCommandListAppendMemoryCopy( ze_command_list_handle_t hCommandList, diff --git a/level_zero/api/core/ze_event_api_entrypoints.h b/level_zero/api/core/ze_event_api_entrypoints.h index 21aea72e27..631c85ebd2 100644 --- a/level_zero/api/core/ze_event_api_entrypoints.h +++ b/level_zero/api/core/ze_event_api_entrypoints.h @@ -10,6 +10,8 @@ #include "level_zero/core/source/event/event.h" #include +#include "graph_captured_apis.h" + namespace L0 { ze_result_t zeEventPoolCreate( ze_context_handle_t hContext, diff --git a/level_zero/api/core/ze_module_api_entrypoints.h b/level_zero/api/core/ze_module_api_entrypoints.h index e31332d44a..ced66622c1 100644 --- a/level_zero/api/core/ze_module_api_entrypoints.h +++ b/level_zero/api/core/ze_module_api_entrypoints.h @@ -14,6 +14,8 @@ #include "level_zero/core/source/module/module_build_log.h" #include +#include "graph_captured_apis.h" + namespace L0 { ze_result_t zeModuleCreate( ze_context_handle_t hContext, diff --git a/level_zero/core/source/cmdlist/cmdlist.h b/level_zero/core/source/cmdlist/cmdlist.h index b4f3778c4a..f23fa041e9 100644 --- a/level_zero/core/source/cmdlist/cmdlist.h +++ b/level_zero/core/source/cmdlist/cmdlist.h @@ -493,7 +493,8 @@ struct CommandList : _ze_command_list_handle_t { template ze_result_t capture(TArgs... apiArgs) { - return L0::captureCommand(*this, this->captureTarget, apiArgs...); + return this->isImmediateType() ? L0::captureCommand(*this, this->captureTarget, apiArgs...) + : ZE_RESULT_ERROR_NOT_AVAILABLE; } inline bool getIsWalkerWithProfilingEnqueued() { diff --git a/level_zero/core/source/event/event.h b/level_zero/core/source/event/event.h index 6889a2bcd2..9e6ee02233 100644 --- a/level_zero/core/source/event/event.h +++ b/level_zero/core/source/event/event.h @@ -353,7 +353,7 @@ struct Event : _ze_event_handle_t { static bool isAggregatedEvent(const Event *event) { return (event && event->getInOrderIncrementValue(1) > 0); } - CommandList *getRecordedSignalFrom() const { + MOCKABLE_VIRTUAL CommandList *getRecordedSignalFrom() const { return this->recordedSignalFrom; } diff --git a/level_zero/core/test/unit_tests/experimental/test_graph.cpp b/level_zero/core/test/unit_tests/experimental/test_graph.cpp index 7325df5e6e..4b91616627 100644 --- a/level_zero/core/test/unit_tests/experimental/test_graph.cpp +++ b/level_zero/core/test/unit_tests/experimental/test_graph.cpp @@ -90,10 +90,42 @@ TEST(GraphTestApiCreate, GivenInvalidGraphThenGraphDestroyReturnsError) { EXPECT_NE(ZE_RESULT_SUCCESS, err); } +TEST(GraphTestApiCaptureBeginEnd, GivenGraphsEnabledWhenCapturingCmdlistThenItWorksForImmediateAndReturnsEarlyForRegular) { + GraphsCleanupGuard graphCleanup; + + struct MyMockEvent : public Mock { + CommandList *getRecordedSignalFrom() const override { + getRecordedSignalFromCalled = true; + return nullptr; + } + mutable bool getRecordedSignalFromCalled = false; + } event; + auto hEvent = event.toHandle(); + + L0::Graph *pGraph = nullptr; + Mock mockCmdList; + mockCmdList.setCaptureTarget(pGraph); + auto hCmdList = mockCmdList.toHandle(); + auto &cmdList = static_cast::BaseClass &>(mockCmdList); + + processUsesGraphs.store(true); + EXPECT_TRUE(areGraphsEnabled()); + EXPECT_FALSE(cmdList.isImmediateType()); + auto ret1 = cmdList.capture(hCmdList, nullptr, 1U, &hEvent); + EXPECT_EQ(ret1, ZE_RESULT_ERROR_NOT_AVAILABLE); + EXPECT_FALSE(event.getRecordedSignalFromCalled); + + mockCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; + auto ret2 = cmdList.capture(hCmdList, nullptr, 1U, &hEvent); + EXPECT_EQ(ret2, ZE_RESULT_ERROR_NOT_AVAILABLE); + EXPECT_TRUE(event.getRecordedSignalFromCalled); +} + TEST(GraphTestApiCaptureBeginEnd, GivenNonNullPNextThenGraphBeginCaptureReturnsError) { GraphsCleanupGuard graphCleanup; Mock ctx; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; auto cmdListHandle = cmdlist.toHandle(); ze_base_desc_t ext = {}; ext.stype = ZE_STRUCTURE_TYPE_MUTABLE_GRAPH_ARGUMENT_EXP_DESC; @@ -471,6 +503,7 @@ TEST_F(GraphTestApiSubmit, GivenInvalidCmdListThenGraphAppendReturnsError) { TEST_F(GraphTestApiSubmit, GivenInvalidGraphThenGraphAppendReturnsError) { GraphsCleanupGuard graphCleanup; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; auto cmdListHandle = cmdlist.toHandle(); auto err = zeCommandListAppendGraphExp(cmdListHandle, nullptr, nullptr, nullptr, 0, nullptr); @@ -615,6 +648,7 @@ TEST(GraphForks, GivenNullEventThenRecordHandleSignaleEventDoesNothing) { }; Mock ctx; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; MockGraph graph{&ctx, true}; recordHandleSignalEventFromPreviousCommand(cmdlist, graph, nullptr); EXPECT_TRUE(graph.recordedSignals.empty()); @@ -628,6 +662,7 @@ TEST(GraphForks, GivenRegularEventDependencyThenCommandlistDoesNotStartRecording Mock regularEvent; ze_event_handle_t regularEventHandle = regularEvent.toHandle(); Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; auto cmdListHandle = cmdlist.toHandle(); auto err = zeCommandListAppendWaitOnEvents(cmdListHandle, 1, ®ularEventHandle); EXPECT_EQ(ZE_RESULT_SUCCESS, err); @@ -639,8 +674,10 @@ TEST_F(GraphInstantiation, GivenSourceGraphThenExecutableIsInstantiatedProperly) MockGraphContextReturningSpecificCmdList ctx; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; auto cmdListHandle = cmdlist.toHandle(); Mock subCmdlist; + subCmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock signalEvents[3]; Mock waitEvents[3]; ze_event_handle_t waitEventsList[3] = {waitEvents[0].toHandle(), waitEvents[1].toHandle(), waitEvents[2].toHandle()}; @@ -709,8 +746,12 @@ TEST_F(GraphInstantiation, GivenSourceGraphThenExecutableIsInstantiatedWithPrese }; struct MockCmdListCheckSequence : Mock { + using WhiteBox<::L0::CommandListImp>::cmdListType; + std::vector &sequenceContainer; - MockCmdListCheckSequence(std::vector &sequenceContainer) : sequenceContainer(sequenceContainer) {} + MockCmdListCheckSequence(std::vector &sequenceContainer) : sequenceContainer(sequenceContainer) { + cmdListType = ::L0::CommandList::CommandListType::typeImmediate; + } ze_result_t appendBarrier(ze_event_handle_t hSignalEvent, uint32_t numWaitEvents, @@ -722,8 +763,10 @@ TEST_F(GraphInstantiation, GivenSourceGraphThenExecutableIsInstantiatedWithPrese MockGraphContextReturningSpecificCmdList ctx; MockGraphCmdListWithContext cmdlist{&ctx}; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; auto cmdListHandle = cmdlist.toHandle(); MockGraphCmdListWithContext subCmdlist{&ctx}; + subCmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; auto subCmdListHandle = subCmdlist.toHandle(); Mock forkEvent; Mock joinEvent; @@ -1357,6 +1400,7 @@ TEST_F(GraphExecution, GivenExecutableGraphWhenSubmittingItToCommandListThenAppe MockGraphContextReturningSpecificCmdList ctx; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; auto cmdListHandle = cmdlist.toHandle(); ctx.cmdListsToReturn.push_back(new Mock()); diff --git a/level_zero/core/test/unit_tests/experimental/test_graph.h b/level_zero/core/test/unit_tests/experimental/test_graph.h index 9f67ac6f71..13bcc81b26 100644 --- a/level_zero/core/test/unit_tests/experimental/test_graph.h +++ b/level_zero/core/test/unit_tests/experimental/test_graph.h @@ -30,7 +30,11 @@ struct GraphsCleanupGuard { }; struct MockGraphCmdListWithContext : Mock { - MockGraphCmdListWithContext(L0::Context *ctx) : ctx(ctx) {} + using WhiteBox<::L0::CommandListImp>::cmdListType; + + MockGraphCmdListWithContext(L0::Context *ctx) : ctx(ctx) { + cmdListType = ::L0::CommandList::CommandListType::typeImmediate; + } ze_result_t getContextHandle(ze_context_handle_t *phContext) override { *phContext = ctx; return ZE_RESULT_SUCCESS; diff --git a/level_zero/core/test/unit_tests/experimental/test_graph_export.cpp b/level_zero/core/test/unit_tests/experimental/test_graph_export.cpp index 33e672381a..3c59ce28ff 100644 --- a/level_zero/core/test/unit_tests/experimental/test_graph_export.cpp +++ b/level_zero/core/test/unit_tests/experimental/test_graph_export.cpp @@ -46,6 +46,7 @@ TEST_F(GraphDotExporterTest, GivenGraphWithSingleCommandWhenExportToStringThenCo Graph testGraph{&ctx, true}; Mock event; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; testGraph.capture(&cmdlist, &event, 0U, nullptr); testGraph.stopCapturing(); @@ -59,6 +60,7 @@ TEST_F(GraphDotExporterTest, GivenGraphWithMultipleCommandsWhenExportToStringThe Graph testGraph{&ctx, true}; Mock event; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; testGraph.capture(&cmdlist, &event, 0U, nullptr); testGraph.capture(&cmdlist, nullptr, nullptr, 0U, nullptr, 0U, nullptr); @@ -87,6 +89,7 @@ TEST_F(GraphDotExporterTest, GivenGraphWithCommandWhenWriteNodesThenGeneratesNod Graph testGraph{&ctx, true}; Mock event; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; testGraph.capture(&cmdlist, &event, 0U, nullptr); testGraph.stopCapturing(); @@ -103,6 +106,7 @@ TEST_F(GraphDotExporterTest, GivenGraphWithMultipleCommandsWhenWriteEdgesThenGen Graph testGraph{&ctx, true}; Mock event; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; testGraph.capture(&cmdlist, &event, 0U, nullptr); testGraph.capture(&cmdlist, nullptr, nullptr, 0U, nullptr, 0U, nullptr); @@ -119,6 +123,7 @@ TEST_F(GraphDotExporterTest, GivenGraphWithCommandWhenGetCommandNodeLabelThenRet Graph testGraph{&ctx, true}; Mock event; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; testGraph.capture(&cmdlist, &event, 0U, nullptr); testGraph.stopCapturing(); @@ -131,6 +136,7 @@ TEST_F(GraphDotExporterTest, GivenDifferentCommandTypesWhenGetCommandNodeAttribu Graph testGraph{&ctx, true}; Mock event; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; testGraph.capture(&cmdlist, &event, 0U, nullptr); testGraph.capture(&cmdlist, nullptr, nullptr, 0U, nullptr, 0U, nullptr); @@ -187,7 +193,9 @@ TEST_F(GraphDotExporterTest, GivenGraphWithSubgraphsWhenWriteSubgraphsThenGenera Mock forkEvent; Mock joinEvent; Mock mainCmdList; + mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList; + subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Graph *testGraphPtr = &testGraph; captureCommand(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr); @@ -221,8 +229,11 @@ TEST_F(GraphDotExporterTest, GivenGraphWithNestedSubgraphsWhenWriteSubgraphsThen Mock joinEvent1; Mock joinEvent2; Mock mainCmdList; + mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList1; + subCmdList1.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList2; + subCmdList2.cmdListType = L0::CommandList::CommandListType::typeImmediate; Graph *testGraphPtr = &testGraph; captureCommand(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent1, 0U, nullptr); @@ -263,8 +274,11 @@ TEST_F(GraphDotExporterTest, GivenGraphWithAdjacentSubgraphsWhenWriteSubgraphsTh Mock joinEvent1; Mock joinEvent2; Mock mainCmdList; + mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList1; + subCmdList1.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList2; + subCmdList2.cmdListType = L0::CommandList::CommandListType::typeImmediate; Graph *testGraphPtr = &testGraph; captureCommand(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent1, 0U, nullptr); @@ -314,7 +328,9 @@ TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexWithInvalidSubgraphThenReturns Mock forkEvent; Mock joinEvent; Mock mainCmdList; + mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList; + subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Graph *testGraphPtr = &testGraph; captureCommand(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr); @@ -339,7 +355,9 @@ TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexWithValidGraphThenReturnsCorre Mock forkEvent; Mock joinEvent; Mock mainCmdList; + mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList; + subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Graph *testGraphPtr = &testGraph; captureCommand(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr); @@ -372,7 +390,9 @@ TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexByCommandListWithInvalidComman Mock forkEvent; Mock joinEvent; Mock mainCmdList; + mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList; + subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Graph *testGraphPtr = &testGraph; captureCommand(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr); @@ -397,7 +417,9 @@ TEST_F(GraphDotExporterTest, WhenFindSubgraphIndexByCommandListWithValidCommandL Mock forkEvent; Mock joinEvent; Mock mainCmdList; + mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList; + subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Graph *testGraphPtr = &testGraph; captureCommand(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr); @@ -422,7 +444,9 @@ TEST_F(GraphDotExporterTest, GivenGraphWithEmptySubgraphWhenWriteForkJoinEdgesTh Mock forkEvent; Mock joinEvent; Mock mainCmdList; + mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList; + subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Graph *testGraphPtr = &testGraph; captureCommand(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr); @@ -446,7 +470,9 @@ TEST_F(GraphDotExporterTest, GivenGraphWithUnjoinedForksWhenWriteUnjoinedForkEdg Graph testGraph{&ctx, true}; Mock forkEvent; Mock mainCmdList; + mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList; + subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Graph *testGraphPtr = &testGraph; captureCommand(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr); @@ -475,7 +501,9 @@ TEST_F(GraphDotExporterTest, GivenGraphWithEmptyUnjoinedSubgraphWhenWriteUnjoine Graph testGraph{&ctx, true}; Mock forkEvent; Mock mainCmdList; + mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList; + subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Graph *testGraphPtr = &testGraph; captureCommand(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr); @@ -520,6 +548,7 @@ TEST_F(GraphDotExporterSimpleStyleTest, GivenCommandWhenGetCommandNodeAttributes Graph testGraph{&ctx, true}; Mock event; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; testGraph.capture(&cmdlist, &event, 0U, nullptr); testGraph.stopCapturing(); @@ -531,6 +560,7 @@ TEST_F(GraphDotExporterSimpleStyleTest, GivenCommandWhenGetCommandNodeLabelThenL Graph testGraph{&ctx, true}; Mock event; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; testGraph.capture(&cmdlist, &event, 0U, nullptr); testGraph.stopCapturing(); @@ -542,6 +572,7 @@ TEST_F(GraphDotExporterSimpleStyleTest, GivenCommandWhenGetCommandNodeLabelThenL TEST_F(GraphDotExporterSimpleStyleTest, GivenKernelCommandWhenGetCommandNodeLabelThenLabelIncludesTypeAndName) { Graph testGraph{&ctx, true}; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; NEO::Device *neoDevice(NEO::MockDevice::createWithNewExecutionEnvironment(NEO::defaultHwInfo.get(), 0)); MockDeviceImp l0Device(neoDevice); @@ -581,7 +612,9 @@ TEST_F(GraphDotExporterSimpleStyleTest, GivenGraphWithSubgraphsWhenWriteSubgraph Mock forkEvent; Mock joinEvent; Mock mainCmdList; + mainCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Mock subCmdList; + subCmdList.cmdListType = L0::CommandList::CommandListType::typeImmediate; Graph *testGraphPtr = &testGraph; captureCommand(mainCmdList, testGraphPtr, &mainCmdList, &forkEvent, 0U, nullptr); @@ -1261,6 +1294,7 @@ TEST_F(GraphDumpApiTest, GivenValidParametersWithNullpNextWhenZeGraphDumpContent Graph testGraph{&ctx, true}; Mock event; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; testGraph.capture(&cmdlist, &event, 0U, nullptr); testGraph.stopCapturing(); @@ -1283,6 +1317,7 @@ TEST_F(GraphDumpApiTest, GivenSimpleStyleExtensionWhenZeGraphDumpContentsExpIsCa Graph testGraph{&ctx, true}; Mock event; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; testGraph.capture(&cmdlist, &event, 0U, nullptr); testGraph.stopCapturing(); @@ -1310,6 +1345,7 @@ TEST_F(GraphDumpApiTest, GivenDetailedStyleExtensionWhenZeGraphDumpContentsExpIs Graph testGraph{&ctx, true}; Mock event; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; testGraph.capture(&cmdlist, &event, 0U, nullptr); testGraph.stopCapturing(); @@ -1334,6 +1370,7 @@ TEST_F(GraphDumpApiTest, GivenInvalidStyleExtensionWhenZeGraphDumpContentsExpIsC Graph testGraph{&ctx, true}; Mock event; Mock cmdlist; + cmdlist.cmdListType = L0::CommandList::CommandListType::typeImmediate; testGraph.capture(&cmdlist, &event, 0U, nullptr); testGraph.stopCapturing();