feature: Add introspection APIs for cmdlist

Added entrypoints for all command-list-related introspection APIs
and implemented corresponding functions in command list.

Modified device to record ordinal when creating command lists.

Related-To: NEO-10265
Signed-off-by: Yoon, Young Jin <young.jin.yoon@intel.com>
This commit is contained in:
Yoon, Young Jin 2024-02-03 12:01:14 +00:00 committed by Compute-Runtime-Automation
parent f6ca565323
commit dac2af299b
8 changed files with 200 additions and 6 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2022 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -64,6 +64,36 @@ ze_result_t zeCommandListAppendQueryKernelTimestamps(
return L0::CommandList::fromHandle(hCommandList)->appendQueryKernelTimestamps(numEvents, phEvents, dstptr, pOffsets, hSignalEvent, numWaitEvents, phWaitEvents);
}
ze_result_t zeCommandListGetDeviceHandle(
ze_command_list_handle_t hCommandList,
ze_device_handle_t *phDevice) {
return L0::CommandList::fromHandle(hCommandList)->getDeviceHandle(phDevice);
}
ze_result_t zeCommandListGetContextHandle(
ze_command_list_handle_t hCommandList,
ze_context_handle_t *phContext) {
return L0::CommandList::fromHandle(hCommandList)->getContextHandle(phContext);
}
ze_result_t zeCommandListGetOrdinal(
ze_command_list_handle_t hCommandList,
uint32_t *pOrdinal) {
return L0::CommandList::fromHandle(hCommandList)->getOrdinal(pOrdinal);
}
ze_result_t zeCommandListImmediateGetIndex(
ze_command_list_handle_t hCommandListImmediate,
uint32_t *pIndex) {
return L0::CommandList::fromHandle(hCommandListImmediate)->getImmediateIndex(pIndex);
}
ze_result_t zeCommandListIsImmediate(
ze_command_list_handle_t hCommandList,
ze_bool_t *pIsImmediate) {
return L0::CommandList::fromHandle(hCommandList)->isImmediate(pIsImmediate);
}
} // namespace L0
extern "C" {
@ -122,4 +152,44 @@ ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListAppendWriteGlobalTimestamp(
numWaitEvents,
phWaitEvents);
}
}
ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListGetDeviceHandle(
ze_command_list_handle_t hCommandList,
ze_device_handle_t *phDevice) {
return L0::zeCommandListGetDeviceHandle(
hCommandList,
phDevice);
}
ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListGetContextHandle(
ze_command_list_handle_t hCommandList,
ze_context_handle_t *phContext) {
return L0::zeCommandListGetContextHandle(
hCommandList,
phContext);
}
ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListGetOrdinal(
ze_command_list_handle_t hCommandList,
uint32_t *pOrdinal) {
return L0::zeCommandListGetOrdinal(
hCommandList,
pOrdinal);
}
ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListImmediateGetIndex(
ze_command_list_handle_t hCommandListImmediate,
uint32_t *pIndex) {
return L0::zeCommandListImmediateGetIndex(
hCommandListImmediate,
pIndex);
}
ZE_APIEXPORT ze_result_t ZE_APICALL zeCommandListIsImmediate(
ze_command_list_handle_t hCommandList,
ze_bool_t *pIsImmediate) {
return L0::zeCommandListIsImmediate(
hCommandList,
pIsImmediate);
}
}

View File

@ -23,6 +23,7 @@
#include <level_zero/zet_api.h>
#include <map>
#include <optional>
#include <unordered_map>
#include <vector>
@ -170,6 +171,12 @@ struct CommandList : _ze_command_list_handle_t {
uint64_t data) = 0;
virtual ze_result_t hostSynchronize(uint64_t timeout) = 0;
virtual ze_result_t getDeviceHandle(ze_device_handle_t *phDevice) = 0;
virtual ze_result_t getContextHandle(ze_context_handle_t *phContext) = 0;
virtual ze_result_t getOrdinal(uint32_t *pOrdinal) = 0;
virtual ze_result_t getImmediateIndex(uint32_t *pIndex) = 0;
virtual ze_result_t isImmediate(ze_bool_t *pIsImmediate) = 0;
static CommandList *create(uint32_t productFamily, Device *device, NEO::EngineGroupType engineGroupType,
ze_command_list_flags_t flags, ze_result_t &resultValue,
bool internalUsage);
@ -188,6 +195,7 @@ struct CommandList : _ze_command_list_handle_t {
return commandListPerThreadScratchSize[slotId];
}
void setOrdinal(uint32_t ord) { ordinal = ord; }
void setCommandListPerThreadScratchSize(uint32_t slotId, uint32_t size) {
UNRECOVERABLE_IF(slotId > 1);
commandListPerThreadScratchSize[slotId] = size;
@ -381,6 +389,7 @@ struct CommandList : _ze_command_list_handle_t {
NEO::PreemptionMode commandListPreemptionMode = NEO::PreemptionMode::Initial;
NEO::EngineGroupType engineGroupType = NEO::EngineGroupType::maxEngineGroups;
NEO::HeapAddressModel cmdListHeapAddressModel = NEO::HeapAddressModel::privateHeaps;
std::optional<uint32_t> ordinal = std::nullopt;
CommandListType cmdListType = CommandListType::typeRegular;
uint32_t commandListPerThreadScratchSize[2]{};

View File

@ -125,6 +125,33 @@ CommandList *CommandList::create(uint32_t productFamily, Device *device, NEO::En
return commandList;
}
ze_result_t CommandListImp::getDeviceHandle(ze_device_handle_t *phDevice) {
*phDevice = getDevice()->toHandle();
return ZE_RESULT_SUCCESS;
}
ze_result_t CommandListImp::getContextHandle(ze_context_handle_t *phContext) {
*phContext = getCmdListContext();
return ZE_RESULT_SUCCESS;
}
ze_result_t CommandListImp::getOrdinal(uint32_t *pOrdinal) {
UNRECOVERABLE_IF(ordinal == std::nullopt);
*pOrdinal = ordinal.value();
return ZE_RESULT_SUCCESS;
}
ze_result_t CommandListImp::getImmediateIndex(uint32_t *pIndex) {
if (isImmediateType()) {
return cmdQImmediate->getIndex(pIndex);
}
return ZE_RESULT_ERROR_INVALID_ARGUMENT;
}
ze_result_t CommandListImp::isImmediate(ze_bool_t *pIsImmediate) {
*pIsImmediate = isImmediateType();
return ZE_RESULT_SUCCESS;
}
CommandList *CommandList::createImmediate(uint32_t productFamily, Device *device,
const ze_command_queue_desc_t *desc,
bool internalUsage, NEO::EngineGroupType engineGroupType,

View File

@ -1,5 +1,5 @@
/*
* Copyright (C) 2020-2023 Intel Corporation
* Copyright (C) 2020-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
@ -26,6 +26,13 @@ struct CommandListImp : public CommandList {
ze_result_t appendMetricQueryBegin(zet_metric_query_handle_t hMetricQuery) override;
ze_result_t appendMetricQueryEnd(zet_metric_query_handle_t hMetricQuery, ze_event_handle_t hSignalEvent,
uint32_t numWaitEvents, ze_event_handle_t *phWaitEvents) override;
ze_result_t getDeviceHandle(ze_device_handle_t *phDevice) override;
ze_result_t getContextHandle(ze_context_handle_t *phContext) override;
ze_result_t getOrdinal(uint32_t *pOrdinal) override;
ze_result_t getImmediateIndex(uint32_t *pIndex) override;
ze_result_t isImmediate(ze_bool_t *pIsImmediate) override;
virtual void appendMultiPartitionPrologue(uint32_t partitionDataSize) = 0;
virtual void appendMultiPartitionEpilogue() = 0;

View File

@ -226,7 +226,9 @@ ze_result_t DeviceImp::createCommandList(const ze_command_list_desc_t *desc,
ze_result_t returnValue = ZE_RESULT_SUCCESS;
auto createCommandList = getCmdListCreateFunc(desc);
*commandList = createCommandList(productFamily, this, engineGroupType, desc->flags, returnValue, false);
if (returnValue == ZE_RESULT_SUCCESS) {
CommandList::fromHandle(*commandList)->setOrdinal(desc->commandQueueGroupOrdinal);
}
return returnValue;
}
@ -238,7 +240,6 @@ ze_result_t DeviceImp::createInternalCommandList(const ze_command_list_desc_t *d
ze_result_t returnValue = ZE_RESULT_SUCCESS;
auto createCommandList = getCmdListCreateFunc(desc);
*commandList = createCommandList(productFamily, this, engineGroupType, desc->flags, returnValue, true);
return returnValue;
}
@ -256,6 +257,9 @@ ze_result_t DeviceImp::createCommandListImmediate(const ze_command_queue_desc_t
auto productFamily = neoDevice->getHardwareInfo().platform.eProductFamily;
ze_result_t returnValue = ZE_RESULT_SUCCESS;
*phCommandList = CommandList::createImmediate(productFamily, this, &commandQueueDesc, false, engineGroupType, returnValue);
if (returnValue == ZE_RESULT_SUCCESS) {
CommandList::fromHandle(*phCommandList)->setOrdinal(desc->ordinal);
}
return returnValue;
}

View File

@ -48,6 +48,10 @@ TEST_F(ContextCommandListCreate, whenCreatingCommandListFromContextThenSuccessIs
EXPECT_EQ(Context::fromHandle(CommandList::fromHandle(hCommandList)->getCmdListContext()), context);
L0::CommandList *commandList = L0::CommandList::fromHandle(hCommandList);
ze_context_handle_t hContext;
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->getContextHandle(&hContext));
EXPECT_EQ(context, hContext);
commandList->destroy();
}
@ -111,7 +115,10 @@ TEST_F(CommandListCreate, whenCommandListIsCreatedThenItIsInitialized) {
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::renderCompute, 0u, returnValue, false));
ASSERT_NE(nullptr, commandList);
ze_device_handle_t hDevice;
EXPECT_EQ(device, commandList->getDevice());
EXPECT_EQ(ZE_RESULT_SUCCESS, commandList->getDeviceHandle(&hDevice));
EXPECT_EQ(device->toHandle(), hDevice);
ASSERT_GT(commandList->getCmdContainer().getCmdBufferAllocations().size(), 0u);
auto numAllocations = 0u;

View File

@ -89,6 +89,15 @@ TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandList
ASSERT_EQ(nullptr, commandList);
}
TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCreateCommandListFromDeviceThenOutOfDeviceMemoryErrorIsReturned) {
ze_command_list_handle_t commandList = nullptr;
ze_command_list_desc_t desc = {ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC};
memoryManager->forceFailureInPrimaryAllocation = true;
auto returnValue = device->createCommandList(&desc, &commandList);
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
ASSERT_EQ(nullptr, commandList);
}
using CommandListCreateNegativeStateBaseAddressTest = Test<CommandListCreateNegativeFixture<1>>;
HWTEST2_F(CommandListCreateNegativeStateBaseAddressTest,

View File

@ -153,6 +153,67 @@ TEST_F(CommandListCreate, givenOrdinalBiggerThanAvailableEnginesWhenCreatingComm
EXPECT_EQ(nullptr, commandList);
}
TEST_F(CommandListCreate, givenCommandListWithValidOrdinalWhenCallingGetOrdinalThenSuccessIsReturned) {
auto availableEngineGroups = neoDevice->getRegularEngineGroups();
ze_command_list_handle_t commandList = nullptr;
for (uint32_t engineGroup = 0; engineGroup < availableEngineGroups.size(); engineGroup++) {
ze_command_list_desc_t desc = {ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC};
desc.commandQueueGroupOrdinal = engineGroup;
auto returnValue = device->createCommandList(&desc, &commandList);
EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
EXPECT_NE(nullptr, commandList);
auto whiteboxCommandList = static_cast<CommandList *>(CommandList::fromHandle(commandList));
uint32_t ordinal = 0;
whiteboxCommandList->getOrdinal(&ordinal);
EXPECT_EQ(engineGroup, ordinal);
whiteboxCommandList->destroy();
}
}
TEST_F(CommandListCreate, givenCommandListWhenCallingImmediateCommandListIndexThenInvalidArgumentIsReturned) {
ze_command_list_desc_t desc = {ZE_STRUCTURE_TYPE_COMMAND_LIST_DESC};
ze_command_list_handle_t commandList = nullptr;
auto returnValue = device->createCommandList(&desc, &commandList);
EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
ASSERT_NE(nullptr, commandList);
auto whiteboxCommandList = static_cast<CommandList *>(CommandList::fromHandle(commandList));
uint32_t index = 4;
ze_bool_t isImmediate = true;
EXPECT_EQ(ZE_RESULT_SUCCESS, whiteboxCommandList->isImmediate(&isImmediate));
EXPECT_FALSE(static_cast<bool>(isImmediate));
EXPECT_EQ(ZE_RESULT_ERROR_INVALID_ARGUMENT, whiteboxCommandList->getImmediateIndex(&index));
EXPECT_EQ(4u, index);
whiteboxCommandList->destroy();
}
TEST_F(CommandListCreate, givenImmediateCommandListWhenCallingImmediateCommandListIndexThenValidIndexIsReturned) {
ze_command_queue_desc_t desc = {ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC};
ze_command_list_handle_t commandList = nullptr;
auto returnValue = device->createCommandListImmediate(&desc, &commandList);
EXPECT_EQ(ZE_RESULT_SUCCESS, returnValue);
ASSERT_NE(nullptr, commandList);
auto whiteboxCommandList = static_cast<CommandList *>(CommandList::fromHandle(commandList));
uint32_t index = 4, cmdQIndex = 2;
ze_bool_t isImmediate = true;
EXPECT_EQ(ZE_RESULT_SUCCESS, whiteboxCommandList->isImmediate(&isImmediate));
EXPECT_TRUE(static_cast<bool>(isImmediate));
EXPECT_EQ(ZE_RESULT_SUCCESS, whiteboxCommandList->getImmediateIndex(&index));
EXPECT_NE(nullptr, whiteboxCommandList->cmdQImmediate);
EXPECT_EQ(ZE_RESULT_SUCCESS, whiteboxCommandList->cmdQImmediate->getIndex(&cmdQIndex));
EXPECT_EQ(cmdQIndex, index);
whiteboxCommandList->destroy();
}
TEST_F(CommandListCreate, givenQueueFlagsWhenCreatingImmediateCommandListThenDontCopyFlags) {
ze_command_queue_desc_t desc = {ZE_STRUCTURE_TYPE_COMMAND_QUEUE_DESC};
desc.flags = ZE_COMMAND_QUEUE_FLAG_EXPLICIT_ONLY;
@ -1921,4 +1982,4 @@ TEST(CommandList, givenContextGroupEnabledWhenCreatingImmediateCommandListThenEa
}
} // namespace ult
} // namespace L0
} // namespace L0