2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2020-02-22 16:28:27 +08:00
|
|
|
* Copyright (C) 2017-2020 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
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-04-22 04:40:21 +08:00
|
|
|
#include "shared/test/unit_test/helpers/debug_manager_state_restore.h"
|
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/kernel/kernel.h"
|
|
|
|
#include "opencl/source/mem_obj/buffer.h"
|
2020-05-28 20:05:12 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/context_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/fixtures/memory_management_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/kernel/kernel_arg_buffer_fixture.h"
|
|
|
|
#include "opencl/test/unit_test/mocks/mock_buffer.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"
|
2020-12-11 23:48:06 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/ult_cl_device_factory.h"
|
2019-02-27 18:39:32 +08:00
|
|
|
#include "test.h"
|
|
|
|
|
|
|
|
#include "CL/cl.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
#include "gtest/gtest.h"
|
2020-07-30 21:02:11 +08:00
|
|
|
#include "hw_cmds.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
typedef Test<KernelArgBufferFixture> KernelArgBufferTest;
|
|
|
|
|
2020-04-27 16:22:25 +08:00
|
|
|
TEST_F(KernelArgBufferTest, GivenValidBufferWhenSettingKernelArgThenBufferAddressIsCorrect) {
|
2017-12-21 07:45:38 +08:00
|
|
|
Buffer *buffer = new MockBuffer();
|
|
|
|
|
|
|
|
auto val = (cl_mem)buffer;
|
|
|
|
auto pVal = &val;
|
|
|
|
|
|
|
|
auto retVal = this->pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
2020-11-19 02:39:32 +08:00
|
|
|
auto pKernelArg = (cl_mem **)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
|
2017-12-21 07:45:38 +08:00
|
|
|
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
|
|
|
|
EXPECT_EQ(buffer->getCpuAddress(), *pKernelArg);
|
|
|
|
|
|
|
|
delete buffer;
|
|
|
|
}
|
|
|
|
|
2020-12-11 23:48:06 +08:00
|
|
|
struct MultiDeviceKernelArgBufferTest : public ::testing::Test {
|
|
|
|
|
|
|
|
void SetUp() override {
|
|
|
|
ClDeviceVector devicesForContext;
|
|
|
|
devicesForContext.push_back(deviceFactory.rootDevices[1]);
|
|
|
|
devicesForContext.push_back(deviceFactory.subDevices[4]);
|
|
|
|
devicesForContext.push_back(deviceFactory.subDevices[5]);
|
|
|
|
pContext = std::make_unique<MockContext>(devicesForContext);
|
|
|
|
kernelInfos.resize(3);
|
|
|
|
kernelInfos[0] = nullptr;
|
|
|
|
pKernelInfosStorage[0] = std::make_unique<KernelInfo>();
|
|
|
|
pKernelInfosStorage[1] = std::make_unique<KernelInfo>();
|
|
|
|
kernelInfos[1] = pKernelInfosStorage[0].get();
|
|
|
|
kernelInfos[2] = pKernelInfosStorage[1].get();
|
|
|
|
|
|
|
|
auto &hwHelper = HwHelper::get(renderCoreFamily);
|
|
|
|
|
|
|
|
// setup kernel arg offsets
|
|
|
|
KernelArgPatchInfo kernelArgPatchInfo;
|
|
|
|
|
|
|
|
for (auto i = 0u; i < 2; i++) {
|
|
|
|
pKernelInfosStorage[i]->heapInfo.pSsh = pSshLocal[i];
|
|
|
|
pKernelInfosStorage[i]->heapInfo.SurfaceStateHeapSize = sizeof(pSshLocal[i]);
|
|
|
|
pKernelInfosStorage[i]->usesSsh = true;
|
|
|
|
pKernelInfosStorage[i]->requiresSshForBuffers = true;
|
|
|
|
pKernelInfosStorage[i]->kernelDescriptor.kernelAttributes.simdSize = hwHelper.getMinimalSIMDSize();
|
|
|
|
|
|
|
|
auto crossThreadDataPointer = &pCrossThreadData[i];
|
|
|
|
memcpy_s(ptrOffset(&pCrossThreadData[i], i * sizeof(void *)), sizeof(void *), &crossThreadDataPointer, sizeof(void *));
|
|
|
|
pKernelInfosStorage[i]->crossThreadData = pCrossThreadData[i];
|
|
|
|
|
|
|
|
pKernelInfosStorage[i]->kernelArgInfo.resize(1);
|
|
|
|
pKernelInfosStorage[i]->kernelArgInfo[0].kernelArgPatchInfoVector.push_back(kernelArgPatchInfo);
|
|
|
|
pKernelInfosStorage[i]->kernelArgInfo[0].isBuffer = true;
|
|
|
|
|
|
|
|
pKernelInfosStorage[i]->patchInfo.dataParameterStream = &dataParameterStream[i];
|
|
|
|
dataParameterStream[i].DataParameterStreamSize = (i + 1) * sizeof(void *);
|
|
|
|
|
|
|
|
pKernelInfosStorage[i]->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset = i * sizeof(void *);
|
|
|
|
pKernelInfosStorage[i]->kernelArgInfo[0].kernelArgPatchInfoVector[0].size = sizeof(void *);
|
|
|
|
}
|
|
|
|
|
|
|
|
auto retVal = CL_INVALID_PROGRAM;
|
|
|
|
pBuffer = std::unique_ptr<Buffer>(Buffer::create(pContext.get(), 0u, MemoryConstants::pageSize, nullptr, retVal));
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, pBuffer);
|
|
|
|
|
|
|
|
pProgram = std::make_unique<MockProgram>(pContext.get(), false, pContext->getDevices());
|
|
|
|
}
|
|
|
|
|
|
|
|
void TearDown() override {
|
|
|
|
for (auto i = 0u; i < 2; i++) {
|
|
|
|
pKernelInfosStorage[i]->crossThreadData = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
UltClDeviceFactory deviceFactory{3, 2};
|
|
|
|
std::unique_ptr<MockContext> pContext;
|
|
|
|
SPatchDataParameterStream dataParameterStream[2]{};
|
|
|
|
std::unique_ptr<KernelInfo> pKernelInfosStorage[2];
|
|
|
|
char pCrossThreadData[2][64]{};
|
|
|
|
char pSshLocal[2][64]{};
|
|
|
|
KernelInfoContainer kernelInfos;
|
|
|
|
std::unique_ptr<Buffer> pBuffer;
|
|
|
|
std::unique_ptr<MockProgram> pProgram;
|
|
|
|
};
|
|
|
|
TEST_F(MultiDeviceKernelArgBufferTest, GivenValidBufferWhenSettingKernelArgThenBufferAddressIsCorrect) {
|
|
|
|
|
|
|
|
auto pKernel = std::unique_ptr<MockKernel>(Kernel::create<MockKernel>(pProgram.get(), kernelInfos, nullptr));
|
|
|
|
|
|
|
|
EXPECT_NE(nullptr, pKernel);
|
|
|
|
cl_mem val = pBuffer.get();
|
|
|
|
auto pVal = &val;
|
|
|
|
|
|
|
|
auto retVal = pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
for (auto &rootDeviceIndex : pContext->getRootDeviceIndices()) {
|
|
|
|
auto pKernelArg = reinterpret_cast<size_t *>(pKernel->getCrossThreadData(rootDeviceIndex) +
|
|
|
|
kernelInfos[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
|
|
|
|
EXPECT_EQ(pBuffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddressToPatch(), *pKernelArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-27 16:22:25 +08:00
|
|
|
TEST_F(KernelArgBufferTest, GivenSvmPtrStatelessWhenSettingKernelArgThenArgumentsAreSetCorrectly) {
|
2017-12-21 07:45:38 +08:00
|
|
|
Buffer *buffer = new MockBuffer();
|
|
|
|
|
|
|
|
auto val = (cl_mem)buffer;
|
|
|
|
auto pVal = &val;
|
|
|
|
|
|
|
|
pKernelInfo->usesSsh = false;
|
|
|
|
pKernelInfo->requiresSshForBuffers = false;
|
|
|
|
|
|
|
|
auto retVal = this->pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_FALSE(pKernel->requiresCoherency());
|
|
|
|
|
2020-11-24 02:01:38 +08:00
|
|
|
EXPECT_EQ(0u, pKernel->getSurfaceStateHeapSize(rootDeviceIndex));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
delete buffer;
|
|
|
|
}
|
|
|
|
|
2020-04-27 16:22:25 +08:00
|
|
|
HWTEST_F(KernelArgBufferTest, GivenSvmPtrStatefulWhenSettingKernelArgThenArgumentsAreSetCorrectly) {
|
2017-12-21 07:45:38 +08:00
|
|
|
Buffer *buffer = new MockBuffer();
|
|
|
|
|
|
|
|
auto val = (cl_mem)buffer;
|
|
|
|
auto pVal = &val;
|
|
|
|
|
|
|
|
pKernelInfo->usesSsh = true;
|
|
|
|
pKernelInfo->requiresSshForBuffers = true;
|
|
|
|
|
|
|
|
auto retVal = this->pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_FALSE(pKernel->requiresCoherency());
|
|
|
|
|
2020-11-24 02:01:38 +08:00
|
|
|
EXPECT_NE(0u, pKernel->getSurfaceStateHeapSize(rootDeviceIndex));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE;
|
|
|
|
auto surfaceState = reinterpret_cast<const RENDER_SURFACE_STATE *>(
|
2020-11-24 02:01:38 +08:00
|
|
|
ptrOffset(pKernel->getSurfaceStateHeap(rootDeviceIndex), pKernelInfo->kernelArgInfo[0].offsetHeap));
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:19:09 +08:00
|
|
|
auto surfaceAddress = surfaceState->getSurfaceBaseAddress();
|
2020-06-09 01:17:23 +08:00
|
|
|
EXPECT_EQ(buffer->getGraphicsAllocation(mockRootDeviceIndex)->getGpuAddress(), surfaceAddress);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
delete buffer;
|
|
|
|
}
|
|
|
|
|
2020-12-11 23:48:06 +08:00
|
|
|
HWTEST_F(MultiDeviceKernelArgBufferTest, GivenSvmPtrStatefulWhenSettingKernelArgThenArgumentsAreSetCorrectly) {
|
|
|
|
cl_mem val = pBuffer.get();
|
|
|
|
auto pVal = &val;
|
|
|
|
|
|
|
|
for (auto i = 0; i < 2; i++) {
|
|
|
|
pKernelInfosStorage[i]->usesSsh = true;
|
|
|
|
pKernelInfosStorage[i]->requiresSshForBuffers = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pKernel = std::unique_ptr<MockKernel>(Kernel::create<MockKernel>(pProgram.get(), kernelInfos, nullptr));
|
|
|
|
|
|
|
|
auto retVal = pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_FALSE(pKernel->requiresCoherency());
|
|
|
|
|
|
|
|
for (auto &rootDeviceIndex : pContext->getRootDeviceIndices()) {
|
|
|
|
EXPECT_NE(0u, pKernel->getSurfaceStateHeapSize(rootDeviceIndex));
|
|
|
|
|
|
|
|
typedef typename FamilyType::RENDER_SURFACE_STATE RENDER_SURFACE_STATE;
|
|
|
|
auto surfaceState = reinterpret_cast<const RENDER_SURFACE_STATE *>(
|
|
|
|
ptrOffset(pKernel->getSurfaceStateHeap(rootDeviceIndex), kernelInfos[rootDeviceIndex]->kernelArgInfo[0].offsetHeap));
|
|
|
|
|
|
|
|
auto surfaceAddress = surfaceState->getSurfaceBaseAddress();
|
|
|
|
EXPECT_EQ(pBuffer->getGraphicsAllocation(rootDeviceIndex)->getGpuAddress(), surfaceAddress);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-27 16:22:25 +08:00
|
|
|
HWTEST_F(KernelArgBufferTest, GivenBufferFromSvmPtrWhenSettingKernelArgThenArgumentsAreSetCorrectly) {
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
Buffer *buffer = new MockBuffer();
|
2020-06-09 01:17:23 +08:00
|
|
|
buffer->getGraphicsAllocation(mockRootDeviceIndex)->setCoherent(true);
|
2017-12-21 07:45:38 +08:00
|
|
|
|
|
|
|
auto val = (cl_mem)buffer;
|
|
|
|
auto pVal = &val;
|
|
|
|
|
|
|
|
auto retVal = this->pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_TRUE(pKernel->requiresCoherency());
|
|
|
|
|
|
|
|
delete buffer;
|
|
|
|
}
|
|
|
|
|
2020-04-27 16:22:25 +08:00
|
|
|
TEST_F(KernelArgBufferTest, GivenInvalidBufferWhenSettingKernelArgThenInvalidMemObjectErrorIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
char *ptr = new char[sizeof(Buffer)];
|
|
|
|
|
|
|
|
auto val = (cl_mem *)ptr;
|
|
|
|
auto pVal = &val;
|
|
|
|
auto retVal = this->pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
EXPECT_EQ(CL_INVALID_MEM_OBJECT, retVal);
|
|
|
|
|
|
|
|
delete[] ptr;
|
|
|
|
}
|
|
|
|
|
2020-04-27 16:22:25 +08:00
|
|
|
TEST_F(KernelArgBufferTest, GivenNullPtrWhenSettingKernelArgThenKernelArgIsNull) {
|
2017-12-21 07:45:38 +08:00
|
|
|
auto val = (cl_mem *)nullptr;
|
|
|
|
auto pVal = &val;
|
|
|
|
this->pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
|
2020-11-19 02:39:32 +08:00
|
|
|
auto pKernelArg = (cl_mem **)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
|
2017-12-21 07:45:38 +08:00
|
|
|
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
|
|
|
|
|
|
|
|
EXPECT_EQ(nullptr, *pKernelArg);
|
|
|
|
}
|
|
|
|
|
2020-12-11 23:48:06 +08:00
|
|
|
TEST_F(MultiDeviceKernelArgBufferTest, GivenNullPtrWhenSettingKernelArgThenKernelArgIsNull) {
|
|
|
|
|
|
|
|
auto pKernel = std::unique_ptr<MockKernel>(Kernel::create<MockKernel>(pProgram.get(), kernelInfos, nullptr));
|
|
|
|
|
|
|
|
auto val = nullptr;
|
|
|
|
auto pVal = &val;
|
|
|
|
pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
for (auto &rootDeviceIndex : pContext->getRootDeviceIndices()) {
|
|
|
|
auto pKernelArg = reinterpret_cast<void **>(pKernel->getCrossThreadData(rootDeviceIndex) +
|
|
|
|
kernelInfos[rootDeviceIndex]->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
|
|
|
|
EXPECT_EQ(nullptr, *pKernelArg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-21 07:45:38 +08:00
|
|
|
TEST_F(KernelArgBufferTest, given32BitDeviceWhenArgPtrPassedIsNullThenOnly4BytesAreBeingPatched) {
|
|
|
|
auto val = (cl_mem *)nullptr;
|
|
|
|
auto pVal = &val;
|
|
|
|
|
|
|
|
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].size = 4;
|
|
|
|
|
2020-11-19 02:39:32 +08:00
|
|
|
auto pKernelArg64bit = (uint64_t *)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
|
2017-12-21 07:45:38 +08:00
|
|
|
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
|
|
|
|
|
|
|
|
uint32_t *pKernelArg32bit = (uint32_t *)pKernelArg64bit;
|
|
|
|
|
|
|
|
*pKernelArg64bit = 0xffffffffffffffff;
|
|
|
|
|
|
|
|
this->pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
uint64_t expValue = 0u;
|
|
|
|
|
|
|
|
EXPECT_EQ(0u, *pKernelArg32bit);
|
|
|
|
EXPECT_NE(expValue, *pKernelArg64bit);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(KernelArgBufferTest, given32BitDeviceWhenArgPassedIsNullThenOnly4BytesAreBeingPatched) {
|
|
|
|
auto pVal = nullptr;
|
|
|
|
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].size = 4;
|
2020-11-19 02:39:32 +08:00
|
|
|
auto pKernelArg64bit = (uint64_t *)(this->pKernel->getCrossThreadData(rootDeviceIndex) +
|
2017-12-21 07:45:38 +08:00
|
|
|
this->pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset);
|
|
|
|
|
|
|
|
*pKernelArg64bit = 0xffffffffffffffff;
|
|
|
|
|
|
|
|
uint32_t *pKernelArg32bit = (uint32_t *)pKernelArg64bit;
|
|
|
|
|
|
|
|
this->pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
uint64_t expValue = 0u;
|
|
|
|
|
|
|
|
EXPECT_EQ(0u, *pKernelArg32bit);
|
|
|
|
EXPECT_NE(expValue, *pKernelArg64bit);
|
|
|
|
}
|
2018-12-06 22:33:02 +08:00
|
|
|
|
2019-03-06 23:35:21 +08:00
|
|
|
TEST_F(KernelArgBufferTest, givenWritableBufferWhenSettingAsArgThenDoNotExpectAllocationInCacheFlushVector) {
|
2018-12-06 22:33:02 +08:00
|
|
|
auto buffer = std::make_unique<MockBuffer>();
|
|
|
|
buffer->mockGfxAllocation.setMemObjectsAllocationWithWritableFlags(true);
|
2019-02-27 21:59:46 +08:00
|
|
|
buffer->mockGfxAllocation.setFlushL3Required(false);
|
2018-12-06 22:33:02 +08:00
|
|
|
|
|
|
|
auto val = static_cast<cl_mem>(buffer.get());
|
|
|
|
auto pVal = &val;
|
|
|
|
|
|
|
|
auto retVal = pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
2019-04-03 17:22:04 +08:00
|
|
|
EXPECT_EQ(nullptr, pKernel->kernelArgRequiresCacheFlush[0]);
|
2018-12-06 22:33:02 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(KernelArgBufferTest, givenCacheFlushBufferWhenSettingAsArgThenExpectAllocationInCacheFlushVector) {
|
|
|
|
auto buffer = std::make_unique<MockBuffer>();
|
|
|
|
buffer->mockGfxAllocation.setMemObjectsAllocationWithWritableFlags(false);
|
2019-02-27 21:59:46 +08:00
|
|
|
buffer->mockGfxAllocation.setFlushL3Required(true);
|
2018-12-06 22:33:02 +08:00
|
|
|
|
|
|
|
auto val = static_cast<cl_mem>(buffer.get());
|
|
|
|
auto pVal = &val;
|
|
|
|
|
|
|
|
auto retVal = pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(&buffer->mockGfxAllocation, pKernel->kernelArgRequiresCacheFlush[0]);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(KernelArgBufferTest, givenNoCacheFlushBufferWhenSettingAsArgThenNotExpectAllocationInCacheFlushVector) {
|
|
|
|
auto buffer = std::make_unique<MockBuffer>();
|
|
|
|
buffer->mockGfxAllocation.setMemObjectsAllocationWithWritableFlags(false);
|
2019-02-27 21:59:46 +08:00
|
|
|
buffer->mockGfxAllocation.setFlushL3Required(false);
|
2018-12-06 22:33:02 +08:00
|
|
|
|
|
|
|
auto val = static_cast<cl_mem>(buffer.get());
|
|
|
|
auto pVal = &val;
|
|
|
|
|
|
|
|
auto retVal = pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_EQ(nullptr, pKernel->kernelArgRequiresCacheFlush[0]);
|
|
|
|
}
|
2020-04-22 04:40:21 +08:00
|
|
|
|
2020-12-16 01:13:28 +08:00
|
|
|
TEST_F(KernelArgBufferTest, givenBufferWhenHasDirectStatelessAccessToHostMemoryIsCalledThenReturnFalse) {
|
|
|
|
MockBuffer buffer;
|
|
|
|
buffer.getGraphicsAllocation(mockRootDeviceIndex)->setAllocationType(GraphicsAllocation::AllocationType::BUFFER);
|
|
|
|
|
|
|
|
auto val = (cl_mem)&buffer;
|
|
|
|
auto pVal = &val;
|
|
|
|
|
|
|
|
for (auto pureStatefulBufferAccess : {false, true}) {
|
|
|
|
pKernelInfo->kernelArgInfo[0].pureStatefulBufferAccess = pureStatefulBufferAccess;
|
|
|
|
|
|
|
|
auto retVal = pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
EXPECT_FALSE(pKernel->hasDirectStatelessAccessToHostMemory());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(KernelArgBufferTest, givenBufferInHostMemoryWhenHasDirectStatelessAccessToHostMemoryIsCalledThenReturnCorrectValue) {
|
|
|
|
MockBuffer buffer;
|
|
|
|
buffer.getGraphicsAllocation(mockRootDeviceIndex)->setAllocationType(GraphicsAllocation::AllocationType::BUFFER_HOST_MEMORY);
|
|
|
|
|
|
|
|
auto val = (cl_mem)&buffer;
|
|
|
|
auto pVal = &val;
|
|
|
|
|
|
|
|
for (auto pureStatefulBufferAccess : {false, true}) {
|
|
|
|
pKernelInfo->kernelArgInfo[0].pureStatefulBufferAccess = pureStatefulBufferAccess;
|
|
|
|
|
|
|
|
auto retVal = pKernel->setArg(0, sizeof(cl_mem *), pVal);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
|
|
|
|
EXPECT_EQ(!pureStatefulBufferAccess, pKernel->hasDirectStatelessAccessToHostMemory());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(KernelArgBufferTest, givenInvalidMemObjWhenHasDirectStatelessAccessToHostMemoryIsCalledThenReturnFalse) {
|
|
|
|
KernelInfo kernelInfo;
|
|
|
|
MockKernel emptyKernel(pProgram, MockKernel::toKernelInfoContainer(kernelInfo, 0));
|
|
|
|
EXPECT_FALSE(emptyKernel.hasDirectStatelessAccessToHostMemory());
|
|
|
|
|
|
|
|
pKernel->kernelArguments.at(0).type = Kernel::NONE_OBJ;
|
|
|
|
EXPECT_FALSE(pKernel->hasDirectStatelessAccessToHostMemory());
|
|
|
|
|
|
|
|
pKernel->kernelArguments.at(0).type = Kernel::BUFFER_OBJ;
|
|
|
|
EXPECT_FALSE(pKernel->hasDirectStatelessAccessToHostMemory());
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(KernelArgBufferTest, whenSettingAuxTranslationRequiredThenIsAuxTranslationRequiredReturnsCorrectValue) {
|
|
|
|
for (auto auxTranslationRequired : {false, true}) {
|
|
|
|
pKernel->setAuxTranslationRequired(auxTranslationRequired);
|
|
|
|
EXPECT_EQ(auxTranslationRequired, pKernel->isAuxTranslationRequired());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-17 19:55:37 +08:00
|
|
|
class KernelArgBufferFixtureBindless : public KernelArgBufferFixture {
|
|
|
|
public:
|
|
|
|
void SetUp() {
|
|
|
|
DebugManager.flags.UseBindlessMode.set(1);
|
|
|
|
KernelArgBufferFixture::SetUp();
|
|
|
|
}
|
2020-11-20 17:48:23 +08:00
|
|
|
void TearDown() override {
|
2020-11-17 19:55:37 +08:00
|
|
|
KernelArgBufferFixture::TearDown();
|
|
|
|
}
|
|
|
|
DebugManagerStateRestore restorer;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef Test<KernelArgBufferFixtureBindless> KernelArgBufferTestBindless;
|
|
|
|
|
|
|
|
HWTEST_F(KernelArgBufferTestBindless, givenUsedBindlessBuffersWhenPatchingSurfaceStateOffsetsThenCorrectOffsetIsPatchedInCrossThreadData) {
|
2020-04-27 21:40:12 +08:00
|
|
|
using DataPortBindlessSurfaceExtendedMessageDescriptor = typename FamilyType::DataPortBindlessSurfaceExtendedMessageDescriptor;
|
2020-04-22 04:40:21 +08:00
|
|
|
DebugManagerStateRestore restorer;
|
2020-10-07 19:53:56 +08:00
|
|
|
DebugManager.flags.UseBindlessMode.set(1);
|
2020-04-22 04:40:21 +08:00
|
|
|
|
|
|
|
pKernelInfo->usesSsh = true;
|
|
|
|
pKernelInfo->requiresSshForBuffers = true;
|
|
|
|
|
|
|
|
auto crossThreadDataOffset = pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset;
|
|
|
|
pKernelInfo->kernelArgInfo[0].offsetHeap = 64;
|
|
|
|
pKernelInfo->kernelArgInfo[0].isBuffer = true;
|
|
|
|
|
2020-11-19 02:39:32 +08:00
|
|
|
auto patchLocation = reinterpret_cast<uint32_t *>(ptrOffset(pKernel->getCrossThreadData(rootDeviceIndex), crossThreadDataOffset));
|
2020-04-22 04:40:21 +08:00
|
|
|
*patchLocation = 0xdead;
|
|
|
|
|
2020-04-27 21:40:12 +08:00
|
|
|
uint32_t sshOffset = 0x1000;
|
2020-11-19 02:39:32 +08:00
|
|
|
pKernel->patchBindlessSurfaceStateOffsets(*pDevice, sshOffset);
|
2020-04-27 21:40:12 +08:00
|
|
|
DataPortBindlessSurfaceExtendedMessageDescriptor extMessageDesc;
|
|
|
|
extMessageDesc.setBindlessSurfaceOffset(sshOffset + pKernelInfo->kernelArgInfo[0].offsetHeap);
|
|
|
|
auto expectedOffset = extMessageDesc.getBindlessSurfaceOffsetToPatch();
|
2020-04-22 04:40:21 +08:00
|
|
|
EXPECT_EQ(expectedOffset, *patchLocation);
|
|
|
|
|
2020-04-27 21:40:12 +08:00
|
|
|
sshOffset = static_cast<uint32_t>(maxNBitValue(20) + 1) - 64;
|
2020-11-19 02:39:32 +08:00
|
|
|
pKernel->patchBindlessSurfaceStateOffsets(*pDevice, sshOffset);
|
2020-04-27 21:40:12 +08:00
|
|
|
extMessageDesc.setBindlessSurfaceOffset(sshOffset + pKernelInfo->kernelArgInfo[0].offsetHeap);
|
|
|
|
expectedOffset = extMessageDesc.getBindlessSurfaceOffsetToPatch();
|
2020-04-22 04:40:21 +08:00
|
|
|
EXPECT_EQ(expectedOffset, *patchLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(KernelArgBufferTest, givenUsedBindlessBuffersAndNonBufferArgWhenPatchingSurfaceStateOffsetsThenCrossThreadDataIsNotPatched) {
|
|
|
|
DebugManagerStateRestore restorer;
|
2020-10-07 19:53:56 +08:00
|
|
|
DebugManager.flags.UseBindlessMode.set(1);
|
2020-04-22 04:40:21 +08:00
|
|
|
|
|
|
|
pKernelInfo->usesSsh = true;
|
|
|
|
pKernelInfo->requiresSshForBuffers = true;
|
|
|
|
|
|
|
|
auto crossThreadDataOffset = pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset;
|
|
|
|
pKernelInfo->kernelArgInfo[0].offsetHeap = 64;
|
|
|
|
pKernelInfo->kernelArgInfo[0].isBuffer = false;
|
|
|
|
|
2020-11-19 02:39:32 +08:00
|
|
|
auto patchLocation = reinterpret_cast<uint32_t *>(ptrOffset(pKernel->getCrossThreadData(rootDeviceIndex), crossThreadDataOffset));
|
2020-04-22 04:40:21 +08:00
|
|
|
*patchLocation = 0xdead;
|
|
|
|
|
|
|
|
uint32_t sshOffset = 4000;
|
2020-11-19 02:39:32 +08:00
|
|
|
pKernel->patchBindlessSurfaceStateOffsets(*pDevice, sshOffset);
|
2020-04-22 04:40:21 +08:00
|
|
|
EXPECT_EQ(0xdeadu, *patchLocation);
|
|
|
|
}
|
|
|
|
|
|
|
|
TEST_F(KernelArgBufferTest, givenNotUsedBindlessBuffersAndBufferArgWhenPatchingSurfaceStateOffsetsThenCrossThreadDataIsNotPatched) {
|
|
|
|
DebugManagerStateRestore restorer;
|
2020-10-07 19:53:56 +08:00
|
|
|
DebugManager.flags.UseBindlessMode.set(0);
|
2020-04-22 04:40:21 +08:00
|
|
|
|
|
|
|
pKernelInfo->usesSsh = true;
|
|
|
|
pKernelInfo->requiresSshForBuffers = true;
|
|
|
|
|
|
|
|
auto crossThreadDataOffset = pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset;
|
|
|
|
pKernelInfo->kernelArgInfo[0].offsetHeap = 64;
|
|
|
|
pKernelInfo->kernelArgInfo[0].isBuffer = true;
|
|
|
|
|
2020-11-19 02:39:32 +08:00
|
|
|
auto patchLocation = reinterpret_cast<uint32_t *>(ptrOffset(pKernel->getCrossThreadData(rootDeviceIndex), crossThreadDataOffset));
|
2020-04-22 04:40:21 +08:00
|
|
|
*patchLocation = 0xdead;
|
|
|
|
|
|
|
|
uint32_t sshOffset = 4000;
|
2020-11-19 02:39:32 +08:00
|
|
|
pKernel->patchBindlessSurfaceStateOffsets(*pDevice, sshOffset);
|
2020-04-22 04:40:21 +08:00
|
|
|
EXPECT_EQ(0xdeadu, *patchLocation);
|
2020-05-04 17:49:35 +08:00
|
|
|
}
|
|
|
|
|
2020-11-17 19:55:37 +08:00
|
|
|
HWTEST_F(KernelArgBufferTestBindless, givenUsedBindlessBuffersAndBuiltinKernelWhenPatchingSurfaceStateOffsetsThenOffsetIsPatched) {
|
2020-05-04 17:49:35 +08:00
|
|
|
using DataPortBindlessSurfaceExtendedMessageDescriptor = typename FamilyType::DataPortBindlessSurfaceExtendedMessageDescriptor;
|
|
|
|
|
|
|
|
pKernelInfo->usesSsh = true;
|
|
|
|
pKernelInfo->requiresSshForBuffers = true;
|
|
|
|
|
|
|
|
auto crossThreadDataOffset = pKernelInfo->kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset;
|
|
|
|
pKernelInfo->kernelArgInfo[0].offsetHeap = 64;
|
|
|
|
pKernelInfo->kernelArgInfo[0].isBuffer = true;
|
|
|
|
|
2020-11-19 02:39:32 +08:00
|
|
|
auto patchLocation = reinterpret_cast<uint32_t *>(ptrOffset(pKernel->getCrossThreadData(rootDeviceIndex), crossThreadDataOffset));
|
2020-05-04 17:49:35 +08:00
|
|
|
*patchLocation = 0xdead;
|
|
|
|
|
|
|
|
pKernel->isBuiltIn = true;
|
|
|
|
|
|
|
|
uint32_t sshOffset = 0x1000;
|
2020-11-19 02:39:32 +08:00
|
|
|
pKernel->patchBindlessSurfaceStateOffsets(*pDevice, sshOffset);
|
2020-10-07 19:53:56 +08:00
|
|
|
EXPECT_NE(0xdeadu, *patchLocation);
|
2020-04-22 04:40:21 +08:00
|
|
|
}
|