Skip to content

Commit

Permalink
Merge branch 'main' into sync-llama-cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
jhen0409 committed Feb 18, 2025
2 parents 5c68a5f + bb9d6e8 commit e475f84
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions android/src/main/java/com/rnllama/LlamaContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ void emitNativeLog(String level, String text) {
}

static void toggleNativeLog(ReactApplicationContext reactContext, boolean enabled) {
if (LlamaContext.isArchNotSupported()) {
throw new IllegalStateException("Only 64-bit architectures are supported");
}
if (enabled) {
setupLog(new NativeLogCallback(reactContext));
} else {
Expand All @@ -54,7 +57,7 @@ static void toggleNativeLog(ReactApplicationContext reactContext, boolean enable
private DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter;

public LlamaContext(int id, ReactApplicationContext reactContext, ReadableMap params) {
if (LlamaContext.isArm64V8a() == false && LlamaContext.isX86_64() == false) {
if (LlamaContext.isArchNotSupported()) {
throw new IllegalStateException("Only 64-bit architectures are supported");
}
if (!params.hasKey("model")) {
Expand Down Expand Up @@ -420,15 +423,13 @@ public void release() {
// Log.d(NAME, "Loading librnllama_v8_7.so with runtime feature detection");
// System.loadLibrary("rnllama_v8_7");
} else if (LlamaContext.isX86_64()) {
Log.d(NAME, "Loading librnllama_x86_64.so");
System.loadLibrary("rnllama_x86_64");
loadedLibrary = "rnllama_x86_64";
Log.d(NAME, "Loading librnllama_x86_64.so");
System.loadLibrary("rnllama_x86_64");
loadedLibrary = "rnllama_x86_64";
} else {
Log.d(NAME, "Loading default librnllama.so");
System.loadLibrary("rnllama");
loadedLibrary = "rnllama";
Log.d(NAME, "ARM32 is not supported, skipping loading library");
}
}
}

private static boolean isArm64V8a() {
return Build.SUPPORTED_ABIS[0].equals("arm64-v8a");
Expand All @@ -438,6 +439,10 @@ private static boolean isX86_64() {
return Build.SUPPORTED_ABIS[0].equals("x86_64");
}

private static boolean isArchNotSupported() {
return isArm64V8a() == false && isX86_64() == false;
}

private static String getCpuFeatures() {
File file = new File("/proc/cpuinfo");
StringBuilder stringBuilder = new StringBuilder();
Expand Down

0 comments on commit e475f84

Please sign in to comment.