Add cmdContainer ULTs - idOffset & numIdd reset, Gfx alloc failure

ULT required to cover IDOffset and numIdd values during reset.
ULT required to cover OUT_OF_MEM retrun during init.
Fix to check for valid gfx allocation inside heap helper & destructor

Change-Id: Ied9049b33dc0605d5f5f51c96114d5e96b26a4f7
Signed-off-by: Vinod Tipparaju <vinod.tipparaju@intel.com>
This commit is contained in:
Vinod Tipparaju
2020-10-20 19:04:58 +05:30
committed by sys_ocldev
parent b7d5427f01
commit 8e6be83fcc
4 changed files with 33 additions and 6 deletions

View File

@@ -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;

View File

@@ -32,8 +32,10 @@ CommandContainer::~CommandContainer() {
}
for (auto allocationIndirectHeap : allocationIndirectHeaps) {
if (heapHelper) {
heapHelper->storeHeapAllocation(allocationIndirectHeap);
}
}
for (auto deallocation : deallocationContainer) {
if (((deallocation->getAllocationType() == GraphicsAllocation::AllocationType::INTERNAL_HEAP) || (deallocation->getAllocationType() == GraphicsAllocation::AllocationType::LINEAR_STREAM))) {
getHeapHelper()->storeHeapAllocation(deallocation);
@@ -48,8 +50,6 @@ ErrorCode CommandContainer::initialize(Device *device) {
}
this->device = device;
heapHelper = std::unique_ptr<HeapHelper>(new HeapHelper(device->getMemoryManager(), device->getDefaultEngine().commandStreamReceiver->getInternalAllocationStorage(), device->getNumAvailableDevices() > 1u));
size_t alignedSize = alignUp<size_t>(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<HeapHelper>(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,

View File

@@ -30,6 +30,8 @@ GraphicsAllocation *HeapHelper::getHeapAllocation(uint32_t heapType, size_t heap
return this->memManager->allocateGraphicsMemoryWithProperties(properties);
}
void HeapHelper::storeHeapAllocation(GraphicsAllocation *heapAllocation) {
if (heapAllocation) {
this->storageForReuse->storeAllocation(std::unique_ptr<NEO::GraphicsAllocation>(heapAllocation), NEO::AllocationUsage::REUSABLE_ALLOCATION);
}
}
} // namespace NEO

View File

@@ -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) {