Skip to content

Commit a2a3dae

Browse files
Introduce DrmMemoryManager::createMultiHostAllocation() method
Signed-off-by: Igor Venevtsev <[email protected]>
1 parent d8a7a60 commit a2a3dae

File tree

7 files changed

+55
-0
lines changed

7 files changed

+55
-0
lines changed

opencl/test/unit_test/os_interface/linux/drm_memory_manager_tests.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4434,4 +4434,12 @@ TEST_F(DrmMemoryManagerTest, givenDrmAllocationWithWithAlignmentFromUserptrWhenI
44344434
auto allocation = static_cast<DrmAllocation *>(memoryManager->createAllocWithAlignmentFromUserptr(allocationData, size, 0, 0, 0x1000));
44354435
EXPECT_EQ(allocation, nullptr);
44364436
}
4437+
4438+
TEST_F(DrmMemoryManagerTest, givenAllocateGraphicsMemoryWithPropertiesCalledWithDebugSurfaceTypeThenDebugSurfaceIsCreated) {
4439+
AllocationProperties debugSurfaceProperties{0, true, MemoryConstants::pageSize, NEO::GraphicsAllocation::AllocationType::DEBUG_CONTEXT_SAVE_AREA, false, false, 0b1011};
4440+
auto debugSurface = static_cast<DrmAllocation *>(memoryManager->allocateGraphicsMemoryWithProperties(debugSurfaceProperties));
4441+
4442+
EXPECT_NE(nullptr, debugSurface);
4443+
memoryManager->freeGraphicsMemory(debugSurface);
4444+
}
44374445
} // namespace NEO

shared/source/os_interface/linux/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ set(NEO_CORE_OS_INTERFACE_LINUX
6868
if(SUPPORT_DG1 AND "${BRANCH_TYPE}" STREQUAL "")
6969
list(APPEND NEO_CORE_OS_INTERFACE_LINUX
7070
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_allocate_in_device_pool_dg1.cpp
71+
${CMAKE_CURRENT_SOURCE_DIR}/drm_memory_manager_create_multi_host_allocation_dg1.cpp
7172
${CMAKE_CURRENT_SOURCE_DIR}/drm_query_dg1.cpp
7273
)
7374
else()
7475
list(APPEND NEO_CORE_OS_INTERFACE_LINUX
7576
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_memory_manager_allocate_in_device_pool.cpp
77+
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_memory_manager_create_multi_host_allocation.cpp
7678
${CMAKE_CURRENT_SOURCE_DIR}${BRANCH_DIR_SUFFIX}/drm_query.cpp
7779
)
7880
endif()

shared/source/os_interface/linux/drm_memory_manager.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,14 @@ DrmAllocation *DrmMemoryManager::createGraphicsAllocation(OsHandleStorage &handl
227227
}
228228

229229
DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) {
230+
if (allocationData.type == NEO::GraphicsAllocation::AllocationType::DEBUG_CONTEXT_SAVE_AREA) {
231+
return createMultiHostAllocation(allocationData);
232+
}
233+
234+
return allocateGraphicsMemoryWithAlignmentImpl(allocationData);
235+
}
236+
237+
DrmAllocation *DrmMemoryManager::allocateGraphicsMemoryWithAlignmentImpl(const AllocationData &allocationData) {
230238
const size_t minAlignment = getUserptrAlignment();
231239
size_t cAlignment = alignUp(std::max(allocationData.alignment, minAlignment), minAlignment);
232240
// When size == 0 allocate allocationAlignment

shared/source/os_interface/linux/drm_memory_manager.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ class DrmMemoryManager : public MemoryManager {
8888
DrmAllocation *createGraphicsAllocation(OsHandleStorage &handleStorage, const AllocationData &allocationData) override;
8989
DrmAllocation *allocateGraphicsMemoryForNonSvmHostPtr(const AllocationData &allocationData) override;
9090
DrmAllocation *allocateGraphicsMemoryWithAlignment(const AllocationData &allocationData) override;
91+
DrmAllocation *allocateGraphicsMemoryWithAlignmentImpl(const AllocationData &allocationData);
9192
DrmAllocation *createUSMHostAllocationFromSharedHandle(osHandle handle, const AllocationProperties &properties);
9293
DrmAllocation *createAllocWithAlignmentFromUserptr(const AllocationData &allocationData, size_t size, size_t alignment, size_t alignedSVMSize, uint64_t gpuAddress);
9394
DrmAllocation *createAllocWithAlignment(const AllocationData &allocationData, size_t size, size_t alignment, size_t alignedSize, uint64_t gpuAddress);
95+
DrmAllocation *createMultiHostAllocation(const AllocationData &allocationData);
9496
void obtainGpuAddress(const AllocationData &allocationData, BufferObject *bo, uint64_t gpuAddress);
9597
DrmAllocation *allocateUSMHostGraphicsMemory(const AllocationData &allocationData) override;
9698
DrmAllocation *allocateGraphicsMemoryWithHostPtr(const AllocationData &allocationData) override;
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/linux/drm_memory_manager.h"
9+
10+
namespace NEO {
11+
DrmAllocation *DrmMemoryManager::createMultiHostAllocation(const AllocationData &allocationData) {
12+
return allocateGraphicsMemoryWithAlignmentImpl(allocationData);
13+
}
14+
} // namespace NEO
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* Copyright (C) 2021 Intel Corporation
3+
*
4+
* SPDX-License-Identifier: MIT
5+
*
6+
*/
7+
8+
#include "shared/source/os_interface/linux/drm_memory_manager.h"
9+
10+
namespace NEO {
11+
DrmAllocation *DrmMemoryManager::createMultiHostAllocation(const AllocationData &allocationData) {
12+
return allocateGraphicsMemoryWithAlignmentImpl(allocationData);
13+
}
14+
} // namespace NEO

shared/test/common/mocks/linux/mock_drm_memory_manager.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
7373
using DrmMemoryManager::createAllocWithAlignment;
7474
using DrmMemoryManager::createAllocWithAlignmentFromUserptr;
7575
using DrmMemoryManager::createGraphicsAllocation;
76+
using DrmMemoryManager::createMultiHostAllocation;
7677
using DrmMemoryManager::eraseSharedBufferObject;
7778
using DrmMemoryManager::getDefaultDrmContextId;
7879
using DrmMemoryManager::getDrm;
@@ -115,5 +116,11 @@ class TestedDrmMemoryManager : public MemoryManagerCreate<DrmMemoryManager> {
115116
size = sharingBufferObjects.size();
116117
return size;
117118
}
119+
void *alignedMallocWrapper(size_t size, size_t alignment) override {
120+
alignedMallocSizeRequired = size;
121+
return alignedMallocShouldFail ? nullptr : DrmMemoryManager::alignedMallocWrapper(size, alignment);
122+
}
123+
bool alignedMallocShouldFail = false;
124+
size_t alignedMallocSizeRequired = 0u;
118125
};
119126
} // namespace NEO

0 commit comments

Comments
 (0)