-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: implementation for creating image with external memory
Related-To: NEO-6757 Signed-off-by: Warchulski, Jaroslaw <jaroslaw.warchulski@intel.com>
- Loading branch information
1 parent
cbce863
commit 9e44344
Showing
15 changed files
with
311 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (C) 2023 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
*/ | ||
|
||
#include "opencl/source/mem_obj/image.h" | ||
#include "opencl/source/sharings/unified/unified_sharing_types.h" | ||
|
||
namespace NEO { | ||
|
||
bool Image::validateHandleType(MemoryProperties &memoryProperties, UnifiedSharingMemoryDescription &extMem) { | ||
if (memoryProperties.handleType == static_cast<uint64_t>(UnifiedSharingHandleType::LinuxFd)) { | ||
extMem.type = UnifiedSharingHandleType::LinuxFd; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} // namespace NEO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* | ||
* Copyright (C) 2023 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
*/ | ||
|
||
#include "opencl/source/mem_obj/image.h" | ||
#include "opencl/source/sharings/unified/unified_sharing_types.h" | ||
|
||
namespace NEO { | ||
|
||
bool Image::validateHandleType(MemoryProperties &memoryProperties, UnifiedSharingMemoryDescription &extMem) { | ||
if (memoryProperties.handleType == static_cast<uint64_t>(UnifiedSharingHandleType::Win32Nt)) { | ||
extMem.type = UnifiedSharingHandleType::Win32Nt; | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
} // namespace NEO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# | ||
# Copyright (C) 2023 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
if(UNIX) | ||
set(RUNTIME_SRCS_SHARINGS_UNIFIED_LINUX | ||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt | ||
${CMAKE_CURRENT_SOURCE_DIR}/unified_image_linux.cpp | ||
) | ||
|
||
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_UNIFIED_LINUX}) | ||
set_property(GLOBAL PROPERTY RUNTIME_SRCS_SHARINGS_UNIFIED_LINUX ${RUNTIME_SRCS_SHARINGS_UNIFIED_LINUX}) | ||
endif() |
29 changes: 29 additions & 0 deletions
29
opencl/source/sharings/unified/linux/unified_image_linux.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright (C) 2023 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
*/ | ||
|
||
#include "shared/source/execution_environment/root_device_environment.h" | ||
#include "shared/source/gmm_helper/gmm.h" | ||
|
||
#include "opencl/source/cl_device/cl_device.h" | ||
#include "opencl/source/context/context.h" | ||
#include "opencl/source/sharings/unified/unified_image.h" | ||
|
||
namespace NEO { | ||
|
||
void *UnifiedImage::swapGmm(GraphicsAllocation *graphicsAllocation, Context *context, ImageInfo *imgInfo) { | ||
if (!graphicsAllocation->getDefaultGmm()) { | ||
auto gmmHelper = context->getDevice(0)->getRootDeviceEnvironment().getGmmHelper(); | ||
auto gmm = std::make_unique<Gmm>(gmmHelper, *imgInfo, StorageInfo{}, false); | ||
gmm->updateImgInfoAndDesc(*imgInfo, 0); | ||
delete graphicsAllocation->getDefaultGmm(); | ||
graphicsAllocation->setDefaultGmm(gmm.release()); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
} // namespace NEO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# | ||
# Copyright (C) 2023 Intel Corporation | ||
# | ||
# SPDX-License-Identifier: MIT | ||
# | ||
|
||
if(WIN32) | ||
set(RUNTIME_SRCS_SHARINGS_UNIFIED_WINDOWS | ||
${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists.txt | ||
${CMAKE_CURRENT_SOURCE_DIR}/unified_image_windows.cpp | ||
) | ||
|
||
target_sources(${NEO_STATIC_LIB_NAME} PRIVATE ${RUNTIME_SRCS_SHARINGS_UNIFIED_WINDOWS}) | ||
set_property(GLOBAL PROPERTY RUNTIME_SRCS_SHARINGS_UNIFIED_WINDOWS ${RUNTIME_SRCS_SHARINGS_UNIFIED_WINDOWS}) | ||
endif() |
30 changes: 30 additions & 0 deletions
30
opencl/source/sharings/unified/windows/unified_image_windows.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/* | ||
* Copyright (C) 2023 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
*/ | ||
|
||
#include "shared/source/execution_environment/root_device_environment.h" | ||
#include "shared/source/gmm_helper/gmm.h" | ||
#include "shared/source/gmm_helper/resource_info.h" | ||
|
||
#include "opencl/source/cl_device/cl_device.h" | ||
#include "opencl/source/context/context.h" | ||
#include "opencl/source/sharings/unified/unified_image.h" | ||
|
||
namespace NEO { | ||
|
||
void *UnifiedImage::swapGmm(GraphicsAllocation *graphicsAllocation, Context *context, ImageInfo *imgInfo) { | ||
if (graphicsAllocation->getDefaultGmm()->gmmResourceInfo->peekGmmResourceInfo()->GetResourceType() == RESOURCE_BUFFER) { | ||
auto gmmHelper = context->getDevice(0)->getRootDeviceEnvironment().getGmmHelper(); | ||
auto gmm = std::make_unique<Gmm>(gmmHelper, *imgInfo, StorageInfo{}, false); | ||
gmm->updateImgInfoAndDesc(*imgInfo, 0); | ||
delete graphicsAllocation->getDefaultGmm(); | ||
graphicsAllocation->setDefaultGmm(gmm.release()); | ||
} | ||
|
||
return 0; | ||
} | ||
|
||
} // namespace NEO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/* | ||
* Copyright (C) 2023 Intel Corporation | ||
* | ||
* SPDX-License-Identifier: MIT | ||
* | ||
*/ | ||
|
||
#include "shared/test/common/test_macros/test.h" | ||
|
||
#include "opencl/source/mem_obj/image.h" | ||
#include "opencl/source/sharings/unified/unified_sharing_types.h" | ||
#include "opencl/test/unit_test/fixtures/cl_device_fixture.h" | ||
#include "opencl/test/unit_test/mocks/mock_context.h" | ||
#include "opencl/test/unit_test/sharings/unified/unified_sharing_fixtures.h" | ||
|
||
using namespace NEO; | ||
|
||
using ImageLinuxTests = Test<ClDeviceFixture>; | ||
|
||
TEST_F(ImageLinuxTests, givenPropertiesWithNtHandleWhenValidateAndCreateImageThenInvalidPropertyIsSet) { | ||
cl_mem_properties properties[] = {CL_EXTERNAL_MEMORY_HANDLE_OPAQUE_WIN32_KHR, 0x1234, 0}; | ||
|
||
cl_image_desc imageDesc = {}; | ||
cl_image_format imageFormat = {}; | ||
imageFormat.image_channel_data_type = CL_UNSIGNED_INT8; | ||
imageFormat.image_channel_order = CL_R; | ||
|
||
std::unique_ptr<MockContext> context; | ||
context.reset(new MockContext(pClDevice)); | ||
cl_mem_flags flags = CL_MEM_READ_WRITE; | ||
cl_int retVal = CL_SUCCESS; | ||
|
||
auto image = ImageFunctions::validateAndCreateImage(context.get(), properties, flags, 0, &imageFormat, &imageDesc, nullptr, retVal); | ||
|
||
EXPECT_EQ(retVal, CL_INVALID_PROPERTY); | ||
EXPECT_EQ(nullptr, image); | ||
|
||
clReleaseMemObject(image); | ||
} | ||
|
||
using UnifiedSharingImageTests = UnifiedSharingFixture<true, true>; | ||
|
||
TEST_F(UnifiedSharingImageTests, givenPropertiesWithDmaBufWhenValidateAndCreateImageThenCorrectImageIsSet) { | ||
cl_mem_properties properties[] = {CL_EXTERNAL_MEMORY_HANDLE_DMA_BUF_KHR, 0x1234, 0}; | ||
|
||
cl_image_desc imageDesc = {}; | ||
imageDesc.image_type = CL_MEM_OBJECT_IMAGE2D; | ||
imageDesc.image_width = 64; | ||
imageDesc.image_height = 64; | ||
cl_image_format imageFormat = {}; | ||
imageFormat.image_channel_data_type = CL_UNSIGNED_INT8; | ||
imageFormat.image_channel_order = CL_R; | ||
|
||
cl_mem_flags flags = CL_MEM_READ_WRITE; | ||
cl_int retVal = CL_INVALID_VALUE; | ||
|
||
auto image = ImageFunctions::validateAndCreateImage(context.get(), properties, flags, 0, &imageFormat, &imageDesc, nullptr, retVal); | ||
|
||
EXPECT_EQ(retVal, CL_SUCCESS); | ||
EXPECT_NE(image, nullptr); | ||
|
||
clReleaseMemObject(image); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.