2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2021-05-17 02:51:16 +08:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2018-09-18 15:11:08 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2020-02-24 05:44:01 +08:00
|
|
|
#include "shared/source/helpers/aligned_memory.h"
|
2021-01-21 20:10:13 +08:00
|
|
|
#include "shared/test/common/helpers/debug_manager_state_restore.h"
|
|
|
|
#include "shared/test/common/mocks/mock_device.h"
|
|
|
|
#include "shared/test/common/test_macros/test_checks_shared.h"
|
2020-02-24 17:22:30 +08:00
|
|
|
|
2021-10-05 21:01:17 +08:00
|
|
|
#include "opencl/source/command_queue/cl_local_work_size.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/context/context.h"
|
|
|
|
#include "opencl/source/kernel/kernel.h"
|
|
|
|
#include "opencl/source/mem_obj/buffer.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/command_queue/command_queue_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/fixtures/image_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/fixtures/platform_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/fixtures/program_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_buffer.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_kernel.h"
|
2020-02-23 05:50:57 +08:00
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-06-29 00:22:38 +08:00
|
|
|
const int maxHintCounter = 6;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
bool containsHint(const char *providedHint, char *userData);
|
|
|
|
|
|
|
|
void CL_CALLBACK callbackFunction(const char *providedHint, const void *flags, size_t size, void *userData);
|
|
|
|
|
2018-03-30 03:26:25 +08:00
|
|
|
struct DriverDiagnosticsTest : public PlatformFixture,
|
2017-12-21 07:45:38 +08:00
|
|
|
public ::testing::Test {
|
|
|
|
using PlatformFixture::SetUp;
|
|
|
|
void SetUp() override {
|
2018-06-26 16:51:01 +08:00
|
|
|
PlatformFixture::SetUp();
|
2017-12-21 07:45:38 +08:00
|
|
|
memset(userData, 0, maxHintCounter * DriverDiagnostics::maxHintStringSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
PlatformFixture::TearDown();
|
|
|
|
}
|
|
|
|
|
2020-03-13 21:59:00 +08:00
|
|
|
cl_int retVal = CL_SUCCESS;
|
|
|
|
char userData[maxHintCounter * DriverDiagnostics::maxHintStringSize]{};
|
|
|
|
char expectedHint[DriverDiagnostics::maxHintStringSize]{};
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct VerboseLevelTest : public DriverDiagnosticsTest,
|
|
|
|
public ::testing::WithParamInterface<unsigned int> {
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
DriverDiagnosticsTest::SetUp();
|
|
|
|
hintId = CL_BUFFER_NEEDS_ALLOCATE_MEMORY;
|
|
|
|
snprintf(expectedHint, DriverDiagnostics::maxHintStringSize, DriverDiagnostics::hintFormat[hintId], 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
DriverDiagnosticsTest::TearDown();
|
|
|
|
}
|
|
|
|
std::vector<unsigned int> validLevels{
|
|
|
|
CL_CONTEXT_DIAGNOSTICS_LEVEL_ALL_INTEL,
|
|
|
|
CL_CONTEXT_DIAGNOSTICS_LEVEL_BAD_INTEL,
|
|
|
|
CL_CONTEXT_DIAGNOSTICS_LEVEL_GOOD_INTEL,
|
|
|
|
CL_CONTEXT_DIAGNOSTICS_LEVEL_NEUTRAL_INTEL};
|
|
|
|
PerformanceHints hintId;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintTest : public DriverDiagnosticsTest,
|
|
|
|
public CommandQueueHwFixture {
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
DriverDiagnosticsTest::SetUp();
|
|
|
|
cl_context_properties validProperties[3] = {CL_CONTEXT_SHOW_DIAGNOSTICS_INTEL, CL_CONTEXT_DIAGNOSTICS_LEVEL_ALL_INTEL, 0};
|
2020-12-03 02:19:05 +08:00
|
|
|
context = Context::create<NEO::MockContext>(validProperties, ClDeviceVector(devices, num_devices), callbackFunction, (void *)userData, retVal);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
CommandQueueHwFixture::TearDown();
|
|
|
|
DriverDiagnosticsTest::TearDown();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintBufferTest : public PerformanceHintTest,
|
|
|
|
public ::testing::WithParamInterface<std::tuple<bool /*address aligned*/, bool /*size aligned*/>> {
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
PerformanceHintTest::SetUp();
|
|
|
|
std::tie(alignedAddress, alignedSize) = GetParam();
|
|
|
|
address = alignedMalloc(2 * MemoryConstants::cacheLineSize, MemoryConstants::cacheLineSize);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
delete buffer;
|
|
|
|
alignedFree(address);
|
|
|
|
PerformanceHintTest::TearDown();
|
|
|
|
}
|
2020-03-13 21:59:00 +08:00
|
|
|
bool alignedSize = false;
|
|
|
|
bool alignedAddress = false;
|
|
|
|
void *address = nullptr;
|
|
|
|
Buffer *buffer = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintCommandQueueTest : public PerformanceHintTest,
|
|
|
|
public ::testing::WithParamInterface<std::tuple<bool /*profiling enabled*/, bool /*preemption supported*/>> {
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
PerformanceHintTest::SetUp();
|
|
|
|
std::tie(profilingEnabled, preemptionSupported) = GetParam();
|
2020-03-24 22:05:12 +08:00
|
|
|
static_cast<MockClDevice *>(context->getDevice(0))->deviceInfo.preemptionSupported = preemptionSupported;
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
clReleaseCommandQueue(cmdQ);
|
|
|
|
PerformanceHintTest::TearDown();
|
|
|
|
}
|
2020-03-13 21:59:00 +08:00
|
|
|
cl_command_queue cmdQ = nullptr;
|
|
|
|
bool profilingEnabled = false;
|
|
|
|
bool preemptionSupported = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintEnqueueTest : public PerformanceHintTest {
|
|
|
|
void SetUp() override {
|
|
|
|
PerformanceHintTest::SetUp();
|
2020-01-14 21:32:11 +08:00
|
|
|
pCmdQ = createCommandQueue(pPlatform->getClDevice(0));
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
PerformanceHintTest::TearDown();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintEnqueueBufferTest : public PerformanceHintEnqueueTest {
|
|
|
|
void SetUp() override {
|
|
|
|
PerformanceHintEnqueueTest::SetUp();
|
|
|
|
address = alignedMalloc(2 * MemoryConstants::cacheLineSize, MemoryConstants::cacheLineSize);
|
|
|
|
buffer = Buffer::create(
|
|
|
|
context,
|
|
|
|
CL_MEM_USE_HOST_PTR,
|
|
|
|
MemoryConstants::cacheLineSize,
|
|
|
|
address,
|
|
|
|
retVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
delete buffer;
|
|
|
|
alignedFree(address);
|
|
|
|
PerformanceHintEnqueueTest::TearDown();
|
|
|
|
}
|
2020-03-13 21:59:00 +08:00
|
|
|
void *address = nullptr;
|
|
|
|
Buffer *buffer = nullptr;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintEnqueueReadBufferTest : public PerformanceHintEnqueueBufferTest,
|
|
|
|
public ::testing::WithParamInterface<std::tuple<bool /*address aligned*/, bool /*size aligned*/>> {
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
PerformanceHintEnqueueBufferTest::SetUp();
|
|
|
|
std::tie(alignedAddress, alignedSize) = GetParam();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
PerformanceHintEnqueueBufferTest::TearDown();
|
|
|
|
}
|
2020-03-13 21:59:00 +08:00
|
|
|
bool alignedSize = false;
|
|
|
|
bool alignedAddress = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintEnqueueImageTest : public PerformanceHintEnqueueTest {
|
|
|
|
|
|
|
|
void SetUp() override {
|
2020-11-25 22:11:11 +08:00
|
|
|
REQUIRE_IMAGES_OR_SKIP(defaultHwInfo);
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
PerformanceHintEnqueueTest::SetUp();
|
|
|
|
address = alignedMalloc(2 * MemoryConstants::cacheLineSize, MemoryConstants::cacheLineSize);
|
|
|
|
image = ImageHelper<ImageUseHostPtr<Image1dDefaults>>::create(context);
|
2018-02-07 21:48:24 +08:00
|
|
|
zeroCopyImage.reset(ImageHelper<Image1dDefaults>::create(context));
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
2020-11-25 22:11:11 +08:00
|
|
|
if (IsSkipped()) {
|
|
|
|
return;
|
|
|
|
}
|
2017-12-21 07:45:38 +08:00
|
|
|
delete image;
|
2018-02-07 21:48:24 +08:00
|
|
|
zeroCopyImage.reset(nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
alignedFree(address);
|
|
|
|
PerformanceHintEnqueueTest::TearDown();
|
|
|
|
}
|
2020-03-13 21:59:00 +08:00
|
|
|
void *address = nullptr;
|
|
|
|
Image *image = nullptr;
|
2018-02-07 21:48:24 +08:00
|
|
|
std::unique_ptr<Image> zeroCopyImage;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintEnqueueReadImageTest : public PerformanceHintEnqueueImageTest,
|
|
|
|
public ::testing::WithParamInterface<std::tuple<bool /*address aligned*/, bool /*size aligned*/>> {
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
PerformanceHintEnqueueImageTest::SetUp();
|
|
|
|
std::tie(alignedAddress, alignedSize) = GetParam();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
PerformanceHintEnqueueImageTest::TearDown();
|
|
|
|
}
|
2020-03-13 21:59:00 +08:00
|
|
|
bool alignedSize = false;
|
|
|
|
bool alignedAddress = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintEnqueueMapTest : public PerformanceHintEnqueueTest,
|
|
|
|
public ::testing::WithParamInterface<bool /*zero-copy obj*/> {
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
PerformanceHintEnqueueTest::SetUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
PerformanceHintEnqueueTest::TearDown();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintEnqueueKernelTest : public PerformanceHintEnqueueTest,
|
|
|
|
public ProgramFixture {
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
PerformanceHintEnqueueTest::SetUp();
|
2020-10-21 16:25:03 +08:00
|
|
|
CreateProgramFromBinary(context, context->getDevices(), "CopyBuffer_simd32");
|
2020-10-30 18:10:00 +08:00
|
|
|
retVal = pProgram->build(pProgram->getDevices(), nullptr, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
2021-03-22 23:26:03 +08:00
|
|
|
kernel = Kernel::create<MockKernel>(pProgram, pProgram->getKernelInfoForKernel("CopyBuffer"), *context->getDevice(0), &retVal);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
globalWorkGroupSize[0] = globalWorkGroupSize[1] = globalWorkGroupSize[2] = 1;
|
2020-12-07 22:41:52 +08:00
|
|
|
rootDeviceIndex = context->getDevice(0)->getRootDeviceIndex();
|
2017-12-21 07:45:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
delete kernel;
|
|
|
|
ProgramFixture::TearDown();
|
|
|
|
PerformanceHintEnqueueTest::TearDown();
|
|
|
|
}
|
2020-12-10 21:22:10 +08:00
|
|
|
MockKernel *kernel = nullptr;
|
2020-12-07 22:41:52 +08:00
|
|
|
uint32_t rootDeviceIndex = std::numeric_limits<uint32_t>::max();
|
2020-03-13 21:59:00 +08:00
|
|
|
size_t globalWorkGroupSize[3]{};
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintEnqueueKernelBadSizeTest : public PerformanceHintEnqueueKernelTest,
|
|
|
|
public ::testing::WithParamInterface<int /*bad size dimension*/> {
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
PerformanceHintEnqueueKernelTest::SetUp();
|
|
|
|
globalWorkGroupSize[0] = globalWorkGroupSize[1] = globalWorkGroupSize[2] = 32;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
PerformanceHintEnqueueKernelTest::TearDown();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintEnqueueKernelPrintfTest : public PerformanceHintEnqueueTest,
|
|
|
|
public ProgramFixture {
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
PerformanceHintEnqueueTest::SetUp();
|
2020-10-21 16:25:03 +08:00
|
|
|
CreateProgramFromBinary(context, context->getDevices(), "printf");
|
2020-10-30 18:10:00 +08:00
|
|
|
retVal = pProgram->build(pProgram->getDevices(), nullptr, false);
|
2017-12-21 07:45:38 +08:00
|
|
|
ASSERT_EQ(CL_SUCCESS, retVal);
|
2021-03-22 23:26:03 +08:00
|
|
|
kernel = Kernel::create(pProgram, pProgram->getKernelInfoForKernel("test"), *context->getDevice(0), &retVal);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
globalWorkGroupSize[0] = globalWorkGroupSize[1] = globalWorkGroupSize[2] = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
delete kernel;
|
|
|
|
ProgramFixture::TearDown();
|
|
|
|
PerformanceHintEnqueueTest::TearDown();
|
|
|
|
}
|
2020-03-13 21:59:00 +08:00
|
|
|
Kernel *kernel = nullptr;
|
|
|
|
size_t globalWorkGroupSize[3]{};
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct PerformanceHintKernelTest : public PerformanceHintTest,
|
|
|
|
public ::testing::WithParamInterface<bool /*zero-sized*/> {
|
|
|
|
|
|
|
|
void SetUp() override {
|
2020-12-03 02:19:05 +08:00
|
|
|
DebugManager.flags.CreateMultipleRootDevices.set(2);
|
|
|
|
DebugManager.flags.EnableMultiRootDeviceContexts.set(true);
|
2017-12-21 07:45:38 +08:00
|
|
|
PerformanceHintTest::SetUp();
|
|
|
|
zeroSized = GetParam();
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
PerformanceHintTest::TearDown();
|
|
|
|
}
|
2020-12-03 02:19:05 +08:00
|
|
|
DebugManagerStateRestore restorer;
|
2020-03-13 21:59:00 +08:00
|
|
|
bool zeroSized = false;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|