Return "OUT_OF_MEMORY" when gfx alloc on device fails during cmdqueue create

Signed-off-by: Vinod Tipparaju <vinod.tipparaju@intel.com>
This commit is contained in:
Vinod Tipparaju
2020-11-04 15:19:26 +05:30
committed by Compute-Runtime-Automation
parent 4c5ff75371
commit f553e1e514
12 changed files with 215 additions and 55 deletions

View File

@@ -46,13 +46,14 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test {
ASSERT_NE(nullptr, device);
ze_command_queue_desc_t queueDesc = {};
ze_result_t returnValue;
commandQueue = whitebox_cast(CommandQueue::create(productFamily, device,
neoDevice->getDefaultEngine().commandStreamReceiver,
&queueDesc,
false));
false,
returnValue));
ASSERT_NE(nullptr, commandQueue->commandStream);
ze_result_t returnValue;
commandList = CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue);
ASSERT_NE(nullptr, commandList);
}

View File

@@ -48,13 +48,14 @@ struct CommandQueueThreadArbitrationPolicyTests : public ::testing::Test {
ASSERT_NE(nullptr, device);
ze_command_queue_desc_t queueDesc = {};
ze_result_t returnValue;
commandQueue = whitebox_cast(CommandQueue::create(productFamily, device,
neoDevice->getDefaultEngine().commandStreamReceiver,
&queueDesc,
false));
false,
returnValue));
ASSERT_NE(nullptr, commandQueue->commandStream);
ze_result_t returnValue;
commandList = CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue);
ASSERT_NE(nullptr, commandList);
}

View File

@@ -10,6 +10,7 @@
#include "shared/test/unit_test/cmd_parse/gen_cmd_parse.h"
#include "shared/test/unit_test/mocks/mock_graphics_allocation.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "test.h"
#include "level_zero/core/source/builtin/builtin_functions_lib_impl.h"
@@ -1063,5 +1064,72 @@ HWTEST2_F(CommandListCreate, givenHostAllocInMapWhenPtrLowerThanAnyInMapThenNull
commandList->hostPtrMap.clear();
}
struct MemoryManagerCommandListCreateNegativeTest : public NEO::MockMemoryManager {
MemoryManagerCommandListCreateNegativeTest(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MockMemoryManager(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const NEO::AllocationProperties &properties) override {
if (forceFailureInPrimaryAllocation) {
return nullptr;
}
return NEO::MemoryManager::allocateGraphicsMemoryWithProperties(properties);
}
bool forceFailureInPrimaryAllocation = false;
};
struct CommandListCreateNegativeTest : public ::testing::Test {
void SetUp() override {
executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
for (uint32_t i = 0; i < numRootDevices; i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(NEO::defaultHwInfo.get());
}
memoryManager = new MemoryManagerCommandListCreateNegativeTest(*executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
std::vector<std::unique_ptr<NEO::Device>> devices;
for (uint32_t i = 0; i < numRootDevices; i++) {
neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, i);
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
}
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0];
}
void TearDown() override {
}
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr;
MemoryManagerCommandListCreateNegativeTest *memoryManager = nullptr;
const uint32_t numRootDevices = 1u;
};
TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandListCreateThenAppropriateValueIsReturned) {
ze_result_t returnValue;
memoryManager->forceFailureInPrimaryAllocation = true;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue));
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
ASSERT_EQ(nullptr, commandList);
}
TEST_F(CommandListCreateNegativeTest, whenDeviceAllocationFailsDuringCommandListImmediateCreateThenAppropriateValueIsReturned) {
ze_result_t returnValue;
const ze_command_queue_desc_t desc = {};
bool internalEngine = true;
memoryManager->forceFailureInPrimaryAllocation = true;
std::unique_ptr<L0::CommandList> commandList(CommandList::createImmediate(productFamily,
device,
&desc,
internalEngine,
NEO::EngineGroupType::RenderCompute,
returnValue));
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
ASSERT_EQ(nullptr, commandList);
}
} // namespace ult
} // namespace L0

View File

@@ -12,6 +12,7 @@
#include "shared/test/unit_test/mocks/mock_command_stream_receiver.h"
#include "opencl/test/unit_test/libult/ult_command_stream_receiver.h"
#include "opencl/test/unit_test/mocks/mock_memory_manager.h"
#include "test.h"
#include "level_zero/core/source/context/context.h"
@@ -32,11 +33,13 @@ TEST_F(CommandQueueCreate, whenCreatingCommandQueueThenItIsInitialized) {
const ze_command_queue_desc_t desc = {};
auto csr = std::unique_ptr<NEO::CommandStreamReceiver>(neoDevice->createCommandStreamReceiver());
ze_result_t returnValue;
L0::CommandQueue *commandQueue = CommandQueue::create(productFamily,
device,
csr.get(),
&desc,
false);
false,
returnValue);
ASSERT_NE(nullptr, commandQueue);
L0::CommandQueueImp *commandQueueImp = reinterpret_cast<L0::CommandQueueImp *>(commandQueue);
@@ -52,11 +55,13 @@ TEST_F(CommandQueueCreate, whenCreatingCommandQueueWithInvalidProductFamilyThenF
const ze_command_queue_desc_t desc = {};
auto csr = std::unique_ptr<NEO::CommandStreamReceiver>(neoDevice->createCommandStreamReceiver());
ze_result_t returnValue;
L0::CommandQueue *commandQueue = CommandQueue::create(PRODUCT_FAMILY::IGFX_MAX_PRODUCT,
device,
csr.get(),
&desc,
false);
false,
returnValue);
ASSERT_EQ(nullptr, commandQueue);
}
@@ -151,14 +156,15 @@ TEST_F(CommandQueueCreate, givenCmdQueueWithBlitCopyWhenExecutingNonCopyBlitComm
auto csr = std::unique_ptr<NEO::CommandStreamReceiver>(neoDevice->createCommandStreamReceiver());
ze_result_t returnValue;
L0::CommandQueue *commandQueue = CommandQueue::create(productFamily,
device,
csr.get(),
&desc,
true);
true,
returnValue);
ASSERT_NE(nullptr, commandQueue);
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue));
auto commandListHandle = commandList->toHandle();
auto status = commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false);
@@ -172,14 +178,15 @@ TEST_F(CommandQueueCreate, givenCmdQueueWithBlitCopyWhenExecutingCopyBlitCommand
const ze_command_queue_desc_t desc = {};
auto defaultCsr = neoDevice->getDefaultEngine().commandStreamReceiver;
ze_result_t returnValue;
L0::CommandQueue *commandQueue = CommandQueue::create(productFamily,
device,
defaultCsr,
&desc,
true);
true,
returnValue);
ASSERT_NE(nullptr, commandQueue);
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, returnValue));
auto commandListHandle = commandList->toHandle();
auto status = commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false);
@@ -214,14 +221,15 @@ HWTEST_F(CommandQueueCommands, givenCommandQueueWhenExecutingCommandListsThenHar
csr.initializeTagAllocation();
csr.setupContext(*neoDevice->getDefaultEngine().osContext);
ze_result_t returnValue;
L0::CommandQueue *commandQueue = CommandQueue::create(productFamily,
device,
&csr,
&desc,
true);
true,
returnValue);
ASSERT_NE(nullptr, commandQueue);
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, returnValue));
auto commandListHandle = commandList->toHandle();
auto status = commandQueue->executeCommandLists(1, &commandListHandle, nullptr, false);
@@ -250,14 +258,15 @@ HWTEST_F(CommandQueueIndirectAllocations, givenCommandQueueWhenExecutingCommandL
csr.initializeTagAllocation();
csr.setupContext(*neoDevice->getDefaultEngine().osContext);
ze_result_t returnValue;
L0::CommandQueue *commandQueue = CommandQueue::create(productFamily,
device,
&csr,
&desc,
true);
true,
returnValue);
ASSERT_NE(nullptr, commandQueue);
ze_result_t returnValue;
std::unique_ptr<L0::CommandList> commandList(CommandList::create(productFamily, device, NEO::EngineGroupType::Copy, returnValue));
void *deviceAlloc = nullptr;
@@ -488,5 +497,65 @@ HWTEST_F(CommandQueueSynchronizeTest, givenCallToSynchronizeThenCorrectEnableTim
L0::CommandQueue::fromHandle(commandQueue)->destroy();
}
struct MemoryManagerCommandQueueCreateNegativeTest : public NEO::MockMemoryManager {
MemoryManagerCommandQueueCreateNegativeTest(NEO::ExecutionEnvironment &executionEnvironment) : NEO::MockMemoryManager(const_cast<NEO::ExecutionEnvironment &>(executionEnvironment)) {}
NEO::GraphicsAllocation *allocateGraphicsMemoryWithProperties(const NEO::AllocationProperties &properties) override {
if (forceFailureInPrimaryAllocation) {
return nullptr;
}
return NEO::MemoryManager::allocateGraphicsMemoryWithProperties(properties);
}
bool forceFailureInPrimaryAllocation = false;
};
struct CommandQueueCreateNegativeTest : public ::testing::Test {
void SetUp() override {
executionEnvironment = new NEO::ExecutionEnvironment();
executionEnvironment->prepareRootDeviceEnvironments(numRootDevices);
for (uint32_t i = 0; i < numRootDevices; i++) {
executionEnvironment->rootDeviceEnvironments[i]->setHwInfo(NEO::defaultHwInfo.get());
}
memoryManager = new MemoryManagerCommandQueueCreateNegativeTest(*executionEnvironment);
executionEnvironment->memoryManager.reset(memoryManager);
std::vector<std::unique_ptr<NEO::Device>> devices;
for (uint32_t i = 0; i < numRootDevices; i++) {
neoDevice = NEO::MockDevice::create<NEO::MockDevice>(executionEnvironment, i);
devices.push_back(std::unique_ptr<NEO::Device>(neoDevice));
}
driverHandle = std::make_unique<Mock<L0::DriverHandleImp>>();
driverHandle->initialize(std::move(devices));
device = driverHandle->devices[0];
}
void TearDown() override {
}
NEO::ExecutionEnvironment *executionEnvironment = nullptr;
std::unique_ptr<Mock<L0::DriverHandleImp>> driverHandle;
NEO::MockDevice *neoDevice = nullptr;
L0::Device *device = nullptr;
MemoryManagerCommandQueueCreateNegativeTest *memoryManager = nullptr;
const uint32_t numRootDevices = 1u;
};
TEST_F(CommandQueueCreateNegativeTest, whenDeviceAllocationFailsDuringCommandQueueCreateThenAppropriateValueIsReturned) {
const ze_command_queue_desc_t desc = {};
auto csr = std::unique_ptr<NEO::CommandStreamReceiver>(neoDevice->createCommandStreamReceiver());
memoryManager->forceFailureInPrimaryAllocation = true;
ze_result_t returnValue;
L0::CommandQueue *commandQueue = CommandQueue::create(productFamily,
device,
csr.get(),
&desc,
false,
returnValue);
EXPECT_EQ(ZE_RESULT_ERROR_OUT_OF_DEVICE_MEMORY, returnValue);
ASSERT_EQ(nullptr, commandQueue);
}
} // namespace ult
} // namespace L0

View File

@@ -98,12 +98,12 @@ HWTEST_F(L0DebuggerTest, givenDebuggingEnabledWhenCommandListIsExecutedThenValid
using STATE_SIP = typename FamilyType::STATE_SIP;
ze_command_queue_desc_t queueDesc = {};
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false));
ze_result_t returnValue;
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, returnValue));
ASSERT_NE(nullptr, commandQueue->commandStream);
auto usedSpaceBefore = commandQueue->commandStream->getUsed();
ze_result_t returnValue;
ze_command_list_handle_t commandLists[] = {
CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue)->toHandle()};
uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);
@@ -164,7 +164,8 @@ HWTEST2_F(L0DebuggerTest, givenDebuggingEnabledAndRequiredGsbaWhenCommandListIsE
using STATE_BASE_ADDRESS = typename FamilyType::STATE_BASE_ADDRESS;
ze_command_queue_desc_t queueDesc = {};
auto cmdQ = CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false);
ze_result_t returnValue;
auto cmdQ = CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, returnValue);
ASSERT_NE(nullptr, cmdQ);
auto commandQueue = whitebox_cast(cmdQ);
@@ -179,7 +180,6 @@ HWTEST2_F(L0DebuggerTest, givenDebuggingEnabledAndRequiredGsbaWhenCommandListIsE
auto usedSpaceBefore = commandQueue->commandStream->getUsed();
ze_result_t returnValue;
ze_command_list_handle_t commandLists[] = {
CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue)->toHandle()};
uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);
@@ -223,10 +223,10 @@ HWTEST_F(L0DebuggerTest, givenDebuggingEnabledAndPrintDebugMessagesWhenCommandQu
testing::internal::CaptureStdout();
ze_command_queue_desc_t queueDesc = {};
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false));
ze_result_t returnValue;
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, returnValue));
ASSERT_NE(nullptr, commandQueue->commandStream);
ze_result_t returnValue;
ze_command_list_handle_t commandLists[] = {
CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue)->toHandle()};
const uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);
@@ -259,10 +259,10 @@ HWTEST_F(L0DebuggerSimpleTest, givenNullL0DebuggerAndPrintDebugMessagesWhenComma
testing::internal::CaptureStdout();
ze_command_queue_desc_t queueDesc = {};
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false));
ze_result_t returnValue;
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, returnValue));
ASSERT_NE(nullptr, commandQueue->commandStream);
ze_result_t returnValue;
ze_command_list_handle_t commandLists[] = {
CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue)->toHandle()};
const uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);
@@ -290,10 +290,10 @@ HWTEST_F(L0DebuggerTest, givenL0DebuggerAndPrintDebugMessagesSetToFalseWhenComma
testing::internal::CaptureStdout();
ze_command_queue_desc_t queueDesc = {};
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false));
ze_result_t returnValue;
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, device, neoDevice->getDefaultEngine().commandStreamReceiver, &queueDesc, false, returnValue));
ASSERT_NE(nullptr, commandQueue->commandStream);
ze_result_t returnValue;
ze_command_list_handle_t commandLists[] = {
CommandList::create(productFamily, device, NEO::EngineGroupType::RenderCompute, returnValue)->toHandle()};
const uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);

View File

@@ -28,12 +28,12 @@ using CommandQueueDebugCommandsTest = Test<ActiveDebuggerFixture>;
HWTEST_F(CommandQueueDebugCommandsTest, givenDebuggingEnabledWhenCommandListIsExecutedThenKernelDebugCommandsAreAdded) {
ze_command_queue_desc_t queueDesc = {};
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, deviceL0, device->getDefaultEngine().commandStreamReceiver, &queueDesc, false));
ze_result_t returnValue;
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, deviceL0, device->getDefaultEngine().commandStreamReceiver, &queueDesc, false, returnValue));
ASSERT_NE(nullptr, commandQueue->commandStream);
auto usedSpaceBefore = commandQueue->commandStream->getUsed();
ze_result_t returnValue;
ze_command_list_handle_t commandLists[] = {
CommandList::create(productFamily, deviceL0, NEO::EngineGroupType::RenderCompute, returnValue)->toHandle()};
uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);
@@ -77,12 +77,12 @@ HWTEST_F(CommandQueueDebugCommandsTest, givenDebuggingEnabledWhenCommandListIsEx
using STATE_SIP = typename FamilyType::STATE_SIP;
ze_command_queue_desc_t queueDesc = {};
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, deviceL0, device->getDefaultEngine().commandStreamReceiver, &queueDesc, false));
ze_result_t returnValue;
auto commandQueue = whitebox_cast(CommandQueue::create(productFamily, deviceL0, device->getDefaultEngine().commandStreamReceiver, &queueDesc, false, returnValue));
ASSERT_NE(nullptr, commandQueue->commandStream);
auto usedSpaceBefore = commandQueue->commandStream->getUsed();
ze_result_t returnValue;
ze_command_list_handle_t commandLists[] = {
CommandList::create(productFamily, deviceL0, NEO::EngineGroupType::RenderCompute, returnValue)->toHandle()};
uint32_t numCommandLists = sizeof(commandLists) / sizeof(commandLists[0]);