[8/n] Unified Shared Memory.

-Wire in host allocations API.

Related-To: NEO-3148

Change-Id: If7213a7c90a35aebb530e2b4d14413138cd84297
Signed-off-by: Mrozek, Michal <michal.mrozek@intel.com>
This commit is contained in:
Mrozek, Michal
2019-06-19 12:14:43 +02:00
committed by sys_ocldev
parent 0a8c821245
commit 3595e6e046
2 changed files with 36 additions and 6 deletions

View File

@@ -3363,9 +3363,19 @@ void *clHostMemAllocINTEL(
size_t size,
cl_uint alignment,
cl_int *errcodeRet) {
cl_int retVal = CL_OUT_OF_HOST_MEMORY;
*errcodeRet = retVal;
Context *neoContext = nullptr;
ErrorCodeHelper err(errcodeRet, CL_SUCCESS);
auto retVal = validateObjects(WithCastToInternal(context, &neoContext));
if (retVal != CL_SUCCESS) {
err.set(retVal);
return nullptr;
}
return neoContext->getSVMAllocsManager()->createUnifiedMemoryAllocation(size, SVMAllocsManager::UnifiedMemoryProperties(InternalMemoryType::HOST_UNIFIED_MEMORY));
}
void *clDeviceMemAllocINTEL(

View File

@@ -6,13 +6,33 @@
*/
#include "runtime/api/api.h"
#include "runtime/memory_manager/svm_memory_manager.h"
#include "unit_tests/mocks/mock_context.h"
using namespace NEO;
TEST(clUnifiedSharedMemoryTests, whenClHostMemAllocINTELisCalledThenOutOfHostMemoryErrorIsReturned) {
TEST(clUnifiedSharedMemoryTests, whenClHostMemAllocINTELisCalledWithoutContextThenInvalidContextIsReturned) {
cl_int retVal = CL_SUCCESS;
clHostMemAllocINTEL(0, nullptr, 0, 0, &retVal);
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
auto ptr = clHostMemAllocINTEL(0, nullptr, 0, 0, &retVal);
EXPECT_EQ(nullptr, ptr);
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
}
TEST(clUnifiedSharedMemoryTests, whenClHostMemAllocIntelIsCalledThenItAllocatesHostUnifiedMemoryAllocation) {
MockContext mockContext;
cl_int retVal = CL_SUCCESS;
auto unifiedMemoryHostAllocation = clHostMemAllocINTEL(&mockContext, nullptr, 4, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, unifiedMemoryHostAllocation);
auto allocationsManager = mockContext.getSVMAllocsManager();
EXPECT_EQ(1u, allocationsManager->getNumAllocs());
auto graphicsAllocation = allocationsManager->getSVMAlloc(unifiedMemoryHostAllocation);
EXPECT_EQ(graphicsAllocation->size, 4u);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::HOST_UNIFIED_MEMORY);
EXPECT_EQ(graphicsAllocation->gpuAllocation->getGpuAddress(), castToUint64(unifiedMemoryHostAllocation));
allocationsManager->freeSVMAlloc(unifiedMemoryHostAllocation);
}
TEST(clUnifiedSharedMemoryTests, whenClDeviceMemAllocINTELisCalledThenOutOfHostMemoryErrorIsReturned) {