diff --git a/level_zero/core/source/cmdlist/cmdlist.h b/level_zero/core/source/cmdlist/cmdlist.h index c184f1d3f5..dcddfb6271 100644 --- a/level_zero/core/source/cmdlist/cmdlist.h +++ b/level_zero/core/source/cmdlist/cmdlist.h @@ -26,8 +26,7 @@ struct Event; struct Kernel; struct CommandList : _ze_command_list_handle_t { - static constexpr uint32_t maxNumInterfaceDescriptorsPerMediaInterfaceDescriptorLoad = 62u; - static constexpr uint32_t defaultNumIddsPerBlock = maxNumInterfaceDescriptorsPerMediaInterfaceDescriptorLoad; + static constexpr uint32_t defaultNumIddsPerBlock = 64u; static constexpr uint32_t commandListimmediateIddsPerBlock = 1u; CommandList() = delete; diff --git a/shared/source/command_container/cmdcontainer.cpp b/shared/source/command_container/cmdcontainer.cpp index f5a29c91c4..c517550907 100644 --- a/shared/source/command_container/cmdcontainer.cpp +++ b/shared/source/command_container/cmdcontainer.cpp @@ -32,7 +32,9 @@ CommandContainer::~CommandContainer() { } for (auto allocationIndirectHeap : allocationIndirectHeaps) { - heapHelper->storeHeapAllocation(allocationIndirectHeap); + if (heapHelper) { + heapHelper->storeHeapAllocation(allocationIndirectHeap); + } } for (auto deallocation : deallocationContainer) { if (((deallocation->getAllocationType() == GraphicsAllocation::AllocationType::INTERNAL_HEAP) || (deallocation->getAllocationType() == GraphicsAllocation::AllocationType::LINEAR_STREAM))) { @@ -48,8 +50,6 @@ ErrorCode CommandContainer::initialize(Device *device) { } this->device = device; - heapHelper = std::unique_ptr(new HeapHelper(device->getMemoryManager(), device->getDefaultEngine().commandStreamReceiver->getInternalAllocationStorage(), device->getNumAvailableDevices() > 1u)); - size_t alignedSize = alignUp(totalCmdBufferSize, MemoryConstants::pageSize64k); AllocationProperties properties{device->getRootDeviceIndex(), true /* allocateMemory*/, @@ -71,7 +71,9 @@ ErrorCode CommandContainer::initialize(Device *device) { commandStream->replaceGraphicsAllocation(cmdBufferAllocation); addToResidencyContainer(cmdBufferAllocation); + constexpr size_t heapSize = 65536u; + heapHelper = std::unique_ptr(new HeapHelper(device->getMemoryManager(), device->getDefaultEngine().commandStreamReceiver->getInternalAllocationStorage(), device->getNumAvailableDevices() > 1u)); for (uint32_t i = 0; i < IndirectHeap::Type::NUM_TYPES; i++) { allocationIndirectHeaps[i] = heapHelper->getHeapAllocation(i, diff --git a/shared/source/helpers/heap_helper.cpp b/shared/source/helpers/heap_helper.cpp index a5812cf377..5656b02010 100644 --- a/shared/source/helpers/heap_helper.cpp +++ b/shared/source/helpers/heap_helper.cpp @@ -30,6 +30,8 @@ GraphicsAllocation *HeapHelper::getHeapAllocation(uint32_t heapType, size_t heap return this->memManager->allocateGraphicsMemoryWithProperties(properties); } void HeapHelper::storeHeapAllocation(GraphicsAllocation *heapAllocation) { - this->storageForReuse->storeAllocation(std::unique_ptr(heapAllocation), NEO::AllocationUsage::REUSABLE_ALLOCATION); + if (heapAllocation) { + this->storageForReuse->storeAllocation(std::unique_ptr(heapAllocation), NEO::AllocationUsage::REUSABLE_ALLOCATION); + } } } // namespace NEO diff --git a/shared/test/unit_test/command_container/command_container_tests.cpp b/shared/test/unit_test/command_container/command_container_tests.cpp index 5ddc1ab1a7..f1c8927127 100644 --- a/shared/test/unit_test/command_container/command_container_tests.cpp +++ b/shared/test/unit_test/command_container/command_container_tests.cpp @@ -9,10 +9,13 @@ #include "shared/test/unit_test/fixtures/device_fixture.h" #include "shared/test/unit_test/mocks/mock_graphics_allocation.h" +#include "opencl/test/unit_test/mocks/mock_memory_manager.h" #include "test.h" using namespace NEO; +constexpr uint32_t defaultNumIddsPerBlock = 64; + class CommandContainerTest : public DeviceFixture, public ::testing::Test { @@ -128,6 +131,9 @@ TEST_F(CommandContainerTest, givenCommandContainerWhenInitializeThenEverythingIs EXPECT_EQ(indirectHeap->getGraphicsAllocation(), heapAllocation); } + EXPECT_EQ(cmdContainer.getIddBlock(), nullptr); + EXPECT_EQ(cmdContainer.getNumIddPerBlock(), defaultNumIddsPerBlock); + auto &hwHelper = HwHelper::get(pDevice->getHardwareInfo().platform.eRenderCoreFamily); EXPECT_EQ(cmdContainer.getInstructionHeapBaseAddress(), @@ -140,6 +146,22 @@ TEST_F(CommandContainerTest, givenCommandContainerWhenInitializeWithoutDeviceThe EXPECT_EQ(ErrorCode::INVALID_DEVICE, status); } +TEST_F(CommandContainerTest, givenCommandContainerDuringInitWhenAllocateGfxMemoryFailsThenErrorIsReturned) { + CommandContainer cmdContainer; + pDevice->executionEnvironment->memoryManager.reset(new FailMemoryManager(0, *pDevice->executionEnvironment)); + auto status = cmdContainer.initialize(pDevice); + EXPECT_EQ(ErrorCode::OUT_OF_DEVICE_MEMORY, status); +} + +TEST_F(CommandContainerTest, givenCommandContainerDuringInitWhenAllocateHeapMemoryFailsThenErrorIsReturned) { + CommandContainer cmdContainer; + auto temp_memoryManager = pDevice->executionEnvironment->memoryManager.release(); + pDevice->executionEnvironment->memoryManager.reset(new FailMemoryManager(1, *pDevice->executionEnvironment)); + auto status = cmdContainer.initialize(pDevice); + EXPECT_EQ(ErrorCode::OUT_OF_DEVICE_MEMORY, status); + delete temp_memoryManager; +} + TEST_F(CommandContainerTest, givenCommandContainerWhenSettingIndirectHeapAllocationThenAllocationIsSet) { CommandContainer cmdContainer; MockGraphicsAllocation mockAllocation; @@ -173,6 +195,8 @@ TEST_F(CommandContainerTest, givenCommandContainerWhenResetThenStateIsReset) { EXPECT_NE(usedSize, cmdContainer.getCommandStream()->getUsed()); EXPECT_EQ(0u, cmdContainer.getCommandStream()->getUsed()); EXPECT_EQ(0u, cmdContainer.lastSentNumGrfRequired); + EXPECT_EQ(cmdContainer.getIddBlock(), nullptr); + EXPECT_EQ(cmdContainer.getNumIddPerBlock(), defaultNumIddsPerBlock); } TEST_F(CommandContainerTest, givenCommandContainerWhenWantToAddNullPtrToResidencyContainerThenNothingIsAdded) {