mirror of
https://github.com/intel/compute-runtime.git
synced 2026-01-08 14:02:58 +08:00
Upload data to cpu inaccessible memory with enqueueWriteBuffer
Change-Id: Ibb33c4248fd0cb4338c82a9deb3994147c0acba5
This commit is contained in:
committed by
sys_ocldev
parent
e06aa17dfc
commit
330b9eddbd
@@ -207,7 +207,7 @@ Buffer *Buffer::create(Context *context,
|
||||
pBuffer->setHostPtrMinSize(size);
|
||||
|
||||
if (copyMemoryFromHostPtr) {
|
||||
if (memory->gmm && memory->gmm->isRenderCompressed) {
|
||||
if ((memory->gmm && memory->gmm->isRenderCompressed) || !MemoryPool::isSystemMemoryPool(memory->getMemoryPool())) {
|
||||
auto cmdQ = context->getSpecialQueue();
|
||||
if (CL_SUCCESS != cmdQ->enqueueWriteBuffer(pBuffer, CL_TRUE, 0, size, hostPtr, 0, nullptr, nullptr)) {
|
||||
errcodeRet = CL_OUT_OF_RESOURCES;
|
||||
@@ -390,7 +390,8 @@ bool Buffer::isReadWriteOnCpuAllowed(cl_bool blocking, cl_uint numEventsInWaitLi
|
||||
return (blocking == CL_TRUE && numEventsInWaitList == 0 && !forceDisallowCPUCopy) && graphicsAllocation->peekSharedHandle() == 0 &&
|
||||
(isMemObjZeroCopy() || (reinterpret_cast<uintptr_t>(ptr) & (MemoryConstants::cacheLineSize - 1)) != 0) &&
|
||||
(!context->getDevice(0)->getDeviceInfo().platformLP || (size <= maxBufferSizeForReadWriteOnCpu)) &&
|
||||
!(graphicsAllocation->gmm && graphicsAllocation->gmm->isRenderCompressed);
|
||||
!(graphicsAllocation->gmm && graphicsAllocation->gmm->isRenderCompressed) &&
|
||||
MemoryPool::isSystemMemoryPool(graphicsAllocation->getMemoryPool());
|
||||
}
|
||||
|
||||
Buffer *Buffer::createBufferHw(Context *context,
|
||||
|
||||
@@ -292,3 +292,21 @@ HWTEST_F(ReadWriteBufferCpuCopyTest, cpuCopyCriteriaNotMet) {
|
||||
alignedFree(alignedHostPtr);
|
||||
alignedFree(alignedBufferPtr);
|
||||
}
|
||||
|
||||
TEST(ReadWriteBufferOnCpu, givenNoHostPtrAndAlignedSizeWhenMemoryAllocationIsInNonSystemMemoryPoolThenIsReadWriteOnCpuAllowedReturnsFalse) {
|
||||
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
||||
auto memoryManager = new MockMemoryManager;
|
||||
|
||||
device->injectMemoryManager(memoryManager);
|
||||
MockContext ctx(device.get());
|
||||
|
||||
cl_int retVal = 0;
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE;
|
||||
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(&ctx, flags, MemoryConstants::pageSize, nullptr, retVal));
|
||||
ASSERT_NE(nullptr, buffer.get());
|
||||
|
||||
EXPECT_TRUE(buffer->isReadWriteOnCpuAllowed(CL_TRUE, 0, reinterpret_cast<void *>(0x1000), MemoryConstants::pageSize));
|
||||
reinterpret_cast<MemoryAllocation *>(buffer->getGraphicsAllocation())->overrideMemoryPool(MemoryPool::SystemCpuInaccessible);
|
||||
EXPECT_FALSE(buffer->isReadWriteOnCpuAllowed(CL_TRUE, 0, reinterpret_cast<void *>(0x1000), MemoryConstants::pageSize));
|
||||
}
|
||||
|
||||
@@ -320,6 +320,32 @@ TEST(Buffer, givenZeroFlagsNoSharedContextAndRenderCompressedBuffersDisabledWhen
|
||||
EXPECT_EQ(GraphicsAllocation::AllocationType::BUFFER, type);
|
||||
}
|
||||
|
||||
TEST(Buffer, givenClMemCopyHostPointerPassedToBufferCreateWhenAllocationIsNotInSystemMemoryPoolThenAllocationIsWrittenByEnqueueWriteBuffer) {
|
||||
std::unique_ptr<MockDevice> device(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
||||
::testing::NiceMock<GMockMemoryManagerFailFirstAllocation> *memoryManager = new ::testing::NiceMock<GMockMemoryManagerFailFirstAllocation>;
|
||||
|
||||
device->injectMemoryManager(memoryManager);
|
||||
MockContext ctx(device.get());
|
||||
|
||||
auto allocateNonSystemGraphicsAllocation = [memoryManager](AllocationFlags flags, DevicesBitfield devicesBitfield, const void *hostPtr, size_t size, GraphicsAllocation::AllocationType type) -> GraphicsAllocation * {
|
||||
auto allocation = memoryManager->allocateGraphicsMemory(size, MemoryConstants::pageSize, false, false);
|
||||
reinterpret_cast<MemoryAllocation *>(allocation)->overrideMemoryPool(MemoryPool::SystemCpuInaccessible);
|
||||
return allocation;
|
||||
};
|
||||
|
||||
EXPECT_CALL(*memoryManager, allocateGraphicsMemoryInPreferredPool(::testing::_, ::testing::_, ::testing::_, ::testing::_, ::testing::_))
|
||||
.WillOnce(::testing::Invoke(allocateNonSystemGraphicsAllocation));
|
||||
|
||||
cl_int retVal = 0;
|
||||
cl_mem_flags flags = CL_MEM_READ_WRITE | CL_MEM_COPY_HOST_PTR;
|
||||
char memory[] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
auto taskCount = device->getCommandStreamReceiver().peekLatestFlushedTaskCount();
|
||||
|
||||
std::unique_ptr<Buffer> buffer(Buffer::create(&ctx, flags, sizeof(memory), memory, retVal));
|
||||
ASSERT_NE(nullptr, buffer.get());
|
||||
auto taskCountSent = device->getCommandStreamReceiver().peekLatestFlushedTaskCount();
|
||||
EXPECT_LT(taskCount, taskCountSent);
|
||||
}
|
||||
struct RenderCompressedBuffersTests : public ::testing::Test {
|
||||
void SetUp() override {
|
||||
localHwInfo = *platformDevices[0];
|
||||
|
||||
Reference in New Issue
Block a user