[Android] Add a Runtime.java
🚀 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
hello there can work for this issue?
Hi @LefterisXefteris feel free to grab it.
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 ohh sorry for the delay, i will do that now, thanks
Hello @keyprocedure @LefterisXefteris please feel free to open up a PR. Thank you!
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_