Skip to content

Android cleanup java api #6022

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
Loading