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 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
|
/*
* Copyright (C) 2017-2020 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/device/device_info.h"
#include "opencl/source/helpers/dispatch_info.h"
#include "opencl/test/unit_test/fixtures/device_host_queue_fixture.h"
#include "opencl/test/unit_test/gen_common/matchers.h"
#include "opencl/test/unit_test/mocks/mock_context.h"
#include "opencl/test/unit_test/mocks/mock_kernel.h"
#include "opencl/test/unit_test/mocks/mock_program.h"
using namespace NEO;
using namespace DeviceHostQueue;
using DeviceQueueSimpleTest = ::testing::Test;
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueSimpleTest, WhenExecutionModelDispatchIsSetupThenNoAdditionalActionsOccur) {
DeviceQueue devQueue;
char buffer[20];
memset(buffer, 1, 20);
size_t size = 20;
IndirectHeap ssh(buffer, size);
IndirectHeap dsh(buffer, size);
devQueue.setupExecutionModelDispatch(ssh, dsh, nullptr, 0, 0, 0x123, 0, false);
EXPECT_EQ(0u, ssh.getUsed());
for (uint32_t i = 0; i < 20; i++) {
EXPECT_EQ(1, buffer[i]);
}
}
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueSimpleTest, WhenResettingDeviceQueueThenIndirectHeapIsNotUsed) {
DeviceQueue devQueue;
devQueue.resetDeviceQueue();
EXPECT_EQ(nullptr, devQueue.getIndirectHeap(IndirectHeap::DYNAMIC_STATE));
}
class DeviceQueueTest : public DeviceHostQueueFixture<DeviceQueue> {
public:
using BaseClass = DeviceHostQueueFixture<DeviceQueue>;
void SetUp() override {
BaseClass::SetUp();
REQUIRE_DEVICE_ENQUEUE_OR_SKIP(pContext);
device = pContext->getDevice(0);
ASSERT_NE(device, nullptr);
}
void TearDown() override {
BaseClass::TearDown();
}
void checkQueueBuffer(cl_uint expedtedSize) {
auto alignedExpectedSize = alignUp(expedtedSize, MemoryConstants::pageSize);
EXPECT_EQ(deviceQueue->getQueueSize(), expedtedSize);
ASSERT_NE(deviceQueue->getQueueBuffer(), nullptr);
EXPECT_EQ(deviceQueue->getQueueBuffer()->getUnderlyingBufferSize(), alignedExpectedSize);
}
DeviceQueue *deviceQueue;
ClDevice *device;
};
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueTest, GivenDeviceQueueCapWhenCreatingAdditionalDeviceQueuesThenQueueIsNotCreated) {
auto maxOnDeviceQueues = device->getDeviceInfo().maxOnDeviceQueues;
const_cast<ClDeviceInfo *>(&device->getDeviceInfo())->maxOnDeviceQueues = 1;
auto deviceQueue1 = createQueueObject();
ASSERT_NE(deviceQueue1, nullptr);
EXPECT_EQ(deviceQueue1->getReference(), 1);
auto deviceQueue2 = createQueueObject();
EXPECT_EQ(deviceQueue2, nullptr);
delete deviceQueue1;
const_cast<ClDeviceInfo *>(&device->getDeviceInfo())->maxOnDeviceQueues = maxOnDeviceQueues;
}
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueTest, GivenDeviceQueueWhenEventPoolIsCreatedThenTimestampResolutionIsSet) {
auto timestampResolution = static_cast<float>(device->getProfilingTimerResolution());
auto deviceQueue = std::unique_ptr<DeviceQueue>(createQueueObject());
ASSERT_NE(deviceQueue, nullptr);
auto eventPoolBuffer = reinterpret_cast<IGIL_EventPool *>(deviceQueue->getEventPoolBuffer()->getUnderlyingBuffer());
EXPECT_FLOAT_EQ(timestampResolution, eventPoolBuffer->m_TimestampResolution);
}
typedef DeviceQueueTest DeviceQueueBuffer;
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueBuffer, GivenNoPropertyWhenCreatingQueueThenPreferredSizeIsSet) {
auto &deviceInfo = device->getDeviceInfo();
deviceQueue = createQueueObject(); // only minimal properties
ASSERT_NE(deviceQueue, nullptr);
checkQueueBuffer(deviceInfo.queueOnDevicePreferredSize);
deviceQueue->release();
}
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueBuffer, GivenInvalidPropertyWhenCreatingQueueThenPreferredSizeIsSet) {
cl_queue_properties properties[5] = {CL_QUEUE_PROPERTIES, deviceQueueProperties::minimumProperties[1],
CL_QUEUE_SIZE, 0, 0};
auto &deviceInfo = device->getDeviceInfo();
deviceQueue = createQueueObject(properties); // zero size
ASSERT_NE(deviceQueue, nullptr);
checkQueueBuffer(deviceInfo.queueOnDevicePreferredSize);
delete deviceQueue;
properties[3] = static_cast<cl_queue_properties>(deviceInfo.queueOnDeviceMaxSize + 1);
deviceQueue = createQueueObject(properties); // greater than max
EXPECT_EQ(deviceQueue, nullptr);
delete deviceQueue;
}
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueBuffer, GivenValidSizeWhenCreatingQueueThenProvidedSizeIsSet) {
auto &deviceInfo = device->getDeviceInfo();
cl_uint validSize = deviceInfo.queueOnDevicePreferredSize - 1;
cl_queue_properties properties[5] = {CL_QUEUE_PROPERTIES, deviceQueueProperties::minimumProperties[1],
CL_QUEUE_SIZE, static_cast<cl_queue_properties>(validSize),
0};
EXPECT_NE(validSize, alignUp(validSize, MemoryConstants::pageSize)); // create aligned
deviceQueue = createQueueObject(properties);
ASSERT_NE(deviceQueue, nullptr);
checkQueueBuffer(validSize);
delete deviceQueue;
}
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueBuffer, WhenDeviceQueueIsCreatedThenItIsCorrectlyInitialized) {
auto &deviceInfo = device->getDeviceInfo();
deviceQueue = createQueueObject();
ASSERT_NE(deviceQueue, nullptr);
IGIL_CommandQueue expectedIgilCmdQueue = getExpectedInitIgilCmdQueue(deviceQueue);
EXPECT_EQ(static_cast<uint32_t>(deviceQueue->isProfilingEnabled()), expectedIgilCmdQueue.m_controls.m_IsProfilingEnabled);
IGIL_EventPool expectedIgilEventPool = {0, 0, 0};
expectedIgilEventPool.m_head = 0;
expectedIgilEventPool.m_size = deviceInfo.maxOnDeviceEvents;
expectedIgilEventPool.m_TimestampResolution = static_cast<float>(device->getProfilingTimerResolution());
// initialized header
EXPECT_EQ(0, memcmp(deviceQueue->getQueueBuffer()->getUnderlyingBuffer(),
&expectedIgilCmdQueue, sizeof(IGIL_CommandQueue)));
EXPECT_EQ(0, memcmp(deviceQueue->getEventPoolBuffer()->getUnderlyingBuffer(),
&expectedIgilEventPool, sizeof(IGIL_EventPool)));
delete deviceQueue;
}
typedef DeviceQueueTest DeviceQueueStackBuffer;
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueStackBuffer, WhenDeviceQueueIsCreatedThenAllocatedResourcesAreZeroed) {
deviceQueue = createQueueObject();
ASSERT_NE(deviceQueue, nullptr);
EXPECT_THAT(deviceQueue->getQueueStorageBuffer()->getUnderlyingBuffer(), MemoryZeroed(deviceQueue->getQueueStorageBuffer()->getUnderlyingBufferSize()));
EXPECT_THAT(deviceQueue->getStackBuffer()->getUnderlyingBuffer(), MemoryZeroed(deviceQueue->getStackBuffer()->getUnderlyingBufferSize()));
delete deviceQueue;
}
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueStackBuffer, WhenDeviceQueueIsCreatedThenStackBufferIsAllocated) {
deviceQueue = createQueueObject();
ASSERT_NE(deviceQueue, nullptr);
auto maxEnqueue = deviceQueue->getQueueSize() / sizeof(IGIL_CommandHeader);
//stack can hold at most 3 full loads of commands
auto expectedStackSize = maxEnqueue * sizeof(uint32_t) * 3;
expectedStackSize = alignUp(expectedStackSize, MemoryConstants::pageSize);
ASSERT_NE(deviceQueue->getStackBuffer(), nullptr);
EXPECT_EQ(deviceQueue->getStackBuffer()->getUnderlyingBufferSize(), expectedStackSize);
delete deviceQueue;
}
typedef DeviceQueueTest DeviceQueueStorageBuffer;
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueStorageBuffer, WhenDeviceQueueIsCreatedThenStorageBufferIsAllocated) {
deviceQueue = createQueueObject();
ASSERT_NE(deviceQueue, nullptr);
auto expectedStorageSize = deviceQueue->getQueueBuffer()->getUnderlyingBufferSize() * 2;
expectedStorageSize = alignUp(expectedStorageSize, MemoryConstants::pageSize);
ASSERT_NE(deviceQueue->getQueueStorageBuffer(), nullptr);
EXPECT_EQ(deviceQueue->getQueueStorageBuffer()->getUnderlyingBufferSize(), expectedStorageSize);
delete deviceQueue;
}
typedef DeviceQueueTest DefaultDeviceQueue;
HWCMDTEST_F(IGFX_GEN8_CORE, DefaultDeviceQueue, GivenSingleDeviceQueueIsSupportedWhenSecondDeviceQueueIsCreatedThenReuseDeviceQueue) {
cl_queue_properties properties[] = {CL_QUEUE_PROPERTIES, CL_QUEUE_ON_DEVICE_DEFAULT, 0, 0, 0};
auto maxOnDeviceQueues = device->getDeviceInfo().maxOnDeviceQueues;
const_cast<ClDeviceInfo *>(&device->getDeviceInfo())->maxOnDeviceQueues = 1;
auto deviceQueue1 = createQueueObject(properties);
ASSERT_NE(deviceQueue1, nullptr);
EXPECT_EQ(pContext->getDefaultDeviceQueue(), deviceQueue1);
EXPECT_EQ(deviceQueue1->getReference(), 1);
auto deviceQueue2 = createQueueObject(properties);
ASSERT_NE(deviceQueue2, nullptr);
EXPECT_EQ(deviceQueue2, deviceQueue1);
EXPECT_EQ(pContext->getDefaultDeviceQueue(), deviceQueue1);
EXPECT_EQ(deviceQueue1->getReference(), 2);
deviceQueue1->release();
deviceQueue2->release();
const_cast<ClDeviceInfo *>(&device->getDeviceInfo())->maxOnDeviceQueues = maxOnDeviceQueues;
}
HWCMDTEST_F(IGFX_GEN8_CORE, DefaultDeviceQueue, GivenMultipleDeviceQueuesIsSupportedWhenSecondDeviceQueueIsCreatedThenReuseDeviceQueue) {
cl_queue_properties properties[] = {CL_QUEUE_PROPERTIES, CL_QUEUE_ON_DEVICE_DEFAULT, 0, 0, 0};
auto maxOnDeviceQueues = device->getDeviceInfo().maxOnDeviceQueues;
const_cast<ClDeviceInfo *>(&device->getDeviceInfo())->maxOnDeviceQueues = 2;
auto deviceQueue1 = createQueueObject(properties);
ASSERT_NE(deviceQueue1, nullptr);
EXPECT_EQ(pContext->getDefaultDeviceQueue(), deviceQueue1);
EXPECT_EQ(deviceQueue1->getReference(), 1);
auto deviceQueue2 = createQueueObject(properties);
ASSERT_NE(deviceQueue2, nullptr);
EXPECT_EQ(deviceQueue2, deviceQueue1);
EXPECT_EQ(pContext->getDefaultDeviceQueue(), deviceQueue1);
EXPECT_EQ(deviceQueue1->getReference(), 2);
deviceQueue1->release();
deviceQueue2->release();
const_cast<ClDeviceInfo *>(&device->getDeviceInfo())->maxOnDeviceQueues = maxOnDeviceQueues;
}
typedef DeviceQueueTest DeviceQueueEventPool;
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueEventPool, WhenDeviceQueueIsCreatedThenEventPoolBufferIsAllocated) {
auto &deviceInfo = device->getDeviceInfo();
// number of events + event pool representation
auto expectedSize = static_cast<uint32_t>(deviceInfo.maxOnDeviceEvents * sizeof(IGIL_DeviceEvent) +
sizeof(IGIL_EventPool));
expectedSize = alignUp(expectedSize, MemoryConstants::pageSize);
auto deviceQueue = createQueueObject();
ASSERT_NE(deviceQueue, nullptr);
ASSERT_NE(deviceQueue->getEventPoolBuffer(), nullptr);
EXPECT_EQ(deviceQueue->getEventPoolBuffer()->getUnderlyingBufferSize(), expectedSize);
delete deviceQueue;
}
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueTest, WhenDeviceQueueIsCreatedThenDshBufferIsAllocated) {
deviceQueue = createQueueObject();
ASSERT_NE(deviceQueue, nullptr);
ASSERT_NE(deviceQueue->getDshBuffer(), nullptr);
auto dshBufferSize = deviceQueue->getDshBuffer()->getUnderlyingBufferSize();
EXPECT_LE(761856u, dshBufferSize);
delete deviceQueue;
}
HWCMDTEST_F(IGFX_GEN8_CORE, DeviceQueueTest, WhenDispatchingSchedulerThenNoAssertsOccur) {
DeviceQueue devQueue;
MockContext context;
MockProgram program(toClDeviceVector(*device));
MockCommandQueue cmdQ(nullptr, nullptr, 0);
KernelInfo info;
MockSchedulerKernel *kernel = new MockSchedulerKernel(&program, info, *device);
LinearStream cmdStream;
devQueue.dispatchScheduler(cmdStream, *kernel, device->getPreemptionMode(), nullptr, nullptr, false);
delete kernel;
}
|