mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-27 15:53:13 +08:00
Add capability to query internal handle from cl_mem.
Related-To: NEO-3252 Change-Id: I935c308dfa3f77c6d965df7316fe3fb4c21b112a Signed-off-by: Mrozek, Michal <michal.mrozek@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
f6bf2c5d0b
commit
14b8bbb3aa
@@ -57,3 +57,5 @@ using cl_mem_flags_intel = cl_mem_flags;
|
||||
|
||||
#define CL_MEM_FORCE_LINEAR_STORAGE_INTEL (1 << 19)
|
||||
#define CL_MEM_FORCE_SHARED_PHYSICAL_MEMORY_INTEL (1 << 20)
|
||||
|
||||
#define CL_MEM_ALLOCATION_HANDLE_INTEL 0x10050
|
||||
|
||||
@@ -118,6 +118,7 @@ cl_int MemObj::getMemObjectInfo(cl_mem_info paramName,
|
||||
cl_uint mapCount = 0;
|
||||
cl_mem clAssociatedMemObject = static_cast<cl_mem>(this->associatedMemObject);
|
||||
cl_context ctx = nullptr;
|
||||
uint64_t internalHandle = 0llu;
|
||||
|
||||
switch (paramName) {
|
||||
case CL_MEM_TYPE:
|
||||
@@ -173,6 +174,11 @@ cl_int MemObj::getMemObjectInfo(cl_mem_info paramName,
|
||||
srcParamSize = sizeof(refCnt);
|
||||
srcParam = &refCnt;
|
||||
break;
|
||||
case CL_MEM_ALLOCATION_HANDLE_INTEL:
|
||||
internalHandle = this->getGraphicsAllocation()->peekInternalHandle();
|
||||
srcParamSize = sizeof(internalHandle);
|
||||
srcParam = &internalHandle;
|
||||
break;
|
||||
|
||||
default:
|
||||
getOsSpecificMemObjectInfo(paramName, &srcParamSize, &srcParam);
|
||||
|
||||
@@ -166,6 +166,7 @@ class GraphicsAllocation : public IDNode<GraphicsAllocation> {
|
||||
bool isResidencyTaskCountBelow(uint32_t taskCount, uint32_t contextId) const { return !isResident(contextId) || getResidencyTaskCount(contextId) < taskCount; }
|
||||
|
||||
virtual std::string getAllocationInfoString() const;
|
||||
virtual uint64_t peekInternalHandle() { return 0llu; }
|
||||
|
||||
static bool isCpuAccessRequired(AllocationType allocationType) {
|
||||
return allocationType == AllocationType::LINEAR_STREAM ||
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
#include "core/helpers/ptr_math.h"
|
||||
#include "runtime/memory_manager/graphics_allocation.h"
|
||||
|
||||
namespace NEO {
|
||||
@@ -35,6 +36,7 @@ class DrmAllocation : public GraphicsAllocation {
|
||||
}
|
||||
return this->bo;
|
||||
}
|
||||
uint64_t peekInternalHandle() override { return castToUint64(getBO()); }
|
||||
|
||||
protected:
|
||||
BufferObject *bo;
|
||||
|
||||
@@ -138,3 +138,8 @@ TEST(GraphicsAllocationTest, givenDefaultAllocationWhenGettingNumHandlesThenOneI
|
||||
MockGraphicsAllocation graphicsAllocation;
|
||||
EXPECT_EQ(1u, graphicsAllocation.getNumHandles());
|
||||
}
|
||||
|
||||
TEST(GraphicsAllocationTest, givenDefaultGraphicsAllocationWhenInternalHandleIsBeingObtainedThenZeroIsReturned) {
|
||||
MockGraphicsAllocation graphicsAllocation;
|
||||
EXPECT_EQ(0llu, graphicsAllocation.peekInternalHandle());
|
||||
}
|
||||
|
||||
@@ -144,6 +144,16 @@ TEST_F(DrmMemoryManagerTest, pinAfterAllocateWhenAskedAndAllowedAndBigAllocation
|
||||
memoryManager->freeGraphicsMemory(alloc);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, whenPeekInternalHandleIsCalledThenBoIsReturend) {
|
||||
mock->ioctl_expected.gemUserptr = 1;
|
||||
mock->ioctl_expected.gemWait = 1;
|
||||
mock->ioctl_expected.gemClose = 1;
|
||||
auto allocation = static_cast<DrmAllocation *>(this->memoryManager->allocateGraphicsMemoryWithProperties(createAllocationProperties(10 * MemoryConstants::pageSize, true)));
|
||||
ASSERT_NE(allocation->getBO(), nullptr);
|
||||
ASSERT_EQ(allocation->peekInternalHandle(), castToUint64(allocation->getBO()));
|
||||
memoryManager->freeGraphicsMemory(allocation);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmContextIdWhenAllocationIsCreatedThenPinWithPassedDrmContextId) {
|
||||
mock->ioctl_expected.gemUserptr = 2;
|
||||
mock->ioctl_expected.execbuffer2 = 1;
|
||||
@@ -1119,6 +1129,32 @@ TEST_F(DrmMemoryManagerTest, GivenSizeAbove2GBWhenAllocHostPtrAndUseHostPtrAreCr
|
||||
delete buffer;
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, givenDrmBufferWhenItIsQueriedForInternalAllocationThenBoIsReturned) {
|
||||
mock->ioctl_expected.total = -1;
|
||||
MockContext context;
|
||||
context.setMemoryManager(memoryManager);
|
||||
|
||||
size_t size = 1u;
|
||||
auto retVal = CL_SUCCESS;
|
||||
|
||||
auto buffer = Buffer::create(
|
||||
&context,
|
||||
CL_MEM_ALLOC_HOST_PTR,
|
||||
size,
|
||||
nullptr,
|
||||
retVal);
|
||||
|
||||
uint64_t handle = 0llu;
|
||||
|
||||
retVal = clGetMemObjectInfo(buffer, CL_MEM_ALLOCATION_HANDLE_INTEL, sizeof(handle), &handle, nullptr);
|
||||
EXPECT_EQ(retVal, CL_SUCCESS);
|
||||
|
||||
auto drmAllocation = static_cast<DrmAllocation *>(buffer->getGraphicsAllocation());
|
||||
EXPECT_EQ(castToUint64(drmAllocation->getBO()), handle);
|
||||
|
||||
clReleaseMemObject(buffer);
|
||||
}
|
||||
|
||||
TEST_F(DrmMemoryManagerTest, Given32BitDeviceWithMemoryManagerWhenInternalHeapIsExhaustedAndNewAllocationsIsMadeThenNullIsReturned) {
|
||||
DebugManagerStateRestore dbgStateRestore;
|
||||
DebugManager.flags.Force32bitAddressing.set(true);
|
||||
|
||||
Reference in New Issue
Block a user