Skip to content

Commit f24ec6e

Browse files
Add DisableZeroCopyForBuffers debug flag.
- This flag disables zero copy for all buffers. Change-Id: I882f01942f99e399e33f5fe2750acbcc0476457c
1 parent dccee61 commit f24ec6e

File tree

5 files changed

+44
-4
lines changed

5 files changed

+44
-4
lines changed

runtime/mem_obj/buffer.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,8 @@ void Buffer::checkMemory(cl_mem_flags flags,
211211
if (alignUp(hostPtr, MemoryConstants::cacheLineSize) != hostPtr ||
212212
alignUp(size, MemoryConstants::cacheLineSize) != size ||
213213
minAddress > reinterpret_cast<uintptr_t>(hostPtr) ||
214-
DebugManager.flags.DisableZeroCopyForUseHostPtr.get()) {
214+
DebugManager.flags.DisableZeroCopyForUseHostPtr.get() ||
215+
DebugManager.flags.DisableZeroCopyForBuffers.get()) {
215216
allocateMemory = true;
216217
isZeroCopy = false;
217218
copyMemoryFromHostPtr = true;
@@ -224,6 +225,9 @@ void Buffer::checkMemory(cl_mem_flags flags,
224225
} else {
225226
allocateMemory = true;
226227
isZeroCopy = true;
228+
if (DebugManager.flags.DisableZeroCopyForBuffers.get()) {
229+
isZeroCopy = false;
230+
}
227231
}
228232

229233
if (flags & CL_MEM_COPY_HOST_PTR) {

runtime/mem_obj/mem_obj.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "runtime/helpers/mipmap.h"
2828
#include "runtime/sharings/sharing.h"
2929
#include "runtime/mem_obj/map_operations_handler.h"
30+
#include "runtime/os_interface/debug_settings_manager.h"
3031
#include <atomic>
3132
#include <cstdint>
3233
#include <vector>
@@ -119,7 +120,7 @@ class MemObj : public BaseObject<_cl_mem> {
119120
void waitForCsrCompletion();
120121
void destroyGraphicsAllocation(GraphicsAllocation *allocation, bool asyncDestroy);
121122
bool checkIfMemoryTransferIsRequired(size_t offsetInMemObjest, size_t offsetInHostPtr, const void *ptr, cl_command_type cmdType);
122-
bool mappingOnCpuAllowed() const { return !allowTiling() && !peekSharingHandler() && !isMipMapped(this); }
123+
bool mappingOnCpuAllowed() const { return !allowTiling() && !peekSharingHandler() && !isMipMapped(this) && !DebugManager.flags.DisableZeroCopyForBuffers.get(); }
123124
virtual size_t calculateOffsetForMapping(const MemObjOffsetArray &offset) const { return offset[0]; }
124125
size_t calculateMappedPtrLength(const MemObjSizeArray &size) const { return calculateOffsetForMapping(size); }
125126
cl_mem_object_type peekClMemObjType() const { return memObjectType; }

runtime/os_interface/DebugVariables.inl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ DECLARE_DEBUG_VARIABLE(bool, DisableConcurrentBlockExecution, 0, "disables concu
6464
DECLARE_DEBUG_VARIABLE(bool, UseNewHeapAllocator, true, "Custom 4GB heap allocator is used")
6565
DECLARE_DEBUG_VARIABLE(bool, UseNoRingFlushesKmdMode, true, "Windows only, passes flag to KMD that informs KMD to not emit any ring buffer flushes.")
6666
DECLARE_DEBUG_VARIABLE(bool, DisableZeroCopyForUseHostPtr, false, "When active all buffer allocations created with CL_MEM_USE_HOST_PTR flag will not share memory with CPU.")
67+
DECLARE_DEBUG_VARIABLE(bool, DisableZeroCopyForBuffers, false, "When active all buffer allocations will not share memory with CPU.")
6768
/*FEATURE FLAGS*/
6869
DECLARE_DEBUG_VARIABLE(bool, EnableNV12, true, "Enables NV12 extension")
6970
DECLARE_DEBUG_VARIABLE(bool, EnablePackedYuv, true, "Enables cl_packed_yuv extension")

unit_tests/mem_obj/zero_copy_tests.cpp

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,20 +147,53 @@ TEST(ZeroCopyBufferTestWithSharedContext, GivenContextThatIsSharedAndDisableZero
147147
EXPECT_TRUE(buffer->isMemObjZeroCopy());
148148
}
149149

150-
TEST(ZeroCopyWithDebugFlag, GivenInputsThatWouldResultInZeroCopyAndDisableZeroCopyFlagWhenBufferIsCreatedThenNonZeroCopyBufferIsReturned) {
150+
TEST(ZeroCopyWithDebugFlag, GivenInputsThatWouldResultInZeroCopyAndUseHostptrDisableZeroCopyFlagWhenBufferIsCreatedThenNonZeroCopyBufferIsReturned) {
151151
DebugManagerStateRestore stateRestore;
152152
DebugManager.flags.DisableZeroCopyForUseHostPtr.set(true);
153153
MockContext context;
154-
auto host_ptr = reinterpret_cast<void *>(alignedMalloc(MemoryConstants::pageSize, MemoryConstants::pageSize));
154+
auto host_ptr = alignedMalloc(MemoryConstants::pageSize, MemoryConstants::pageSize);
155+
auto size = MemoryConstants::pageSize;
156+
auto retVal = CL_SUCCESS;
157+
158+
std::unique_ptr<Buffer> buffer(Buffer::create(&context, CL_MEM_USE_HOST_PTR, size, host_ptr, retVal));
159+
EXPECT_EQ(CL_SUCCESS, retVal);
160+
EXPECT_FALSE(buffer->isMemObjZeroCopy());
161+
alignedFree(host_ptr);
162+
}
163+
164+
TEST(ZeroCopyWithDebugFlag, GivenInputsThatWouldResultInZeroCopyAndDisableZeroCopyFlagWhenBufferIsCreatedThenNonZeroCopyBufferIsReturned) {
165+
DebugManagerStateRestore stateRestore;
166+
DebugManager.flags.DisableZeroCopyForBuffers.set(true);
167+
MockContext context;
168+
auto host_ptr = alignedMalloc(MemoryConstants::pageSize, MemoryConstants::pageSize);
155169
auto size = MemoryConstants::pageSize;
156170
auto retVal = CL_SUCCESS;
157171

158172
std::unique_ptr<Buffer> buffer(Buffer::create(&context, CL_MEM_USE_HOST_PTR, size, host_ptr, retVal));
159173
EXPECT_EQ(CL_SUCCESS, retVal);
160174
EXPECT_FALSE(buffer->isMemObjZeroCopy());
175+
EXPECT_FALSE(buffer->mappingOnCpuAllowed());
161176
alignedFree(host_ptr);
162177
}
163178

179+
TEST(ZeroCopyWithDebugFlag, GivenBufferInputsThatWouldResultInZeroCopyAndDisableZeroCopyFlagWhenBufferIsCreatedThenNonZeroCopyBufferIsReturned) {
180+
DebugManagerStateRestore stateRestore;
181+
DebugManager.flags.DisableZeroCopyForBuffers.set(true);
182+
MockContext context;
183+
auto retVal = CL_SUCCESS;
184+
std::unique_ptr<Buffer> buffer(Buffer::create(&context, CL_MEM_ALLOC_HOST_PTR, MemoryConstants::pageSize, nullptr, retVal));
185+
EXPECT_EQ(CL_SUCCESS, retVal);
186+
EXPECT_FALSE(buffer->isMemObjZeroCopy());
187+
EXPECT_FALSE(buffer->mappingOnCpuAllowed());
188+
EXPECT_EQ(nullptr, buffer->getHostPtr());
189+
EXPECT_EQ(nullptr, buffer->getAllocatedMapPtr());
190+
auto bufferAllocation = buffer->getGraphicsAllocation()->getUnderlyingBuffer();
191+
192+
auto mapAllocation = buffer->getBasePtrForMap();
193+
EXPECT_EQ(mapAllocation, buffer->getAllocatedMapPtr());
194+
EXPECT_NE(mapAllocation, bufferAllocation);
195+
}
196+
164197
TEST(ZeroCopyBufferWith32BitAddressing, GivenDeviceSupporting32BitAddressingWhenAskedForBufferCreationFromHostPtrThenNonZeroCopyBufferIsReturned) {
165198
DebugManagerStateRestore dbgRestorer;
166199
DebugManager.flags.Force32bitAddressing.set(true);

unit_tests/test_files/igdrcl.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,5 @@ AddPatchInfoCommentsForAUBDump = false
6565
HwQueueSupported = false
6666
DisableZeroCopyForUseHostPtr = false
6767
SchedulerGWS = 0
68+
DisableZeroCopyForBuffers = false
6869
OverrideAubDeviceId = -1

0 commit comments

Comments
 (0)