Skip to content

Commit ade9591

Browse files
OpenCL interoperability sample (KhronosGroup#326)
* OpenCL interoperability sample * OpenCL Headers as submodule * Removed OpenCL from ignore files, removed gradle.properties * Moved android_hardware_buffer include, added casts, checks, initialization * Fixed clang format check (include indents, space after 'if') * OpenCL extensions check, proper loading of extensions functions * Added prefix to the sample name and a list of potential OpenCL libraries to load. * Reverted looking for libraries other than libOpenCL.so
1 parent fb1c52c commit ade9591

14 files changed

+1161
-1
lines changed

Diff for: .gitmodules

+3
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,6 @@
5050
[submodule "third_party/cli11"]
5151
path = third_party/cli11
5252
url = https://github.com/CLIUtils/CLI11.git
53+
[submodule "third_party/opencl"]
54+
path = third_party/opencl
55+
url = https://github.com/KhronosGroup/OpenCL-Headers.git

Diff for: samples/README.md

+4
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,10 @@ Shows how to rebuild the acceleration structure and when to set it to fast rebui
223223
**Extensions**: [```VK_KHR_external_memory```](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_KHR_external_memory.html), [```VK_KHR_external_semaphore```](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_KHR_external_semaphore.html)<br/>
224224
Render a procedural image using OpenGL and incorporate that rendered content into a Vulkan scene. Demonstrates using the same backing memory for a texture in both OpenGL and Vulkan and how to synchronize the APIs using shared semaphores and barriers.
225225

226+
### [Arm OpenCL interoperability](./extensions/open_cl_interop)<br/>
227+
**Extensions**: [```VK_ANDROID_EXTERNAL_MEMORY_ANDROID_HARDWARE_BUFFER_EXTENSION_NAME```](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_ANDROID_external_memory_android_hardware_buffer.html)<br/>
228+
This sample demonstrates usage of OpenCL extensions available on Arm devices. Fill a procedural texture using OpenCL and display it using Vulkan. In this sample data sharing between APIs is achieved using Android Hardware Buffers.
229+
226230
### [Timeline semaphore](./extensions/timeline_semaphore)<br/>
227231
**Extensions**: [```VK_KHR_timeline_semaphore```](https://www.khronos.org/registry/vulkan/specs/1.2-extensions/man/html/VK_KHR_timeline_semaphore.html)
228232
Demonstrates various use cases which are enabled with timeline semaphores. The sample implements "Game of Life" in an esoteric way,

Diff for: samples/extensions/open_cl_interop/CMakeLists.txt

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Copyright (c) 2021, Arm Limited and Contributors
2+
#
3+
# SPDX-License-Identifier: Apache-2.0
4+
#
5+
# Licensed under the Apache License, Version 2.0 the "License";
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
18+
# The OpenCL interoperability only works on Android
19+
get_filename_component(FOLDER_NAME ${CMAKE_CURRENT_LIST_DIR} NAME)
20+
get_filename_component(PARENT_DIR ${CMAKE_CURRENT_LIST_DIR} PATH)
21+
get_filename_component(CATEGORY_NAME ${PARENT_DIR} NAME)
22+
23+
if(ANDROID)
24+
add_sample_with_tags(
25+
ID ${FOLDER_NAME}
26+
CATEGORY ${CATEGORY_NAME}
27+
AUTHOR "Arm"
28+
NAME "Arm OpenCL Interoperability"
29+
DESCRIPTION "Example showing sharing resources between OpenCL and Vulkan on Arm devices"
30+
TAGS "arm"
31+
LIBS opencl
32+
FILES
33+
open_cl_functions.inl
34+
open_cl_utils.h
35+
open_cl_utils.cpp)
36+
endif()

Diff for: samples/extensions/open_cl_interop/images/sample.png

595 KB
Loading
Loading
+49
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* Copyright (c) 2021, Arm Limited and Contributors
2+
*
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 the "License";
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
// Core OpenCL functions, loaded from libOpenCL.so
19+
#if !defined(OPENCL_EXPORTED_FUNCTION)
20+
#define OPENCL_EXPORTED_FUNCTION(fun)
21+
#endif
22+
23+
OPENCL_EXPORTED_FUNCTION(clCreateContext);
24+
OPENCL_EXPORTED_FUNCTION(clGetDeviceIDs);
25+
OPENCL_EXPORTED_FUNCTION(clGetPlatformIDs);
26+
OPENCL_EXPORTED_FUNCTION(clCreateBuffer);
27+
OPENCL_EXPORTED_FUNCTION(clReleaseMemObject);
28+
OPENCL_EXPORTED_FUNCTION(clCreateProgramWithSource);
29+
OPENCL_EXPORTED_FUNCTION(clBuildProgram);
30+
OPENCL_EXPORTED_FUNCTION(clCreateKernel);
31+
OPENCL_EXPORTED_FUNCTION(clSetKernelArg);
32+
OPENCL_EXPORTED_FUNCTION(clEnqueueNDRangeKernel);
33+
OPENCL_EXPORTED_FUNCTION(clFlush);
34+
OPENCL_EXPORTED_FUNCTION(clFinish);
35+
OPENCL_EXPORTED_FUNCTION(clCreateCommandQueue);
36+
OPENCL_EXPORTED_FUNCTION(clReleaseContext);
37+
OPENCL_EXPORTED_FUNCTION(clGetPlatformInfo);
38+
OPENCL_EXPORTED_FUNCTION(clGetExtensionFunctionAddressForPlatform);
39+
40+
#undef OPENCL_EXPORTED_FUNCTION
41+
42+
// Extension functions, loaded using clGetExtensionFunctionAddressForPlatform
43+
#if !defined(OPENCL_EXPORTED_EXTENSION_FUNCTION)
44+
#define OPENCL_EXPORTED_EXTENSION_FUNCTION(fun)
45+
#endif
46+
47+
OPENCL_EXPORTED_EXTENSION_FUNCTION(clImportMemoryARM);
48+
49+
#undef OPENCL_EXPORTED_EXTENSION_FUNCTION

0 commit comments

Comments
 (0)