[10/n] Unified Shared Memory.

- Wire in support for clDeviceMemAllocINTEL
- Wire in support for clSharedMemAllocINTEL
- Wire in support for clSetKernelArgMemPointerINTEL

Related-To: NEO-3148

Change-Id: I9e182beb6f4dda3adfc0f2f23ffd129640ebd73c
Signed-off-by: Mrozek, Michal <michal.mrozek@intel.com>
This commit is contained in:
Mrozek, Michal
2019-06-19 15:34:30 +02:00
committed by sys_ocldev
parent 9dfc02116a
commit 37e4bca788
3 changed files with 90 additions and 15 deletions

View File

@ -8,6 +8,7 @@
#include "runtime/api/api.h"
#include "runtime/memory_manager/svm_memory_manager.h"
#include "unit_tests/mocks/mock_context.h"
#include "unit_tests/mocks/mock_kernel.h"
using namespace NEO;
@ -36,16 +37,54 @@ TEST(clUnifiedSharedMemoryTests, whenClHostMemAllocIntelIsCalledThenItAllocatesH
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST(clUnifiedSharedMemoryTests, whenClDeviceMemAllocINTELisCalledThenOutOfHostMemoryErrorIsReturned) {
TEST(clUnifiedSharedMemoryTests, whenClDeviceMemAllocINTELisCalledWithWrongContextThenInvalidContextErrorIsReturned) {
cl_int retVal = CL_SUCCESS;
clDeviceMemAllocINTEL(0, 0, nullptr, 0, 0, &retVal);
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
auto ptr = clDeviceMemAllocINTEL(0, 0, nullptr, 0, 0, &retVal);
EXPECT_EQ(nullptr, ptr);
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
}
TEST(clUnifiedSharedMemoryTests, whenClSharedMemAllocINTELisCalledThenOutOfHostMemoryErrorIsReturned) {
TEST(clUnifiedSharedMemoryTests, whenClDeviceMemAllocIntelIsCalledThenItAllocatesDeviceUnifiedMemoryAllocation) {
MockContext mockContext;
cl_int retVal = CL_SUCCESS;
clSharedMemAllocINTEL(0, 0, nullptr, 0, 0, &retVal);
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
auto unfiedMemoryDeviceAllocation = clDeviceMemAllocINTEL(&mockContext, mockContext.getDevice(0u), nullptr, 4, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, unfiedMemoryDeviceAllocation);
auto allocationsManager = mockContext.getSVMAllocsManager();
EXPECT_EQ(1u, allocationsManager->getNumAllocs());
auto graphicsAllocation = allocationsManager->getSVMAlloc(unfiedMemoryDeviceAllocation);
EXPECT_EQ(graphicsAllocation->size, 4u);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::DEVICE_UNIFIED_MEMORY);
EXPECT_EQ(graphicsAllocation->gpuAllocation->getGpuAddress(), castToUint64(unfiedMemoryDeviceAllocation));
retVal = clMemFreeINTEL(&mockContext, unfiedMemoryDeviceAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST(clUnifiedSharedMemoryTests, whenClSharedMemAllocINTELisCalledWithWrongContextThenInvalidContextErrorIsReturned) {
cl_int retVal = CL_SUCCESS;
auto ptr = clSharedMemAllocINTEL(0, 0, nullptr, 0, 0, &retVal);
EXPECT_EQ(nullptr, ptr);
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
}
TEST(clUnifiedSharedMemoryTests, whenClSharedMemAllocIntelIsCalledThenItAllocatesSharedUnifiedMemoryAllocation) {
MockContext mockContext;
cl_int retVal = CL_SUCCESS;
auto unfiedMemorySharedAllocation = clSharedMemAllocINTEL(&mockContext, mockContext.getDevice(0u), nullptr, 4, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
ASSERT_NE(nullptr, unfiedMemorySharedAllocation);
auto allocationsManager = mockContext.getSVMAllocsManager();
EXPECT_EQ(1u, allocationsManager->getNumAllocs());
auto graphicsAllocation = allocationsManager->getSVMAlloc(unfiedMemorySharedAllocation);
EXPECT_EQ(graphicsAllocation->size, 4u);
EXPECT_EQ(graphicsAllocation->memoryType, InternalMemoryType::SHARED_UNIFIED_MEMORY);
EXPECT_EQ(graphicsAllocation->gpuAllocation->getGpuAddress(), castToUint64(unfiedMemorySharedAllocation));
retVal = clMemFreeINTEL(&mockContext, unfiedMemorySharedAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST(clUnifiedSharedMemoryTests, whenClMemFreeINTELisCalledWithIncorrectContextThenReturnError) {
@ -90,9 +129,26 @@ TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledThenOutOfHost
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
}
TEST(clUnifiedSharedMemoryTests, whenClSetKernelArgMemPointerINTELisCalledThenOutOfHostMemoryErrorIsReturned) {
TEST(clUnifiedSharedMemoryTests, whenClSetKernelArgMemPointerINTELisCalledWithInvalidKernelThenInvaliKernelErrorIsReturned) {
auto retVal = clSetKernelArgMemPointerINTEL(0, 0, nullptr);
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
EXPECT_EQ(CL_INVALID_KERNEL, retVal);
}
TEST(clUnifiedSharedMemoryTests, whenClSetKernelArgMemPointerINTELisCalledWithValidUnifiedMemoryAllocationThenProperFieldsAreSet) {
auto mockContext = std::make_unique<MockContext>();
cl_int retVal = CL_SUCCESS;
auto unfiedMemoryDeviceAllocation = clDeviceMemAllocINTEL(mockContext.get(), mockContext->getDevice(0u), nullptr, 4, 0, &retVal);
EXPECT_EQ(CL_SUCCESS, retVal);
MockKernelWithInternals mockKernel(*mockContext->getDevice(0u), mockContext.get(), true);
retVal = clSetKernelArgMemPointerINTEL(mockKernel.mockKernel, 0, unfiedMemoryDeviceAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
auto svmAlloc = mockContext->getSVMAllocsManager()->getSVMAlloc(unfiedMemoryDeviceAllocation);
EXPECT_EQ(mockKernel.mockKernel->kernelArguments[0].object, svmAlloc->gpuAllocation);
retVal = clMemFreeINTEL(mockContext.get(), unfiedMemoryDeviceAllocation);
EXPECT_EQ(CL_SUCCESS, retVal);
}
TEST(clUnifiedSharedMemoryTests, whenclEnqueueMemsetINTELisCalledThenOutOfHostMemoryErrorIsReturned) {

View File

@ -300,6 +300,7 @@ class MockKernelWithInternals {
kernelInfo.kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset = 0;
kernelInfo.kernelArgInfo[0].kernelArgPatchInfoVector[0].size = sizeof(uintptr_t);
mockKernel->setKernelArguments(defaultKernelArguments);
mockKernel->kernelArgRequiresCacheFlush.resize(1);
}
}
~MockKernelWithInternals() {