[9/n] Unified Shared Memory

- Wire in support for clMemFreeINTEL.

Related-To: NEO-3148

Change-Id: Ibef61b7d9bdfa3021533faa0019b6b443145f1be
Signed-off-by: Mrozek, Michal <michal.mrozek@intel.com>
This commit is contained in:
Mrozek, Michal
2019-06-19 14:10:53 +02:00
committed by sys_ocldev
parent 72841e36c2
commit 0758661c52
4 changed files with 53 additions and 6 deletions

View File

@ -3443,7 +3443,19 @@ void *clSharedMemAllocINTEL(
cl_int clMemFreeINTEL(
cl_context context,
const void *ptr) {
return CL_OUT_OF_HOST_MEMORY;
Context *neoContext = nullptr;
auto retVal = validateObjects(WithCastToInternal(context, &neoContext));
if (retVal != CL_SUCCESS) {
return retVal;
}
if (!neoContext->getSVMAllocsManager()->freeSVMAlloc(const_cast<void *>(ptr))) {
return CL_INVALID_VALUE;
}
return CL_SUCCESS;
}
cl_int clGetMemAllocInfoINTEL(

View File

@ -118,7 +118,7 @@ SvmAllocationData *SVMAllocsManager::getSVMAlloc(const void *ptr) {
return SVMAllocs.get(ptr);
}
void SVMAllocsManager::freeSVMAlloc(void *ptr) {
bool SVMAllocsManager::freeSVMAlloc(void *ptr) {
SvmAllocationData *svmData = getSVMAlloc(ptr);
if (svmData) {
std::unique_lock<SpinLock> lock(mtx);
@ -127,7 +127,9 @@ void SVMAllocsManager::freeSVMAlloc(void *ptr) {
} else {
freeSvmAllocationWithDeviceStorage(svmData);
}
return true;
}
return false;
}
void *SVMAllocsManager::createZeroCopySvmAllocation(size_t size, const SvmAllocationProperties &svmProperties) {

View File

@ -77,7 +77,7 @@ class SVMAllocsManager {
void *createSVMAlloc(size_t size, const SvmAllocationProperties svmProperties);
void *createUnifiedMemoryAllocation(size_t size, const UnifiedMemoryProperties svmProperties);
SvmAllocationData *getSVMAlloc(const void *ptr);
void freeSVMAlloc(void *ptr);
bool freeSVMAlloc(void *ptr);
size_t getNumAllocs() const { return SVMAllocs.getNumAllocs(); }
void insertSvmMapOperation(void *regionSvmPtr, size_t regionSize, void *baseSvmPtr, size_t offset, bool readOnlyMap);

View File

@ -32,7 +32,8 @@ TEST(clUnifiedSharedMemoryTests, whenClHostMemAllocIntelIsCalledThenItAllocatesH
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::HOST_UNIFIED_MEMORY);
EXPECT_EQ(graphicsAllocation->gpuAllocation->getGpuAddress(), castToUint64(unifiedMemoryHostAllocation));
allocationsManager->freeSVMAlloc(unifiedMemoryHostAllocation);
retVal = clMemFreeINTEL(&mockContext, unifiedMemoryHostAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST(clUnifiedSharedMemoryTests, whenClDeviceMemAllocINTELisCalledThenOutOfHostMemoryErrorIsReturned) {
@ -47,9 +48,41 @@ TEST(clUnifiedSharedMemoryTests, whenClSharedMemAllocINTELisCalledThenOutOfHostM
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
}
TEST(clUnifiedSharedMemoryTests, whenClMemFreeINTELisCalledThenOutOfHostMemoryErrorIsReturned) {
TEST(clUnifiedSharedMemoryTests, whenClMemFreeINTELisCalledWithIncorrectContextThenReturnError) {
auto retVal = clMemFreeINTEL(0, nullptr);
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
}
TEST(clUnifiedSharedMemoryTests, whenClMemFreeINTELisCalledWithValidUmPointerThenMemoryIsFreed) {
MockContext mockContext;
cl_int retVal = CL_SUCCESS;
auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(&mockContext, nullptr, 4, 0, &retVal);
auto allocationsManager = mockContext.getSVMAllocsManager();
EXPECT_EQ(1u, allocationsManager->getNumAllocs());
retVal = clMemFreeINTEL(&mockContext, unifiedMemoryHostAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(0u, allocationsManager->getNumAllocs());
}
TEST(clUnifiedSharedMemoryTests, whenClMemFreeINTELisCalledWithInvalidUmPointerThenMemoryIsNotFreed) {
MockContext mockContext;
cl_int retVal = CL_SUCCESS;
auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(&mockContext, nullptr, 4, 0, &retVal);
auto allocationsManager = mockContext.getSVMAllocsManager();
EXPECT_EQ(1u, allocationsManager->getNumAllocs());
retVal = clMemFreeINTEL(&mockContext, ptrOffset(unifiedMemoryHostAllocation, 4));
EXPECT_EQ(CL_INVALID_VALUE, retVal);
EXPECT_EQ(1u, allocationsManager->getNumAllocs());
retVal = clMemFreeINTEL(&mockContext, unifiedMemoryHostAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
EXPECT_EQ(0u, allocationsManager->getNumAllocs());
}
TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledThenOutOfHostMemoryErrorIsReturned) {