2017-12-21 07:45:38 +08:00
|
|
|
/*
|
2023-01-04 23:00:09 +08:00
|
|
|
* Copyright (C) 2018-2023 Intel Corporation
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
2019-02-27 18:39:32 +08:00
|
|
|
* SPDX-License-Identifier: MIT
|
2017-12-21 07:45:38 +08:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2023-01-09 23:02:00 +08:00
|
|
|
#include "shared/source/gmm_helper/gmm_helper.h"
|
2021-10-21 22:50:10 +08:00
|
|
|
#include "shared/test/common/fixtures/memory_management_fixture.h"
|
2021-12-15 01:40:08 +08:00
|
|
|
#include "shared/test/common/test_macros/test.h"
|
2021-10-21 22:50:10 +08:00
|
|
|
|
2020-02-23 05:50:57 +08:00
|
|
|
#include "opencl/source/mem_obj/pipe.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h"
|
2020-03-04 22:28:58 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_command_queue.h"
|
2020-02-23 22:20:22 +08:00
|
|
|
#include "opencl/test/unit_test/mocks/mock_context.h"
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2019-03-26 18:59:46 +08:00
|
|
|
using namespace NEO;
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2023-01-04 23:00:09 +08:00
|
|
|
// Tests for pipes
|
2017-12-21 07:45:38 +08:00
|
|
|
|
2020-06-02 19:38:13 +08:00
|
|
|
class PipeTest : public ::testing::Test, public MemoryManagementFixture {
|
2017-12-21 07:45:38 +08:00
|
|
|
public:
|
|
|
|
protected:
|
|
|
|
void SetUp() override {
|
|
|
|
}
|
|
|
|
void TearDown() override {
|
|
|
|
}
|
2020-06-02 19:38:13 +08:00
|
|
|
cl_int retVal = CL_INVALID_PIPE_SIZE;
|
2017-12-21 07:45:38 +08:00
|
|
|
MockContext context;
|
2020-06-02 19:38:13 +08:00
|
|
|
size_t size = 0u;
|
2017-12-21 07:45:38 +08:00
|
|
|
};
|
|
|
|
|
2020-05-27 16:18:58 +08:00
|
|
|
TEST_F(PipeTest, WhenCreatingPipeThenSuccessIsReturned) {
|
2017-12-21 07:45:38 +08:00
|
|
|
int errCode = CL_SUCCESS;
|
|
|
|
|
|
|
|
auto pipe = Pipe::create(&context, CL_MEM_READ_ONLY, 1, 20, nullptr, errCode);
|
|
|
|
|
|
|
|
EXPECT_NE(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, errCode);
|
|
|
|
|
|
|
|
delete pipe;
|
|
|
|
}
|
|
|
|
|
2020-05-27 16:18:58 +08:00
|
|
|
TEST_F(PipeTest, WhenCreatingPipeThenHeaderSizeAdditionIsReserved) {
|
2017-12-21 07:45:38 +08:00
|
|
|
int errCode = CL_SUCCESS;
|
|
|
|
|
|
|
|
auto pipe = Pipe::create(&context, CL_MEM_READ_ONLY, 1, 20, nullptr, errCode);
|
|
|
|
|
|
|
|
ASSERT_NE(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, errCode);
|
|
|
|
EXPECT_EQ((1 * (20 + 1)) + Pipe::intelPipeHeaderReservedSpace, pipe->getSize());
|
|
|
|
|
|
|
|
delete pipe;
|
|
|
|
}
|
|
|
|
|
2020-05-27 16:18:58 +08:00
|
|
|
TEST_F(PipeTest, WhenCreatingPipeThenHeaderIsInitialized) {
|
2017-12-21 07:45:38 +08:00
|
|
|
int errCode = CL_SUCCESS;
|
|
|
|
|
|
|
|
auto pipe = Pipe::create(&context, CL_MEM_READ_ONLY, 1, 20, nullptr, errCode);
|
|
|
|
|
|
|
|
ASSERT_NE(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, errCode);
|
|
|
|
|
|
|
|
EXPECT_EQ(21u, *reinterpret_cast<unsigned int *>(pipe->getCpuAddress()));
|
|
|
|
|
|
|
|
delete pipe;
|
|
|
|
}
|
|
|
|
|
2020-05-27 16:18:58 +08:00
|
|
|
TEST_F(PipeTest, GivenFailedAllocationInjectionWhenCreatingPipeThenOnlyFailingAllocationsAreNull) {
|
2017-12-21 07:45:38 +08:00
|
|
|
InjectedFunction method = [this](size_t failureIndex) {
|
|
|
|
auto retVal = CL_INVALID_VALUE;
|
|
|
|
auto pipe = Pipe::create(&context, CL_MEM_READ_ONLY, 1, 20, nullptr, retVal);
|
|
|
|
|
2019-07-15 17:30:19 +08:00
|
|
|
if (MemoryManagement::nonfailingAllocation == failureIndex) {
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
|
|
|
EXPECT_NE(nullptr, pipe);
|
|
|
|
delete pipe;
|
|
|
|
} else {
|
|
|
|
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal) << "for allocation " << failureIndex;
|
|
|
|
EXPECT_EQ(nullptr, pipe);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
injectFailures(method);
|
|
|
|
}
|
|
|
|
|
2018-02-01 20:40:30 +08:00
|
|
|
TEST_F(PipeTest, givenPipeWhenEnqueueWriteForUnmapIsCalledThenReturnError) {
|
2017-12-21 07:45:38 +08:00
|
|
|
int errCode = CL_SUCCESS;
|
2018-02-01 20:40:30 +08:00
|
|
|
std::unique_ptr<Pipe> pipe(Pipe::create(&context, CL_MEM_READ_ONLY, 1, 20, nullptr, errCode));
|
2017-12-21 07:45:38 +08:00
|
|
|
ASSERT_NE(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, errCode);
|
|
|
|
|
2020-03-04 22:28:58 +08:00
|
|
|
MockCommandQueue cmdQ;
|
2018-02-21 22:25:46 +08:00
|
|
|
errCode = clEnqueueUnmapMemObject(&cmdQ, pipe.get(), nullptr, 0, nullptr, nullptr);
|
2017-12-21 07:45:38 +08:00
|
|
|
EXPECT_EQ(CL_INVALID_MEM_OBJECT, errCode);
|
|
|
|
}
|
2019-06-21 22:22:21 +08:00
|
|
|
|
|
|
|
TEST_F(PipeTest, givenPipeWithDifferentCpuAndGpuAddressesWhenSetArgPipeThenUseGpuAddress) {
|
|
|
|
int errCode = CL_SUCCESS;
|
|
|
|
|
|
|
|
auto pipe = Pipe::create(&context, CL_MEM_READ_ONLY, 1, 20, nullptr, errCode);
|
|
|
|
|
|
|
|
ASSERT_NE(nullptr, pipe);
|
|
|
|
EXPECT_EQ(CL_SUCCESS, errCode);
|
|
|
|
|
|
|
|
EXPECT_EQ(21u, *reinterpret_cast<unsigned int *>(pipe->getCpuAddress()));
|
|
|
|
uint64_t gpuAddress = 0x12345;
|
2020-06-02 19:38:13 +08:00
|
|
|
auto pipeAllocation = pipe->getGraphicsAllocation(context.getDevice(0)->getRootDeviceIndex());
|
2022-06-07 04:34:20 +08:00
|
|
|
auto gmmHelper = context.getDevice(0)->getGmmHelper();
|
|
|
|
auto canonizedGpuAddress = gmmHelper->canonize(gpuAddress);
|
|
|
|
pipeAllocation->setCpuPtrAndGpuAddress(pipeAllocation->getUnderlyingBuffer(), canonizedGpuAddress);
|
2019-06-21 22:22:21 +08:00
|
|
|
EXPECT_NE(reinterpret_cast<uint64_t>(pipeAllocation->getUnderlyingBuffer()), pipeAllocation->getGpuAddress());
|
|
|
|
uint64_t valueToPatch;
|
2020-06-24 17:01:35 +08:00
|
|
|
pipe->setPipeArg(&valueToPatch, sizeof(valueToPatch), context.getDevice(0)->getRootDeviceIndex());
|
2019-06-21 22:22:21 +08:00
|
|
|
EXPECT_EQ(valueToPatch, pipeAllocation->getGpuAddressToPatch());
|
|
|
|
|
|
|
|
delete pipe;
|
2019-12-04 20:45:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
using MultiRootDeviceTests = MultiRootDeviceFixture;
|
|
|
|
|
2020-12-09 01:43:41 +08:00
|
|
|
TEST_F(MultiRootDeviceTests, GivenPipeGraphicsAllocationThenItHasCorrectRootDeviceIndex) {
|
2019-12-04 20:45:32 +08:00
|
|
|
int errCode = CL_SUCCESS;
|
|
|
|
|
|
|
|
std::unique_ptr<Pipe> pipe(Pipe::create(context.get(), CL_MEM_READ_ONLY, 1, 20, nullptr, errCode));
|
|
|
|
EXPECT_EQ(CL_SUCCESS, errCode);
|
|
|
|
ASSERT_NE(nullptr, pipe.get());
|
2020-06-02 19:38:13 +08:00
|
|
|
auto graphicsAllocation = pipe->getGraphicsAllocation(expectedRootDeviceIndex);
|
2019-12-04 20:45:32 +08:00
|
|
|
ASSERT_NE(nullptr, graphicsAllocation);
|
|
|
|
EXPECT_EQ(expectedRootDeviceIndex, graphicsAllocation->getRootDeviceIndex());
|
2020-03-04 22:28:58 +08:00
|
|
|
}
|