mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
Extended DRM memory manager with function to copy memory to allocation
Related-To: NEO-2687 Change-Id: I2cd20c1d59dc0c28609fca7a11a5d805e2f21de4
This commit is contained in:

committed by
sys_ocldev

parent
a38e9da034
commit
6b77f94275
@ -726,7 +726,7 @@ void Kernel::substituteKernelHeap(void *newKernelHeap, size_t newKernelHeapSize)
|
||||
auto currentAllocationSize = pKernelInfo->kernelAllocation->getUnderlyingBufferSize();
|
||||
bool status = false;
|
||||
if (currentAllocationSize >= newKernelHeapSize) {
|
||||
status = memoryManager->copyMemoryToAllocation(pKernelInfo->kernelAllocation, newKernelHeap, static_cast<uint32_t>(newKernelHeapSize));
|
||||
status = memoryManager->copyMemoryToAllocation(pKernelInfo->kernelAllocation, newKernelHeap, newKernelHeapSize);
|
||||
} else {
|
||||
memoryManager->checkGpuUsageAndDestroyGraphicsAllocations(pKernelInfo->kernelAllocation);
|
||||
pKernelInfo->kernelAllocation = nullptr;
|
||||
|
@ -425,7 +425,8 @@ HeapIndex MemoryManager::selectHeap(const GraphicsAllocation *allocation, bool h
|
||||
// Limited range allocation goes to STANDARD heap
|
||||
return HeapIndex::HEAP_STANDARD;
|
||||
}
|
||||
bool MemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, uint32_t sizeToCopy) const {
|
||||
|
||||
bool MemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy) {
|
||||
if (!graphicsAllocation->getUnderlyingBuffer()) {
|
||||
return false;
|
||||
}
|
||||
|
@ -150,7 +150,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;
|
||||
virtual bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy);
|
||||
static HeapIndex selectHeap(const GraphicsAllocation *allocation, bool hasPointer, bool isFullRangeSVM);
|
||||
static std::unique_ptr<MemoryManager> createMemoryManager(ExecutionEnvironment &executionEnvironment);
|
||||
virtual void *reserveCpuAddressRange(size_t size) = 0;
|
||||
|
@ -658,6 +658,10 @@ bool DrmMemoryManager::setDomainCpu(GraphicsAllocation &graphicsAllocation, bool
|
||||
}
|
||||
|
||||
void *DrmMemoryManager::lockResourceImpl(GraphicsAllocation &graphicsAllocation) {
|
||||
if (MemoryPool::LocalMemory == graphicsAllocation.getMemoryPool()) {
|
||||
return lockResourceInLocalMemoryImpl(graphicsAllocation);
|
||||
}
|
||||
|
||||
auto cpuPtr = graphicsAllocation.getUnderlyingBuffer();
|
||||
if (cpuPtr != nullptr) {
|
||||
auto success = setDomainCpu(graphicsAllocation, false);
|
||||
@ -700,6 +704,7 @@ void DrmMemoryManager::unlockResourceImpl(GraphicsAllocation &graphicsAllocation
|
||||
|
||||
bo->setLockedAddress(nullptr);
|
||||
}
|
||||
|
||||
void *DrmMemoryManager::reserveCpuAddressRange(size_t size) {
|
||||
void *reservePtr = mmapFunction(nullptr, size, PROT_NONE, MAP_PRIVATE | MAP_ANONYMOUS | MAP_NORESERVE, -1, 0);
|
||||
return reservePtr;
|
||||
|
@ -50,6 +50,7 @@ class DrmMemoryManager : public MemoryManager {
|
||||
}
|
||||
|
||||
DrmGemCloseWorker *peekGemCloseWorker() const { return this->gemCloseWorker.get(); }
|
||||
bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy) override;
|
||||
void *reserveCpuAddressRange(size_t size) override;
|
||||
void releaseReservedCpuAddressRange(void *reserved, size_t size) override;
|
||||
|
||||
@ -74,6 +75,7 @@ class DrmMemoryManager : public MemoryManager {
|
||||
GraphicsAllocation *allocateGraphicsMemoryForImageImpl(const AllocationData &allocationData, std::unique_ptr<Gmm> gmm) override;
|
||||
|
||||
void *lockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
||||
void *lockResourceInLocalMemoryImpl(GraphicsAllocation &graphicsAllocation);
|
||||
void unlockResourceImpl(GraphicsAllocation &graphicsAllocation) override;
|
||||
DrmAllocation *allocate32BitGraphicsMemoryImpl(const AllocationData &allocationData) override;
|
||||
GraphicsAllocation *allocateGraphicsMemoryInDevicePool(const AllocationData &allocationData, AllocationStatus &status) override;
|
||||
|
@ -12,4 +12,12 @@ GraphicsAllocation *DrmMemoryManager::allocateGraphicsMemoryInDevicePool(const A
|
||||
status = AllocationStatus::RetryInNonDevicePool;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void *DrmMemoryManager::lockResourceInLocalMemoryImpl(GraphicsAllocation &graphicsAllocation) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
bool DrmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy) {
|
||||
return MemoryManager::copyMemoryToAllocation(graphicsAllocation, memoryToCopy, sizeToCopy);
|
||||
}
|
||||
} // namespace NEO
|
||||
|
@ -57,7 +57,7 @@ class WddmMemoryManager : public MemoryManager {
|
||||
|
||||
AlignedMallocRestrictions *getAlignedMallocRestrictions() override;
|
||||
|
||||
bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, uint32_t sizeToCopy) const override;
|
||||
bool copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy) override;
|
||||
void *reserveCpuAddressRange(size_t size) override;
|
||||
void releaseReservedCpuAddressRange(void *reserved, size_t size) override;
|
||||
|
||||
|
@ -12,7 +12,7 @@ GraphicsAllocation *WddmMemoryManager::allocateGraphicsMemoryInDevicePool(const
|
||||
status = AllocationStatus::RetryInNonDevicePool;
|
||||
return nullptr;
|
||||
}
|
||||
bool WddmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, uint32_t sizeToCopy) const {
|
||||
bool WddmMemoryManager::copyMemoryToAllocation(GraphicsAllocation *graphicsAllocation, const void *memoryToCopy, size_t sizeToCopy) {
|
||||
return MemoryManager::copyMemoryToAllocation(graphicsAllocation, memoryToCopy, sizeToCopy);
|
||||
}
|
||||
bool WddmMemoryManager::mapGpuVirtualAddress(WddmAllocation *allocation, const void *requiredPtr) {
|
||||
|
@ -290,9 +290,7 @@ class DrmMockCustom : public Drm {
|
||||
} break;
|
||||
|
||||
default:
|
||||
std::cout << std::hex << DRM_IOCTL_I915_GEM_WAIT << std::endl;
|
||||
std::cout << "unexpected IOCTL: " << std::hex << request << std::endl;
|
||||
UNRECOVERABLE_IF(true);
|
||||
ioctlExtra(request, arg);
|
||||
}
|
||||
|
||||
if (ext->no != -1 && ext->no == ioctl_cnt.total.load()) {
|
||||
@ -303,6 +301,16 @@ class DrmMockCustom : public Drm {
|
||||
return ioctl_res.load();
|
||||
};
|
||||
|
||||
virtual int ioctlExtra(unsigned long request, void *arg) {
|
||||
switch (request) {
|
||||
default:
|
||||
std::cout << "unexpected IOCTL: " << std::hex << request << std::endl;
|
||||
UNRECOVERABLE_IF(true);
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
IoctlResExt NONE = {-1, 0};
|
||||
void reset() {
|
||||
ioctl_res = 0;
|
||||
|
@ -8,12 +8,14 @@
|
||||
#include "runtime/execution_environment/execution_environment.h"
|
||||
#include "runtime/os_interface/linux/drm_memory_manager.h"
|
||||
#include "runtime/os_interface/linux/os_interface.h"
|
||||
#include "test.h"
|
||||
#include "unit_tests/mocks/linux/mock_drm_memory_manager.h"
|
||||
#include "unit_tests/mocks/mock_execution_environment.h"
|
||||
#include "unit_tests/os_interface/linux/drm_memory_manager_tests.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace NEO;
|
||||
using namespace ::testing;
|
||||
|
||||
using AllocationData = TestedDrmMemoryManager::AllocationData;
|
||||
|
||||
@ -32,3 +34,34 @@ TEST(DrmMemoryManagerSimpleTest, givenDrmMemoryManagerWhenAllocateInDevicePoolIs
|
||||
EXPECT_EQ(nullptr, allocation);
|
||||
EXPECT_EQ(MemoryManager::AllocationStatus::RetryInNonDevicePool, status);
|
||||
}
|
||||
|
||||
using DrmMemoryManagerWithLocalMemoryTest = Test<DrmMemoryManagerWithLocalMemoryFixture>;
|
||||
|
||||
TEST_F(DrmMemoryManagerWithLocalMemoryTest, givenDrmMemoryManagerWithLocalMemoryWhenLockResourceIsCalledOnAllocationInLocalMemoryThenReturnNullPtr) {
|
||||
DrmAllocation drmAllocation(GraphicsAllocation::AllocationType::UNKNOWN, nullptr, nullptr, 0u, 0u, MemoryPool::LocalMemory, false);
|
||||
|
||||
auto ptr = memoryManager->lockResource(&drmAllocation);
|
||||
EXPECT_EQ(nullptr, ptr);
|
||||
|
||||
memoryManager->unlockResource(&drmAllocation);
|
||||
}
|
||||
|
||||
using DrmMemoryManagerTest = Test<DrmMemoryManagerFixture>;
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmMemoryManagerWhenCopyMemoryToAllocationThenAllocationIsFilledWithCorrectData) {
|
||||
mock->ioctl_expected.gemUserptr = 1;
|
||||
mock->ioctl_expected.gemWait = 1;
|
||||
mock->ioctl_expected.gemClose = 1;
|
||||
|
||||
std::vector<uint8_t> dataToCopy(MemoryConstants::pageSize, 1u);
|
||||
|
||||
auto allocation = memoryManager->allocateGraphicsMemoryWithProperties({dataToCopy.size(), GraphicsAllocation::AllocationType::BUFFER});
|
||||
ASSERT_NE(nullptr, allocation);
|
||||
|
||||
auto ret = memoryManager->copyMemoryToAllocation(allocation, dataToCopy.data(), dataToCopy.size());
|
||||
EXPECT_TRUE(ret);
|
||||
|
||||
EXPECT_EQ(0, memcmp(allocation->getUnderlyingBuffer(), dataToCopy.data(), dataToCopy.size()));
|
||||
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
@ -1890,7 +1890,7 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatShareTheSameBufferOb
|
||||
auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false);
|
||||
|
||||
executionEnvironment->osInterface = std::make_unique<OSInterface>();
|
||||
executionEnvironment->osInterface->get()->setDrm(mock);
|
||||
executionEnvironment->osInterface->get()->setDrm(mock.get());
|
||||
auto testedCsr = new TestedDrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*executionEnvironment);
|
||||
device->resetCommandStreamReceiver(testedCsr);
|
||||
|
||||
@ -1918,7 +1918,7 @@ TEST_F(DrmMemoryManagerTest, givenTwoGraphicsAllocationsThatDoesnShareTheSameBuf
|
||||
auto graphicsAllocation2 = memoryManager->createGraphicsAllocationFromSharedHandle(sharedHandle, properties, false);
|
||||
|
||||
executionEnvironment->osInterface = std::make_unique<OSInterface>();
|
||||
executionEnvironment->osInterface->get()->setDrm(mock);
|
||||
executionEnvironment->osInterface->get()->setDrm(mock.get());
|
||||
auto testedCsr = new TestedDrmCommandStreamReceiver<DEFAULT_TEST_FAMILY_NAME>(*executionEnvironment);
|
||||
device->resetCommandStreamReceiver(testedCsr);
|
||||
|
||||
|
@ -32,19 +32,23 @@ class DrmMemoryManagerBasic : public ::testing::Test {
|
||||
|
||||
class DrmMemoryManagerFixture : public MemoryManagementFixture {
|
||||
public:
|
||||
std::unique_ptr<DrmMockCustom> mock;
|
||||
TestedDrmMemoryManager *memoryManager = nullptr;
|
||||
DrmMockCustom *mock;
|
||||
MockDevice *device = nullptr;
|
||||
|
||||
void SetUp() override {
|
||||
SetUp(new DrmMockCustom, false);
|
||||
}
|
||||
|
||||
void SetUp(DrmMockCustom *mock, bool localMemoryEnabled) {
|
||||
MemoryManagementFixture::SetUp();
|
||||
this->mock = new DrmMockCustom;
|
||||
this->mock = std::unique_ptr<DrmMockCustom>(mock);
|
||||
executionEnvironment = new MockExecutionEnvironment(*platformDevices);
|
||||
executionEnvironment->incRefInternal();
|
||||
executionEnvironment->osInterface = std::make_unique<OSInterface>();
|
||||
executionEnvironment->osInterface->get()->setDrm(mock);
|
||||
|
||||
memoryManager = new (std::nothrow) TestedDrmMemoryManager(*executionEnvironment);
|
||||
memoryManager = new (std::nothrow) TestedDrmMemoryManager(localMemoryEnabled, false, false, *executionEnvironment);
|
||||
//assert we have memory manager
|
||||
ASSERT_NE(nullptr, memoryManager);
|
||||
if (memoryManager->getgemCloseWorker()) {
|
||||
@ -60,8 +64,6 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture {
|
||||
|
||||
this->mock->testIoctls();
|
||||
|
||||
delete this->mock;
|
||||
this->mock = nullptr;
|
||||
MemoryManagementFixture::TearDown();
|
||||
}
|
||||
|
||||
@ -71,6 +73,16 @@ class DrmMemoryManagerFixture : public MemoryManagementFixture {
|
||||
AllocationData allocationData;
|
||||
};
|
||||
|
||||
class DrmMemoryManagerWithLocalMemoryFixture : public DrmMemoryManagerFixture {
|
||||
public:
|
||||
void SetUp() override {
|
||||
DrmMemoryManagerFixture::SetUp(new DrmMockCustom, true);
|
||||
}
|
||||
void TearDown() override {
|
||||
DrmMemoryManagerFixture::TearDown();
|
||||
}
|
||||
};
|
||||
|
||||
class DrmMemoryManagerFixtureWithoutQuietIoctlExpectation {
|
||||
public:
|
||||
std::unique_ptr<TestedDrmMemoryManager> memoryManager;
|
||||
|
Reference in New Issue
Block a user