Skip to content

Commit

Permalink
Modernize Gradle Configuration, Dependencies, and Upgrade Gradle to 8…
Browse files Browse the repository at this point in the history
….1.4 in /lite/examples/super_resolution/android
  • Loading branch information
jawad111 committed Sep 30, 2024
1 parent 46fcd97 commit 594e671
Show file tree
Hide file tree
Showing 16 changed files with 1,516 additions and 30 deletions.
79 changes: 51 additions & 28 deletions lite/examples/super_resolution/android/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,62 +1,85 @@
apply plugin: 'com.android.application'
apply plugin: 'de.undercouch.download'
plugins {
id("com.android.application")
id("de.undercouch.download")
}

android {
compileSdkVersion 28
namespace = "org.tensorflow.lite.examples.superresolution"
compileSdk 34
ndkVersion = "27.1.12297006" // Replace with the desired NDK version

defaultConfig {
applicationId "org.tensorflow.lite.examples.superresolution"
minSdkVersion 21
targetSdkVersion 28
versionCode 1
versionName "1.0"
applicationId = "org.tensorflow.lite.examples.superresolution"
minSdk 21
targetSdk 34
versionCode = 1
versionName = "1.0"

externalNativeBuild {
cmake {
arguments '-DANDROID_STL=c++_shared'
arguments("-DANDROID_STL=c++_shared")
}
}

ndk {
abiFilters 'armeabi-v7a','arm64-v8a'
}


}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro")
packagingOptions {
doNotStrip("**//.so") // Strip the so files in release builds
}
}
debug {
debuggable true
jniDebuggable true
packagingOptions { doNotStrip "**//.so" }
debuggable(true)
// isJniDebuggable = true // Explicitly setting JNI debuggable if really needed
packagingOptions {
doNotStrip("**//.so")
}
}
}

aaptOptions {
noCompress "tflite"
}
compileOptions {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
lintOptions {
abortOnError false

lint {
abortOnError = false
}

sourceSets {
main {
// let gradle pack the shared library into apk
jniLibs.srcDirs = ['../libraries/tensorflowlite/jni',
'../libraries/tensorflowlite-gpu/jni']
named("main") {
jniLibs {
srcDirs("../libraries/tensorflowlite/jni", "../libraries/tensorflowlite-gpu/jni")
}
}
}


externalNativeBuild {
cmake {
path "src/main/cc/CMakeLists.txt"
version "3.6.0"
path = file("src/main/cc/CMakeLists.txt")
version = "3.6.0"
}
}

configurations.all {
resolutionStrategy {
force "org.jetbrains.kotlin:kotlin-stdlib:1.8.22"
force "org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.8.22"
force "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.8.22"
}
}




}

// import download tasks
Expand All @@ -65,7 +88,7 @@ project.ext.ASSET_DIR = projectDir.toString() + '/src/main/assets'
apply from: 'download.gradle'

dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.guava:guava:30.0-android'
implementation 'com.android.support:design:23.0.1'
implementation 'androidx.appcompat:appcompat:1.7.0'
implementation 'com.google.guava:guava:32.1.3-android'
implementation 'com.android.support:design:28.0.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:screenOrientation="portrait">
android:screenOrientation="portrait"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
Expand Down
2 changes: 1 addition & 1 deletion lite/examples/super_resolution/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:4.2.0'
classpath 'com.android.tools.build:gradle:8.1.4'
classpath 'de.undercouch:gradle-download-task:4.1.1'
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
/* Copyright 2019 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/

#ifndef TENSORFLOW_LITE_DELEGATES_GPU_DELEGATE_H_
#define TENSORFLOW_LITE_DELEGATES_GPU_DELEGATE_H_

#include <stdint.h>

#include "tensorflow/lite/c/common.h"

#ifdef SWIG
#define TFL_CAPI_EXPORT
#else
#if defined(_WIN32)
#ifdef TFL_COMPILE_LIBRARY
#define TFL_CAPI_EXPORT __declspec(dllexport)
#else
#define TFL_CAPI_EXPORT __declspec(dllimport)
#endif // TFL_COMPILE_LIBRARY
#else
#define TFL_CAPI_EXPORT __attribute__((visibility("default")))
#endif // _WIN32
#endif // SWIG

#ifdef __cplusplus
extern "C" {
#endif // __cplusplus

// Encapsulated compilation/runtime tradeoffs.
enum TfLiteGpuInferenceUsage {
// Delegate will be used only once, therefore, bootstrap/init time should
// be taken into account.
TFLITE_GPU_INFERENCE_PREFERENCE_FAST_SINGLE_ANSWER = 0,

// Prefer maximizing the throughput. Same delegate will be used repeatedly on
// multiple inputs.
TFLITE_GPU_INFERENCE_PREFERENCE_SUSTAINED_SPEED = 1,
};

enum TfLiteGpuInferencePriority {
// AUTO priority is needed when a single priority is the most important
// factor. For example,
// priority1 = MIN_LATENCY would result in the configuration that achieves
// maximum performance.
TFLITE_GPU_INFERENCE_PRIORITY_AUTO = 0,
TFLITE_GPU_INFERENCE_PRIORITY_MAX_PRECISION = 1,
TFLITE_GPU_INFERENCE_PRIORITY_MIN_LATENCY = 2,
TFLITE_GPU_INFERENCE_PRIORITY_MIN_MEMORY_USAGE = 3,
};

// Used to toggle experimental flags used in the delegate. Note that this is a
// bitmask, so the values should be 1, 2, 4, 8, ...etc.
enum TfLiteGpuExperimentalFlags {
TFLITE_GPU_EXPERIMENTAL_FLAGS_NONE = 0,
// Enables inference on quantized models with the delegate.
TFLITE_GPU_EXPERIMENTAL_FLAGS_ENABLE_QUANT = 1 << 0,
// Enforces execution with the provided backend.
TFLITE_GPU_EXPERIMENTAL_FLAGS_CL_ONLY = 1 << 1,
TFLITE_GPU_EXPERIMENTAL_FLAGS_GL_ONLY = 1 << 2
};

// IMPORTANT: Always use TfLiteGpuDelegateOptionsV2Default() method to create
// new instance of TfLiteGpuDelegateOptionsV2, otherwise every new added option
// may break inference.
typedef struct {
// When set to zero, computations are carried out in maximal possible
// precision. Otherwise, the GPU may quantify tensors, downcast values,
// process in FP16 to increase performance. For most models precision loss is
// warranted.
// [OBSOLETE]: to be removed
int32_t is_precision_loss_allowed;

// Preference is defined in TfLiteGpuInferenceUsage.
int32_t inference_preference;

// Ordered priorities provide better control over desired semantics,
// where priority(n) is more important than priority(n+1), therefore,
// each time inference engine needs to make a decision, it uses
// ordered priorities to do so.
// For example:
// MAX_PRECISION at priority1 would not allow to decrease precision,
// but moving it to priority2 or priority3 would result in F16 calculation.
//
// Priority is defined in TfLiteGpuInferencePriority.
// AUTO priority can only be used when higher priorities are fully specified.
// For example:
// VALID: priority1 = MIN_LATENCY, priority2 = AUTO, priority3 = AUTO
// VALID: priority1 = MIN_LATENCY, priority2 = MAX_PRECISION,
// priority3 = AUTO
// INVALID: priority1 = AUTO, priority2 = MIN_LATENCY, priority3 = AUTO
// INVALID: priority1 = MIN_LATENCY, priority2 = AUTO,
// priority3 = MAX_PRECISION
// Invalid priorities will result in error.
int32_t inference_priority1;
int32_t inference_priority2;
int32_t inference_priority3;

// Bitmask flags. See the comments in TfLiteGpuExperimentalFlags.
int64_t experimental_flags;

// A graph could have multiple partitions that can be delegated to the GPU.
// This limits the maximum number of partitions to be delegated. By default,
// it's set to 1 in TfLiteGpuDelegateOptionsV2Default().
int32_t max_delegated_partitions;
} TfLiteGpuDelegateOptionsV2;

// Populates TfLiteGpuDelegateOptionsV2 as follows:
// is_precision_loss_allowed = false
// inference_preference = TFLITE_GPU_INFERENCE_PREFERENCE_FAST_SINGLE_ANSWER
// priority1 = TFLITE_GPU_INFERENCE_PRIORITY_MAX_PRECISION
// priority2 = TFLITE_GPU_INFERENCE_PRIORITY_AUTO
// priority3 = TFLITE_GPU_INFERENCE_PRIORITY_AUTO
TFL_CAPI_EXPORT TfLiteGpuDelegateOptionsV2 TfLiteGpuDelegateOptionsV2Default();

// Creates a new delegate instance that need to be destroyed with
// TfLiteGpuDelegateV2Delete when delegate is no longer used by TFLite.
//
// This delegate encapsulates multiple GPU-acceleration APIs under the hood to
// make use of the fastest available on a device.
//
// When `options` is set to `nullptr`, then default options are used.
TFL_CAPI_EXPORT TfLiteDelegate* TfLiteGpuDelegateV2Create(
const TfLiteGpuDelegateOptionsV2* options);

// Destroys a delegate created with `TfLiteGpuDelegateV2Create` call.
TFL_CAPI_EXPORT void TfLiteGpuDelegateV2Delete(TfLiteDelegate* delegate);

#ifdef __cplusplus
}
#endif // __cplusplus

#endif // TENSORFLOW_LITE_DELEGATES_GPU_DELEGATE_H_
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading

0 comments on commit 594e671

Please sign in to comment.