Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions flutter/android/android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ ifeq (${WITH_STABLEDIFFUSION},1)
-f ${backend_qti_checksum_file}
endif
endif
ifeq (${WITH_MEDIATEK},1)
@echo "Validate checksum of Mediatek lib files"
flutter/tool/validate-checksum.sh \
-d ${backend_mediatek_lib_root} \
-f ${backend_mediatek_checksum_file}
endif

.PHONY: flutter/android/libs/deps
flutter/android/libs/deps:
Expand Down
6 changes: 6 additions & 0 deletions flutter/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@
<!-- Mediatek -->
<uses-native-library android:name="libapuwareapusys_v2.mtk.so"
android:required="false"/>
<!-- Mediatek -->
<uses-native-library android:name="libmvpu_engine_25_pub.mtk.so"
android:required="false"/>
<!-- Mediatek -->
<uses-native-library android:name="libmvpu_pattern_25_pub.mtk.so"
android:required="false"/>

<activity android:name=".MainActivity"
android:exported="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@

#include <dlfcn.h>

#include <string>

#include "NeuronAdapter.h"
#include "tensorflow/core/platform/logging.h"
std::string GetPlatformName();

#define LOAD_ADAPTER_FUNCTION(name) \
static name##_fn fn = reinterpret_cast<name##_fn>(loadAdapterFunction(#name));
Expand Down Expand Up @@ -77,7 +80,12 @@ inline void* loadAdapterLibrary(const char* name) {

inline void* getAdapterLibraryHandle() {
if (sHandle == nullptr) {
sHandle = loadAdapterLibrary("libneuronusdk_adapter.mtk.so");
const std::string device = GetPlatformName();
if (device == "mt6989") {
sHandle = loadAdapterLibrary("libneuronusdk_adapter.mtk.mt6989.so");
} else if (device == "mt6991") {
sHandle = loadAdapterLibrary("libneuronusdk_adapter.mtk.mt6991.so");
}
}
if (sHandle == nullptr) {
sHandle = loadAdapterLibrary("libneuron_adapter_mgvi.so");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
9124e150ab2da667ed87f8619dc3c9282ad6a87772aa8e201b80f8fa4e7e6ec9 mt6989/libneuronusdk_adapter.mtk.mt6989.so
7196b7aec72f77408aaeb84e2da4e202ca613489640a48f198f1affb38335475 mt6991/libneuronusdk_adapter.mtk.mt6991.so
Binary file not shown.
Binary file not shown.
2 changes: 2 additions & 0 deletions mobile_back_tflite/cpp/backend_tflite/neuron/neuron_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -343,4 +343,6 @@ bool neuron_issue_query(neuron_backend_ptr_t backend_ptr);
bool neuron_convert_input(neuron_backend_ptr_t backend_ptr, int bytes,
void *data);

std::string GetPlatformName();

#endif
20 changes: 16 additions & 4 deletions mobile_back_tflite/cpp/backend_tflite/tflite_c.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,23 @@ void reset_pipeline() { pipeline.reset(); }
static bool neuron_tflite_backend(const char **not_allowed_message,
const mlperf_device_info_t *device_info) {
bool neuron_capable = false;

bool neuron_adapter = false;
void *libneuron_adapter;

// Try to load the default neuron adapter library
libneuron_adapter =
dlopen("libneuron_adapter.mtk.so", RTLD_LAZY | RTLD_LOCAL);

// If not found, try to load platform-specific libraries
if (libneuron_adapter == nullptr) {
// Try to dlopen Neuron universal SDK
libneuron_adapter =
dlopen("libneuronusdk_adapter.mtk.so", RTLD_LAZY | RTLD_LOCAL);
const std::string device = GetPlatformName();
if (device == "mt6989") {
libneuron_adapter =
dlopen("libneuronusdk_adapter.mtk.mt6989.so", RTLD_LAZY | RTLD_LOCAL);
} else if (device == "mt6991") {
libneuron_adapter =
dlopen("libneuronusdk_adapter.mtk.mt6991.so", RTLD_LAZY | RTLD_LOCAL);
}
if (libneuron_adapter != nullptr) neuron_adapter = true;
} else {
neuron_adapter = true;
Expand Down Expand Up @@ -97,12 +105,16 @@ bool mlperf_backend_matches_hardware(const char **not_allowed_message,
*not_allowed_message = nullptr;
#if MTK_TFLITE_NEURON_BACKEND && defined(__ANDROID__)
std::string device = GetPlatformName();
LOG(INFO) << "The platform name is " << device;

*settings = tflite_settings_mtk.c_str();

if (device == "mt6989") {
*settings = tflite_settings_mtk_mt6989.c_str();
} else if (device == "mt6991") {
*settings = tflite_settings_mtk_mt6991.c_str();
}

return neuron_tflite_backend(not_allowed_message, device_info);
#elif __APPLE__
tflite_settings_apple = tflite_settings_apple_main;
Expand Down
10 changes: 8 additions & 2 deletions mobile_back_tflite/tflite_backend.mk
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ endif
ifeq (${WITH_MEDIATEK},1)
$(info WITH_MEDIATEK=1)
backend_mediatek_android_files= \
${BAZEL_LINKS_PREFIX}bin/mobile_back_tflite/cpp/backend_tflite/neuron/libtfliteneuronbackend.so \
bazel-bin/external/neuron_delegate/neuron/java/libtensorflowlite_neuron_jni.so
${BAZEL_LINKS_PREFIX}bin/mobile_back_tflite/cpp/backend_tflite/neuron/libtfliteneuronbackend.so \
bazel-bin/external/neuron_delegate/neuron/java/libtensorflowlite_neuron_jni.so \
mobile_back_tflite/cpp/backend_tflite/neuron/libs/mt6989/libneuronusdk_adapter.mtk.mt6989.so \
mobile_back_tflite/cpp/backend_tflite/neuron/libs/mt6991/libneuronusdk_adapter.mtk.mt6991.so
backend_mediatek_android_target=//mobile_back_tflite/cpp/backend_tflite/neuron:libtfliteneuronbackend.so
backend_mediatek_filename=libtfliteneuronbackend

# variables needed to run make target flutter/android/libs/checksum
backend_mediatek_lib_root=mobile_back_tflite/cpp/backend_tflite/neuron/libs
backend_mediatek_checksum_file=${backend_mediatek_lib_root}/checksums.txt
endif
Loading