2017-12-21 00:45:38 +01:00
|
|
|
/*
|
2021-05-16 20:51:16 +02:00
|
|
|
* Copyright (C) 2018-2021 Intel Corporation
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
2018-09-18 09:11:08 +02:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 00:45:38 +01:00
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-02-23 22:44:01 +01:00
|
|
|
#include "shared/source/helpers/basic_math.h"
|
|
|
|
|
#include "shared/source/helpers/ptr_math.h"
|
2021-12-14 17:40:08 +00:00
|
|
|
#include "shared/test/common/test_macros/test.h"
|
2020-02-24 10:22:30 +01:00
|
|
|
|
2020-02-22 22:50:57 +01:00
|
|
|
#include "opencl/source/kernel/kernel.h"
|
2020-12-22 17:29:56 +00:00
|
|
|
#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h"
|
2020-02-23 15:20:22 +01:00
|
|
|
#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"
|
2019-02-27 11:39:32 +01:00
|
|
|
|
2017-12-21 00:45:38 +01:00
|
|
|
#include "gtest/gtest.h"
|
|
|
|
|
|
2019-03-26 11:59:46 +01:00
|
|
|
using namespace NEO;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-12-22 17:29:56 +00:00
|
|
|
class KernelSlmArgTest : public MultiRootDeviceWithSubDevicesFixture {
|
2017-12-21 00:45:38 +01:00
|
|
|
protected:
|
|
|
|
|
void SetUp() override {
|
2020-12-22 17:29:56 +00:00
|
|
|
MultiRootDeviceWithSubDevicesFixture::SetUp();
|
|
|
|
|
|
|
|
|
|
program = std::make_unique<MockProgram>(context.get(), false, context->getDevices());
|
2021-04-08 11:05:45 +02:00
|
|
|
pKernelInfo = std::make_unique<MockKernelInfo>();
|
|
|
|
|
|
2021-03-19 11:22:17 +00:00
|
|
|
KernelVectorType kernels;
|
|
|
|
|
kernels.resize(3);
|
2020-12-22 17:29:56 +00:00
|
|
|
|
2021-04-08 11:05:45 +02:00
|
|
|
KernelInfoContainer kernelInfos;
|
|
|
|
|
kernelInfos.resize(3);
|
|
|
|
|
kernelInfos[0] = kernelInfos[1] = kernelInfos[2] = pKernelInfo.get();
|
|
|
|
|
|
|
|
|
|
pKernelInfo->kernelDescriptor.kernelAttributes.simdSize = 1;
|
|
|
|
|
|
|
|
|
|
pKernelInfo->addArgLocal(0, 0x10, 0x1);
|
|
|
|
|
|
|
|
|
|
pKernelInfo->addArgBuffer(1, 0x20, sizeof(void *));
|
|
|
|
|
|
|
|
|
|
pKernelInfo->addArgLocal(2, 0x30, 0x10);
|
|
|
|
|
|
|
|
|
|
pKernelInfo->kernelDescriptor.kernelAttributes.slmInlineSize = 3 * KB;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2021-03-19 11:22:17 +00:00
|
|
|
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
|
2021-04-08 11:05:45 +02:00
|
|
|
pKernel[rootDeviceIndex] = new MockKernel(program.get(), *pKernelInfo, *deviceFactory->rootDevices[rootDeviceIndex]);
|
2021-03-19 11:22:17 +00:00
|
|
|
kernels[rootDeviceIndex] = pKernel[rootDeviceIndex];
|
|
|
|
|
ASSERT_EQ(CL_SUCCESS, pKernel[rootDeviceIndex]->initialize());
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-22 15:26:03 +00:00
|
|
|
pMultiDeviceKernel = std::make_unique<MultiDeviceKernel>(kernels, kernelInfos);
|
2020-12-22 17:29:56 +00:00
|
|
|
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
|
|
|
|
|
crossThreadData[rootDeviceIndex][0x20 / sizeof(uint32_t)] = 0x12344321;
|
2021-03-19 11:22:17 +00:00
|
|
|
|
2021-03-22 09:49:27 +00:00
|
|
|
pKernel[rootDeviceIndex]->setCrossThreadData(&crossThreadData[rootDeviceIndex], sizeof(crossThreadData[rootDeviceIndex]));
|
2020-12-22 17:29:56 +00:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TearDown() override {
|
2020-12-22 17:29:56 +00:00
|
|
|
MultiRootDeviceWithSubDevicesFixture::TearDown();
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
cl_int retVal = CL_SUCCESS;
|
2018-08-09 11:34:50 +02:00
|
|
|
std::unique_ptr<MockProgram> program;
|
2021-03-19 11:22:17 +00:00
|
|
|
MockKernel *pKernel[3] = {nullptr};
|
|
|
|
|
std::unique_ptr<MultiDeviceKernel> pMultiDeviceKernel;
|
2021-04-08 11:05:45 +02:00
|
|
|
std::unique_ptr<MockKernelInfo> pKernelInfo;
|
2017-12-21 00:45:38 +01:00
|
|
|
|
|
|
|
|
static const size_t slmSize0 = 0x200;
|
|
|
|
|
static const size_t slmSize2 = 0x30;
|
2020-12-22 17:29:56 +00:00
|
|
|
uint32_t crossThreadData[3][0x40]{};
|
2017-12-21 00:45:38 +01:00
|
|
|
};
|
|
|
|
|
|
2020-05-05 13:00:47 +02:00
|
|
|
TEST_F(KernelSlmArgTest, WhenSettingSizeThenAlignmentOfHigherSlmArgsIsUpdated) {
|
2021-03-19 11:22:17 +00:00
|
|
|
pMultiDeviceKernel->setArg(0, slmSize0, nullptr);
|
|
|
|
|
pMultiDeviceKernel->setArg(2, slmSize2, nullptr);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-12-22 17:29:56 +00:00
|
|
|
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
|
2021-03-22 11:06:23 +00:00
|
|
|
auto crossThreadData = reinterpret_cast<uint32_t *>(pKernel[rootDeviceIndex]->getCrossThreadData());
|
2020-12-22 17:29:56 +00:00
|
|
|
auto slmOffset = ptrOffset(crossThreadData, 0x10);
|
|
|
|
|
EXPECT_EQ(0u, *slmOffset);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-12-22 17:29:56 +00:00
|
|
|
slmOffset = ptrOffset(crossThreadData, 0x20);
|
|
|
|
|
EXPECT_EQ(0x12344321u, *slmOffset);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-12-22 17:29:56 +00:00
|
|
|
slmOffset = ptrOffset(crossThreadData, 0x30);
|
2021-04-08 11:05:45 +02:00
|
|
|
EXPECT_EQ(0x200u, *slmOffset);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2021-04-08 11:05:45 +02:00
|
|
|
EXPECT_EQ(4 * KB, pKernel[rootDeviceIndex]->slmTotalSize);
|
2020-12-22 17:29:56 +00:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-05 13:00:47 +02:00
|
|
|
TEST_F(KernelSlmArgTest, GivenReverseOrderWhenSettingSizeThenAlignmentOfHigherSlmArgsIsUpdated) {
|
2021-03-19 11:22:17 +00:00
|
|
|
pMultiDeviceKernel->setArg(2, slmSize2, nullptr);
|
|
|
|
|
pMultiDeviceKernel->setArg(0, slmSize0, nullptr);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-12-22 17:29:56 +00:00
|
|
|
for (auto &rootDeviceIndex : this->context->getRootDeviceIndices()) {
|
2021-03-22 11:06:23 +00:00
|
|
|
auto crossThreadData = reinterpret_cast<uint32_t *>(pKernel[rootDeviceIndex]->getCrossThreadData());
|
2020-12-22 17:29:56 +00:00
|
|
|
auto slmOffset = ptrOffset(crossThreadData, 0x10);
|
|
|
|
|
EXPECT_EQ(0u, *slmOffset);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-12-22 17:29:56 +00:00
|
|
|
slmOffset = ptrOffset(crossThreadData, 0x20);
|
|
|
|
|
EXPECT_EQ(0x12344321u, *slmOffset);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2020-12-22 17:29:56 +00:00
|
|
|
slmOffset = ptrOffset(crossThreadData, 0x30);
|
2021-04-08 11:05:45 +02:00
|
|
|
EXPECT_EQ(0x200u, *slmOffset);
|
2017-12-21 00:45:38 +01:00
|
|
|
|
2021-04-08 11:05:45 +02:00
|
|
|
EXPECT_EQ(4 * KB, pKernel[rootDeviceIndex]->slmTotalSize);
|
2020-12-22 17:29:56 +00:00
|
|
|
}
|
2017-12-21 00:45:38 +01:00
|
|
|
}
|