gpu / JOCL

Java bindings for OpenCL
http://www.jocl.org
Other
187 stars 33 forks source link

JOCL on Mac OS Big Sur & Apple Silicon M1 #32

Closed psobolewskiPhD closed 3 years ago

psobolewskiPhD commented 3 years ago

(First time on GitHub, not really a coder, so please be gentle.) Out of interest in running CLIJ (https://clij.github.io) which enables running ImageJ macros on GPU, I tried to compile JOCL on my M1 MacBook Pro (Big Sur 11.1, latest command line dev tools) I installed native CMake (3.19.2) Cloned JOCL and JOCLCommon, according to the build instructions I then edited the CMakeLists.txt to add at line 60/61 elseif(CMAKE_OSX_ARCHITECTURES STREQUAL "arm64") set(JOCL_TARGET_ARCH "arm64") I'm running Zulu 15 JDK. In CMake I set the new Env variable CMAKE_APPLE_SILICON_PROCESSOR to arm64 also set CMAKE_OSX_ARCHITECTURES to arm64

make generated 5 warnings of 'weak-import' but finished: [100%] Built target JOCL_2_0_1-apple-arm64

Adding the obtained dylib to Fiji along with CLIJ and CLIJ2 yielded functioning GPU processing. Using benchmarks from CLIJ (https://clij.github.io/clij2-docs/md/benchmarking/): the new binary enabled a ~60X speedup: Native CPU: ~1200 ms, Native GPU: ~20 ms (For reference, using a fully Rosetta Fiji: Rosetta CPU: ~1600 ms, Rosetta GPU: ~160 ms)

I can share the binary or edited CMakelists.txt See also: twitter thread with maintainer of CLIJ @haesleinhuepf https://twitter.com/psobolewskiPhD/status/1342494593082920960?s=20

gpu commented 3 years ago

Thanks for that heads-up @psobolewskiPhD !

I had a short look at CLIJ in the context of a PR ( https://github.com/gpu/JOCL/pull/26 ), but haven't looked at the details yet. It's a pity. However, the speedup looks great. Benchmarking in detail can be difficult, but if this an existing reference benchmark, then the proof may indeed be in the wall-clock time.

For the updated CMakeLists.txt, you could either create a PR, or (if this is easier for you) post it here or send it via mail to jocl at jocl.org.

(The binary could be helpful for an actual release that could go into Maven Central, but that's currently not on my schedule ... at least, probably not before I also have time to tackle the update to OpenCL 3.0...)

psobolewskiPhD commented 3 years ago

I'm going to be brave and try and do a PR. Fingers crossed.

gpu commented 3 years ago

Thanks for the PR, I just merged it, and think it's OK to close this issue then.

psobolewskiPhD commented 3 years ago

Just in case you want the binary (compiled on M1 for M1). libJOCL_2_0_1-apple-arm64.dylib.zip

gpu commented 3 years ago

Thanks. If I decide to make another release on Maven Central before the update to 3.0, this will be included. (Otherwise, people can just drop this binary into their local directory, and it will be picked up accordingly)