1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
|
/*
* Copyright (C) 2018-2024 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/indirect_heap/indirect_heap.h"
#include "shared/source/memory_manager/surface.h"
#include "shared/test/common/fixtures/device_fixture.h"
#include "shared/test/common/helpers/raii_gfx_core_helper.h"
#include "shared/test/common/mocks/mock_csr.h"
#include "shared/test/common/mocks/mock_gfx_core_helper.h"
#include "shared/test/common/test_macros/hw_test.h"
#include "opencl/source/mem_obj/buffer.h"
#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h"
#include "opencl/test/unit_test/mocks/mock_context.h"
#include "gtest/gtest.h"
using namespace NEO;
TEST(ClCommandStreamReceiverTest, WhenMakingResidentThenBufferResidencyFlagIsSet) {
MockContext context;
auto commandStreamReceiver = context.getDevice(0)->getDefaultEngine().commandStreamReceiver;
float srcMemory[] = {1.0f};
auto retVal = CL_INVALID_VALUE;
auto buffer = Buffer::create(
&context,
CL_MEM_USE_HOST_PTR,
sizeof(srcMemory),
srcMemory,
retVal);
ASSERT_NE(nullptr, buffer);
auto graphicsAllocation = buffer->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex());
EXPECT_FALSE(graphicsAllocation->isResident(commandStreamReceiver->getOsContext().getContextId()));
commandStreamReceiver->makeResident(*graphicsAllocation);
EXPECT_TRUE(graphicsAllocation->isResident(commandStreamReceiver->getOsContext().getContextId()));
delete buffer;
}
using ClCommandStreamReceiverTests = Test<DeviceFixture>;
HWTEST_F(ClCommandStreamReceiverTests, givenCommandStreamReceiverWhenFenceAllocationIsRequiredAndCreateGlobalFenceAllocationIsCalledThenFenceAllocationIsAllocated) {
RAIIGfxCoreHelperFactory<MockGfxCoreHelperHw<FamilyType>> gfxCoreHelperBackup{
*pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]};
MockCsrHw<FamilyType> csr(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
csr.setupContext(*pDevice->getDefaultEngine().osContext);
EXPECT_EQ(nullptr, csr.globalFenceAllocation);
EXPECT_TRUE(csr.createGlobalFenceAllocation());
ASSERT_NE(nullptr, csr.globalFenceAllocation);
EXPECT_EQ(AllocationType::globalFence, csr.globalFenceAllocation->getAllocationType());
}
HWTEST_F(ClCommandStreamReceiverTests, givenCommandStreamReceiverWhenGettingFenceAllocationThenCorrectFenceAllocationIsReturned) {
RAIIGfxCoreHelperFactory<MockGfxCoreHelperHw<FamilyType>> gfxCoreHelperBackup{
*pDevice->executionEnvironment->rootDeviceEnvironments[pDevice->getRootDeviceIndex()]};
CommandStreamReceiverHw<FamilyType> csr(*pDevice->executionEnvironment, pDevice->getRootDeviceIndex(), pDevice->getDeviceBitfield());
csr.setupContext(*pDevice->getDefaultEngine().osContext);
EXPECT_EQ(nullptr, csr.getGlobalFenceAllocation());
EXPECT_TRUE(csr.createGlobalFenceAllocation());
ASSERT_NE(nullptr, csr.getGlobalFenceAllocation());
EXPECT_EQ(AllocationType::globalFence, csr.getGlobalFenceAllocation()->getAllocationType());
}
using CommandStreamReceiverMultiRootDeviceTest = MultiRootDeviceFixture;
TEST_F(CommandStreamReceiverMultiRootDeviceTest, WhenCreatingCommandStreamGraphicsAllocationsThenTheyHaveCorrectRootDeviceIndex) {
auto commandStreamReceiver = &device1->getGpgpuCommandStreamReceiver();
mockMemoryManager->localMemorySupported[1] = false;
ASSERT_NE(nullptr, commandStreamReceiver);
EXPECT_EQ(expectedRootDeviceIndex, commandStreamReceiver->getRootDeviceIndex());
// Linear stream / Command buffer
GraphicsAllocation *allocation = mockMemoryManager->allocateGraphicsMemoryWithProperties({expectedRootDeviceIndex, 128u, AllocationType::commandBuffer, device1->getDeviceBitfield()});
LinearStream commandStream{allocation};
commandStreamReceiver->ensureCommandBufferAllocation(commandStream, 100u, 0u);
EXPECT_EQ(allocation, commandStream.getGraphicsAllocation());
EXPECT_EQ(MemoryConstants::pageSize, commandStream.getMaxAvailableSpace());
EXPECT_EQ(expectedRootDeviceIndex, commandStream.getGraphicsAllocation()->getRootDeviceIndex());
commandStreamReceiver->ensureCommandBufferAllocation(commandStream, MemoryConstants::pageSize64k, 0u);
EXPECT_NE(allocation, commandStream.getGraphicsAllocation());
EXPECT_EQ(0u, commandStream.getMaxAvailableSpace() % MemoryConstants::pageSize);
EXPECT_EQ(expectedRootDeviceIndex, commandStream.getGraphicsAllocation()->getRootDeviceIndex());
mockMemoryManager->freeGraphicsMemory(commandStream.getGraphicsAllocation());
// Debug surface
auto debugSurface = commandStreamReceiver->allocateDebugSurface(MemoryConstants::pageSize);
ASSERT_NE(nullptr, debugSurface);
EXPECT_EQ(expectedRootDeviceIndex, debugSurface->getRootDeviceIndex());
// Indirect heaps
IndirectHeap::Type heapTypes[]{IndirectHeap::Type::dynamicState, IndirectHeap::Type::indirectObject, IndirectHeap::Type::surfaceState};
for (auto heapType : heapTypes) {
IndirectHeap *heap = nullptr;
commandStreamReceiver->allocateHeapMemory(heapType, MemoryConstants::pageSize, heap);
ASSERT_NE(nullptr, heap);
ASSERT_NE(nullptr, heap->getGraphicsAllocation());
EXPECT_EQ(expectedRootDeviceIndex, heap->getGraphicsAllocation()->getRootDeviceIndex());
mockMemoryManager->freeGraphicsMemory(heap->getGraphicsAllocation());
delete heap;
}
// Tag allocation
ASSERT_NE(nullptr, commandStreamReceiver->getTagAllocation());
EXPECT_EQ(expectedRootDeviceIndex, commandStreamReceiver->getTagAllocation()->getRootDeviceIndex());
// Preemption allocation
if (nullptr == commandStreamReceiver->getPreemptionAllocation()) {
commandStreamReceiver->createPreemptionAllocation();
}
EXPECT_EQ(expectedRootDeviceIndex, commandStreamReceiver->getPreemptionAllocation()->getRootDeviceIndex());
// HostPtr surface
char memory[8] = {1, 2, 3, 4, 5, 6, 7, 8};
HostPtrSurface surface(memory, sizeof(memory), true);
EXPECT_TRUE(commandStreamReceiver->createAllocationForHostSurface(surface, false));
ASSERT_NE(nullptr, surface.getAllocation());
EXPECT_EQ(expectedRootDeviceIndex, surface.getAllocation()->getRootDeviceIndex());
EXPECT_EQ(1u, surface.getAllocation()->hostPtrTaskCountAssignment.load());
surface.getAllocation()->hostPtrTaskCountAssignment--;
}
|