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 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176
|
/*
* Copyright (C) 2018-2025 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#pragma once
#include "shared/source/helpers/gfx_core_helper.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_memory_manager.h"
#include "opencl/source/command_queue/command_queue_hw.h"
#include "opencl/test/unit_test/command_queue/command_queue_fixture.h"
#include "opencl/test/unit_test/command_stream/command_stream_fixture.h"
#include "opencl/test/unit_test/fixtures/buffer_fixture.h"
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
#include "opencl/test/unit_test/fixtures/image_fixture.h"
#include "opencl/test/unit_test/helpers/cl_hw_parse.h"
#include "opencl/test/unit_test/indirect_heap/indirect_heap_fixture.h"
#include "opencl/test/unit_test/mocks/mock_command_queue_hw.h"
namespace NEO {
struct CommandDeviceFixture : public ClDeviceFixture,
public CommandQueueHwFixture {
using CommandQueueHwFixture::setUp;
void setUp(cl_command_queue_properties cmdQueueProperties = 0) {
ClDeviceFixture::setUp();
CommandQueueHwFixture::setUp(pClDevice, cmdQueueProperties);
}
void tearDown() {
CommandQueueHwFixture::tearDown();
ClDeviceFixture::tearDown();
}
};
struct CommandEnqueueBaseFixture : CommandDeviceFixture,
public IndirectHeapFixture,
virtual public ClHardwareParse {
using IndirectHeapFixture::setUp;
void setUp(cl_command_queue_properties cmdQueueProperties = 0) {
CommandDeviceFixture::setUp(cmdQueueProperties);
IndirectHeapFixture::setUp(pCmdQ);
ClHardwareParse::setUp();
}
void tearDown() {
ClHardwareParse::tearDown();
IndirectHeapFixture::tearDown();
CommandDeviceFixture::tearDown();
}
};
struct CommandEnqueueFixture : public CommandEnqueueBaseFixture,
public CommandStreamFixture {
void setUp(cl_command_queue_properties cmdQueueProperties = 0) {
CommandEnqueueBaseFixture::setUp(cmdQueueProperties);
CommandStreamFixture::setUp(pCmdQ);
}
void tearDown() {
CommandEnqueueBaseFixture::tearDown();
CommandStreamFixture::tearDown();
}
};
struct SurfaceStateAccessor : virtual public ClHardwareParse {
template <typename FamilyType>
const FamilyType::RENDER_SURFACE_STATE *getSurfaceState(std::unique_ptr<MockCommandQueueHw<FamilyType>> &mockCmdQ, uint32_t index) {
typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE;
const RENDER_SURFACE_STATE *surfaceState = nullptr;
auto kernel = mockCmdQ->storedMultiDispatchInfo.begin()->getKernel();
const auto &kernelInfo = kernel->getKernelInfo();
if (kernelInfo.kernelDescriptor.kernelAttributes.imageAddressingMode == KernelDescriptor::AddressingMode::Bindless) {
auto bindlessOffset = static_cast<uint32_t>(kernelInfo.getArgDescriptorAt(index).template as<ArgDescImage>().bindless);
auto bindlessSurfaceStateIndex = kernel->getSurfaceStateIndexForBindlessOffset(bindlessOffset);
void *surfaceStateAddress = ptrOffset(kernel->getSurfaceStateHeap(), bindlessSurfaceStateIndex * sizeof(RENDER_SURFACE_STATE));
surfaceState = reinterpret_cast<RENDER_SURFACE_STATE *>(surfaceStateAddress);
} else {
uint32_t bindfulIndex = static_cast<uint32_t>(kernelInfo.getArgDescriptorAt(index).template as<ArgDescImage>().bindful) / sizeof(RENDER_SURFACE_STATE);
surfaceState = HardwareParse::getSurfaceState<FamilyType>(&mockCmdQ->getIndirectHeap(IndirectHeap::Type::surfaceState, 0), bindfulIndex);
}
return surfaceState;
}
};
struct NegativeFailAllocationCommandEnqueueBaseFixture : public CommandEnqueueBaseFixture {
void setUp() {
CommandEnqueueBaseFixture::setUp();
failMemManager.reset(new FailMemoryManager(*pDevice->getExecutionEnvironment()));
BufferDefaults::context = context;
Image2dDefaults::context = context;
buffer.reset(BufferHelper<>::create());
image.reset(ImageHelperUlt<Image2dDefaults>::create());
ptr = static_cast<void *>(array);
oldMemManager = pDevice->getExecutionEnvironment()->memoryManager.release();
pDevice->injectMemoryManager(failMemManager.release());
}
void tearDown() {
pDevice->injectMemoryManager(oldMemManager);
buffer.reset(nullptr);
image.reset(nullptr);
BufferDefaults::context = nullptr;
Image2dDefaults::context = nullptr;
CommandEnqueueBaseFixture::tearDown();
}
std::unique_ptr<Buffer> buffer;
std::unique_ptr<Image> image;
std::unique_ptr<FailMemoryManager> failMemManager;
char array[MemoryConstants::cacheLineSize];
void *ptr;
MemoryManager *oldMemManager;
};
template <typename FamilyType>
struct CommandQueueStateless : public CommandQueueHw<FamilyType> {
CommandQueueStateless(Context *context, ClDevice *device) : CommandQueueHw<FamilyType>(context, device, nullptr, false){};
void enqueueHandlerHook(const unsigned int commandType, const MultiDispatchInfo &dispatchInfo) override {
auto kernel = dispatchInfo.begin()->getKernel();
EXPECT_TRUE(kernel->getKernelInfo().kernelDescriptor.kernelAttributes.supportsBuffersBiggerThan4Gb());
if (kernel->getKernelInfo().getArgDescriptorAt(0).is<ArgDescriptor::argTPointer>()) {
EXPECT_FALSE(kernel->getKernelInfo().getArgDescriptorAt(0).as<ArgDescPointer>().isPureStateful());
}
if (validateKernelSystemMemory) {
if (expectedKernelSystemMemory) {
EXPECT_TRUE(kernel->getDestinationAllocationInSystemMemory());
} else {
EXPECT_FALSE(kernel->getDestinationAllocationInSystemMemory());
}
}
}
bool validateKernelSystemMemory = false;
bool expectedKernelSystemMemory = false;
};
template <typename FamilyType>
struct CommandQueueStateful : public CommandQueueHw<FamilyType> {
CommandQueueStateful(Context *context, ClDevice *device) : CommandQueueHw<FamilyType>(context, device, nullptr, false){
};
void enqueueHandlerHook(const unsigned int commandType, const MultiDispatchInfo &dispatchInfo) override {
auto kernel = dispatchInfo.begin()->getKernel();
EXPECT_FALSE(kernel->getKernelInfo().kernelDescriptor.kernelAttributes.supportsBuffersBiggerThan4Gb());
auto &gfxCoreHelper = kernel->getContext().getDevice(0)->getGfxCoreHelper();
if (gfxCoreHelper.isStatelessToStatefulWithOffsetSupported()) {
EXPECT_TRUE(kernel->allBufferArgsStateful);
}
if (validateKernelSystemMemory) {
if (expectedKernelSystemMemory) {
EXPECT_TRUE(kernel->getDestinationAllocationInSystemMemory());
} else {
EXPECT_FALSE(kernel->getDestinationAllocationInSystemMemory());
}
}
}
bool validateKernelSystemMemory = false;
bool expectedKernelSystemMemory = false;
};
} // namespace NEO
|