From 72841e36c2e1dfc3e451e3e18c95a176ad0ee340 Mon Sep 17 00:00:00 2001 From: Kamil Kopryk Date: Wed, 19 Jun 2019 13:58:41 +0200 Subject: [PATCH] Add clCreateImageWithPropertiesINTEL API Related-To: NEO-3147 Change-Id: I4a8a9d73fe75e0680226fbd0625342f639ddd201 Signed-off-by: Kamil Kopryk --- runtime/api/api.cpp | 39 ++++++++++++++ runtime/api/api.h | 8 +++ unit_tests/api/cl_create_image_tests.cpp | 51 +++++++++++++++++++ ...l_get_extension_function_address_tests.inl | 5 ++ 4 files changed, 103 insertions(+) diff --git a/runtime/api/api.cpp b/runtime/api/api.cpp index b9207600c2..566a2e8c6b 100644 --- a/runtime/api/api.cpp +++ b/runtime/api/api.cpp @@ -766,6 +766,44 @@ cl_mem CL_API_CALL clCreateImage(cl_context context, return image; } +cl_mem CL_API_CALL clCreateImageWithPropertiesINTEL(cl_context context, + cl_mem_properties_intel *properties, + const cl_image_format *imageFormat, + const cl_image_desc *imageDesc, + void *hostPtr, + cl_int *errcodeRet) { + cl_int retVal = CL_SUCCESS; + + API_ENTER(&retVal); + DBG_LOG_INPUTS("cl_context", context, + "cl_mem_properties_intel", properties, + "cl_image_format.channel_data_type", imageFormat->image_channel_data_type, + "cl_image_format.channel_order", imageFormat->image_channel_order, + "cl_image_desc.width", imageDesc->image_width, + "cl_image_desc.heigth", imageDesc->image_height, + "cl_image_desc.depth", imageDesc->image_depth, + "cl_image_desc.type", imageDesc->image_type, + "cl_image_desc.array_size", imageDesc->image_array_size, + "hostPtr", hostPtr); + + cl_mem image = nullptr; + Context *pContext = nullptr; + MemoryProperties propertiesStruct{}; + retVal = validateObjects(WithCastToInternal(context, &pContext)); + + if (retVal == CL_SUCCESS) { + if (MemObjHelper::parseMemoryProperties(properties, propertiesStruct)) { + image = Image::validateAndCreateImage(pContext, propertiesStruct, imageFormat, imageDesc, hostPtr, retVal); + } else { + retVal = CL_INVALID_VALUE; + } + } + + ErrorCodeHelper err(errcodeRet, retVal); + DBG_LOG_INPUTS("image", image); + return image; +} + // deprecated OpenCL 1.1 cl_mem CL_API_CALL clCreateImage2D(cl_context context, cl_mem_flags flags, @@ -3656,6 +3694,7 @@ void *CL_API_CALL clGetExtensionFunctionAddress(const char *funcName) { RETURN_FUNC_PTR_IF_EXIST(clRetainAcceleratorINTEL); RETURN_FUNC_PTR_IF_EXIST(clReleaseAcceleratorINTEL); RETURN_FUNC_PTR_IF_EXIST(clCreateBufferWithPropertiesINTEL); + RETURN_FUNC_PTR_IF_EXIST(clCreateImageWithPropertiesINTEL); RETURN_FUNC_PTR_IF_EXIST(clAddCommentINTEL); RETURN_FUNC_PTR_IF_EXIST(clEnqueueVerifyMemoryINTEL); diff --git a/runtime/api/api.h b/runtime/api/api.h index ea89f0e095..bb2da84e68 100644 --- a/runtime/api/api.h +++ b/runtime/api/api.h @@ -144,6 +144,14 @@ cl_mem CL_API_CALL clCreateImage( void *hostPtr, cl_int *errcodeRet); +cl_mem CL_API_CALL clCreateImageWithPropertiesINTEL( + cl_context context, + cl_mem_properties_intel *properties, + const cl_image_format *imageFormat, + const cl_image_desc *imageDesc, + void *hostPtr, + cl_int *errcodeRet); + // deprecated OpenCL 1.1 cl_mem CL_API_CALL clCreateImage2D( cl_context context, diff --git a/unit_tests/api/cl_create_image_tests.cpp b/unit_tests/api/cl_create_image_tests.cpp index b7da5e304d..8d0b00b3e2 100644 --- a/unit_tests/api/cl_create_image_tests.cpp +++ b/unit_tests/api/cl_create_image_tests.cpp @@ -745,6 +745,57 @@ TEST_F(clCreateImage3DTest, GivenInvalidContextsWhenCreating3DImageThenInvalidCo EXPECT_EQ(nullptr, image); } +using clCreateImageWithPropertiesINTELTest = clCreateImageTest; + +TEST_F(clCreateImageWithPropertiesINTELTest, GivenInvalidContextWhenCreatingImageWithPropertiesThenInvalidContextErrorIsReturned) { + + auto image = clCreateImageWithPropertiesINTEL( + nullptr, + nullptr, + nullptr, + nullptr, + nullptr, + &retVal); + + ASSERT_EQ(CL_INVALID_CONTEXT, retVal); + EXPECT_EQ(nullptr, image); +} + +TEST_F(clCreateImageWithPropertiesINTELTest, GivenValidParametersWhenCreatingImageWithPropertiesThenImageIsCreatedAndSuccessReturned) { + + cl_mem_properties_intel properties[] = {CL_MEM_FLAGS, CL_MEM_READ_WRITE, 0}; + + auto image = clCreateImageWithPropertiesINTEL( + pContext, + properties, + &imageFormat, + &imageDesc, + nullptr, + &retVal); + + ASSERT_EQ(CL_SUCCESS, retVal); + EXPECT_NE(nullptr, image); + + retVal = clReleaseMemObject(image); + EXPECT_EQ(CL_SUCCESS, retVal); +} + +TEST_F(clCreateImageWithPropertiesINTELTest, GivenInvalidPropertyKeyWhenCreatingImageWithPropertiesThenInvalidValueErrorIsReturned) { + + cl_mem_properties_intel properties[] = {(cl_mem_properties_intel(1) << 31), 0, 0}; + + auto image = clCreateImageWithPropertiesINTEL( + pContext, + properties, + &imageFormat, + &imageDesc, + nullptr, + &retVal); + + EXPECT_EQ(nullptr, image); + EXPECT_EQ(CL_INVALID_VALUE, retVal); +} + typedef clCreateImageTests<::testing::Test> clCreateImageFromImageTest; TEST_F(clCreateImageFromImageTest, GivenImage2dWhenCreatingImage2dFromImageWithTheSameDescriptorAndValidFormatThenImageIsCreatedAndSuccessReturned) { diff --git a/unit_tests/api/cl_get_extension_function_address_tests.inl b/unit_tests/api/cl_get_extension_function_address_tests.inl index 5a5b463e81..d79c030632 100644 --- a/unit_tests/api/cl_get_extension_function_address_tests.inl +++ b/unit_tests/api/cl_get_extension_function_address_tests.inl @@ -58,6 +58,11 @@ TEST_F(clGetExtensionFunctionAddressTests, GivenClCreateBufferWithPropertiesINTE EXPECT_EQ(functionPointer, reinterpret_cast(clCreateBufferWithPropertiesINTEL)); } +TEST_F(clGetExtensionFunctionAddressTests, GivenClCreateImageWithPropertiesINTELWhenGettingExtensionFunctionThenCorrectAddressIsReturned) { + auto functionPointer = clGetExtensionFunctionAddress("clCreateImageWithPropertiesINTEL"); + EXPECT_EQ(functionPointer, reinterpret_cast(clCreateImageWithPropertiesINTEL)); +} + TEST_F(clGetExtensionFunctionAddressTests, givenClAddCommentToAubIntelAsInputWhenFunctionIsCalledThenProperPointerIsReturned) { auto functionPointer = clGetExtensionFunctionAddress("clAddCommentINTEL"); EXPECT_EQ(functionPointer, reinterpret_cast(clAddCommentINTEL));