[Java] Initial Apple Silicon support (#5891)

* Rearranging checks in onnxruntime_mlas.cmake to pickup Apple Silicon.

On an M1 Macbook Pro clang reports:

$ clang -dumpmachine
arm64-apple-darwin20.1.0

So the regex check needs to look for "arm64" first, as otherwise it
matches 32-bit ARM and you get NEON compilation failures.

* Adding Java side library loading support for Apple Silicon (and other aarch64 architectures).

* Adding Qgemm fix from @tracysh

* Fixes the java packaging on Windows.

* Missed a check in the java platform detector.
This commit is contained in:
Adam Pocock 2020-11-24 18:51:40 -05:00 committed by GitHub
parent ee908eb0aa
commit 8b83c51a35
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 35 additions and 6 deletions

View file

@ -100,13 +100,31 @@ if (CMAKE_SYSTEM_NAME STREQUAL "Android")
file(MAKE_DIRECTORY ${ANDROID_PACKAGE_OUTPUT_DIR})
endif()
# Set platform and ach for packaging
# Set platform and arch for packaging
# Checks the names set by MLAS on non-Windows platforms first
if (CMAKE_SYSTEM_NAME STREQUAL "Android")
set(JNI_ARCH ${ANDROID_ABI})
elseif (CMAKE_SIZEOF_VOID_P EQUAL "8")
elseif (ARM64)
set(JNI_ARCH aarch64)
elseif (X86_64)
set(JNI_ARCH x64)
elseif (POWER)
set(JNI_ARCH ppc64)
else()
message(FATAL_ERROR "Java is currently not supported for x86 architecture")
# Now mirror the checks used with MSVC
if(MSVC)
if(onnxruntime_target_platform STREQUAL "ARM64")
set(JNI_ARCH aarch64)
elseif(onnxruntime_target_platform STREQUAL "x64")
set(JNI_ARCH x64)
else()
# if everything else failed then we're on a 32-bit arch and Java isn't supported
message(FATAL_ERROR "Java is currently not supported on 32-bit x86 architecture")
endif()
else()
# if everything else failed then we're on a 32-bit arch and Java isn't supported
message(FATAL_ERROR "Java is currently not supported on 32-bit x86 architecture")
endif()
endif()
if (WIN32)

View file

@ -151,7 +151,9 @@ else()
OUTPUT_VARIABLE dumpmachine_output
ERROR_QUIET
)
if(dumpmachine_output MATCHES "^arm.*")
if(dumpmachine_output MATCHES "^arm64.*")
set(ARM64 TRUE)
elseif(dumpmachine_output MATCHES "^arm.*")
set(ARM TRUE)
elseif(dumpmachine_output MATCHES "^aarch64.*")
set(ARM64 TRUE)

View file

@ -59,10 +59,15 @@ final class OnnxRuntime {
}
String detectedArch = null;
String arch = System.getProperty("os.arch", "generic").toLowerCase(Locale.ENGLISH);
if (arch.indexOf("amd64") == 0 || arch.indexOf("x86_64") == 0) {
if (arch.startsWith("amd64") || arch.startsWith("x86_64")) {
detectedArch = "x64";
} else if (arch.indexOf("x86") == 0) {
} else if (arch.startsWith("x86")) {
// 32-bit x86 is not supported by the Java API
detectedArch = "x86";
} else if (arch.startsWith("aarch64")) {
detectedArch = "aarch64";
} else if (arch.startsWith("ppc64")) {
detectedArch = "ppc64";
} else if (isAndroid()) {
detectedArch = arch;
} else {

View file

@ -23,7 +23,11 @@ Abstract:
.equ .LGemmU8X8KernelFrame_ColumnSumBuffer, 0
.equ .LGemmU8X8KernelFrame_DepthValue, 8
#if defined(__APPLE__)
.equ .LGemmU8X8KernelFrame_ZeroMode, 12
#else
.equ .LGemmU8X8KernelFrame_ZeroMode, 16
#endif
.text