javacpp-presets icon indicating copy to clipboard operation
javacpp-presets copied to clipboard

Apple Silicon Support

Open peterrojs opened this issue 4 years ago • 24 comments

Since there are going to be more and more Apple Silicon computers in the wild, it would make sense to make a JAR for macosx-aarch64

peterrojs avatar Aug 10 '21 09:08 peterrojs

Thanks to W. Bradford Paley and @oxisto, we now have builds for OpenBLAS, OpenCV, and LLVM!

Please give it a try with the snapshots: http://bytedeco.org/builds/

saudet avatar Nov 05 '21 01:11 saudet

For FFMPEG, I found this build for Mac M1: ffmpeg Apple silicon. Please take a look and integrate in the presets.

TimKieu avatar Nov 29 '21 17:11 TimKieu

In the case of FFmpeg, we also need to build the dependencies, so that means "porting" all of this: https://github.com/bytedeco/javacpp-presets/blob/master/ffmpeg/cppbuild.sh#L1322-L1426 It's probably not a huge amount of work, but someone has to do it and contributions are welcome! Please open a pull request: https://github.com/bytedeco/javacpp-presets/pulls

saudet avatar Nov 30 '21 00:11 saudet

I've introduced macosx-arm64 builds for FFmpeg in commit https://github.com/bytedeco/javacpp-presets/commit/e38c9d192505b76227acb8a645a405e986bfc696. Please give it a try with the snapshots: http://bytedeco.org/builds/

saudet avatar Jan 21 '22 05:01 saudet

Hi,

I'm currently experiencing more or less the same issue as the author of the ticket https://github.com/bytedeco/javacv/issues/1696 . I'm compiling a project in Kotlin through gradle while using your libs

    javacpp_version = '1.5.7-SNAPSHOT'
    ffmpeg_version = "4.4.1-$javacpp_version"

    runtimeOnly "org.bytedeco:ffmpeg:$ffmpeg_version:macosx-x86_64"
    runtimeOnly "org.bytedeco:javacpp:$javacpp_version:macosx-arm64"

I also tried with other mixes of version (4.4-1.5.6/ 4.3.1-1.5.4)

The project used to run perfectly on intel Macs with version 4.3.1-1.5.4 But now, on a Mac M1 whatever the versions used I always get the same error

├─ org.bytedeco.ffmpeg.global.avutil.<clinit>(avutil.java:14)
├─ org.bytedeco.javacpp.Loader.load(Loader.java:1123)
├─ org.bytedeco.javacpp.Loader.load(Loader.java:1300)
├─ org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1683)
├─ java.lang.System.loadLibrary(System.java:1989)
├─ java.lang.Runtime.loadLibrary0(Runtime.java:818)
├─ java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)
│
↑ no jniavutil in java.library.path: /Users/faw/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:. (UnsatisfiedLinkError) 
├─ java.lang.ClassLoader.loadLibrary(ClassLoader.java:2429)

I was wondering if you had directions to provide to fix this issue? Specific versions to use or different packages to use?

For reference here is the java version I currently use :

openjdk 17.0.2 2022-01-18
OpenJDK Runtime Environment (build 17.0.2+8-86)
OpenJDK 64-Bit Server VM (build 17.0.2+8-86, mixed mode, sharing)

Faz95210 avatar Feb 09 '22 09:02 Faz95210

The builds are for FFmpeg 5.0, not 4.4.1.

saudet avatar Feb 09 '22 09:02 saudet

All right, I changed the FFmpeg versions for the project and adapted it from v4 to v5, but then I have a new error :

├─ org.bytedeco.ffmpeg.global.postproc.<clinit>(postproc.java:182)
│  org.bytedeco.ffmpeg.global.postproc.LIBPOSTPROC_VERSION_INT(postproc.java:-2)
│
↑ 'int org.bytedeco.ffmpeg.global.postproc.LIBPOSTPROC_VERSION_INT()' (UnsatisfiedLinkError)

My FFmpeg -version output :

ffmpeg version 5.0 Copyright (c) 2000-2022 the FFmpeg developers
built with Apple clang version 13.0.0 (clang-1300.0.29.30)
configuration: --prefix=/opt/homebrew/Cellar/ffmpeg/5.0 --enable-shared --enable-pthreads --enable-version3 --cc=clang --host-cflags= --host-ldflags= --enable-ffplay --enable-gnutls --enable-gpl --enable-libaom --enable-libbluray --enable-libdav1d --enable-libmp3lame --enable-libopus --enable-librav1e --enable-librist --enable-librubberband --enable-libsnappy --enable-libsrt --enable-libtesseract --enable-libtheora --enable-libvidstab --enable-libvmaf --enable-libvorbis --enable-libvpx --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxml2 --enable-libxvid --enable-lzma --enable-libfontconfig --enable-libfreetype --enable-frei0r --enable-libass --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-libspeex --enable-libsoxr --enable-libzmq --enable-libzimg --disable-libjack --disable-indev=jack --enable-videotoolbox --enable-neon
libavutil      57. 17.100 / 57. 17.100
libavcodec     59. 18.100 / 59. 18.100
libavformat    59. 16.100 / 59. 16.100
libavdevice    59.  4.100 / 59.  4.100
libavfilter     8. 24.100 /  8. 24.100
libswscale      6.  4.100 /  6.  4.100
libswresample   4.  3.100 /  4.  3.100
libpostproc    56.  3.100 / 56.  3.100

libpostproc seems to be installed correctly

Faz95210 avatar Feb 10 '22 08:02 Faz95210

I've fixed that in the just released version. Try again with "5.0-1.5.7" (without "-SNAPSHOT"): https://repo1.maven.org/maven2/org/bytedeco/ffmpeg/5.0-1.5.7/

saudet avatar Feb 10 '22 08:02 saudet

Thanks ! it seems to work fine now 👍

Faz95210 avatar Feb 10 '22 09:02 Faz95210

@TheMode It looks like libffi works pretty much out of the box for macosx-arm64, so I've enabled builds for that in commit https://github.com/bytedeco/javacpp-presets/commit/fff341552268aa0652576e3b7234875ae63367f6. Please give it a try with the snapshots: http://bytedeco.org/builds/

saudet avatar May 30 '22 13:05 saudet

Thanks! Currently getting

'int org.bytedeco.libffi.global.ffi.FFI_TYPE_SMALL_STRUCT_1B()'
java.lang.UnsatisfiedLinkError: 'int org.bytedeco.libffi.global.ffi.FFI_TYPE_SMALL_STRUCT_1B()'
	at org.bytedeco.libffi.global.ffi.FFI_TYPE_SMALL_STRUCT_1B(Native Method)
	at org.bytedeco.libffi.global.ffi.<clinit>(ffi.java:109)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:467)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1282)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1227)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1203)
	at org.bytedeco.libffi.ffi_cif.<clinit>(ffi_cif.java:16)

when calling new ffi_cif(); on org.bytedeco:libffi-platform:3.4.2-1.5.8-SNAPSHOT

TheMode avatar May 31 '22 00:05 TheMode

I see, those values are not available on that platform, but they only seem to be used internally, so we probably don't need them. I've fixed that by commenting them out in commit https://github.com/bytedeco/javacpp-presets/commit/ba57140b05138e44f99819b83137a511550365c1. Please give it another try! Thanks for testing @TheMode

saudet avatar May 31 '22 01:05 saudet

Seems to work, thanks!

TheMode avatar May 31 '22 02:05 TheMode

A fresh build of org.bytedeco.ffmpeg-platform via maven worked properly for me with either version 5.0-1.5.7 or 5.1.2-1.5.8 as the ffmpeg-platform version. On macOS Ventura 13.1 on an M1 MacBook Air.

This is in the context of building the jmisb project.

lannybroo avatar Jan 15 '23 14:01 lannybroo

What do we need to do build HDF5 for macosx-aarch64?

mkitti avatar Mar 10 '23 21:03 mkitti

I tried to complete onnx M1 Silicon Support manually, packaged and compiled without problems, and generated the jar files without problems, but when I used it, Throw an exception.

macosx-arm64/libjnionnx.dylib, 0x0001): symbol not found in flat namespace '_onnxGetBackendCompatibility'

the following exception occurred and I was hoping for help. thanks

Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnionnx in java.library.path: /Users/ouyubin/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:.
	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2423)
	at java.base/java.lang.Runtime.loadLibrary0(Runtime.java:808)
	at java.base/java.lang.System.loadLibrary(System.java:1893)
	at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1825)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1416)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1227)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1203)
	at org.bytedeco.onnx.global.onnx.<clinit>(onnx.java:14)
	at java.base/java.lang.Class.forName0(Native Method)
	at java.base/java.lang.Class.forName(Class.java:466)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1282)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1227)
	at org.bytedeco.javacpp.Loader.load(Loader.java:1203)
	at org.bytedeco.onnx.ISchemaRegistry.<clinit>(ISchemaRegistry.java:16)
	at onnx.LoadModel.main(LoadModel.java:9)
Caused by: java.lang.UnsatisfiedLinkError: /Users/ouyubin/.javacpp/cache/onnx-1.12.0-1.5.8-macosx-arm64.jar/org/bytedeco/onnx/macosx-arm64/libjnionnx.dylib: dlopen(/Users/ouyubin/.javacpp/cache/onnx-1.12.0-1.5.8-macosx-arm64.jar/org/bytedeco/onnx/macosx-arm64/libjnionnx.dylib, 0x0001): symbol not found in flat namespace '_onnxGetBackendCompatibility'
	at java.base/jdk.internal.loader.NativeLibraries.load(Native Method)
	at java.base/jdk.internal.loader.NativeLibraries$NativeLibraryImpl.open(NativeLibraries.java:383)
	at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:227)
	at java.base/jdk.internal.loader.NativeLibraries.loadLibrary(NativeLibraries.java:169)
	at java.base/java.lang.ClassLoader.loadLibrary(ClassLoader.java:2383)
	at java.base/java.lang.Runtime.load0(Runtime.java:746)
	at java.base/java.lang.System.load(System.java:1857)
	at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:1772)

OuYubin avatar Mar 21 '23 09:03 OuYubin

We can most likely fix that with a new Info("onnxGetBackendCompatibility").skip(): https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes#skipping-lines-from-header-files

saudet avatar Mar 21 '23 10:03 saudet

We can most likely fix that with a new Info("onnxGetBackendCompatibility").skip(): https://github.com/bytedeco/javacpp/wiki/Mapping-Recipes#skipping-lines-from-header-files

Done,Thanks:)

.put(new Info("onnxGetBackendCompatibility","onnxGetBackendIDs","onnxGetBackendInfo","onnxGetEventState","onnxInitBackend","onnxInitEvent","onnxInitGraph","onnxReleaseBackend","onnxReleaseBackendID","onnxReleaseEvent","onnxReleaseGraph","onnxRunGraph","onnxSetGraphIO","onnxSignalEvent","onnxWaitEvent").skip());

OuYubin avatar Mar 21 '23 12:03 OuYubin

mkl still not find jar for macosx-arm64 image

shouriken avatar Mar 28 '23 02:03 shouriken

Intel doesn't provide an ARM version of MKL, that's normal. Please use OpenBLAS instead: https://github.com/bytedeco/javacpp-presets/tree/master/openblas

saudet avatar Mar 28 '23 02:03 saudet

javacpp haven 1.5.5 version for macosx-arm64, but javacpp-presets‘ sub-modules haven't any for macosx-arm64

shouriken avatar Mar 28 '23 02:03 shouriken

Looks like GitHub Actions now has free M1 runners. That should make it easier to get builds running: https://github.blog/changelog/2024-01-30-github-actions-introducing-the-new-m1-macos-runner-available-to-open-source/

saudet avatar Feb 01 '24 23:02 saudet

Looks like GitHub Actions now has free M1 runners. That should make it easier to get builds running: https://github.blog/changelog/2024-01-30-github-actions-introducing-the-new-m1-macos-runner-available-to-open-source/

They need to run on macOS 14 though. If you choose a macos-14 runner, it will automatically run on M1, while macos-11/12/13 runners are provisioned on Intel. Also many paths are different due to homebrew installing under /opt/homebrew instead of /usr/local on ARM. I guess we'll either have to create a new action or put a few conditionals into the existing one.

sbrunk avatar Feb 12 '24 14:02 sbrunk

Let's not create a new action, let's add branches and what not to deploy-macosx, yes. From what I understand GCC isn't available at all on Apple Silicon, so we can skip all that, and no need to worry about /usr/local paths there.

saudet avatar Feb 12 '24 23:02 saudet