SIGN IN SIGN UP

Add api to explicitly load a method (#2408)

Summary:
We lazy load methods during the first execute (forward). However, sometimes we want to explicitly load the method before the first inference, so that we get consistent performance between all runs.

Adding a method so that user can load method, if they wish. Otherwise, they can still depend on execute to lazy load for them.

Pull Request resolved: https://github.com/pytorch/executorch/pull/2408

Test Plan:
CI

Explicitly call this:
```
 diff --git a/xplat/executorch/examples/demo-apps/android/ExecuTorchDemo/app/src/main/java/com/example/executorchdemo/MainActivity.java b/xplat/executorch/examples/demo-apps/android/ExecuTorchDemo/app/src/main/java/com/example/executorchdemo/MainActivity.java
 --- a/xplat/executorch/examples/demo-apps/android/ExecuTorchDemo/app/src/main/java/com/example/executorchdemo/MainActivity.java
+++ b/xplat/executorch/examples/demo-apps/android/ExecuTorchDemo/app/src/main/java/com/example/executorchdemo/MainActivity.java
@@ -101,6 +101,7 @@
     try {
       mModule =
           Module.load(MainActivity.assetFilePath(getApplicationContext(), "dl3_xnnpack_fp32.pte"));
+      mModule.loadMethod("forward");

     } catch (IOException e) {
       Log.e("ImageSegmentation", "Error reading assets", e);
@@ -136,6 +137,7 @@
               mModule =
                   Module.load(
                       MainActivity.assetFilePath(getApplicationContext(), "dl3_xnnpack_fp32.pte"));
+              mModule.loadMethod("forward");
             } catch (IOException e) {
               Log.e("ImageSegmentation", "Error reading assets", e);
               finish();
```
```
buck install fbandroid/mode/opt xplat/executorch/examples/demo-apps/android/ExecuTorchDemo/app/src/main:ExecuTorchDemo
```
and run app

Differential Revision: D54868635

Pulled By: kirklandsign

fbshipit-source-id: a680862020b41a73e1aa2c68a84cd68c22cb18c9
H
Hansong Zhang committed
9a53ffec68fc9b30b0e52188b0eea572e4f662fd
Parent: ad9f186
Committed by Facebook GitHub Bot <facebook-github-bot@users.noreply.github.com> on 3/13/2024, 9:06:58 PM