Delete experimental/bindings/java
These don't currently build and are bit-rotting. They can be restored
from history if they are useful again.
PiperOrigin-RevId: 410812498
diff --git a/experimental/bindings/java/.clang-format b/experimental/bindings/java/.clang-format
deleted file mode 100644
index de06ba6..0000000
--- a/experimental/bindings/java/.clang-format
+++ /dev/null
@@ -1,9 +0,0 @@
-# Copyright 2019 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-# Disable formatting for any code under bindings/java for now.
-# TODO: Re-evalutate this when moving bindings/java to Github first.
-DisableFormat: true
diff --git a/experimental/bindings/java/CMakeLists.txt b/experimental/bindings/java/CMakeLists.txt
deleted file mode 100644
index abacda9..0000000
--- a/experimental/bindings/java/CMakeLists.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-# Copyright 2020 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-add_subdirectory(com/google/iree/native)
-
-if (${IREE_BUILD_TESTS})
- add_subdirectory(com/google/iree/tests)
-endif()
diff --git a/experimental/bindings/java/README.md b/experimental/bindings/java/README.md
deleted file mode 100644
index 8ded078..0000000
--- a/experimental/bindings/java/README.md
+++ /dev/null
@@ -1,13 +0,0 @@
-# IREE for Java
-
-### Instructions for compiling the AAR:
-
-Note: This currently only builds on linux.
-
-* Open iree/bindings/java/build.gradle in Android Studio
-
-* Click **Build > Make Project** (Ctrl + F9)
-
-* A .aar file will be in build/outputs/aar/
-
-TODO(jennik): Add command line instructions for building the AAR.
diff --git a/experimental/bindings/java/build.gradle b/experimental/bindings/java/build.gradle
deleted file mode 100644
index afd4e32..0000000
--- a/experimental/bindings/java/build.gradle
+++ /dev/null
@@ -1,92 +0,0 @@
-repositories {
- google()
- jcenter()
-}
-
-buildscript {
- repositories {
- google()
- jcenter()
- }
-
- dependencies {
- classpath 'com.android.tools.build:gradle:4.0.0'
- }
-}
-
-apply plugin: 'com.android.library'
-
-def cmakeListDir = "${rootDir}/../../../"
-def hostBuildDir = "${cmakeListDir}/../iree-build-host"
-def hostInstallDir = "${hostBuildDir}/install"
-
-android {
- compileSdkVersion 29
-
- defaultConfig {
- minSdkVersion 28
- targetSdkVersion 29
-
- externalNativeBuild {
- cmake {
- arguments "-DIREE_BUILD_EXPERIMENTAL_JAVA_BINDINGS=ON",
- "-DIREE_HAL_DRIVERS_TO_BUILD=VMLA",
-
- // Disable all but the runtime components needed for the
- // java bindings.
- "-DIREE_BUILD_COMPILER=OFF",
- "-DIREE_ENABLE_MLIR=OFF",
- "-DIREE_BUILD_TESTS=OFF",
- "-DIREE_BUILD_SAMPLES=OFF",
- "-DIREE_BUILD_PYTHON_BINDINGS=OFF",
- "-DIREE_HOST_BINARY_ROOT=${hostInstallDir}"
- }
- }
- }
-
- sourceSets {
- main {
- java.srcDirs = ['java/com/google/iree']
- jni.srcDirs = ['java/com/google/iree/native']
- manifest.srcFile 'com/google/iree/tests/TestManifest.xml'
- }
- }
-
- externalNativeBuild {
- cmake {
- version "3.13.4.0+"
- path "../../../CMakeLists.txt"
- }
- }
-}
-
-// Task to cmake configure the host
-task cmakeConfigureHost(type: Exec) {
- doFirst {
- println "Configuring host tools with cmake..."
- }
- workingDir cmakeListDir
- commandLine "cmake",
- "-G" , "Ninja",
- "-B", hostBuildDir ,
- "-DIREE_TARGET_BACKENDS_TO_BUILD=vmla",
- "-DIREE_HAL_DRIVERS_TO_BUILD=vmla",
- "-DIREE_BUILD_COMPILER=ON",
- "-DIREE_BUILD_TESTS=OFF ",
- "-DIREE_BUILD_SAMPLES=OFF",
- "-DCMAKE_INSTALL_PREFIX=${hostInstallDir}",
- "."
-}
-
-// Task to cmake build the host
-task cmakeBuildHost(type: Exec) {
- doFirst {
- println "Building host tools with cmake..."
- }
- workingDir cmakeListDir
- commandLine "cmake", "--build", hostBuildDir, "--target", "install"
-}
-
-// Build host tools before building the app
-preBuild.dependsOn cmakeBuildHost
-cmakeBuildHost.dependsOn cmakeConfigureHost
diff --git a/experimental/bindings/java/com/google/iree/Context.java b/experimental/bindings/java/com/google/iree/Context.java
deleted file mode 100644
index d7fdc61..0000000
--- a/experimental/bindings/java/com/google/iree/Context.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * Copyright 2020 The IREE Authors
- *
- * Licensed under the Apache License v2.0 with LLVM Exceptions.
- * See https://llvm.org/LICENSE.txt for license information.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-package com.google.iree;
-
-import java.nio.FloatBuffer;
-import java.util.List;
-
-/** An isolated execution context. */
-final class Context {
- public Context(Instance instance) throws Exception {
- isStatic = false;
- nativeAddress = nativeNew();
- Status status = Status.fromCode(nativeCreate(instance.getNativeAddress()));
-
- if (!status.isOk()) {
- throw status.toException("Could not create Context");
- }
- }
-
- // TODO(jennik): Consider using ImmutableList here.
- public Context(Instance instance, List<Module> modules) throws Exception {
- isStatic = true;
- nativeAddress = nativeNew();
- long[] moduleAdresses = getModuleAdresses(modules);
- Status status =
- Status.fromCode(nativeCreateWithModules(instance.getNativeAddress(), moduleAdresses));
- if (!status.isOk()) {
- throw status.toException("Could not create Context");
- }
- }
-
- public void registerModules(List<Module> modules) throws Exception {
- if (isStatic) {
- throw new IllegalStateException("Cannot register modules to a static context");
- }
-
- long[] moduleAdresses = getModuleAdresses(modules);
- Status status = Status.fromCode(nativeRegisterModules(moduleAdresses));
- if (!status.isOk()) {
- throw status.toException("Could not register Modules");
- }
- }
-
- public Function resolveFunction(String name) throws Exception {
- Function function = new Function();
- Status status = Status.fromCode(nativeResolveFunction(function.getNativeAddress(), name));
- if (!status.isOk()) {
- throw status.toException("Could not resolve function");
- }
- return function;
- }
-
- public void invokeFunction(
- Function function, FloatBuffer[] inputs, int inputElementCount, FloatBuffer output)
- throws Exception {
- Status status =
- Status.fromCode(
- nativeInvokeFunction(function.getNativeAddress(), inputs, inputElementCount, output));
- if (!status.isOk()) {
- throw status.toException("Could not invoke function");
- }
- }
-
- public int getId() {
- return nativeGetId();
- }
-
- public void free() {
- nativeFree();
- }
-
- private static long[] getModuleAdresses(List<Module> modules) {
- long[] moduleAddresses = new long[modules.size()];
- for (int i = 0; i < modules.size(); i++) {
- moduleAddresses[i] = modules.get(i).getNativeAddress();
- }
- return moduleAddresses;
- }
-
- private final long nativeAddress;
-
- private final boolean isStatic;
-
- private native long nativeNew();
-
- private native int nativeCreate(long instanceAddress);
-
- private native int nativeCreateWithModules(long instanceAddress, long[] moduleAddresses);
-
- private native int nativeRegisterModules(long[] moduleAddresses);
-
- private native int nativeResolveFunction(long functionAddress, String name);
-
- // TODO(jennik): 'output' should be a Floatbuffer[].
- private native int nativeInvokeFunction(
- long functionAddress, FloatBuffer[] inputs, int inputElementCount, FloatBuffer output);
-
- private native void nativeFree();
-
- private native int nativeGetId();
-}
diff --git a/experimental/bindings/java/com/google/iree/Function.java b/experimental/bindings/java/com/google/iree/Function.java
deleted file mode 100644
index 615be9d..0000000
--- a/experimental/bindings/java/com/google/iree/Function.java
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * Copyright 2020 The IREE Authors
- *
- * Licensed under the Apache License v2.0 with LLVM Exceptions.
- * See https://llvm.org/LICENSE.txt for license information.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-package com.google.iree;
-
-import android.util.Log;
-
-/** A function reference. */
-final class Function {
- private static final String TAG = Function.class.getCanonicalName();
-
- public static class Signature {
- String callingConvention;
-
- private Signature(String callingConvention) {
- this.callingConvention = callingConvention;
- }
- }
-
- public Function() {
- nativeAddress = nativeNew();
- }
-
- public long getNativeAddress() {
- return nativeAddress;
- }
-
- public String getName() {
- return nativeGetName();
- }
-
- public Signature getSignature() {
- return nativeGetSignature();
- }
-
- public String getDebugString() {
- String name = getName();
- Signature signature = getSignature();
- String debugString = String.format("Function debug string\n"
- + "-Name: %s\n"
- + "-Calling convention: %s\n",
- name, signature.callingConvention);
- return debugString;
- }
-
- public void printDebugString() {
- Log.d(TAG, getDebugString());
- }
-
- public void free() {
- nativeFree();
- }
-
- private final long nativeAddress;
-
- private native long nativeNew();
-
- private native String nativeGetName();
-
- private native Signature nativeGetSignature();
-
- private native void nativeFree();
-}
diff --git a/experimental/bindings/java/com/google/iree/Instance.java b/experimental/bindings/java/com/google/iree/Instance.java
deleted file mode 100644
index cf3c903..0000000
--- a/experimental/bindings/java/com/google/iree/Instance.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2020 The IREE Authors
- *
- * Licensed under the Apache License v2.0 with LLVM Exceptions.
- * See https://llvm.org/LICENSE.txt for license information.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-package com.google.iree;
-
-/**
- * Shared runtime instance responsible for routing Context events, enumerating and creating hardware
- * device interfaces, and managing device resource pools.
- */
-final class Instance {
- /**
- * Loads the native IREE shared library. This must be called first before doing anything with the
- * IREE Java API.
- */
- public static void loadNativeLibrary() {
- System.loadLibrary("iree");
- loaded = true;
- }
-
- public Instance() throws Exception {
- if (!loaded) {
- throw new IllegalStateException("Native library is not loaded");
- }
-
- nativeAddress = nativeNew();
- Status status = Status.fromCode(nativeCreate());
-
- if (!status.isOk()) {
- throw status.toException("Could not create Instance");
- }
- }
-
- public long getNativeAddress() {
- return nativeAddress;
- }
-
- public void free() {
- nativeFree();
- }
-
- private static boolean loaded = false;
-
- private final long nativeAddress;
-
- private native long nativeNew();
-
- private native int nativeCreate();
-
- private native void nativeFree();
-}
diff --git a/experimental/bindings/java/com/google/iree/Module.java b/experimental/bindings/java/com/google/iree/Module.java
deleted file mode 100644
index b7fbe94..0000000
--- a/experimental/bindings/java/com/google/iree/Module.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Copyright 2020 The IREE Authors
- *
- * Licensed under the Apache License v2.0 with LLVM Exceptions.
- * See https://llvm.org/LICENSE.txt for license information.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-package com.google.iree;
-
-import android.util.Log;
-import java.nio.ByteBuffer;
-
-/** A VM module. */
-// TODO(jennik): Add BytecodeModule and HALModule classes.
-final class Module {
- private static final String TAG = Module.class.getCanonicalName();
-
- private static class Signature {
- int importFunctionCount;
- int exportFunctionCount;
- int internalFunctionCount;
-
- public Signature(int importFunctionCount, int exportFunctionCount, int internalFunctionCount) {
- this.importFunctionCount = importFunctionCount;
- this.exportFunctionCount = exportFunctionCount;
- this.internalFunctionCount = internalFunctionCount;
- }
- }
-
- /**
- * Creates a VM module from a flatbuffer. The input ByteBuffer must be direct, and acceptable
- * schemas for the flatbuffer are available at iree/schemas
- */
- public Module(ByteBuffer flatbufferData) throws Exception {
- nativeAddress = nativeNew();
- Status status = Status.fromCode(nativeCreate(flatbufferData));
-
- if (!status.isOk()) {
- throw status.toException("Could not create Module");
- }
- }
-
- public long getNativeAddress() {
- return nativeAddress;
- }
-
- public String getName() {
- return nativeGetName();
- }
-
- public Signature getSignature() {
- return nativeGetSignature();
- }
-
- public String getDebugString() {
- String name = getName();
- Signature signature = getSignature();
- String debugString = String.format("Module debug string\n"
- + "-Name: %s\n"
- + "-Import function count: %d\n"
- + "-Export function count: %d\n"
- + "-Internal function count: %d",
- name, signature.importFunctionCount, signature.exportFunctionCount,
- signature.internalFunctionCount);
- return debugString;
- }
-
- public void printDebugString() {
- Log.d(TAG, getDebugString());
- }
-
- public void free() {
- nativeFree();
- }
-
- private final long nativeAddress;
-
- private native long nativeNew();
-
- private native int nativeCreate(ByteBuffer flatbufferData);
-
- private native String nativeGetName();
-
- private native Signature nativeGetSignature();
-
- private native void nativeFree();
-}
diff --git a/experimental/bindings/java/com/google/iree/Status.java b/experimental/bindings/java/com/google/iree/Status.java
deleted file mode 100644
index 864d9c4..0000000
--- a/experimental/bindings/java/com/google/iree/Status.java
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Copyright 2020 The IREE Authors
- *
- * Licensed under the Apache License v2.0 with LLVM Exceptions.
- * See https://llvm.org/LICENSE.txt for license information.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-package com.google.iree;
-
-import java.util.concurrent.CancellationException;
-import java.util.concurrent.TimeoutException;
-
-/** Well-known status codes matching iree_status_code_t values. */
-public enum Status {
- OK,
- CANCELLED,
- UNKNOWN,
- INVALID_ARGUMENT,
- DEADLINE_EXCEEDED,
- NOT_FOUND,
- ALREADY_EXISTS,
- PERMISSION_DENIED,
- UNAUTHENTICATED,
- RESOURCE_EXHAUSTED,
- FAILED_PRECONDITION,
- ABORTED,
- OUT_OF_RANGE,
- UNIMPLEMENTED,
- INTERNAL,
- UNAVAILABLE,
- DATA_LOSS;
-
- public boolean isOk() {
- return this == Status.OK;
- }
-
- public Exception toException(String message) {
- String messageWithStatus = this + ": " + message;
- switch (this) {
- case CANCELLED:
- return new CancellationException(messageWithStatus);
- case UNKNOWN:
- return new RuntimeException(messageWithStatus);
- case INVALID_ARGUMENT:
- return new IllegalArgumentException(messageWithStatus);
- case DEADLINE_EXCEEDED:
- return new TimeoutException(messageWithStatus);
- case NOT_FOUND:
- return new RuntimeException(messageWithStatus);
- case ALREADY_EXISTS:
- return new IllegalStateException(messageWithStatus);
- case PERMISSION_DENIED:
- return new IllegalAccessException(messageWithStatus);
- case RESOURCE_EXHAUSTED:
- return new RuntimeException(messageWithStatus);
- case FAILED_PRECONDITION:
- return new IllegalStateException(messageWithStatus);
- case ABORTED:
- return new InterruptedException(messageWithStatus);
- case OUT_OF_RANGE:
- return new IndexOutOfBoundsException(messageWithStatus);
- case UNIMPLEMENTED:
- return new UnsupportedOperationException(messageWithStatus);
- case INTERNAL:
- return new RuntimeException(messageWithStatus);
- case UNAVAILABLE:
- return new IllegalStateException(messageWithStatus);
- case DATA_LOSS:
- return new RuntimeException(messageWithStatus);
- case UNAUTHENTICATED:
- return new IllegalStateException(messageWithStatus);
- default:
- return new RuntimeException(messageWithStatus);
- }
- }
-
- public static Status fromCode(int code) {
- return Status.values()[code];
- }
-}
diff --git a/experimental/bindings/java/com/google/iree/native/CMakeLists.txt b/experimental/bindings/java/com/google/iree/native/CMakeLists.txt
deleted file mode 100644
index a983a8a..0000000
--- a/experimental/bindings/java/com/google/iree/native/CMakeLists.txt
+++ /dev/null
@@ -1,33 +0,0 @@
-# Copyright 2020 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-iree_cc_library(
- NAME
- cc_wrappers
- SRCS
- "context_wrapper.cc"
- "function_wrapper.cc"
- "instance_wrapper.cc"
- "module_wrapper.cc"
- HDRS
- "context_wrapper.h"
- "function_wrapper.h"
- "instance_wrapper.h"
- "module_wrapper.h"
- DEPS
- iree::base::api
- iree::base::internal::flags
- iree::base::logging
- iree::base::status
- iree::hal::api
- iree::hal::drivers
- iree::modules::hal
- iree::modules::strings::strings_module
- iree::modules::tensorlist::native_module
- iree::vm
- iree::vm::cc
- iree::vm::bytecode_module
-)
diff --git a/experimental/bindings/java/com/google/iree/native/context_jni.cc b/experimental/bindings/java/com/google/iree/native/context_jni.cc
deleted file mode 100644
index 04b8b0f..0000000
--- a/experimental/bindings/java/com/google/iree/native/context_jni.cc
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#include <jni.h>
-
-#include <vector>
-
-#include "experimental/bindings/java/com/google/iree/native/context_wrapper.h"
-#include "experimental/bindings/java/com/google/iree/native/function_wrapper.h"
-#include "experimental/bindings/java/com/google/iree/native/instance_wrapper.h"
-#include "experimental/bindings/java/com/google/iree/native/module_wrapper.h"
-#include "iree/base/logging.h"
-
-#define JNI_FUNC extern "C" JNIEXPORT
-#define JNI_PREFIX(METHOD) Java_com_google_iree_Context_##METHOD
-
-using iree::java::ContextWrapper;
-using iree::java::FunctionWrapper;
-using iree::java::InstanceWrapper;
-using iree::java::ModuleWrapper;
-
-namespace {
-
-// Returns a pointer to the native IREE context stored by the ContextWrapper
-// object.
-static ContextWrapper* GetContextWrapper(JNIEnv* env, jobject obj) {
- jclass clazz = env->GetObjectClass(obj);
- IREE_CHECK(clazz);
-
- jfieldID field = env->GetFieldID(clazz, "nativeAddress", "J");
- IREE_CHECK(field);
-
- return reinterpret_cast<ContextWrapper*>(env->GetLongField(obj, field));
-}
-
-std::vector<ModuleWrapper*> GetModuleWrappersFromAdresses(
- JNIEnv* env, jlongArray moduleAddresses) {
- // Get the addresses of the ModuleWrappers.
- jsize modules_size = env->GetArrayLength(moduleAddresses);
- std::vector<int64_t> module_addresses(modules_size);
- env->GetLongArrayRegion(moduleAddresses, 0, modules_size,
- reinterpret_cast<jlong*>(module_addresses.data()));
-
- // Convert the addresses to ModuleWrappers.
- std::vector<ModuleWrapper*> modules(modules_size);
- for (int i = 0; i < modules_size; i++) {
- modules[i] = (ModuleWrapper*)module_addresses[i];
- }
- return modules;
-}
-
-} // namespace
-
-JNI_FUNC jlong JNI_PREFIX(nativeNew)(JNIEnv* env, jobject thiz) {
- return reinterpret_cast<jlong>(new ContextWrapper());
-}
-
-JNI_FUNC void JNI_PREFIX(nativeFree)(JNIEnv* env, jobject thiz, jlong handle) {
- ContextWrapper* context = GetContextWrapper(env, thiz);
- IREE_CHECK_NE(context, nullptr);
- delete context;
-}
-
-JNI_FUNC jint JNI_PREFIX(nativeCreate)(JNIEnv* env, jobject thiz,
- jlong instanceAddress) {
- ContextWrapper* context = GetContextWrapper(env, thiz);
- IREE_CHECK_NE(context, nullptr);
-
- auto instance = (InstanceWrapper*)instanceAddress;
- auto status = context->Create(*instance);
- return (jint)status.code();
-}
-
-JNI_FUNC jint JNI_PREFIX(nativeCreateWithModules)(JNIEnv* env, jobject thiz,
- jlong instanceAddress,
- jlongArray moduleAddresses) {
- ContextWrapper* context = GetContextWrapper(env, thiz);
- IREE_CHECK_NE(context, nullptr);
-
- auto instance = (InstanceWrapper*)instanceAddress;
- auto modules = GetModuleWrappersFromAdresses(env, moduleAddresses);
-
- auto status = context->CreateWithModules(*instance, modules);
- return (jint)status.code();
-}
-
-JNI_FUNC jint JNI_PREFIX(nativeRegisterModules)(JNIEnv* env, jobject thiz,
- jlongArray moduleAddresses) {
- ContextWrapper* context = GetContextWrapper(env, thiz);
- IREE_CHECK_NE(context, nullptr);
-
- auto modules = GetModuleWrappersFromAdresses(env, moduleAddresses);
- auto status = context->RegisterModules(modules);
- return (jint)status.code();
-}
-
-JNI_FUNC jint JNI_PREFIX(nativeResolveFunction)(JNIEnv* env, jobject thiz,
- jlong functionAddress,
- jstring name) {
- ContextWrapper* context = GetContextWrapper(env, thiz);
- IREE_CHECK_NE(context, nullptr);
-
- auto function = (FunctionWrapper*)functionAddress;
- const char* native_name = env->GetStringUTFChars(name, /*isCopy=*/nullptr);
-
- auto status = context->ResolveFunction(
- iree_string_view_t{native_name, strlen(native_name)}, function);
- env->ReleaseStringUTFChars(name, native_name);
- return (jint)status.code();
-}
-
-JNI_FUNC jint JNI_PREFIX(nativeInvokeFunction)(JNIEnv* env, jobject thiz,
- jlong functionAddress,
- jobjectArray inputs,
- jint inputElementCount,
- jobject output) {
- ContextWrapper* context = GetContextWrapper(env, thiz);
- IREE_CHECK_NE(context, nullptr);
-
- const jsize inputs_size = env->GetArrayLength(inputs);
- std::vector<float*> native_inputs(inputs_size);
-
- for (int i = 0; i < inputs_size; i++) {
- jobject input = env->GetObjectArrayElement(inputs, i);
- float* native_input = (float*)env->GetDirectBufferAddress(input);
- native_inputs[i] = native_input;
- }
-
- auto function = (FunctionWrapper*)functionAddress;
- float* native_output = (float*)env->GetDirectBufferAddress(output);
- auto status = context->InvokeFunction(*function, native_inputs,
- (int)inputElementCount, native_output);
- return (jint)status.code();
-}
-
-JNI_FUNC jint JNI_PREFIX(nativeGetId)(JNIEnv* env, jobject thiz) {
- ContextWrapper* context = GetContextWrapper(env, thiz);
- IREE_CHECK_NE(context, nullptr);
-
- int context_id = context->id();
- return (jint)context_id;
-}
diff --git a/experimental/bindings/java/com/google/iree/native/context_wrapper.cc b/experimental/bindings/java/com/google/iree/native/context_wrapper.cc
deleted file mode 100644
index 4ec5f1e..0000000
--- a/experimental/bindings/java/com/google/iree/native/context_wrapper.cc
+++ /dev/null
@@ -1,155 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#include "experimental/bindings/java/com/google/iree/native/context_wrapper.h"
-
-#include <vector>
-
-#include "iree/base/api.h"
-#include "iree/base/logging.h"
-#include "iree/vm/ref_cc.h"
-
-namespace iree {
-namespace java {
-
-namespace {
-
-std::vector<iree_vm_module_t*> GetModulesFromModuleWrappers(
- const std::vector<ModuleWrapper*>& module_wrappers) {
- std::vector<iree_vm_module_t*> modules(module_wrappers.size());
- for (int i = 0; i < module_wrappers.size(); i++) {
- modules[i] = module_wrappers[i]->module();
- }
- return modules;
-}
-
-} // namespace
-
-Status ContextWrapper::Create(const InstanceWrapper& instance_wrapper) {
- IREE_RETURN_IF_ERROR(iree_vm_context_create(
- instance_wrapper.instance(), iree_allocator_system(), &context_));
- IREE_RETURN_IF_ERROR(CreateDefaultModules());
- std::vector<iree_vm_module_t*> default_modules = {hal_module_};
- IREE_RETURN_IF_ERROR(iree_vm_context_register_modules(
- context_, default_modules.data(), default_modules.size()));
- return OkStatus();
-}
-
-Status ContextWrapper::CreateWithModules(
- const InstanceWrapper& instance_wrapper,
- const std::vector<ModuleWrapper*>& module_wrappers) {
- auto modules = GetModulesFromModuleWrappers(module_wrappers);
- IREE_RETURN_IF_ERROR(CreateDefaultModules());
-
- // The ordering of modules matters, so default modules need to be at the
- // beginning of the vector.
- modules.insert(modules.begin(), hal_module_);
-
- IREE_RETURN_IF_ERROR(iree_vm_context_create_with_modules(
- instance_wrapper.instance(), modules.data(), modules.size(),
- iree_allocator_system(), &context_));
- return OkStatus();
-}
-
-Status ContextWrapper::RegisterModules(
- const std::vector<ModuleWrapper*>& module_wrappers) {
- auto modules = GetModulesFromModuleWrappers(module_wrappers);
- IREE_RETURN_IF_ERROR(iree_vm_context_register_modules(
- context_, modules.data(), modules.size()));
- return OkStatus();
-}
-
-Status ContextWrapper::ResolveFunction(iree_string_view_t name,
- FunctionWrapper* function_wrapper) {
- return iree_vm_context_resolve_function(context_, name,
- function_wrapper->function());
-}
-
-Status ContextWrapper::InvokeFunction(const FunctionWrapper& function_wrapper,
- const std::vector<float*>& inputs,
- int input_element_count, float* output) {
- vm::ref<iree_vm_list_t> input_list;
- IREE_RETURN_IF_ERROR(iree_vm_list_create(
- /*element_type=*/nullptr, input_element_count, iree_allocator_system(),
- &input_list));
-
- iree_hal_allocator_t* allocator = iree_hal_device_allocator(device_);
- iree_hal_memory_type_t input_memory_type =
- static_cast<iree_hal_memory_type_t>(IREE_HAL_MEMORY_TYPE_HOST_LOCAL |
- IREE_HAL_MEMORY_TYPE_DEVICE_VISIBLE);
- iree_hal_buffer_usage_t input_buffer_usage =
- static_cast<iree_hal_buffer_usage_t>(IREE_HAL_BUFFER_USAGE_ALL |
- IREE_HAL_BUFFER_USAGE_CONSTANT);
-
- for (auto input : inputs) {
- // Write the input into a mappable buffer.
- iree_hal_buffer_t* input_buffer = nullptr;
- IREE_RETURN_IF_ERROR(iree_hal_allocator_allocate_buffer(
- allocator, input_memory_type, input_buffer_usage,
- sizeof(float) * input_element_count, &input_buffer));
- IREE_RETURN_IF_ERROR(iree_hal_buffer_write_data(
- input_buffer, 0, input, input_element_count * sizeof(float)));
-
- // Wrap the input buffers in buffer views.
- iree_hal_buffer_view_t* input_buffer_view = nullptr;
- IREE_RETURN_IF_ERROR(iree_hal_buffer_view_create(
- input_buffer,
- /*shape=*/&input_element_count,
- /*shape_rank=*/1, IREE_HAL_ELEMENT_TYPE_FLOAT_32, &input_buffer_view));
- iree_hal_buffer_release(input_buffer);
-
- // Marshal the input buffer views through the input VM variant list.
- auto input_buffer_view_ref =
- iree_hal_buffer_view_move_ref(input_buffer_view);
- IREE_RETURN_IF_ERROR(
- iree_vm_list_push_ref_move(input_list.get(), &input_buffer_view_ref));
- }
-
- // Prepare outputs list to accept results from the invocation.
- vm::ref<iree_vm_list_t> outputs;
- IREE_RETURN_IF_ERROR(iree_vm_list_create(/*element_type=*/nullptr,
- 4 * sizeof(float),
- iree_allocator_system(), &outputs));
-
- // Synchronously invoke the function.
- IREE_RETURN_IF_ERROR(iree_vm_invoke(context_, *function_wrapper.function(),
- /*policy=*/nullptr, input_list.get(),
- outputs.get(), iree_allocator_system()));
-
- // Read back the results into the given output buffer.
- auto* output_buffer_view =
- reinterpret_cast<iree_hal_buffer_view_t*>(iree_vm_list_get_ref_deref(
- outputs.get(), 0, iree_hal_buffer_view_get_descriptor()));
- auto* output_buffer = iree_hal_buffer_view_buffer(output_buffer_view);
- // TODO(jennik): this is unsafe - we don't know the size of output ptr here!
- IREE_RETURN_IF_ERROR(iree_hal_buffer_read_data(
- output_buffer, 0, output, iree_hal_buffer_byte_length(output_buffer)));
- return OkStatus();
-}
-
-int ContextWrapper::id() const { return iree_vm_context_id(context_); }
-
-ContextWrapper::~ContextWrapper() {
- iree_vm_context_release(context_);
- iree_vm_module_release(hal_module_);
- iree_hal_device_release(device_);
- iree_hal_driver_release(driver_);
-}
-
-// TODO(jennik): Also create default string and tensorlist modules.
-Status ContextWrapper::CreateDefaultModules() {
- IREE_RETURN_IF_ERROR(iree_hal_driver_registry_try_create_by_name(
- iree_hal_driver_registry_default(), iree_make_cstring_view("vmla"),
- iree_allocator_system(), &driver_));
- IREE_RETURN_IF_ERROR(iree_hal_driver_create_default_device(
- driver_, iree_allocator_system(), &device_));
- IREE_RETURN_IF_ERROR(
- iree_hal_module_create(device_, iree_allocator_system(), &hal_module_));
- return OkStatus();
-}
-
-} // namespace java
-} // namespace iree
diff --git a/experimental/bindings/java/com/google/iree/native/context_wrapper.h b/experimental/bindings/java/com/google/iree/native/context_wrapper.h
deleted file mode 100644
index 7bcc7cd..0000000
--- a/experimental/bindings/java/com/google/iree/native/context_wrapper.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#ifndef IREE_EXPERIMENTAL_BINDINGS_JAVA_COM_GOOGLE_IREE_NATIVE_CONTEXT_WRAPPER_H_
-#define IREE_EXPERIMENTAL_BINDINGS_JAVA_COM_GOOGLE_IREE_NATIVE_CONTEXT_WRAPPER_H_
-
-#include <vector>
-
-#include "experimental/bindings/java/com/google/iree/native/function_wrapper.h"
-#include "experimental/bindings/java/com/google/iree/native/instance_wrapper.h"
-#include "experimental/bindings/java/com/google/iree/native/module_wrapper.h"
-#include "iree/base/status.h"
-#include "iree/hal/api.h"
-#include "iree/modules/hal/hal_module.h"
-#include "iree/vm/api.h"
-
-namespace iree {
-namespace java {
-
-class ContextWrapper {
- public:
- Status Create(const InstanceWrapper& instance_wrapper);
-
- Status CreateWithModules(const InstanceWrapper& instance_wrapper,
- const std::vector<ModuleWrapper*>& module_wrappers);
-
- Status RegisterModules(const std::vector<ModuleWrapper*>& module_wrappers);
-
- Status ResolveFunction(iree_string_view_t name,
- FunctionWrapper* function_wrapper);
-
- // TODO(jennik): Support other input types aside from floats.
- Status InvokeFunction(const FunctionWrapper& function_wrapper,
- const std::vector<float*>& inputs,
- int input_element_count, float* output);
-
- int id() const;
-
- ~ContextWrapper();
-
- private:
- Status CreateDefaultModules();
-
- iree_vm_context_t* context_ = nullptr;
- // TODO(jennik): These need to be configurable on the java side.
- iree_hal_driver_t* driver_ = nullptr;
- iree_hal_device_t* device_ = nullptr;
- iree_vm_module_t* hal_module_ = nullptr;
-};
-
-} // namespace java
-} // namespace iree
-
-#endif // IREE_EXPERIMENTAL_BINDINGS_JAVA_COM_GOOGLE_IREE_NATIVE_CONTEXT_WRAPPER_H_
diff --git a/experimental/bindings/java/com/google/iree/native/function_jni.cc b/experimental/bindings/java/com/google/iree/native/function_jni.cc
deleted file mode 100644
index 427f6a6..0000000
--- a/experimental/bindings/java/com/google/iree/native/function_jni.cc
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#include <jni.h>
-
-#include "experimental/bindings/java/com/google/iree/native/function_wrapper.h"
-#include "iree/base/logging.h"
-
-#define JNI_FUNC extern "C" JNIEXPORT
-#define JNI_PREFIX(METHOD) Java_com_google_iree_Function_##METHOD
-
-using iree::java::FunctionWrapper;
-
-namespace {
-
-// Returns a pointer to the native IREE function stored by the FunctionWrapper
-// object.
-static FunctionWrapper* GetFunctionWrapper(JNIEnv* env, jobject obj) {
- jclass clazz = env->GetObjectClass(obj);
- IREE_CHECK(clazz);
-
- jfieldID field = env->GetFieldID(clazz, "nativeAddress", "J");
- IREE_CHECK(field);
-
- return reinterpret_cast<FunctionWrapper*>(env->GetLongField(obj, field));
-}
-
-} // namespace
-
-JNI_FUNC jlong JNI_PREFIX(nativeNew)(JNIEnv* env, jobject thiz) {
- return reinterpret_cast<jlong>(new FunctionWrapper());
-}
-
-JNI_FUNC void JNI_PREFIX(nativeFree)(JNIEnv* env, jobject thiz) {
- FunctionWrapper* function = GetFunctionWrapper(env, thiz);
- IREE_CHECK_NE(function, nullptr);
- delete function;
-}
-
-JNI_FUNC jstring JNI_PREFIX(nativeGetName)(JNIEnv* env, jobject thiz) {
- FunctionWrapper* function = GetFunctionWrapper(env, thiz);
- IREE_CHECK_NE(function, nullptr);
-
- iree_string_view_t function_name = function->name();
- return env->NewStringUTF(function_name.data);
-}
-
-JNI_FUNC jobject JNI_PREFIX(nativeGetSignature)(JNIEnv* env, jobject thiz) {
- FunctionWrapper* function = GetFunctionWrapper(env, thiz);
- IREE_CHECK_NE(function, nullptr);
-
- // TODO(jennik): Look into caching the results of these lookups.
- iree_vm_function_signature_t function_signature = function->signature();
- jclass cls = env->FindClass("com/google/iree/Function$Signature");
- jmethodID constructor =
- env->GetMethodID(cls, "<init>", "(Ljava/lang/String;)V");
- return env->NewObject(
- cls, constructor,
- env->NewStringUTF(function_signature.calling_convention.data));
-}
diff --git a/experimental/bindings/java/com/google/iree/native/function_wrapper.cc b/experimental/bindings/java/com/google/iree/native/function_wrapper.cc
deleted file mode 100644
index 3751d18..0000000
--- a/experimental/bindings/java/com/google/iree/native/function_wrapper.cc
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#include "experimental/bindings/java/com/google/iree/native/function_wrapper.h"
-
-namespace iree {
-namespace java {
-
-iree_vm_function_t* FunctionWrapper::function() const {
- return function_.get();
-}
-
-iree_string_view_t FunctionWrapper::name() const {
- return iree_vm_function_name(function_.get());
-}
-
-iree_vm_function_signature_t FunctionWrapper::signature() const {
- return iree_vm_function_signature(function_.get());
-}
-
-} // namespace java
-} // namespace iree
diff --git a/experimental/bindings/java/com/google/iree/native/function_wrapper.h b/experimental/bindings/java/com/google/iree/native/function_wrapper.h
deleted file mode 100644
index 4566300..0000000
--- a/experimental/bindings/java/com/google/iree/native/function_wrapper.h
+++ /dev/null
@@ -1,33 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#ifndef IREE_EXPERIMENTAL_BINDINGS_JAVA_COM_GOOGLE_IREE_NATIVE_FUNCTION_WRAPPER_H_
-#define IREE_EXPERIMENTAL_BINDINGS_JAVA_COM_GOOGLE_IREE_NATIVE_FUNCTION_WRAPPER_H_
-
-#include <memory>
-
-#include "iree/vm/api.h"
-
-namespace iree {
-namespace java {
-
-class FunctionWrapper {
- public:
- iree_vm_function_t* function() const;
-
- iree_string_view_t name() const;
-
- iree_vm_function_signature_t signature() const;
-
- private:
- std::unique_ptr<iree_vm_function_t> function_ =
- std::make_unique<iree_vm_function_t>();
-};
-
-} // namespace java
-} // namespace iree
-
-#endif // IREE_EXPERIMENTAL_BINDINGS_JAVA_COM_GOOGLE_IREE_NATIVE_FUNCTION_WRAPPER_H_
diff --git a/experimental/bindings/java/com/google/iree/native/instance_jni.cc b/experimental/bindings/java/com/google/iree/native/instance_jni.cc
deleted file mode 100644
index bfdfda6..0000000
--- a/experimental/bindings/java/com/google/iree/native/instance_jni.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#include <jni.h>
-
-#include "experimental/bindings/java/com/google/iree/native/instance_wrapper.h"
-#include "iree/base/logging.h"
-
-#define JNI_FUNC extern "C" JNIEXPORT
-#define JNI_PREFIX(METHOD) Java_com_google_iree_Instance_##METHOD
-
-using iree::java::InstanceWrapper;
-
-namespace {
-
-// Returns a pointer to the native IREE instance stored by the InstanceWrapper
-// object.
-static InstanceWrapper* GetInstanceWrapper(JNIEnv* env, jobject obj) {
- jclass clazz = env->GetObjectClass(obj);
- IREE_CHECK(clazz);
-
- jfieldID field = env->GetFieldID(clazz, "nativeAddress", "J");
- IREE_CHECK(field);
-
- return reinterpret_cast<InstanceWrapper*>(env->GetLongField(obj, field));
-}
-
-} // namespace
-
-JNI_FUNC jlong JNI_PREFIX(nativeNew)(JNIEnv* env, jobject thiz) {
- return reinterpret_cast<jlong>(new InstanceWrapper());
-}
-
-JNI_FUNC void JNI_PREFIX(nativeFree)(JNIEnv* env, jobject thiz, jlong handle) {
- InstanceWrapper* instance = GetInstanceWrapper(env, thiz);
- IREE_CHECK_NE(instance, nullptr);
- delete instance;
-}
-
-JNI_FUNC jint JNI_PREFIX(nativeCreate)(JNIEnv* env, jobject thiz) {
- InstanceWrapper* instance = GetInstanceWrapper(env, thiz);
- IREE_CHECK_NE(instance, nullptr);
-
- auto status = instance->Create();
- return (jint)status.code();
-}
diff --git a/experimental/bindings/java/com/google/iree/native/instance_wrapper.cc b/experimental/bindings/java/com/google/iree/native/instance_wrapper.cc
deleted file mode 100644
index eaa2dc5..0000000
--- a/experimental/bindings/java/com/google/iree/native/instance_wrapper.cc
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#include "experimental/bindings/java/com/google/iree/native/instance_wrapper.h"
-
-#include <mutex>
-
-#include "iree/base/internal/flags.h"
-#include "iree/hal/vmla/registration/driver_module.h"
-#include "iree/modules/hal/hal_module.h"
-#include "iree/modules/strings/strings_module.h"
-#include "iree/modules/tensorlist/native_module.h"
-
-namespace iree {
-namespace java {
-
-namespace {
-
-void SetupVm() {
- // TODO(jennik): Pass flags through from java and us iree_flags_parse.
- // This checked version will abort()/exit() and that's... not great.
- char binname[] = "libiree.so";
- char* argv[] = {binname};
- char** aargv = argv;
- int argc = 1;
- iree_flags_parse_checked(IREE_FLAGS_PARSE_MODE_DEFAULT, &argc, &aargv);
-
- // TODO(jennik): register all available drivers
- IREE_CHECK_OK(iree_hal_vmla_driver_module_register(
- iree_hal_driver_registry_default()));
- IREE_CHECK_OK(iree_vm_register_builtin_types());
- IREE_CHECK_OK(iree_hal_module_register_types());
- IREE_CHECK_OK(iree_tensorlist_module_register_types());
- IREE_CHECK_OK(iree_strings_module_register_types());
-}
-
-} // namespace
-
-Status InstanceWrapper::Create() {
- static std::once_flag setup_vm_once;
- std::call_once(setup_vm_once, [] { SetupVm(); });
-
- return iree_vm_instance_create(iree_allocator_system(), &instance_);
-}
-
-iree_vm_instance_t* InstanceWrapper::instance() const { return instance_; }
-
-InstanceWrapper::~InstanceWrapper() { iree_vm_instance_release(instance_); }
-
-} // namespace java
-} // namespace iree
diff --git a/experimental/bindings/java/com/google/iree/native/instance_wrapper.h b/experimental/bindings/java/com/google/iree/native/instance_wrapper.h
deleted file mode 100644
index 1c2c545..0000000
--- a/experimental/bindings/java/com/google/iree/native/instance_wrapper.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#ifndef IREE_EXPERIMENTAL_BINDINGS_JAVA_COM_GOOGLE_IREE_NATIVE_INSTANCE_WRAPPER_H_
-#define IREE_EXPERIMENTAL_BINDINGS_JAVA_COM_GOOGLE_IREE_NATIVE_INSTANCE_WRAPPER_H_
-
-#include "iree/base/status.h"
-#include "iree/vm/api.h"
-
-namespace iree {
-namespace java {
-
-class InstanceWrapper {
- public:
- Status Create();
-
- iree_vm_instance_t* instance() const;
-
- ~InstanceWrapper();
-
- private:
- iree_vm_instance_t* instance_ = nullptr;
-};
-
-} // namespace java
-} // namespace iree
-
-#endif // IREE_EXPERIMENTAL_BINDINGS_JAVA_COM_GOOGLE_IREE_NATIVE_INSTANCE_WRAPPER_H_
diff --git a/experimental/bindings/java/com/google/iree/native/module_jni.cc b/experimental/bindings/java/com/google/iree/native/module_jni.cc
deleted file mode 100644
index 493c1df..0000000
--- a/experimental/bindings/java/com/google/iree/native/module_jni.cc
+++ /dev/null
@@ -1,71 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#include <jni.h>
-
-#include "experimental/bindings/java/com/google/iree/native/module_wrapper.h"
-
-#define JNI_FUNC extern "C" JNIEXPORT
-#define JNI_PREFIX(METHOD) Java_com_google_iree_Module_##METHOD
-
-using iree::java::ModuleWrapper;
-
-namespace {
-
-// Returns a pointer to the native IREE module stored by the ModuleWrapper
-// object.
-static ModuleWrapper* GetModuleWrapper(JNIEnv* env, jobject obj) {
- jclass clazz = env->GetObjectClass(obj);
- IREE_CHECK(clazz);
-
- jfieldID field = env->GetFieldID(clazz, "nativeAddress", "J");
- IREE_CHECK(field);
-
- return reinterpret_cast<ModuleWrapper*>(env->GetLongField(obj, field));
-}
-
-} // namespace
-
-JNI_FUNC jlong JNI_PREFIX(nativeNew)(JNIEnv* env, jobject thiz) {
- return reinterpret_cast<jlong>(new ModuleWrapper());
-}
-
-JNI_FUNC void JNI_PREFIX(nativeFree)(JNIEnv* env, jobject thiz) {
- ModuleWrapper* module = GetModuleWrapper(env, thiz);
- IREE_CHECK_NE(module, nullptr);
- delete module;
-}
-
-JNI_FUNC jint JNI_PREFIX(nativeCreate)(JNIEnv* env, jobject thiz, jobject buf) {
- ModuleWrapper* module = GetModuleWrapper(env, thiz);
- IREE_CHECK_NE(module, nullptr);
-
- const uint8_t* data = (uint8_t*)env->GetDirectBufferAddress(buf);
- int length = env->GetDirectBufferCapacity(buf);
- auto status = module->Create(data, length);
- return (jint)status.code();
-}
-
-JNI_FUNC jstring JNI_PREFIX(nativeGetName)(JNIEnv* env, jobject thiz) {
- ModuleWrapper* module = GetModuleWrapper(env, thiz);
- IREE_CHECK_NE(module, nullptr);
-
- iree_string_view_t module_name = module->name();
- return env->NewStringUTF(module_name.data);
-}
-
-JNI_FUNC jobject JNI_PREFIX(nativeGetSignature)(JNIEnv* env, jobject thiz) {
- ModuleWrapper* module = GetModuleWrapper(env, thiz);
- IREE_CHECK_NE(module, nullptr);
-
- iree_vm_module_signature_t module_signature = module->signature();
- jclass cls = env->FindClass("com/google/iree/Module$Signature");
- jmethodID constructor = env->GetMethodID(cls, "<init>", "(III)V");
- return env->NewObject(cls, constructor,
- module_signature.import_function_count,
- module_signature.export_function_count,
- module_signature.internal_function_count);
-}
diff --git a/experimental/bindings/java/com/google/iree/native/module_wrapper.cc b/experimental/bindings/java/com/google/iree/native/module_wrapper.cc
deleted file mode 100644
index e5e64b6..0000000
--- a/experimental/bindings/java/com/google/iree/native/module_wrapper.cc
+++ /dev/null
@@ -1,32 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#include "experimental/bindings/java/com/google/iree/native/module_wrapper.h"
-
-namespace iree {
-namespace java {
-
-Status ModuleWrapper::Create(const uint8_t* flatbuffer_data,
- iree_host_size_t length) {
- return iree_vm_bytecode_module_create(
- iree_const_byte_span_t{flatbuffer_data, length}, iree_allocator_null(),
- iree_allocator_system(), &module_);
-}
-
-iree_vm_module_t* ModuleWrapper::module() const { return module_; }
-
-iree_string_view_t ModuleWrapper::name() const {
- return iree_vm_module_name(module_);
-}
-
-iree_vm_module_signature_t ModuleWrapper::signature() const {
- return iree_vm_module_signature(module_);
-}
-
-ModuleWrapper::~ModuleWrapper() { iree_vm_module_release(module_); }
-
-} // namespace java
-} // namespace iree
diff --git a/experimental/bindings/java/com/google/iree/native/module_wrapper.h b/experimental/bindings/java/com/google/iree/native/module_wrapper.h
deleted file mode 100644
index d49c821..0000000
--- a/experimental/bindings/java/com/google/iree/native/module_wrapper.h
+++ /dev/null
@@ -1,35 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#ifndef IREE_EXPERIMENTAL_BINDINGS_JAVA_COM_GOOGLE_IREE_NATIVE_MODULE_WRAPPER_H_
-#define IREE_EXPERIMENTAL_BINDINGS_JAVA_COM_GOOGLE_IREE_NATIVE_MODULE_WRAPPER_H_
-
-#include "iree/base/status.h"
-#include "iree/vm/bytecode_module.h"
-
-namespace iree {
-namespace java {
-
-class ModuleWrapper {
- public:
- Status Create(const uint8_t* flatbuffer_data, iree_host_size_t length);
-
- iree_vm_module_t* module() const;
-
- iree_string_view_t name() const;
-
- iree_vm_module_signature_t signature() const;
-
- ~ModuleWrapper();
-
- private:
- iree_vm_module_t* module_ = nullptr;
-};
-
-} // namespace java
-} // namespace iree
-
-#endif // IREE_EXPERIMENTAL_BINDINGS_JAVA_COM_GOOGLE_IREE_NATIVE_MODULE_WRAPPER_H_
diff --git a/experimental/bindings/java/com/google/iree/tests/CMakeLists.txt b/experimental/bindings/java/com/google/iree/tests/CMakeLists.txt
deleted file mode 100644
index bc00079..0000000
--- a/experimental/bindings/java/com/google/iree/tests/CMakeLists.txt
+++ /dev/null
@@ -1,30 +0,0 @@
-# Copyright 2020 The IREE Authors
-#
-# Licensed under the Apache License v2.0 with LLVM Exceptions.
-# See https://llvm.org/LICENSE.txt for license information.
-# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-if(${IREE_BUILD_COMPILER})
- iree_bytecode_module(
- NAME
- simple_mul_bytecode_module
- SRC
- "simple_mul.mlir"
- C_IDENTIFIER
- "iree_java_testdata_simple_mul_bytecode_module"
- FLAGS
- "-iree-mlir-to-vm-bytecode-module"
- "-iree-hal-target-backends=vmla"
- )
-
- iree_cc_binary(
- NAME
- integration_test
- SRCS
- "integration_test.cc"
- DEPS
- experimental::bindings::java::com::google::iree::native::cc_wrappers
- experimental::bindings::java::com::google::iree::tests::simple_mul_bytecode_module_c
- iree::base::status
- )
-endif()
diff --git a/experimental/bindings/java/com/google/iree/tests/IntegrationTest.java b/experimental/bindings/java/com/google/iree/tests/IntegrationTest.java
deleted file mode 100644
index 5e20d0f..0000000
--- a/experimental/bindings/java/com/google/iree/tests/IntegrationTest.java
+++ /dev/null
@@ -1,156 +0,0 @@
-/*
- * Copyright 2020 The IREE Authors
- *
- * Licensed under the Apache License v2.0 with LLVM Exceptions.
- * See https://llvm.org/LICENSE.txt for license information.
- * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
- */
-
-package com.google.iree;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.fail;
-
-import android.content.Context;
-import android.content.res.Resources;
-import android.util.Log;
-import androidx.test.core.app.ApplicationProvider;
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-import java.io.IOException;
-import java.io.InputStream;
-import java.nio.ByteBuffer;
-import java.nio.ByteOrder;
-import java.nio.FloatBuffer;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import org.apache.commons.io.IOUtils;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@RunWith(AndroidJUnit4.class)
-public final class IntegrationTest {
- private static final String TAG = IntegrationTest.class.getCanonicalName();
-
- @Test
- public void throwsExceptionWithoutNativeLib() throws Exception {
- try {
- new Instance();
- fail();
- } catch (IllegalStateException expected) {
- }
- }
-
- @Test
- public void simpleMulWithStaticContext() throws Exception {
- Instance.loadNativeLibrary();
- Instance instance = new Instance();
-
- Context context = ApplicationProvider.getApplicationContext();
- Resources resources = context.getResources();
- InputStream moduleInputStream = resources.openRawResource(R.raw.simple_mul_bytecode_module);
- ByteBuffer moduleByteBuffer = convertInputStreamToByteBuffer(moduleInputStream);
- Module module = new Module(moduleByteBuffer);
- module.printDebugString();
-
- List<Module> modules = new ArrayList<>();
- modules.add(module);
- com.google.iree.Context ireeContext = new com.google.iree.Context(instance, modules);
-
- assertNotEquals(ireeContext.getId(), -1);
-
- String functionName = "module.simple_mul";
- Function function = ireeContext.resolveFunction(functionName);
- function.printDebugString();
-
- int elementCount = 4;
- FloatBuffer x = ByteBuffer.allocateDirect(elementCount * /*sizeof(float)=*/4)
- .order(ByteOrder.nativeOrder())
- .asFloatBuffer()
- .put(new float[] {4.0f, 4.0f, 4.0f, 4.0f});
- FloatBuffer y = ByteBuffer.allocateDirect(elementCount * /*sizeof(float)=*/4)
- .order(ByteOrder.nativeOrder())
- .asFloatBuffer()
- .put(new float[] {2.0f, 2.0f, 2.0f, 2.0f});
- FloatBuffer[] inputs = {x, y};
-
- // TODO(jennik): Allocate outputs in C++ rather than here.
- FloatBuffer outputBuffer = ByteBuffer.allocateDirect(elementCount * /*sizeof(float)=*/4)
- .order(ByteOrder.nativeOrder())
- .asFloatBuffer()
- .put(new float[] {1.0f, 2.0f, 3.0f, 4.0f});
- ireeContext.invokeFunction(function, inputs, elementCount, outputBuffer);
-
- float[] output = new float[elementCount];
- outputBuffer.position(0);
- outputBuffer.get(output);
- Log.d(TAG, "Output: " + Arrays.toString(output));
- assertArrayEquals(new float[] {8.0f, 8.0f, 8.0f, 8.0f}, output, 0.1f);
-
- function.free();
- module.free();
- ireeContext.free();
- instance.free();
- }
-
- @Test
- public void simpleMulWithDynamicContext() throws Exception {
- Instance.loadNativeLibrary();
- Instance instance = new Instance();
- com.google.iree.Context ireeContext = new com.google.iree.Context(instance);
-
- assertNotEquals(ireeContext.getId(), -1);
-
- Context context = ApplicationProvider.getApplicationContext();
- Resources resources = context.getResources();
- InputStream moduleInputStream = resources.openRawResource(R.raw.simple_mul_bytecode_module);
- ByteBuffer moduleByteBuffer = convertInputStreamToByteBuffer(moduleInputStream);
- Module module = new Module(moduleByteBuffer);
- module.printDebugString();
-
- List<Module> modules = new ArrayList<>();
- modules.add(module);
- ireeContext.registerModules(modules);
-
- String functionName = "module.simple_mul";
- Function function = ireeContext.resolveFunction(functionName);
- function.printDebugString();
-
- int elementCount = 4;
- FloatBuffer x = ByteBuffer.allocateDirect(elementCount * /*sizeof(float)=*/4)
- .order(ByteOrder.nativeOrder())
- .asFloatBuffer()
- .put(new float[] {4.0f, 4.0f, 4.0f, 4.0f});
- FloatBuffer y = ByteBuffer.allocateDirect(elementCount * /*sizeof(float)=*/4)
- .order(ByteOrder.nativeOrder())
- .asFloatBuffer()
- .put(new float[] {2.0f, 2.0f, 2.0f, 2.0f});
- FloatBuffer[] inputs = {x, y};
-
- FloatBuffer outputBuffer = ByteBuffer.allocateDirect(elementCount * /*sizeof(float)=*/4)
- .order(ByteOrder.nativeOrder())
- .asFloatBuffer()
- .put(new float[] {1.0f, 2.0f, 3.0f, 4.0f});
- ireeContext.invokeFunction(function, inputs, elementCount, outputBuffer);
-
- float[] output = new float[elementCount];
- outputBuffer.position(0);
- outputBuffer.get(output);
- Log.d(TAG, "Output: " + Arrays.toString(output));
- assertArrayEquals(new float[] {8.0f, 8.0f, 8.0f, 8.0f}, output, 0.1f);
-
- function.free();
- module.free();
- ireeContext.free();
- instance.free();
- }
-
- private static ByteBuffer convertInputStreamToByteBuffer(InputStream inputStream)
- throws IOException {
- byte[] bytes = IOUtils.toByteArray(inputStream);
- ByteBuffer byteBuffer = ByteBuffer.allocateDirect(bytes.length);
- byteBuffer.put(bytes, 0, bytes.length);
- return byteBuffer;
- }
-}
diff --git a/experimental/bindings/java/com/google/iree/tests/TestManifest.xml b/experimental/bindings/java/com/google/iree/tests/TestManifest.xml
deleted file mode 100644
index f2ff26a..0000000
--- a/experimental/bindings/java/com/google/iree/tests/TestManifest.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- Copyright 2020 The IREE Authors
-
- Licensed under the Apache License v2.0 with LLVM Exceptions.
- See https://llvm.org/LICENSE.txt for license information.
- SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
--->
-<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.google.iree" >
-
- <uses-sdk android:minSdkVersion="28" android:targetSdkVersion="29" />
-
- <instrumentation
- android:name="androidx.test.runner.AndroidJUnitRunner"
- android:functionalTest="false"
- android:handleProfiling="false"
- android:label="Tests com.google.iree"
- android:targetPackage="com.google.iree" />
-
- <application android:label="InstrumentationTests">
- <uses-library android:name="android.test.runner" />
- </application>
-
-</manifest>
diff --git a/experimental/bindings/java/com/google/iree/tests/integration_test.cc b/experimental/bindings/java/com/google/iree/tests/integration_test.cc
deleted file mode 100644
index c1f6e3e..0000000
--- a/experimental/bindings/java/com/google/iree/tests/integration_test.cc
+++ /dev/null
@@ -1,84 +0,0 @@
-// Copyright 2020 The IREE Authors
-//
-// Licensed under the Apache License v2.0 with LLVM Exceptions.
-// See https://llvm.org/LICENSE.txt for license information.
-// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
-
-#include <memory>
-
-#include "experimental/bindings/java/com/google/iree/native/context_wrapper.h"
-#include "experimental/bindings/java/com/google/iree/native/function_wrapper.h"
-#include "experimental/bindings/java/com/google/iree/native/instance_wrapper.h"
-#include "experimental/bindings/java/com/google/iree/native/module_wrapper.h"
-#include "experimental/bindings/java/com/google/iree/tests/simple_mul_bytecode_module_c.h"
-#include "iree/base/internal/flags.h"
-
-namespace iree {
-namespace java {
-namespace {
-
-extern "C" int main(int argc, char** argv) {
- auto instance = std::make_unique<InstanceWrapper>();
- auto instance_status = instance->Create();
- if (!instance_status.ok()) {
- IREE_LOG(ERROR) << "Instance error: " << instance_status.code();
- return 1;
- }
- IREE_LOG(INFO) << "Instance created";
-
- auto module = std::make_unique<ModuleWrapper>();
- const struct iree_file_toc_t* module_file =
- iree_java_testdata_simple_mul_bytecode_module_create();
- auto module_status = module->Create(
- reinterpret_cast<const uint8_t*>(module_file->data), module_file->size);
- if (!module_status.ok()) {
- IREE_LOG(ERROR) << "Module error: " << module_status.code();
- return 1;
- }
- std::vector<ModuleWrapper*> modules = {module.get()};
- IREE_LOG(INFO) << "Module created";
-
- auto context = std::make_unique<ContextWrapper>();
- auto context_status = context->CreateWithModules(*instance, modules);
- if (!context_status.ok()) {
- IREE_LOG(ERROR) << "Context error: " << context_status.code();
- return 1;
- }
- IREE_LOG(INFO) << "Context created";
-
- FunctionWrapper function;
- const char* function_name = "module.simple_mul";
- auto function_status = context->ResolveFunction(
- iree_string_view_t{function_name, strlen(function_name)}, &function);
- if (!context_status.ok()) {
- IREE_LOG(ERROR) << "Function error: " << function_status.code();
- return 1;
- }
- IREE_LOG(INFO) << "Function created";
- IREE_LOG(INFO) << "Function name: "
- << std::string(function.name().data, function.name().size);
-
- float input_x[] = {2.0f, 2.0f, 2.0f, 2.0f};
- float input_y[] = {4.0f, 4.0f, 4.0f, 4.0f};
- std::vector<float*> input{input_x, input_y};
- float output[4] = {0.0f, 1.0f, 2.0f, 3.0f};
- int element_count = 4;
-
- auto invoke_status =
- context->InvokeFunction(function, input, element_count, output);
- if (!context_status.ok()) {
- IREE_LOG(ERROR) << "Invoke function error: " << function_status.code();
- return 1;
- }
-
- IREE_LOG(INFO) << "Function output:";
- for (int i = 0; i < element_count; i++) {
- IREE_LOG(INFO) << output[i];
- }
-
- return 0;
-}
-
-} // namespace
-} // namespace java
-} // namespace iree
diff --git a/experimental/bindings/java/com/google/iree/tests/simple_mul.mlir b/experimental/bindings/java/com/google/iree/tests/simple_mul.mlir
deleted file mode 100644
index 7966f82..0000000
--- a/experimental/bindings/java/com/google/iree/tests/simple_mul.mlir
+++ /dev/null
@@ -1,5 +0,0 @@
-func @simple_mul(%arg0: tensor<4xf32>, %arg1: tensor<4xf32>) -> tensor<4xf32>
- attributes { iree.module.export } {
- %0 = "mhlo.multiply"(%arg0, %arg1) {name = "mul.1"} : (tensor<4xf32>, tensor<4xf32>) -> tensor<4xf32>
- return %0 : tensor<4xf32>
-}