diff --git a/runtime/mem_obj/buffer.cpp b/runtime/mem_obj/buffer.cpp index 630f70b44e..e3c2892c87 100644 --- a/runtime/mem_obj/buffer.cpp +++ b/runtime/mem_obj/buffer.cpp @@ -30,6 +30,7 @@ #include "runtime/helpers/ptr_math.h" #include "runtime/helpers/validators.h" #include "runtime/helpers/string.h" +#include "runtime/gmm_helper/gmm.h" #include "runtime/memory_manager/svm_memory_manager.h" #include "runtime/os_interface/debug_settings_manager.h" @@ -346,7 +347,8 @@ size_t Buffer::calculateHostPtrSize(const size_t *origin, const size_t *region, bool Buffer::isReadWriteOnCpuAllowed(cl_bool blocking, cl_uint numEventsInWaitList, void *ptr, size_t size) { return (blocking == CL_TRUE && numEventsInWaitList == 0 && !forceDisallowCPUCopy) && graphicsAllocation->peekSharedHandle() == 0 && (isMemObjZeroCopy() || (reinterpret_cast(ptr) & (MemoryConstants::cacheLineSize - 1)) != 0) && - (!context->getDevice(0)->getDeviceInfo().platformLP || (size <= maxBufferSizeForReadWriteOnCpu)); + (!context->getDevice(0)->getDeviceInfo().platformLP || (size <= maxBufferSizeForReadWriteOnCpu)) && + !(graphicsAllocation->gmm && graphicsAllocation->gmm->isRenderCompressed); } Buffer *Buffer::createBufferHw(Context *context, diff --git a/runtime/mem_obj/mem_obj.cpp b/runtime/mem_obj/mem_obj.cpp index 8625031481..4e00c9bde9 100644 --- a/runtime/mem_obj/mem_obj.cpp +++ b/runtime/mem_obj/mem_obj.cpp @@ -26,6 +26,7 @@ #include "runtime/mem_obj/mem_obj.h" #include "runtime/memory_manager/deferred_deleter.h" #include "runtime/memory_manager/memory_manager.h" +#include "runtime/gmm_helper/gmm.h" #include "runtime/helpers/aligned_memory.h" #include "runtime/helpers/get_info.h" #include "runtime/command_stream/command_stream_receiver.h" @@ -346,4 +347,9 @@ bool MemObj::addMappedPtr(void *ptr, size_t ptrLength, cl_map_flags &mapFlags, return mapOperationsHandler.add(ptr, ptrLength, mapFlags, size, offset, mipLevel); } + +bool MemObj::mappingOnCpuAllowed() const { + return !allowTiling() && !peekSharingHandler() && !isMipMapped(this) && !DebugManager.flags.DisableZeroCopyForBuffers.get() && + !(graphicsAllocation->gmm && graphicsAllocation->gmm->isRenderCompressed); +} } // namespace OCLRT diff --git a/runtime/mem_obj/mem_obj.h b/runtime/mem_obj/mem_obj.h index aedc1c03df..a2a2e99900 100644 --- a/runtime/mem_obj/mem_obj.h +++ b/runtime/mem_obj/mem_obj.h @@ -120,7 +120,7 @@ class MemObj : public BaseObject<_cl_mem> { void waitForCsrCompletion(); void destroyGraphicsAllocation(GraphicsAllocation *allocation, bool asyncDestroy); bool checkIfMemoryTransferIsRequired(size_t offsetInMemObjest, size_t offsetInHostPtr, const void *ptr, cl_command_type cmdType); - bool mappingOnCpuAllowed() const { return !allowTiling() && !peekSharingHandler() && !isMipMapped(this) && !DebugManager.flags.DisableZeroCopyForBuffers.get(); } + bool mappingOnCpuAllowed() const; virtual size_t calculateOffsetForMapping(const MemObjOffsetArray &offset) const { return offset[0]; } size_t calculateMappedPtrLength(const MemObjSizeArray &size) const { return calculateOffsetForMapping(size); } cl_mem_object_type peekClMemObjType() const { return memObjectType; } diff --git a/unit_tests/command_queue/read_write_buffer_cpu_copy.cpp b/unit_tests/command_queue/read_write_buffer_cpu_copy.cpp index aa93207ffe..43935860a7 100644 --- a/unit_tests/command_queue/read_write_buffer_cpu_copy.cpp +++ b/unit_tests/command_queue/read_write_buffer_cpu_copy.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Intel Corporation + * Copyright (c) 2017 - 2018, Intel Corporation * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), @@ -20,14 +20,32 @@ * OTHER DEALINGS IN THE SOFTWARE. */ -#include "unit_tests/command_queue/enqueue_read_buffer_fixture.h" #include "runtime/helpers/basic_math.h" +#include "runtime/gmm_helper/gmm.h" +#include "unit_tests/command_queue/enqueue_read_buffer_fixture.h" #include "test.h" using namespace OCLRT; typedef EnqueueReadBufferTypeTest ReadWriteBufferCpuCopyTest; +HWTEST_F(ReadWriteBufferCpuCopyTest, givenRenderCompressedGmmWhenAskingForCpuOperationThenDisallow) { + cl_int retVal; + std::unique_ptr buffer(Buffer::create(context, CL_MEM_READ_WRITE, 1, nullptr, retVal)); + auto gmm = new Gmm(nullptr, 1, false); + gmm->isRenderCompressed = false; + buffer->getGraphicsAllocation()->gmm = gmm; + + auto alignedPtr = alignedMalloc(2, MemoryConstants::cacheLineSize); + auto unalignedPtr = ptrOffset(alignedPtr, 1); + EXPECT_TRUE(buffer->isReadWriteOnCpuAllowed(CL_TRUE, 0, unalignedPtr, 1)); + + gmm->isRenderCompressed = true; + EXPECT_FALSE(buffer->isReadWriteOnCpuAllowed(CL_TRUE, 0, unalignedPtr, 1)); + + alignedFree(alignedPtr); +} + HWTEST_F(ReadWriteBufferCpuCopyTest, simpleRead) { cl_int retVal; size_t offset = 1; @@ -286,4 +304,4 @@ HWTEST_F(ReadWriteBufferCpuCopyTest, cpuCopyCriteriaNotMet) { alignedFree(largeBufferPtr); alignedFree(alignedHostPtr); alignedFree(alignedBufferPtr); -} \ No newline at end of file +} diff --git a/unit_tests/mem_obj/mem_obj_tests.cpp b/unit_tests/mem_obj/mem_obj_tests.cpp index ef01b2b6f1..5de2db1aee 100644 --- a/unit_tests/mem_obj/mem_obj_tests.cpp +++ b/unit_tests/mem_obj/mem_obj_tests.cpp @@ -22,6 +22,7 @@ #include "runtime/mem_obj/mem_obj.h" #include "runtime/device/device.h" +#include "runtime/gmm_helper/gmm.h" #include "runtime/helpers/properties_helper.h" #include "unit_tests/mocks/mock_context.h" #include "unit_tests/mocks/mock_deferred_deleter.h" @@ -297,10 +298,34 @@ TEST(MemObj, givenTiledObjectWhenAskedForCpuMappingThenReturnFalse) { EXPECT_FALSE(memObj.mappingOnCpuAllowed()); } +TEST(MemObj, givenRenderCompressedGmmWhenAskingForMappingOnCpuThenDisallow) { + MockMemoryManager memoryManager; + MockContext context; + + context.setMemoryManager(&memoryManager); + + auto allocation = memoryManager.allocateGraphicsMemory(1, 1); + allocation->gmm = new Gmm(nullptr, 1, false); + + MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_READ_WRITE, + 1, allocation->getUnderlyingBuffer(), nullptr, allocation, false, false, false); + + allocation->gmm->isRenderCompressed = false; + EXPECT_TRUE(memObj.mappingOnCpuAllowed()); + allocation->gmm->isRenderCompressed = true; + EXPECT_FALSE(memObj.mappingOnCpuAllowed()); +} + TEST(MemObj, givenDefaultWhenAskedForCpuMappingThenReturnTrue) { - char mem[64]; - MemObj memObj(nullptr, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR, - MemoryConstants::pageSize, mem, nullptr, nullptr, true, false, false); + MockMemoryManager memoryManager; + MockContext context; + + context.setMemoryManager(&memoryManager); + + auto allocation = memoryManager.allocateGraphicsMemory(64, 1); + + MemObj memObj(&context, CL_MEM_OBJECT_BUFFER, CL_MEM_COPY_HOST_PTR, + 64, allocation->getUnderlyingBuffer(), nullptr, allocation, true, false, false); EXPECT_FALSE(memObj.allowTiling()); EXPECT_FALSE(memObj.peekSharingHandler());