mirror of
https://github.com/intel/compute-runtime.git
synced 2025-12-24 20:39:56 +08:00
Add clGetMemAllocInfoIntel
Related-To: NEO-3317 Change-Id: If46be932e170d45793fe143ebb54fcfb0cda9ccc Signed-off-by: Krzysztof Gibala <krzysztof.gibala@intel.com>
This commit is contained in:
committed by
sys_ocldev
parent
267fec40ad
commit
407c0213f1
@@ -79,3 +79,12 @@ using cl_unified_shared_memory_capabilities_intel = cl_bitfield;
|
||||
#define CL_DEVICE_SINGLE_DEVICE_SHARED_MEM_CAPABILITIES_INTEL 0x10052
|
||||
#define CL_DEVICE_CROSS_DEVICE_SHARED_MEM_CAPABILITIES_INTEL 0x10053
|
||||
#define CL_DEVICE_SHARED_SYSTEM_MEM_CAPABILITIES_INTEL 0x10054
|
||||
|
||||
#define CL_MEM_ALLOC_TYPE_INTEL 0x10020
|
||||
#define CL_MEM_ALLOC_BASE_PTR_INTEL 0x10021
|
||||
#define CL_MEM_ALLOC_SIZE_INTEL 0x10022
|
||||
|
||||
#define CL_MEM_TYPE_UNKNOWN_INTEL 0x10030
|
||||
#define CL_MEM_TYPE_HOST_INTEL 0x10031
|
||||
#define CL_MEM_TYPE_DEVICE_INTEL 0x10032
|
||||
#define CL_MEM_TYPE_SHARED_INTEL 0x10033
|
||||
|
||||
@@ -3483,7 +3483,52 @@ cl_int clGetMemAllocInfoINTEL(
|
||||
size_t paramValueSize,
|
||||
void *paramValue,
|
||||
size_t *paramValueSizeRet) {
|
||||
return CL_OUT_OF_HOST_MEMORY;
|
||||
Context *pContext = nullptr;
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
retVal = validateObject(WithCastToInternal(context, &pContext));
|
||||
|
||||
if (!pContext) {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
auto allocationsManager = pContext->getSVMAllocsManager();
|
||||
if (!allocationsManager) {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
auto unifiedMemoryAllocation = allocationsManager->getSVMAlloc(ptr);
|
||||
if (!unifiedMemoryAllocation) {
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
GetInfoHelper info(paramValue, paramValueSize, paramValueSizeRet);
|
||||
switch (paramName) {
|
||||
case CL_MEM_ALLOC_TYPE_INTEL: {
|
||||
if (unifiedMemoryAllocation->memoryType == InternalMemoryType::HOST_UNIFIED_MEMORY) {
|
||||
retVal = info.set<cl_int>(CL_MEM_TYPE_HOST_INTEL);
|
||||
return retVal;
|
||||
} else if (unifiedMemoryAllocation->memoryType == InternalMemoryType::DEVICE_UNIFIED_MEMORY) {
|
||||
retVal = info.set<cl_int>(CL_MEM_TYPE_DEVICE_INTEL);
|
||||
return retVal;
|
||||
} else {
|
||||
retVal = info.set<cl_int>(CL_MEM_TYPE_SHARED_INTEL);
|
||||
return retVal;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case CL_MEM_ALLOC_BASE_PTR_INTEL: {
|
||||
retVal = info.set<uint64_t>(unifiedMemoryAllocation->gpuAllocation->getGpuAddress());
|
||||
return retVal;
|
||||
}
|
||||
case CL_MEM_ALLOC_SIZE_INTEL: {
|
||||
retVal = info.set<size_t>(unifiedMemoryAllocation->size);
|
||||
return retVal;
|
||||
}
|
||||
default: {
|
||||
}
|
||||
}
|
||||
|
||||
return CL_INVALID_VALUE;
|
||||
}
|
||||
|
||||
cl_int clSetKernelArgMemPointerINTEL(
|
||||
|
||||
@@ -124,9 +124,147 @@ TEST(clUnifiedSharedMemoryTests, whenClMemFreeINTELisCalledWithInvalidUmPointerT
|
||||
EXPECT_EQ(0u, allocationsManager->getNumAllocs());
|
||||
}
|
||||
|
||||
TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledThenOutOfHostMemoryErrorIsReturned) {
|
||||
TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithoutContextThenInvalidContextIsReturned) {
|
||||
auto retVal = clGetMemAllocInfoINTEL(0, nullptr, 0, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
|
||||
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
|
||||
}
|
||||
|
||||
TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithoutAllocationThenInvalidValueIsReturned) {
|
||||
MockContext mockContext;
|
||||
auto retVal = clGetMemAllocInfoINTEL(&mockContext, nullptr, 0, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
||||
}
|
||||
|
||||
TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithoutSVMAllocationThenInvalidValueIsReturned) {
|
||||
MockContext mockContext;
|
||||
delete mockContext.svmAllocsManager;
|
||||
mockContext.svmAllocsManager = nullptr;
|
||||
auto retVal = clGetMemAllocInfoINTEL(&mockContext, nullptr, 0, 0, nullptr, nullptr);
|
||||
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
||||
}
|
||||
|
||||
TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithValidUnifiedMemoryHostAllocationThenProperFieldsAreSet) {
|
||||
MockContext mockContext;
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
size_t paramValueSize = sizeof(cl_int);
|
||||
cl_int paramValue = 0;
|
||||
size_t paramValueSizeRet = 0;
|
||||
|
||||
auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(&mockContext, nullptr, 4, 0, &retVal);
|
||||
auto allocationsManager = mockContext.getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryHostAllocation);
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemoryHostAllocation, CL_MEM_ALLOC_TYPE_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::HOST_UNIFIED_MEMORY);
|
||||
EXPECT_EQ(CL_MEM_TYPE_HOST_INTEL, paramValue);
|
||||
EXPECT_EQ(sizeof(cl_int), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
retVal = clMemFreeINTEL(&mockContext, unifiedMemoryHostAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
|
||||
TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithValidUnifiedMemoryDeviceAllocationThenProperFieldsAreSet) {
|
||||
MockContext mockContext;
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
size_t paramValueSize = sizeof(cl_int);
|
||||
cl_int paramValue = 0;
|
||||
size_t paramValueSizeRet = 0;
|
||||
|
||||
auto unifiedMemoryDeviceAllocation = clDeviceMemAllocINTEL(&mockContext, mockContext.getDevice(0u), nullptr, 4, 0, &retVal);
|
||||
auto allocationsManager = mockContext.getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryDeviceAllocation);
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemoryDeviceAllocation, CL_MEM_ALLOC_TYPE_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::DEVICE_UNIFIED_MEMORY);
|
||||
EXPECT_EQ(CL_MEM_TYPE_DEVICE_INTEL, paramValue);
|
||||
EXPECT_EQ(sizeof(cl_int), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
retVal = clMemFreeINTEL(&mockContext, unifiedMemoryDeviceAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
|
||||
TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithValidUnifiedMemorySharedAllocationThenProperFieldsAreSet) {
|
||||
MockContext mockContext;
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
size_t paramValueSize = sizeof(cl_int);
|
||||
cl_int paramValue = 0;
|
||||
size_t paramValueSizeRet = 0;
|
||||
|
||||
auto unifiedMemorySharedAllocation = clSharedMemAllocINTEL(&mockContext, mockContext.getDevice(0u), nullptr, 4, 0, &retVal);
|
||||
auto allocationsManager = mockContext.getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemorySharedAllocation);
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemorySharedAllocation, CL_MEM_ALLOC_TYPE_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::SHARED_UNIFIED_MEMORY);
|
||||
EXPECT_EQ(CL_MEM_TYPE_SHARED_INTEL, paramValue);
|
||||
EXPECT_EQ(sizeof(cl_int), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
retVal = clMemFreeINTEL(&mockContext, unifiedMemorySharedAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
|
||||
TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithAllocationBasePtrParamNameThenProperFieldsAreSet) {
|
||||
MockContext mockContext;
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
size_t paramValueSize = sizeof(uint64_t);
|
||||
uint64_t paramValue = 0;
|
||||
size_t paramValueSizeRet = 0;
|
||||
|
||||
auto unifiedMemorySharedAllocation = clSharedMemAllocINTEL(&mockContext, mockContext.getDevice(0u), nullptr, 4, 0, &retVal);
|
||||
auto allocationsManager = mockContext.getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemorySharedAllocation);
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemorySharedAllocation, CL_MEM_ALLOC_BASE_PTR_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::SHARED_UNIFIED_MEMORY);
|
||||
EXPECT_EQ(graphicsAllocation->gpuAllocation->getGpuAddress(), paramValue);
|
||||
EXPECT_EQ(sizeof(uint64_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
retVal = clMemFreeINTEL(&mockContext, unifiedMemorySharedAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
|
||||
TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithAllocationSizeParamNameThenProperFieldsAreSet) {
|
||||
MockContext mockContext;
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
size_t paramValueSize = sizeof(size_t);
|
||||
size_t paramValue = 0;
|
||||
size_t paramValueSizeRet = 0;
|
||||
|
||||
auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(&mockContext, nullptr, 4, 0, &retVal);
|
||||
auto allocationsManager = mockContext.getSVMAllocsManager();
|
||||
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryHostAllocation);
|
||||
|
||||
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemoryHostAllocation, CL_MEM_ALLOC_SIZE_INTEL, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
|
||||
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::HOST_UNIFIED_MEMORY);
|
||||
EXPECT_EQ(graphicsAllocation->size, paramValue);
|
||||
EXPECT_EQ(sizeof(size_t), paramValueSizeRet);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
|
||||
retVal = clMemFreeINTEL(&mockContext, unifiedMemoryHostAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
|
||||
TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledWithoutParamNameThenInvalidValueIsReturned) {
|
||||
MockContext mockContext;
|
||||
cl_int retVal = CL_SUCCESS;
|
||||
size_t paramValueSize = sizeof(cl_uint);
|
||||
cl_uint paramValue = 0;
|
||||
size_t paramValueSizeRet = 0;
|
||||
|
||||
auto unifiedMemorySharedAllocation = clSharedMemAllocINTEL(&mockContext, mockContext.getDevice(0u), nullptr, 4, 0, &retVal);
|
||||
retVal = clGetMemAllocInfoINTEL(&mockContext, unifiedMemorySharedAllocation, 0, paramValueSize, ¶mValue, ¶mValueSizeRet);
|
||||
EXPECT_EQ(CL_INVALID_VALUE, retVal);
|
||||
|
||||
retVal = clMemFreeINTEL(&mockContext, unifiedMemorySharedAllocation);
|
||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||
}
|
||||
|
||||
TEST(clUnifiedSharedMemoryTests, whenClSetKernelArgMemPointerINTELisCalledWithInvalidKernelThenInvaliKernelErrorIsReturned) {
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace NEO {
|
||||
class MockContext : public Context {
|
||||
public:
|
||||
using Context::sharingFunctions;
|
||||
|
||||
using Context::svmAllocsManager;
|
||||
MockContext(Device *device, bool noSpecialQueue = false);
|
||||
MockContext(
|
||||
void(CL_CALLBACK *funcNotify)(const char *, const void *, size_t, void *),
|
||||
|
||||
Reference in New Issue
Block a user