KhronosGroup / KhronosGroup/OpenCL-CLHPP
how to handle extension API function pointers
- Dominant language
- C++
- Stars
- 425
- Forks
- 133
- Avg merge
- 3h 30m
- Merged PRs (30d)
- 1
Description
This issue is slightly related to #146, which also has to do with handling extensions. #146 seems to have more to do with extension defined than extension function pointers though, so I am filing a separate issue instead. If desired, we can combine them.
TL;DR: We should rethink how we handle extension API function pointers in these C++ bindings, to improve functionality, performance, and maintainability.
Currently when we want to call an extension API we query the function pointer, store it in a (sometimes static) variable, and call it. Here is one example:
```c++
static PFN_clEnqueueAcquireD3D10ObjectsKHR pfn_clEnqueueAcquireD3D10ObjectsKHR = NULL;
#if CL_HPP_TARGET_OPENCL_VERSION >= 120
cl_context context = getInfo();
cl::Device device(getInfo());
cl_platform_id platform = device.getInfo();
CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_(platform, clEnqueueAcquireD3D10ObjectsKHR);
#endif
#if CL_HPP_TARGET_OPENCL_VERSION >= 110
CL_HPP_INIT_CL_EXT_FCN_PTR_(clEnqueueAcquireD3D10ObjectsKHR);
#endif
```
Some issues with this code are:
* Calling an extension API takes multiple lines of code and is error-prone and inconsistent.
* Storing in a static variable means the same extension API can only be called for one platform.
* Storing in a static variable complicates unit testing.
* Storing in a non-static variable instead requires costly queries per-call, both to query the platform and to query the function pointer itself.
Can we do better? Some non-mutually-exclusive options:
* Support libraries like the [OpenCL Extension Loader](https://github.com/KhronosGroup/OpenCL-SDK/pull/66) when an extra dependency is acceptable.
* Move extension queries and function definitions to a separate header file, to centralize queries while still providing an all-in-one solution.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by tracing the extension function-pointer handling around CL_HPP_INIT_CL_EXT_FCN_PTR_PLATFORM_ and CL_HPP_INIT_CL_EXT_FCN_PTR_, then compare the OpenCL Extension Loader option mentioned in the issue. A complete change should address repeated call-site setup, multi-platform use, unit testing, and per-call query costs while keeping the bindings usable without an extra dependency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- api
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100