Forums - android native library can't get GPU/DSP runtime.

3 posts / 0 new
Last post
android native library can't get GPU/DSP runtime.
likai2
Join Date: 27 Dec 22
Posts: 24
Posted: Wed, 2023-03-15 06:19

Hi, my devices is

Moto X40 Qualcomm 8Gen2

Android 13

SNPE SDK 2.5.0

I created Android application, import native libraries from snpe-2.5.0.4052\lib\aarch64-android-clang8.0.

My CMakelist.txt is

cmake_minimum_required(VERSION 3.18.1)

# Sets include directories for the project.
set(SNPE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../Snpe")
include_directories(${SNPE_DIR}/include/zdl) 

set(SNPE_LIB_DIR "${SNPE_DIR}/lib/aarch64-android-clang8.0")
set(DSP_LIB_DIR "${SNPE_DIR}/lib/dsp")

# Collects all source files in the current directory.
aux_source_directory(. SOURCES)

# Declares and names the project.
project("snpedemo")

# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.

add_library( # Sets the name of the library.
             snpedemo

             # Sets the library as a shared library.
             SHARED

             # Provides a relative path to your source file(s).
             ${SOURCES} )

add_library(SNPE SHARED IMPORTED)
set_target_properties(SNPE PROPERTIES IMPORTED_LOCATION ${SNPE_LIB_DIR}/libSNPE.so)
add_library(STL SHARED IMPORTED)
set_target_properties(STL PROPERTIES IMPORTED_LOCATION ${SNPE_LIB_DIR}/libc++_shared.so)

# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.

find_library( # Sets the name of the path variable.
              log-lib

              # Specifies the name of the NDK library that
              # you want CMake to locate.
              log )

# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.

target_link_libraries( # Specifies the target library.
        snpedemo

        SNPE
        STL
        # Links the target library to the log library
        # included in the NDK.
        ${log-lib})

My cmake params in app/build.gradle is

externalNativeBuild {
    cmake {
        abiFilters 'arm64-v8a'
        cppFlags '-std=c++11'
        arguments '-DANDROID_PLATFORM=android-29', '-DANDROID_TOOLCHAIN=clang'//, '-DANDROID_STL=c++_shared'
    }
}

My apk is built successfully. But apk only get CPU runtime, can't get GPU & DSP. 

My native C++ code is

extern "C" JNIEXPORT jstring JNICALL Java_com_lenovo_snpedemo_nativelibrary_SnpeNative_detectSnpeRuntime
        (JNIEnv *env, jobject instance) {
    std::string hello = "";

    zdl::DlSystem::Runtime_t runtime_cpu = zdl::DlSystem::Runtime_t::CPU;
    zdl::DlSystem::Runtime_t runtime_gpu = zdl::DlSystem::Runtime_t::GPU;
    zdl::DlSystem::Runtime_t runtime_dsp = zdl::DlSystem::Runtime_t::DSP;

    if (zdl::SNPE::SNPEFactory::isRuntimeAvailable(runtime_cpu)) {
        hello += "CPU ";
    } else {
        hello += "CPU not available ";
    }
    if (zdl::SNPE::SNPEFactory::isRuntimeAvailable(runtime_gpu)) {
        hello += "GPU ";
    } else {
        hello += "GPU not available ";
    }
    if (zdl::SNPE::SNPEFactory::isRuntimeAvailable(runtime_dsp)) {
        hello += "DSP ";
    } else {
        hello += "DSP not available ";
    }

    return env->NewStringUTF(hello.c_str());
}

Could Anyone kindly tell me how to using android native so with CMakeList, how to get GPU/DSP runtime?

Thanks for help.

  • Up0
  • Down0
weihuan
Join Date: 12 Apr 20
Posts: 270
Posted: Sun, 2023-03-19 06:24

Dear developer,

You can take a look at the SNPE sample code inside SDK. But another hand is that you may want to add pocily to your plicy possibilbity.

BR.

Wei

 

  • Up0
  • Down0
likai2
Join Date: 27 Dec 22
Posts: 24
Posted: Sun, 2023-03-19 20:08

Dear weihuan,

Thanks for your reply.

I have found that SNPE 2.5.0 native librares can NOT get GPU & DSP runtime on Android SDK 31 and above.

On Android SDK 30 and below, SNPE 2.5.0  (libSNPE.so) does get GPU runtime, but still does NOT DSP runtime.

I have run SDK's native code sample, after set LD_LIBRARY_PATH & ADSP_LIBRARY_PATH enviormrnt vars, the sample does get DSP runtime.

Please kindly help tell me how to set the environment variable in the Android native code, is there any sample code in SDK?

Thanks!

Best regards!

  • Up0
  • Down0
or Register

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.