There are not only plans. Such classes already exist. But they are far to rough around the edges to be published.
You mentioned „leaving the existing classes the same“, and interface
es. The „core“ of the current state of my local „JOCLUtils“ project indeed consists mainly of static
utility methods. It already allows to write code like this:
cl_platform_id platform = Platforms.getPlatforms().get(0);
cl_device_id device = Devices.getDevices(platform).get(0);
cl_context context = Contexts.create(platform, device);
cl_mem srcA = Mems.create(context, srcArrayA);
cl_mem dst = Mems.create(context, 1000 * Sizeof.cl_float);
cl_kernel kernel = Kernels.createFromSource(context, programSource, "sampleKernel");
Which already can be much more concise than the „low-level API“.
And these static
methods avoid one problem that was the main reason of why I hesitated to create „real“, „object oriented“ wrappers. It may seem tempting to work towards something like this pseudocode :
Queue queue = Wrapper.createQueue(Device.withHighestFlops());
float result[] = queue.read(array).compute(kernel).write(result);
But there’s one thing that makes a „high-level, object oriented wrapper“ really, really difficult:
State!
Assuming that such a Wrapper-API should be 100% thread-safe, to be used and mixed arbitrarily with Java Threads, ThreadPoolExecutors
and so on, it can be really challenging to avoid race conditions.
Beyond that, there are many more details. An obvious one is the Garbage Collector. One might think that ~„some reference-counting could work here“, the answer is: No, it does not work and will never work. Any attempt to do automatic resource management on the GPU with Java is doomed to fail.
However, I agree that people could benefit greatly from some sort of convenience wrapper, even if it is not really „Object Oriented“, but only a set of utility functions.
As mentioned in the other thread: Maybe I’ll have a bit of time for that soon, so I might be able to publish an early state of the core of the „JOCLUtils“ project, as some sort of „preview version“, to gather feedback.