Goal
As per this thread: GPU vs. CPU processing - what is the future for audio processing? Can we access the GPU now? If so, how?
I am trying to add the OpenCL Wrapper project here to a JUCE project: https://github.com/ProjectPhysX/OpenCL-Wrapper
OpenCL Wrapper Project
The OpenCL project is incredibly small and easy to run by itself, as explained at that GitHub link. Basic requirements listed there:
- video card drivers installed (like NVIDIA) as they will typically install OpenCL automatically.
- Intel CPU Runtime for OpenCL linked there.
- Visual Studio 2022, Windows 10 SDK, and MSVC v142 in Visual Studio Installer
Then if you clone that project, just open the sln file and click Debug. It opens a basic window showing some simple arithmetic has been completed as per main.cpp, which has only:
#include "opencl.hpp"
int main() {
Device device(select_device_with_most_flops()); // compile OpenCL C code for the fastest available device
const uint N = 1024u; // size of vectors
Memory<float> A(device, N); // allocate memory on both host and device
Memory<float> B(device, N);
Memory<float> C(device, N);
Kernel add_kernel(device, N, "add_kernel", A, B, C); // kernel that runs on the device
for(uint n=0u; n<N; n++) {
A[n] = 3.0f; // initialize memory
B[n] = 2.0f;
C[n] = 1.0f;
}
print_info("Value before kernel execution: C[0] = "+to_string(C[0]));
A.write_to_device(); // copy data from host memory to device memory
B.write_to_device();
add_kernel.run(); // run add_kernel on the device
C.read_from_device(); // copy data from device memory to host memory
print_info("Value after kernel execution: C[0] = "+to_string(C[0]));
wait();
return 0;
}
This is the simplified nature of the OpenCL wrapper. It allows very easy GPU utilization in principle.
Contents of OpenCL Wrapper Project
There are only the following files in the project:
kernel.cpp
kernel.hpp
main.cpp
opencl.hpp
utilities.hpp
cl.h
cl.hpp
cl_ext.h
cl_gl.h
cl_gl_ext.h
cl_platform.h
opencl.h
OpenCL.lib
libOpenCL.so
We don’t need main.cpp certainly when pulling this over to JUCE projects.
I note examining the project, I can’t figure out why he has them in the file folder structure he does. Or how this type of thing (related to that) works:
I mean, there is only one cl.h in the file structure, so I’m not sure what this accomplishes (?) for example here re: Apple or not… This is just a minor point of interest though.
The biggest problem stopping me: The .so and the .lib files - I’m not sure what to do with these at all.
Steps So Far
My approach is to (i) try to add the OpenCL Wrapper files to a JUCE project, then (ii) copy and paste the simple commands from the wrapper project’s test main.cpp above inside the JUCE project (with DBG substituted to output result instead of print_info).
I have tried the following:
- Copy and paste all OpenCL Wrapper project files listed above into an
OpenGLfolder inside my project (minus main.cpp). - Drag these into Projucer file manager so they are seen as part of project.
- Open in Visual Studio.
- Fix now broken addresses of OpenCL Wrapper file paths regarding
#includelike above. - Annoying - Manually rename all the OpenCL Wrapper
to_stringfunctions inutilities.hpptocl_to_string- These are ambiguous withstd::to_stringand will break things otherwise.
(Re: step 5, it was minor mistake in my opinion that the OpenCL Wrapper designer named a critical function in his utilities.hpp as to_string which overlaps std::to_string. This must be renamed carefully or you will get ambiguous or other errors.)
Result
This lets me add OpenCL Wrapper functions in my JUCE project without errors while coding, but I can’t build without link errors. Presumably the step I am missing has to do with the .lib / .so files. I don’t know what I’m supposed to do with them.
I get the following errors on trying to build:
So I presume I must do something with the .lib/.so files to “link” them? As I presume that is the core function library that the wrapper code is supposed to be interacting with?
Question
Any thoughts on what the missing step might be then? Or any better way to handle bringing this over into a JUCE project?
Thanks for any help or ideas.


