Home / Class/ PyTorchAndroid Class — pytorch Architecture

PyTorchAndroid Class — pytorch Architecture

Architecture documentation for the PyTorchAndroid class in PyTorchAndroid.java from the pytorch codebase.

Entity Profile

Source Code

android/pytorch_android/src/main/java/org/pytorch/PyTorchAndroid.java lines 8–50

public final class PyTorchAndroid {
  static {
    if (!NativeLoader.isInitialized()) {
      NativeLoader.init(new SystemDelegate());
    }
    NativeLoader.loadLibrary("pytorch_jni_lite");
    PyTorchCodegenLoader.loadNativeLibs();
  }

  /**
   * Attention: This is not recommended way of loading production modules, as prepackaged assets
   * increase apk size etc. For production usage consider using loading from file on the disk {@link
   * org.pytorch.Module#load(String)}.
   *
   * <p>This method is meant to use in tests and demos.
   */
  public static Module loadModuleFromAsset(
      final AssetManager assetManager, final String assetName, final Device device) {
    return new Module(new NativePeer(assetName, assetManager, device));
  }

  public static Module loadModuleFromAsset(
      final AssetManager assetManager, final String assetName) {
    return new Module(new NativePeer(assetName, assetManager, Device.CPU));
  }

  /**
   * Globally sets the number of threads used on native side. Attention: Has global effect, all
   * modules use one thread pool with specified number of threads.
   *
   * @param numThreads number of threads, must be positive number.
   */
  public static void setNumThreads(int numThreads) {
    if (numThreads < 1) {
      throw new IllegalArgumentException("Number of threads cannot be less than 1");
    }

    nativeSetNumThreads(numThreads);
  }

  @DoNotStrip
  private static native void nativeSetNumThreads(int numThreads);
}

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free