Initial implementation for creating buffer with ext memory for OpenCl

Related-To: NEO-6757

Signed-off-by: Baj, Tomasz <tomasz.baj@intel.com>
This commit is contained in:
Baj, Tomasz
2022-04-26 10:25:41 +00:00
committed by Compute-Runtime-Automation
parent 28317e7062
commit 2a0c395db5
14 changed files with 383 additions and 5 deletions

View File

@ -0,0 +1,15 @@
#
# Copyright (C) 2022 Intel Corporation
#
# SPDX-License-Identifier: MIT
#
if(WIN32)
set(IGDRCL_SRCS_tests_mem_obj_windows
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt
${CMAKE_CURRENT_SOURCE_DIR}/buffer_windows_tests.cpp
)
target_sources(igdrcl_tests PRIVATE ${IGDRCL_SRCS_tests_mem_obj_windows})
set_property(GLOBAL PROPERTY IGDRCL_SRCS_tests_mem_obj_windows ${IGDRCL_SRCS_tests_mem_obj_windows})
endif()

View File

@ -0,0 +1,112 @@
/*
* Copyright (C) 2022 Intel Corporation
*
* SPDX-License-Identifier: MIT
*
*/
#include "shared/source/gmm_helper/gmm_helper.h"
#include "shared/source/helpers/array_count.h"
#include "shared/source/helpers/compiler_hw_info_config.h"
#include "shared/source/helpers/hw_helper.h"
#include "shared/source/memory_manager/memory_operations_handler.h"
#include "shared/source/memory_manager/unified_memory_manager.h"
#include "shared/test/common/fixtures/memory_management_fixture.h"
#include "shared/test/common/helpers/ult_hw_config.h"
#include "shared/test/common/helpers/unit_test_helper.h"
#include "shared/test/common/mocks/mock_allocation_properties.h"
#include "shared/test/common/mocks/mock_device.h"
#include "shared/test/common/mocks/mock_execution_environment.h"
#include "shared/test/common/mocks/mock_gmm.h"
#include "shared/test/common/mocks/ult_device_factory.h"
#include "shared/test/common/test_macros/test.h"
#include "opencl/extensions/public/cl_ext_private.h"
#include "opencl/source/command_queue/command_queue_hw.h"
#include "opencl/source/mem_obj/mem_obj_helper.h"
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h"
#include "opencl/test/unit_test/fixtures/multi_root_device_fixture.h"
#include "opencl/test/unit_test/mocks/mock_buffer.h"
#include "opencl/test/unit_test/mocks/mock_command_queue.h"
using namespace NEO;
static const unsigned int g_scTestBufferSizeInBytes = 16;
TEST(Buffer, WhenValidateHandleTypeThenReturnFalse) {
MemoryProperties memoryProperties;
UnifiedSharingMemoryDescription extMem;
bool isValid = Buffer::validateHandleType(memoryProperties, extMem);
EXPECT_FALSE(isValid);
}
class ExportBufferTests : public ClDeviceFixture,
public testing::Test {
public:
ExportBufferTests() {
}
protected:
void SetUp() override {
flags = CL_MEM_READ_WRITE;
ClDeviceFixture::SetUp();
context.reset(new MockContext(pClDevice));
}
void TearDown() override {
context.reset();
ClDeviceFixture::TearDown();
}
cl_int retVal = CL_SUCCESS;
std::unique_ptr<MockContext> context;
MemoryManager *contextMemoryManager;
cl_mem_flags flags = CL_MEM_READ_WRITE;
unsigned char pHostPtr[g_scTestBufferSizeInBytes];
};
struct ValidExportHostPtr
: public ExportBufferTests,
public MemoryManagementFixture {
typedef ExportBufferTests BaseClass;
using ExportBufferTests::SetUp;
using MemoryManagementFixture::SetUp;
ValidExportHostPtr() {
}
void SetUp() override {
MemoryManagementFixture::SetUp();
BaseClass::SetUp();
ASSERT_NE(nullptr, pDevice);
}
void TearDown() override {
delete buffer;
BaseClass::TearDown();
MemoryManagementFixture::TearDown();
}
Buffer *createBuffer() {
return Buffer::create(
context.get(),
flags,
g_scTestBufferSizeInBytes,
pHostPtr,
retVal);
}
cl_int retVal = CL_INVALID_VALUE;
Buffer *buffer = nullptr;
};
TEST_F(ValidExportHostPtr, givenPropertiesWithDmaBufWhenValidateInputAndCreateBufferThenCorrectBufferIsSet) {
cl_mem_properties properties[] = {CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR, 0x1234, 0};
auto buffer = BufferFunctions::validateInputAndCreateBuffer(context.get(), properties, flags, 0, g_scTestBufferSizeInBytes, nullptr, retVal);
EXPECT_EQ(retVal, CL_INVALID_PROPERTY);
EXPECT_EQ(nullptr, buffer);
clReleaseMemObject(buffer);
}