mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Add entry points for detecting whether cpu copy is required.
Change-Id: I04438da6241eedf127fd7e51ab257d22186d904e Signed-off-by: Michal Mrozek <michal.mrozek@intel.com>
This commit is contained in:

committed by
sys_ocldev

parent
4c781c1b98
commit
4803e82eda
@ -556,6 +556,10 @@ size_t CommandQueue::estimateTimestampPacketNodesCount(const MultiDispatchInfo &
|
||||
bool CommandQueue::bufferCpuCopyAllowed(Buffer *buffer, cl_command_type commandType, cl_bool blocking, size_t size, void *ptr,
|
||||
cl_uint numEventsInWaitList, const cl_event *eventWaitList) {
|
||||
|
||||
if (buffer->getMemoryManager() && buffer->getMemoryManager()->isCpuCopyRequired(ptr)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
auto debugVariableSet = false;
|
||||
// Requested by debug variable or allowed by Buffer
|
||||
if (CL_COMMAND_READ_BUFFER == commandType && DebugManager.flags.DoCpuCopyOnReadBuffer.get() != -1) {
|
||||
|
@ -263,6 +263,27 @@ TEST(ReadWriteBufferOnCpu, givenNoHostPtrAndAlignedSizeWhenMemoryAllocationIsInN
|
||||
}
|
||||
}
|
||||
|
||||
TEST(ReadWriteBufferOnCpu, givenPointerThatRequiresCpuCopyWhenCpuCopyIsEvaluatedThenTrueIsReturned) {
|
||||
auto device = std::make_unique<MockClDevice>(MockDevice::createWithNewExecutionEnvironment<MockDevice>(nullptr));
|
||||
auto memoryManager = new MockMemoryManager(*device->getExecutionEnvironment());
|
||||
|
||||
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));
|
||||
buffer->forceDisallowCPUCopy = true;
|
||||
|
||||
ASSERT_NE(nullptr, buffer.get());
|
||||
auto mockCommandQueue = std::unique_ptr<MockCommandQueue>(new MockCommandQueue);
|
||||
|
||||
EXPECT_FALSE(mockCommandQueue->bufferCpuCopyAllowed(buffer.get(), CL_COMMAND_READ_BUFFER, true, MemoryConstants::pageSize, nullptr, 0u, nullptr));
|
||||
memoryManager->cpuCopyRequired = true;
|
||||
EXPECT_TRUE(mockCommandQueue->bufferCpuCopyAllowed(buffer.get(), CL_COMMAND_READ_BUFFER, true, MemoryConstants::pageSize, nullptr, 0u, nullptr));
|
||||
}
|
||||
|
||||
TEST(ReadWriteBufferOnCpu, given32BitApplicationWhenLocalMemoryPoolAllocationIsAskedForPreferenceThenCpuIsChoosen) {
|
||||
if (is64bit) {
|
||||
GTEST_SKIP();
|
||||
|
@ -105,6 +105,8 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
||||
return OsAgnosticMemoryManager::reserveCpuAddressRange(size, rootDeviceIndex);
|
||||
}
|
||||
|
||||
bool isCpuCopyRequired(const void *ptr) override { return cpuCopyRequired; }
|
||||
|
||||
GraphicsAllocation *allocate32BitGraphicsMemory(size_t size, const void *ptr, GraphicsAllocation::AllocationType allocationType);
|
||||
GraphicsAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
|
||||
|
||||
@ -126,6 +128,7 @@ class MockMemoryManager : public MemoryManagerCreate<OsAgnosticMemoryManager> {
|
||||
bool failReserveAddress = false;
|
||||
bool failAllocateSystemMemory = false;
|
||||
bool failAllocate32Bit = false;
|
||||
bool cpuCopyRequired = false;
|
||||
std::unique_ptr<MockExecutionEnvironment> mockExecutionEnvironment;
|
||||
};
|
||||
|
||||
|
@ -164,6 +164,7 @@ class MemoryManager {
|
||||
|
||||
static uint32_t maxOsContextCount;
|
||||
virtual void commonCleanup(){};
|
||||
virtual bool isCpuCopyRequired(const void *ptr) { return false; }
|
||||
|
||||
protected:
|
||||
struct AllocationData {
|
||||
|
Reference in New Issue
Block a user