mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-20 00:24:58 +08:00
Move logic of copying ISA to separated method
Change-Id: I2c5fd3004fa41ed1bf1cf3d54741756f546f6941 Signed-off-by: Mateusz Jablonski <mateusz.jablonski@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
0939743874
commit
5b2d13765a
@@ -400,4 +400,11 @@ HeapIndex MemoryManager::selectHeap(const GraphicsAllocation *allocation, const
|
||||
}
|
||||
return HeapIndex::HEAP_LIMITED;
|
||||
}
|
||||
bool MemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, uint32_t sizeToCopy) const {
|
||||
if (!graphicsAllocation || !memoryToCopy || sizeToCopy == 0u) {
|
||||
return false;
|
||||
}
|
||||
memcpy_s(graphicsAllocation->getUnderlyingBuffer(), graphicsAllocation->getUnderlyingBufferSize(), memoryToCopy, sizeToCopy);
|
||||
return true;
|
||||
}
|
||||
} // namespace OCLRT
|
||||
|
||||
@@ -190,6 +190,7 @@ class MemoryManager {
|
||||
EngineControl *getRegisteredEngineForCsr(CommandStreamReceiver *commandStreamReceiver);
|
||||
HostPtrManager *getHostPtrManager() const { return hostPtrManager.get(); }
|
||||
void setDefaultEngineIndex(uint32_t index) { defaultEngineIndex = index; }
|
||||
virtual bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, uint32_t sizeToCopy) const;
|
||||
|
||||
static HeapIndex selectHeap(const GraphicsAllocation *allocation, const void *ptr, const HardwareInfo &hwInfo);
|
||||
|
||||
|
||||
@@ -60,6 +60,8 @@ class WddmMemoryManager : public MemoryManager {
|
||||
|
||||
AlignedMallocRestrictions *getAlignedMallocRestrictions() override;
|
||||
|
||||
bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, uint32_t sizeToCopy) const override;
|
||||
|
||||
protected:
|
||||
GraphicsAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2018 Intel Corporation
|
||||
* Copyright (C) 2018-2019 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: MIT
|
||||
*
|
||||
@@ -11,4 +11,7 @@ namespace OCLRT {
|
||||
GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) {
|
||||
return MemoryManager::allocateGraphicsMemoryInDevicePool(allocationData, status);
|
||||
}
|
||||
bool WddmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, uint32_t sizeToCopy) const {
|
||||
return MemoryManager::copyMemoryToAllocation(graphicsAllocation, memoryToCopy, sizeToCopy);
|
||||
}
|
||||
} // namespace OCLRT
|
||||
|
||||
@@ -488,12 +488,7 @@ bool KernelInfo::createKernelAllocation(MemoryManager *memoryManager) {
|
||||
UNRECOVERABLE_IF(kernelAllocation);
|
||||
auto kernelIsaSize = heapInfo.pKernelHeader->KernelHeapSize;
|
||||
kernelAllocation = memoryManager->allocateGraphicsMemoryWithProperties({kernelIsaSize, GraphicsAllocation::AllocationType::KERNEL_ISA});
|
||||
if (kernelAllocation) {
|
||||
memcpy_s(kernelAllocation->getUnderlyingBuffer(), kernelIsaSize, heapInfo.pKernelHeap, kernelIsaSize);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
return memoryManager->copyMemoryToAllocation(kernelAllocation, heapInfo.pKernelHeap, kernelIsaSize);
|
||||
}
|
||||
|
||||
} // namespace OCLRT
|
||||
|
||||
@@ -1717,3 +1717,25 @@ TEST_F(MemoryAllocatorTest, whenCommandStreamerIsNotRegisteredThenReturnNullEngi
|
||||
auto engineControl = memoryManager->getRegisteredEngineForCsr(dummyCsr);
|
||||
EXPECT_EQ(nullptr, engineControl);
|
||||
}
|
||||
TEST(MemoryManagerCopyMemoryTest, givenNullPointerOrZeroSizeWhenCopyMemoryToAllocationThenReturnFalse) {
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
MockMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
constexpr uint8_t allocationSize = 10;
|
||||
uint8_t allocationStorage[allocationSize];
|
||||
MockGraphicsAllocation allocation{allocationStorage, allocationSize};
|
||||
uint8_t memory = 1;
|
||||
EXPECT_FALSE(memoryManager.copyMemoryToAllocation(nullptr, &memory, sizeof(memory)));
|
||||
EXPECT_FALSE(memoryManager.copyMemoryToAllocation(&allocation, nullptr, sizeof(memory)));
|
||||
EXPECT_FALSE(memoryManager.copyMemoryToAllocation(&allocation, &memory, 0u));
|
||||
}
|
||||
TEST(MemoryManagerCopyMemoryTest, givenValidAllocationAndMemoryWhenCopyMemoryToAllocationThenDataIsCopied) {
|
||||
ExecutionEnvironment executionEnvironment;
|
||||
MockMemoryManager memoryManager(false, false, executionEnvironment);
|
||||
constexpr uint8_t allocationSize = 10;
|
||||
uint8_t allocationStorage[allocationSize] = {0};
|
||||
MockGraphicsAllocation allocation{allocationStorage, allocationSize};
|
||||
uint8_t memory = 1u;
|
||||
EXPECT_EQ(0u, allocationStorage[0]);
|
||||
EXPECT_TRUE(memoryManager.copyMemoryToAllocation(&allocation, &memory, sizeof(memory)));
|
||||
EXPECT_EQ(memory, allocationStorage[0]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user