Got it working. ![]()
Full Workflow:
I post the full workflow I used to convert the OpenCL Wrapper project into JUCE as I presume the OpenCL Wrapper may be updated over time but likely not directly disappear. Similarly things may change in JUCE. So simply sharing the files without the workflow is likely less safe for future reference.
As long as this forum, the OpenCL Wrapper, and JUCE continue to exist this should work with perhaps minor alterations over time.
EDITING OPEN CL WRAPPER PROJECT FOR JUCE
- Clone OpenCL Wrapper here: https://github.com/ProjectPhysX/OpenCL-Wrapper
- Open project in Visual Studio 2022 and ensure runs to start with.
- Move all files inside
OpenCL-Wrapper/src/OpenCL/include/CL/toOpenCL-Wrapper/src/so everything shares a same directory except thelibfile. - Right click project, select properties > C/C++ > remove the
src/OpenCL/include/CL/directory as an external include folder (as we have now moved the files out of here) - forget where exactly this setting is but it is there - Select “Show All Files” to see the new files in Visual Studio as per https://stackoverflow.com/a/69812456, click them and set include in project to “true” so you can see them.
- Keep trying to build and fix
#includeerrors from moving files until solved. - Ensure can still build project.
- Open
utilities.hppand right click anyto_stringfunction there, rename tocl_to_string, and select ALL possible functions that come up to rename this way (due to conflict otherwise withstd::to_stringonce you bring over to JUCE). - Ensure can still build project (should still all work perfectly)
ADDING TO JUCE
- Copy all these
.h/.hpp/.cppfiles from the modified OpenCL Wrapper project into a folder likeOpenCLinside your Projucer project directory and drag this folder into your Projucer File Directory to add it to project. - Copy
OpenCL.libinto yourBuilds/VisualStudio2022folder and add it in the Projucer Exporters Visual Studio 2022 “External Libraries to Link” asOpenCL.lib. - Comment out with
/* */the contents of the functionprint_messageofutilities.hppas this will break in JUCE now once ported over. - Open anywhere in your JUCE project code in Visual Studio and add
#include "OpenCL/opencl.hpp" - Run this test code taken from the Open CL Wrapper
main.cppin that page (with modification made toDBGoutput):
//=====================
//TEST OPENCL
//===================
DBG("START OPENCL TEST");
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;
}
DBG("Value before kernel execution: C[0] = " + cl_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
DBG("Value after kernel execution: C[0] = " + cl_to_string(C[0]));
//===================
- You will see the debugged math performed on the GPU successfully.
![]()
