Skip to content

Commit

Permalink
Add support for cooperative kernels to immediate command lists
Browse files Browse the repository at this point in the history
Signed-off-by: Zbigniew Zdanowicz <[email protected]>
  • Loading branch information
zzdanowicz authored and Compute-Runtime-Automation committed Sep 26, 2022
1 parent af3dd28 commit fc72de1
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 11 deletions.
4 changes: 2 additions & 2 deletions level_zero/core/source/cmdlist/cmdlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,9 +99,9 @@ struct CommandList : _ze_command_list_handle_t {
const CmdListKernelLaunchParams &launchParams) = 0;
virtual ze_result_t appendLaunchCooperativeKernel(ze_kernel_handle_t kernelHandle,
const ze_group_count_t *launchKernelArgs,
ze_event_handle_t hSignalEvent,
ze_event_handle_t signalEvent,
uint32_t numWaitEvents,
ze_event_handle_t *phWaitEvents) = 0;
ze_event_handle_t *waitEventHandles) = 0;
virtual ze_result_t appendLaunchKernelIndirect(ze_kernel_handle_t kernelHandle,
const ze_group_count_t *pDispatchArgumentsBuffer,
ze_event_handle_t hEvent, uint32_t numWaitEvents,
Expand Down
4 changes: 2 additions & 2 deletions level_zero/core/source/cmdlist/cmdlist_hw.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ struct CommandListCoreFamily : CommandListImp {
const CmdListKernelLaunchParams &launchParams) override;
ze_result_t appendLaunchCooperativeKernel(ze_kernel_handle_t kernelHandle,
const ze_group_count_t *launchKernelArgs,
ze_event_handle_t hSignalEvent,
ze_event_handle_t signalEvent,
uint32_t numWaitEvents,
ze_event_handle_t *phWaitEvents) override;
ze_event_handle_t *waitEventHandles) override;
ze_result_t appendLaunchKernelIndirect(ze_kernel_handle_t kernelHandle,
const ze_group_count_t *pDispatchArgumentsBuffer,
ze_event_handle_t hEvent, uint32_t numWaitEvents,
Expand Down
10 changes: 5 additions & 5 deletions level_zero/core/source/cmdlist/cmdlist_hw.inl
Original file line number Diff line number Diff line change
Expand Up @@ -253,18 +253,18 @@ ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendLaunchKernel(ze_kernel_h
template <GFXCORE_FAMILY gfxCoreFamily>
ze_result_t CommandListCoreFamily<gfxCoreFamily>::appendLaunchCooperativeKernel(ze_kernel_handle_t kernelHandle,
const ze_group_count_t *launchKernelArgs,
ze_event_handle_t hSignalEvent,
ze_event_handle_t signalEvent,
uint32_t numWaitEvents,
ze_event_handle_t *phWaitEvents) {
ze_event_handle_t *waitEventHandles) {

ze_result_t ret = addEventsToCmdList(numWaitEvents, phWaitEvents);
ze_result_t ret = addEventsToCmdList(numWaitEvents, waitEventHandles);
if (ret) {
return ret;
}

Event *event = nullptr;
if (hSignalEvent) {
event = Event::fromHandle(hSignalEvent);
if (signalEvent) {
event = Event::fromHandle(signalEvent);
}

CmdListKernelLaunchParams launchParams = {};
Expand Down
6 changes: 6 additions & 0 deletions level_zero/core/source/cmdlist/cmdlist_hw_immediate.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,12 @@ struct CommandListCoreFamilyImmediate : public CommandListCoreFamily<gfxCoreFami
uint32_t numWaitEvents,
ze_event_handle_t *phWaitEvents) override;

ze_result_t appendLaunchCooperativeKernel(ze_kernel_handle_t kernelHandle,
const ze_group_count_t *launchKernelArgs,
ze_event_handle_t signalEvent,
uint32_t numWaitEvents,
ze_event_handle_t *waitEventHandles) override;

MOCKABLE_VIRTUAL ze_result_t executeCommandListImmediateWithFlushTask(bool performMigration);

void checkAvailableSpace();
Expand Down
13 changes: 13 additions & 0 deletions level_zero/core/source/cmdlist/cmdlist_hw_immediate.inl
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,19 @@ ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendMemoryRangesBar
return flushImmediate(ret, true);
}

template <GFXCORE_FAMILY gfxCoreFamily>
ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::appendLaunchCooperativeKernel(ze_kernel_handle_t kernelHandle,
const ze_group_count_t *launchKernelArgs,
ze_event_handle_t signalEvent,
uint32_t numWaitEvents,
ze_event_handle_t *waitEventHandles) {
if (this->isFlushTaskSubmissionEnabled) {
checkAvailableSpace();
}
auto ret = CommandListCoreFamily<gfxCoreFamily>::appendLaunchCooperativeKernel(kernelHandle, launchKernelArgs, signalEvent, numWaitEvents, waitEventHandles);
return flushImmediate(ret, true);
}

template <GFXCORE_FAMILY gfxCoreFamily>
ze_result_t CommandListCoreFamilyImmediate<gfxCoreFamily>::flushImmediate(ze_result_t inputRet, bool performMigration) {
if (inputRet == ZE_RESULT_SUCCESS) {
Expand Down
4 changes: 2 additions & 2 deletions level_zero/core/test/unit_tests/mocks/mock_cmdlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,9 @@ struct MockCommandList : public CommandList {
ADDMETHOD_NOBASE(appendLaunchCooperativeKernel, ze_result_t, ZE_RESULT_SUCCESS,
(ze_kernel_handle_t kernelHandle,
const ze_group_count_t *launchKernelArgs,
ze_event_handle_t hSignalEvent,
ze_event_handle_t signalEvent,
uint32_t numWaitEvents,
ze_event_handle_t *phWaitEvents));
ze_event_handle_t *waitEventHandles));

ADDMETHOD_NOBASE(appendLaunchKernelIndirect, ze_result_t, ZE_RESULT_SUCCESS,
(ze_kernel_handle_t kernelHandle,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -784,5 +784,41 @@ HWTEST_F(CommandListAppendLaunchKernel, givenInvalidEventListWhenAppendLaunchCoo
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, returnValue);
}

HWTEST2_F(CommandListAppendLaunchKernel, givenImmediateCommandListWhenAppendLaunchCooperativeKernelUsingFlushTaskThenExpectCorrectExecuteCall, IsAtLeastSkl) {
createKernel();

MockCommandListImmediateHw<gfxCoreFamily> cmdList;
cmdList.isFlushTaskSubmissionEnabled = true;
cmdList.cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
cmdList.csr = device->getNEODevice()->getDefaultEngine().commandStreamReceiver;
cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u);

ze_group_count_t groupCount{1, 1, 1};
ze_result_t returnValue;

returnValue = cmdList.appendLaunchCooperativeKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr);
EXPECT_EQ(0u, cmdList.executeCommandListImmediateCalledCount);
EXPECT_EQ(1u, cmdList.executeCommandListImmediateWithFlushTaskCalledCount);
EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
}

HWTEST2_F(CommandListAppendLaunchKernel, givenImmediateCommandListWhenAppendLaunchCooperativeKernelNotUsingFlushTaskThenExpectCorrectExecuteCall, IsAtLeastSkl) {
createKernel();

MockCommandListImmediateHw<gfxCoreFamily> cmdList;
cmdList.isFlushTaskSubmissionEnabled = false;
cmdList.cmdListType = CommandList::CommandListType::TYPE_IMMEDIATE;
cmdList.csr = device->getNEODevice()->getDefaultEngine().commandStreamReceiver;
cmdList.initialize(device, NEO::EngineGroupType::RenderCompute, 0u);

ze_group_count_t groupCount{1, 1, 1};
ze_result_t returnValue;

returnValue = cmdList.appendLaunchCooperativeKernel(kernel->toHandle(), &groupCount, nullptr, 0, nullptr);
EXPECT_EQ(1u, cmdList.executeCommandListImmediateCalledCount);
EXPECT_EQ(0u, cmdList.executeCommandListImmediateWithFlushTaskCalledCount);
EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
}

} // namespace ult
} // namespace L0

0 comments on commit fc72de1

Please sign in to comment.