executorch icon indicating copy to clipboard operation
executorch copied to clipboard

[Android] Add a Runtime.java

Open kirklandsign opened this issue 7 months ago • 2 comments

🚀 The feature, motivation and pitch

Right now we have two places loading library https://github.com/search?q=repo%3Apytorch%2Fexecutorch%20loadlib&type=code

Instead, can we just have one place, in a new file say Runtime.java?

class Runtime {
static {
  // Loads libexecutorch.so from jniLibs
  NativeLoader.loadLibrary("executorch");
}

static boolean isInitialized() {
  // maybe check something else?
}
}

Then in NativePeer.java and LlmModule.java

static {
  if (!Runtime.isInitialized()) {
    throw ...
  }
}

Alternatives

No response

Additional context

No response

RFC (Optional)

No response

cc @cbilgin

kirklandsign avatar Apr 24 '25 19:04 kirklandsign

hello there can work for this issue?

LefterisXefteris avatar Apr 24 '25 20:04 LefterisXefteris

Hi @LefterisXefteris feel free to grab it.

kirklandsign avatar Apr 24 '25 21:04 kirklandsign

Hi @LefterisXefteris, I'm working on adding Java API for runtime info. I've implemented Runtime.java (along with a unit test) for the feature. Feel free to use the code from my branch if it helps to close out this issue.

keyprocedure avatar Apr 30 '25 18:04 keyprocedure

@keyprocedure ohh sorry for the delay, i will do that now, thanks

LefterisXefteris avatar May 03 '25 21:05 LefterisXefteris

Hello @keyprocedure @LefterisXefteris please feel free to open up a PR. Thank you!

kirklandsign avatar May 07 '25 19:05 kirklandsign

For delegate list, use https://github.com/pytorch/executorch/blob/9f6c0f2d85fed86f9daac76e8ccb13af2b838c3d/runtime/backend/interface.h#L146-L151

So in Java, expect something like

public class Runtime {
public String[] getRegisteredBackends() {} -> JNI #include <executorch/runtime/backend/interface.h> and for (int size_t i = 0; i < executorch::ET_RUNTIME_NAMESPACE::get_num_registered_backends()) { result.add(get_backend_name(i)) }
}

For kernels (ops) it's https://github.com/pytorch/executorch/blob/9f6c0f2d85fed86f9daac76e8ccb13af2b838c3d/runtime/kernel/operator_registry.h#L237-L240 and you can visit kernel.name_

kirklandsign avatar May 15 '25 22:05 kirklandsign