Skip to content

Commit

Permalink
Android cleanup java api (#6022)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #6022

Reviewed By: shoumikhin

Differential Revision: D64073604

Pulled By: kirklandsign

fbshipit-source-id: 2bbe0792b7094ef7438b602c958adddd9b55a6d1
  • Loading branch information
kirklandsign authored and facebook-github-bot committed Oct 9, 2024
1 parent 72b3bb3 commit a6b213b
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
12 changes: 2 additions & 10 deletions extension/android/jni/jni_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -243,19 +243,11 @@ class ExecuTorchJni : public facebook::jni::HybridClass<ExecuTorchJni> {
static facebook::jni::local_ref<jhybriddata> initHybrid(
facebook::jni::alias_ref<jclass>,
facebook::jni::alias_ref<jstring> modelPath,
facebook::jni::alias_ref<
facebook::jni::JMap<facebook::jni::JString, facebook::jni::JString>>
extraFiles,
jint loadMode) {
return makeCxxInstance(modelPath, extraFiles, loadMode);
return makeCxxInstance(modelPath, loadMode);
}

ExecuTorchJni(
facebook::jni::alias_ref<jstring> modelPath,
facebook::jni::alias_ref<
facebook::jni::JMap<facebook::jni::JString, facebook::jni::JString>>
extraFiles,
jint loadMode) {
ExecuTorchJni(facebook::jni::alias_ref<jstring> modelPath, jint loadMode) {
Module::LoadMode load_mode = Module::LoadMode::Mmap;
if (loadMode == 0) {
load_mode = Module::LoadMode::File;
Expand Down
21 changes: 3 additions & 18 deletions extension/android/src/main/java/org/pytorch/executorch/Module.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

import com.facebook.soloader.nativeloader.NativeLoader;
import com.facebook.soloader.nativeloader.SystemDelegate;
import java.util.Map;
import org.pytorch.executorch.annotations.Experimental;

/**
Expand All @@ -36,32 +35,18 @@ public class Module {
/** Reference to the NativePeer object of this module. */
private NativePeer mNativePeer;

/**
* Loads a serialized ExecuTorch module from the specified path on the disk. Uses default load
* FILE.
*
* @param modelPath path to file that contains the serialized ExecuTorch module.
* @param extraFiles map with extra files names as keys, content of them will be loaded to values.
* @return new {@link org.pytorch.executorch.Module} object which owns the model module.
*/
public static Module load(final String modelPath, final Map<String, String> extraFiles) {
return load(modelPath, extraFiles, LOAD_MODE_FILE);
}

/**
* Loads a serialized ExecuTorch module from the specified path on the disk.
*
* @param modelPath path to file that contains the serialized ExecuTorch module.
* @param extraFiles map with extra files names as keys, content of them will be loaded to values.
* @param loadMode load mode for the module. See constants in {@link Module}.
* @return new {@link org.pytorch.executorch.Module} object which owns the model module.
*/
public static Module load(
final String modelPath, final Map<String, String> extraFiles, int loadMode) {
public static Module load(final String modelPath, int loadMode) {
if (!NativeLoader.isInitialized()) {
NativeLoader.init(new SystemDelegate());
}
return new Module(new NativePeer(modelPath, extraFiles, loadMode));
return new Module(new NativePeer(modelPath, loadMode));
}

/**
Expand All @@ -71,7 +56,7 @@ public static Module load(
* @return new {@link org.pytorch.executorch.Module} object which owns the model module.
*/
public static Module load(final String modelPath) {
return load(modelPath, null);
return load(modelPath, LOAD_MODE_FILE);
}

Module(NativePeer nativePeer) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import com.facebook.jni.HybridData;
import com.facebook.jni.annotations.DoNotStrip;
import com.facebook.soloader.nativeloader.NativeLoader;
import java.util.Map;
import org.pytorch.executorch.annotations.Experimental;

/**
Expand All @@ -29,11 +28,10 @@ class NativePeer {
private final HybridData mHybridData;

@DoNotStrip
private static native HybridData initHybrid(
String moduleAbsolutePath, Map<String, String> extraFiles, int loadMode);
private static native HybridData initHybrid(String moduleAbsolutePath, int loadMode);

NativePeer(String moduleAbsolutePath, Map<String, String> extraFiles, int loadMode) {
mHybridData = initHybrid(moduleAbsolutePath, extraFiles, loadMode);
NativePeer(String moduleAbsolutePath, int loadMode) {
mHybridData = initHybrid(moduleAbsolutePath, loadMode);
}

/** Clean up the native resources associated with this instance */
Expand Down

0 comments on commit a6b213b

Please sign in to comment.