From 30a534a4e461eed96c24f1c825d6518e599e4bfb Mon Sep 17 00:00:00 2001 From: Mateusz Jablonski Date: Fri, 21 Jun 2019 16:22:21 +0200 Subject: [PATCH] Use GPU address when patching pipe Change-Id: I4e4ca7ab2597fa97aa8cd1229382187974b22dde Signed-off-by: Mateusz Jablonski --- runtime/mem_obj/pipe.cpp | 2 +- unit_tests/mem_obj/pipe_tests.cpp | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/runtime/mem_obj/pipe.cpp b/runtime/mem_obj/pipe.cpp index 92b360c932..45a417233d 100644 --- a/runtime/mem_obj/pipe.cpp +++ b/runtime/mem_obj/pipe.cpp @@ -109,7 +109,7 @@ cl_int Pipe::getPipeInfo(cl_image_info paramName, } void Pipe::setPipeArg(void *memory, uint32_t patchSize) { - patchWithRequiredSize(memory, patchSize, (uintptr_t)getCpuAddress()); + patchWithRequiredSize(memory, patchSize, static_cast(getGraphicsAllocation()->getGpuAddressToPatch())); } Pipe::~Pipe() = default; diff --git a/unit_tests/mem_obj/pipe_tests.cpp b/unit_tests/mem_obj/pipe_tests.cpp index d0cbf3780f..8bb7cc1c26 100644 --- a/unit_tests/mem_obj/pipe_tests.cpp +++ b/unit_tests/mem_obj/pipe_tests.cpp @@ -93,3 +93,23 @@ TEST_F(PipeTest, givenPipeWhenEnqueueWriteForUnmapIsCalledThenReturnError) { errCode = clEnqueueUnmapMemObject(&cmdQ, pipe.get(), nullptr, 0, nullptr, nullptr); EXPECT_EQ(CL_INVALID_MEM_OBJECT, errCode); } + +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(pipe->getCpuAddress())); + uint64_t gpuAddress = 0x12345; + auto pipeAllocation = pipe->getGraphicsAllocation(); + pipeAllocation->setCpuPtrAndGpuAddress(pipeAllocation->getUnderlyingBuffer(), gpuAddress); + EXPECT_NE(reinterpret_cast(pipeAllocation->getUnderlyingBuffer()), pipeAllocation->getGpuAddress()); + uint64_t valueToPatch; + pipe->setPipeArg(&valueToPatch, sizeof(valueToPatch)); + EXPECT_EQ(valueToPatch, pipeAllocation->getGpuAddressToPatch()); + + delete pipe; +} \ No newline at end of file