Project import generated by Copybara.

GitOrigin-RevId: a6e7ccd12eb2ad9da2f723eb344658295ed85d46
This commit is contained in:
MediaPipe Team 2020-04-16 11:29:01 -07:00 committed by jqtang
parent 16e5d7242d
commit 024f7bf0f1
5 changed files with 41 additions and 22 deletions

View File

@ -23,9 +23,9 @@
#include "mediapipe/framework/calculator_framework.h"
#include "mediapipe/framework/port/ret_check.h"
#if !defined(__EMSCRIPTEN__)
#if !defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__)
#include "mediapipe/util/cpu_util.h"
#endif // !__EMSCRIPTEN__
#endif // !__EMSCRIPTEN__ || __EMSCRIPTEN_PTHREADS__
#include "mediapipe/util/resource_util.h"
#include "tensorflow/lite/error_reporter.h"
@ -121,7 +121,7 @@ struct GPUData {
// Returns number of threads to configure XNNPACK delegate with.
// (Equal to user provided value if specified. Otherwise, it returns number of
// high cores (hard-coded to 1 for __EMSCRIPTEN__))
// high cores (hard-coded to 1 for Emscripten without Threads extension))
int GetXnnpackNumThreads(
const mediapipe::TfLiteInferenceCalculatorOptions& opts) {
static constexpr int kDefaultNumThreads = -1;
@ -129,11 +129,11 @@ int GetXnnpackNumThreads(
opts.delegate().xnnpack().num_threads() != kDefaultNumThreads) {
return opts.delegate().xnnpack().num_threads();
}
#if !defined(__EMSCRIPTEN__)
#if !defined(__EMSCRIPTEN__) || defined(__EMSCRIPTEN_PTHREADS__)
return InferHigherCoreIds().size();
#else
return 1;
#endif // !__EMSCRIPTEN__
#endif // !__EMSCRIPTEN__ || __EMSCRIPTEN_PTHREADS__
}
// Calculator Header Section

View File

@ -32,13 +32,14 @@ project.
2. Run the Bazel build command to generate the AAR.
```bash
bazel build -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a //path/to/the/aar/build/file:aar_name
bazel build -c opt --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --fat_apk_cpu=arm64-v8a,armeabi-v7a \
//path/to/the/aar/build/file:aar_name
```
For the face detection AAR target we made in the step 1, run:
```bash
bazel build -c opt --fat_apk_cpu=arm64-v8a,armeabi-v7a \
bazel build -c opt --host_crosstool_top=@bazel_tools//tools/cpp:toolchain --fat_apk_cpu=arm64-v8a,armeabi-v7a \
//mediapipe/examples/android/src/java/com/google/mediapipe/apps/aar_example:mp_face_detection_aar
# It should print:

View File

@ -527,7 +527,7 @@ REGISTER_CALCULATOR(Modulo3SourceCalculator);
// calculator.
class OutputAllSourceCalculator : public CalculatorBase {
public:
static const int kNumOutputPackets = 100;
static constexpr int kNumOutputPackets = 100;
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
cc->Outputs().Index(0).Set<int>();
@ -550,7 +550,7 @@ REGISTER_CALCULATOR(OutputAllSourceCalculator);
// progress.
class OutputOneAtATimeSourceCalculator : public CalculatorBase {
public:
static const int kNumOutputPackets = 1000;
static constexpr int kNumOutputPackets = 1000;
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
cc->Outputs().Index(0).Set<int>();
@ -577,7 +577,7 @@ REGISTER_CALCULATOR(OutputOneAtATimeSourceCalculator);
// input stream connected to this calculator can become full.
class DecimatorCalculator : public CalculatorBase {
public:
static const int kDecimationRatio = 101;
static constexpr int kDecimationRatio = 101;
static ::mediapipe::Status GetContract(CalculatorContract* cc) {
cc->Inputs().Index(0).SetAny();

View File

@ -56,6 +56,19 @@ void AddJNINativeMethod(std::vector<JNINativeMethodStrings> *methods,
void RegisterNativesVector(JNIEnv *env, jclass cls,
const std::vector<JNINativeMethodStrings> &methods) {
// A client Java project may not use some methods and classes that we attempt
// to register and could be removed by Proguard. In that case, we want to
// avoid triggering a crash due to ClassNotFoundException, so we are trading
// safety check here in exchange for flexibility to list out all registrations
// without worrying about usage subset by client Java projects.
if (!cls || methods.empty()) {
LOG(INFO) << "Skipping registration and clearing exception. Class or "
"native methods not found, may be unused and/or trimmed by "
"Proguard.";
env->ExceptionClear();
return;
}
JNINativeMethod *methods_array = new JNINativeMethod[methods.size()];
for (int i = 0; i < methods.size(); i++) {
JNINativeMethod jniNativeMethod{
@ -97,6 +110,13 @@ void RegisterGraphNatives(JNIEnv *env) {
(void *)&GRAPH_METHOD(nativeStartRunningGraph));
AddJNINativeMethod(&graph_methods, graph, "nativeSetParentGlContext", "(JJ)V",
(void *)&GRAPH_METHOD(nativeSetParentGlContext));
AddJNINativeMethod(&graph_methods, graph, "nativeCloseAllPacketSources",
"(J)V",
(void *)&GRAPH_METHOD(nativeCloseAllPacketSources));
AddJNINativeMethod(&graph_methods, graph, "nativeWaitUntilGraphDone", "(J)V",
(void *)&GRAPH_METHOD(nativeWaitUntilGraphDone));
AddJNINativeMethod(&graph_methods, graph, "nativeReleaseGraph", "(J)V",
(void *)&GRAPH_METHOD(nativeReleaseGraph));
RegisterNativesVector(env, graph_class, graph_methods);
}

View File

@ -130,11 +130,11 @@ cat > $(OUTS) <<EOF
"//third_party:androidx_legacy_support_v4",
"//third_party:camerax_core",
"//third_party:camera2",
"@com_google_code_findbugs//jar",
"@com_google_common_flogger//jar",
"@com_google_common_flogger_system_backend//jar",
"@com_google_guava_android//jar",
"@androidx_lifecycle//jar",
"@maven//:com_google_code_findbugs_jsr305",
"@maven//:com_google_flogger_flogger",
"@maven//:com_google_flogger_flogger_system_backend",
"@maven//:com_google_guava_guava",
"@maven//:androidx_lifecycle_lifecycle_common",
],
)
@ -144,18 +144,16 @@ def _proto_java_src_generator(name, proto_src, java_lite_out, srcs = []):
native.genrule(
name = name + "_proto_java_src_generator",
srcs = srcs + [
"@com_google_protobuf_javalite//:well_known_protos",
"@com_google_protobuf//:well_known_protos",
],
outs = [java_lite_out],
cmd = "$(location @com_google_protobuf_javalite//:protoc) " +
"--plugin=protoc-gen-javalite=$(location @com_google_protobuf_javalite//:protoc_gen_javalite) " +
cmd = "$(location @com_google_protobuf//:protoc) " +
"--proto_path=. --proto_path=$(GENDIR) " +
"--proto_path=$$(pwd)/external/com_google_protobuf_javalite/src " +
"--javalite_out=$(GENDIR) " + proto_src + " && " +
"--proto_path=$$(pwd)/external/com_google_protobuf/src " +
"--java_out=lite:$(GENDIR) " + proto_src + " && " +
"mv $(GENDIR)/" + java_lite_out + " $$(dirname $(location " + java_lite_out + "))",
tools = [
"@com_google_protobuf_javalite//:protoc",
"@com_google_protobuf_javalite//:protoc_gen_javalite",
"@com_google_protobuf//:protoc",
],
)