Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid argument(s): Failed to lookup symbol 'TFLGpuDelegateCreate' : undefined symbol: TFLGpuDelegateCreate #82

Closed
ayyysh04 opened this issue Jun 7, 2023 · 9 comments

Comments

@ayyysh04
Copy link

ayyysh04 commented Jun 7, 2023

Dart version : Dart SDK version: 2.19.6 (stable)
Flutter version : Flutter 3.7.9
tflite_flutter: ^0.10.0

image

Flutter code load interpreter :

   Future<Interpreter> loadModel() async {
        final options = InterpreterOptions()..threads = 6;
        options.addDelegate(GpuDelegate());
        // Load model from assets
        final interpreter = await Interpreter.fromAsset(
            "assets/tflite/keypoint.tflite",
            options: options);
        return interpreter;
      }

Build Gradle :

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
    localPropertiesFile.withReader('UTF-8') { reader ->
        localProperties.load(reader)
    }
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
    throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

def flutterVersionCode = localProperties.getProperty('flutter.versionCode')
if (flutterVersionCode == null) {
    flutterVersionCode = '1'
}

def flutterVersionName = localProperties.getProperty('flutter.versionName')
if (flutterVersionName == null) {
    flutterVersionName = '1.0'
}

apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
    packagingOptions {
        exclude("META-INF/DEPENDENCIES")
        exclude("META-INF/LICENSE")
        exclude("META-INF/LICENSE.txt")
        exclude("META-INF/license.txt")
        exclude("META-INF/NOTICE")
        exclude("META-INF/NOTICE.txt")
        exclude("META-INF/notice.txt")
        exclude("META-INF/ASL2.0")
        exclude("META-INF/*.kotlin_module")
    }
    compileSdkVersion 33

    compileOptions {
        sourceCompatibility 1.8
        targetCompatibility 1.8
    }

    kotlinOptions {
        jvmTarget = '1.8'
    }

    sourceSets {
        main.java.srcDirs += 'src/main/kotlin'
    }

    lintOptions {
        checkReleaseBuilds false
    }

    defaultConfig {
        // TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
        applicationId "com.exaple.app"
        minSdkVersion 22
        targetSdkVersion 33
        versionCode flutterVersionCode.toInteger()
        versionName flutterVersionName
        multiDexEnabled true
        // ndk {
        //     abiFilters "armeabi", "x86", "armeabi-v7a","x86_64", "mips",
        //             "mips64", "arm64-v8a"
        // }
        ndk {
            abiFilters "arm64-v8a", "armeabi-v7a", "x86", "x86_64"
            }
	  externalNativeBuild {
            cmake {
                // Enabling exceptions, RTTI
                // And setting C++ standard version
                cppFlags '-frtti -fexceptions -std=c++11'

                // Shared runtime for shared libraries
                arguments "-DANDROID_STL=c++_shared"
            }
        }
    }
     
    externalNativeBuild {
        cmake {
            path "CMakeLists.txt"
        }
    }

    buildTypes {
        release {
            // TODO: Add your own signing config for the release build.
            // Signing with the debug keys for now, so `flutter run --release` works.
            signingConfig signingConfigs.debug
        }
    }

    flavorDimensions "flavors"
    productFlavors {
        dev {
            dimension "flavors"
            applicationIdSuffix ".dev"
            versionNameSuffix "-dev"
        }
        staging {
            dimension "flavors"
            applicationIdSuffix ".staging"
            versionNameSuffix "-staging"
        }
        prod {
            dimension "flavors"
        }
    }

}

flutter {
    source '../..'
}

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation 'com.android.support:multidex:1.0.3'
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation("androidx.core:core-ktx:1.9.0")
    implementation 'com.appsflyer:af-android-sdk:6.3.2'
    implementation("androidx.lifecycle:lifecycle-process:2.2.0")
    implementation("com.moengage:moe-android-sdk:12.5.04")
    implementation 'com.facebook.android:facebook-android-sdk:latest.release'
    implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1'
    implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.4")
    implementation 'com.tom-roush:pdfbox-android:2.0.27.0'
}

apply plugin: 'com.google.gms.google-services'
apply plugin: 'com.google.firebase.crashlytics'
@gregorscholz
Copy link
Contributor

Are you trying this on an emulator or a real device?

@ayyysh04
Copy link
Author

ayyysh04 commented Jun 7, 2023

Are you trying this on an emulator or a real device?

Real device :
Tried on two phones : Redmi note 7 pro (Qualcomm Snapdragon 675) and Redmi Note 10 (Qualcomm SDM678 Snapdragon)

@ayyysh04
Copy link
Author

ayyysh04 commented Jun 8, 2023

While fixing i found out that the tflite version used by plugin in 2.12.0
and my model tflite version is 2.5.0
Is this the reason of my model not working with gpudelegate properly and giving low performance ?
plugin build gradle :

// The Android Gradle Plugin builds the native code with the Android NDK.

group 'org.tensorflow.tflite_flutter'
version '1.0'

buildscript {
    repositories {
        google()
        mavenCentral()
    }

    dependencies {
        // The Android Gradle Plugin knows how to build native code with the NDK.
        classpath 'com.android.tools.build:gradle:7.3.0'
    }
}

rootProject.allprojects {
    repositories {
        google()
        mavenCentral()
    }
}

apply plugin: 'com.android.library'

android {
    // Bumping the plugin compileSdkVersion requires all clients of this plugin
    // to bump the version in their app.
    compileSdkVersion 31

    // Bumping the plugin ndkVersion requires all clients of this plugin to bump
    // the version in their app and to download a newer version of the NDK.
    // ndkVersion "23.1.7779620"

    // Invoke the shared CMake build with the Android Gradle Plugin.
    externalNativeBuild {
        // cmake {
        //     path "../src/CMakeLists.txt"

        //     // The default CMake version for the Android Gradle Plugin is 3.10.2.
        //     // https://developer.android.com/studio/projects/install-ndk#vanilla_cmake
        //     //
        //     // The Flutter tooling requires that developers have CMake 3.10 or later
        //     // installed. You should not increase this version, as doing so will cause
        //     // the plugin to fail to compile for some customers of the plugin.
        //     // version "3.10.2"
        // }
    }

    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }

    defaultConfig {
        minSdkVersion 19
    }
}


dependencies {
    def tflite_version = "2.12.0"
    
    implementation("org.tensorflow:tensorflow-lite:${tflite_version}")
    implementation("org.tensorflow:tensorflow-lite-gpu:${tflite_version}")
}

@xyzacademic
Copy link

If your model can run on CPU. Probably some operators are not supported by GPU. Maybe you can try to do GPU compatibility analysis when you do the Tflite model converting. https://www.tensorflow.org/lite/guide/model_analyzer

@ayyysh04
Copy link
Author

ayyysh04 commented Jun 8, 2023

yup i tried it ,the model i am using is not compatible with GPU

@ayyysh04
Copy link
Author

ayyysh04 commented Jun 8, 2023

@xyzacademic I am using a cnn custom tensorflow model with input 1 x 512 x 320 x 3 for corner detection ,it is working good on mid and high end devices but not good with low end (1 sec latency) ,any way to fix this ? Thats the reason why i was trying to use GpuDelegate

@xyzacademic
Copy link

@xyzacademic I am using a cnn custom tensorflow model with input 1 x 512 x 320 x 3 for corner detection ,it is working good on mid and high end devices but not good with low end (1 sec latency) ,any way to fix this ? Thats the reason why i was trying to use GpuDelegate

I suggest designing the network with GPU-compatible operators. This is what I did. Maybe there is any other way I don't know.

@ayyysh04
Copy link
Author

@xyzacademic I am using a cnn custom tensorflow model with input 1 x 512 x 320 x 3 for corner detection ,it is working good on mid and high end devices but not good with low end (1 sec latency) ,any way to fix this ? Thats the reason why i was trying to use GpuDelegate

I suggest designing the network with GPU-compatible operators. This is what I did. Maybe there is any other way I don't know.

how much improvement did u get before and after ?

@xyzacademic
Copy link

The performance improvement of migrating CPU to GPU? Maybe twice faster. It depends on the model.
Also, if the phone call runs the model frequently, overheating will lower the performance and result in laggy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants