mirror of
https://github.com/intel/compute-runtime.git
synced 2025-09-15 13:01:45 +08:00
[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:

committed by
sys_ocldev

parent
9dfc02116a
commit
37e4bca788
@ -3423,9 +3423,18 @@ void *clDeviceMemAllocINTEL(
|
|||||||
size_t size,
|
size_t size,
|
||||||
cl_uint alignment,
|
cl_uint alignment,
|
||||||
cl_int *errcodeRet) {
|
cl_int *errcodeRet) {
|
||||||
cl_int retVal = CL_OUT_OF_HOST_MEMORY;
|
Context *neoContext = nullptr;
|
||||||
*errcodeRet = retVal;
|
|
||||||
return 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::DEVICE_UNIFIED_MEMORY));
|
||||||
}
|
}
|
||||||
|
|
||||||
void *clSharedMemAllocINTEL(
|
void *clSharedMemAllocINTEL(
|
||||||
@ -3435,9 +3444,18 @@ void *clSharedMemAllocINTEL(
|
|||||||
size_t size,
|
size_t size,
|
||||||
cl_uint alignment,
|
cl_uint alignment,
|
||||||
cl_int *errcodeRet) {
|
cl_int *errcodeRet) {
|
||||||
cl_int retVal = CL_OUT_OF_HOST_MEMORY;
|
Context *neoContext = nullptr;
|
||||||
*errcodeRet = retVal;
|
|
||||||
return 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::SHARED_UNIFIED_MEMORY));
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_int clMemFreeINTEL(
|
cl_int clMemFreeINTEL(
|
||||||
@ -3472,7 +3490,7 @@ cl_int clSetKernelArgMemPointerINTEL(
|
|||||||
cl_kernel kernel,
|
cl_kernel kernel,
|
||||||
cl_uint argIndex,
|
cl_uint argIndex,
|
||||||
const void *argValue) {
|
const void *argValue) {
|
||||||
return CL_OUT_OF_HOST_MEMORY;
|
return clSetKernelArgSVMPointer(kernel, argIndex, argValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
cl_int clEnqueueMemsetINTEL(
|
cl_int clEnqueueMemsetINTEL(
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
#include "runtime/api/api.h"
|
#include "runtime/api/api.h"
|
||||||
#include "runtime/memory_manager/svm_memory_manager.h"
|
#include "runtime/memory_manager/svm_memory_manager.h"
|
||||||
#include "unit_tests/mocks/mock_context.h"
|
#include "unit_tests/mocks/mock_context.h"
|
||||||
|
#include "unit_tests/mocks/mock_kernel.h"
|
||||||
|
|
||||||
using namespace NEO;
|
using namespace NEO;
|
||||||
|
|
||||||
@ -36,16 +37,54 @@ TEST(clUnifiedSharedMemoryTests, whenClHostMemAllocIntelIsCalledThenItAllocatesH
|
|||||||
EXPECT_EQ(CL_SUCCESS, retVal);
|
EXPECT_EQ(CL_SUCCESS, retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(clUnifiedSharedMemoryTests, whenClDeviceMemAllocINTELisCalledThenOutOfHostMemoryErrorIsReturned) {
|
TEST(clUnifiedSharedMemoryTests, whenClDeviceMemAllocINTELisCalledWithWrongContextThenInvalidContextErrorIsReturned) {
|
||||||
cl_int retVal = CL_SUCCESS;
|
cl_int retVal = CL_SUCCESS;
|
||||||
clDeviceMemAllocINTEL(0, 0, nullptr, 0, 0, &retVal);
|
auto ptr = clDeviceMemAllocINTEL(0, 0, nullptr, 0, 0, &retVal);
|
||||||
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
|
EXPECT_EQ(nullptr, ptr);
|
||||||
|
EXPECT_EQ(CL_INVALID_CONTEXT, retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(clUnifiedSharedMemoryTests, whenClSharedMemAllocINTELisCalledThenOutOfHostMemoryErrorIsReturned) {
|
TEST(clUnifiedSharedMemoryTests, whenClDeviceMemAllocIntelIsCalledThenItAllocatesDeviceUnifiedMemoryAllocation) {
|
||||||
|
MockContext mockContext;
|
||||||
cl_int retVal = CL_SUCCESS;
|
cl_int retVal = CL_SUCCESS;
|
||||||
clSharedMemAllocINTEL(0, 0, nullptr, 0, 0, &retVal);
|
auto unfiedMemoryDeviceAllocation = clDeviceMemAllocINTEL(&mockContext, mockContext.getDevice(0u), nullptr, 4, 0, &retVal);
|
||||||
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, 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) {
|
TEST(clUnifiedSharedMemoryTests, whenClMemFreeINTELisCalledWithIncorrectContextThenReturnError) {
|
||||||
@ -90,9 +129,26 @@ TEST(clUnifiedSharedMemoryTests, whenClGetMemAllocInfoINTELisCalledThenOutOfHost
|
|||||||
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
|
EXPECT_EQ(CL_OUT_OF_HOST_MEMORY, retVal);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(clUnifiedSharedMemoryTests, whenClSetKernelArgMemPointerINTELisCalledThenOutOfHostMemoryErrorIsReturned) {
|
TEST(clUnifiedSharedMemoryTests, whenClSetKernelArgMemPointerINTELisCalledWithInvalidKernelThenInvaliKernelErrorIsReturned) {
|
||||||
auto retVal = clSetKernelArgMemPointerINTEL(0, 0, nullptr);
|
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) {
|
TEST(clUnifiedSharedMemoryTests, whenclEnqueueMemsetINTELisCalledThenOutOfHostMemoryErrorIsReturned) {
|
||||||
|
@ -300,6 +300,7 @@ class MockKernelWithInternals {
|
|||||||
kernelInfo.kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset = 0;
|
kernelInfo.kernelArgInfo[0].kernelArgPatchInfoVector[0].crossthreadOffset = 0;
|
||||||
kernelInfo.kernelArgInfo[0].kernelArgPatchInfoVector[0].size = sizeof(uintptr_t);
|
kernelInfo.kernelArgInfo[0].kernelArgPatchInfoVector[0].size = sizeof(uintptr_t);
|
||||||
mockKernel->setKernelArguments(defaultKernelArguments);
|
mockKernel->setKernelArguments(defaultKernelArguments);
|
||||||
|
mockKernel->kernelArgRequiresCacheFlush.resize(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
~MockKernelWithInternals() {
|
~MockKernelWithInternals() {
|
||||||
|
Reference in New Issue
Block a user