Modified internal dependencies.

PiperOrigin-RevId: 484407262
This commit is contained in:
MediaPipe Team 2022-10-27 19:06:04 -07:00 committed by Copybara-Service
parent abd1ff66c8
commit de5fe27e05
3 changed files with 39 additions and 42 deletions

View File

@ -84,33 +84,28 @@ cc_library(
"//conditions:default": ["tflite_gpu_runner.h"],
}),
deps = select({
"//mediapipe:ios": [],
"//mediapipe:macos": [],
"//conditions:default": [
"@com_google_absl//absl/strings",
"//mediapipe/framework/port:ret_check",
"//mediapipe/framework/port:status",
"//mediapipe/framework/port:statusor",
"@org_tensorflow//tensorflow/lite:framework",
"@org_tensorflow//tensorflow/lite/delegates/gpu:api",
"@org_tensorflow//tensorflow/lite/delegates/gpu/common:model",
"@org_tensorflow//tensorflow/lite/delegates/gpu/common:model_builder",
"@org_tensorflow//tensorflow/lite/delegates/gpu/gl:api2",
],
"//mediapipe:android": [
"@com_google_absl//absl/strings",
"//mediapipe/framework/port:ret_check",
"//mediapipe/framework/port:status",
"//mediapipe/framework/port:statusor",
"@org_tensorflow//tensorflow/lite:framework",
"@org_tensorflow//tensorflow/lite/delegates/gpu:api",
"@org_tensorflow//tensorflow/lite/delegates/gpu/cl:api",
"@org_tensorflow//tensorflow/lite/delegates/gpu/common:model",
"@org_tensorflow//tensorflow/lite/delegates/gpu/common:model_builder",
"@org_tensorflow//tensorflow/lite/delegates/gpu/gl:api2",
],
}) + [
"//mediapipe:ios": [],
"//mediapipe:macos": [],
"//conditions:default": [
"@com_google_absl//absl/strings",
"//mediapipe/framework/port:ret_check",
"//mediapipe/framework/port:status",
"//mediapipe/framework/port:statusor",
"@org_tensorflow//tensorflow/lite:framework",
"@org_tensorflow//tensorflow/lite/delegates/gpu:api",
"@org_tensorflow//tensorflow/lite/delegates/gpu/common:model",
"@org_tensorflow//tensorflow/lite/delegates/gpu/common:model_builder",
"@org_tensorflow//tensorflow/lite/delegates/gpu/gl:api2",
],
}) +
select({
"//mediapipe:android": [
"@org_tensorflow//tensorflow/lite/delegates/gpu/cl:api",
],
"//conditions:default": [],
}) + [
"@com_google_absl//absl/status",
"//mediapipe/framework:port",
"@org_tensorflow//tensorflow/lite/core/api",
],
)

View File

@ -34,7 +34,7 @@
// This code should be enabled as soon as TensorFlow version, which mediapipe
// uses, will include this module.
#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
#include "tensorflow/lite/delegates/gpu/cl/api.h"
#endif
@ -82,7 +82,7 @@ ObjectDef GetSSBOObjectDef(int channels) {
return gpu_object_def;
}
#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
cl::InferenceOptions GetClInferenceOptions(const InferenceOptions& options) {
cl::InferenceOptions result{};
@ -106,7 +106,7 @@ absl::Status VerifyShapes(const std::vector<TensorObjectDef>& actual,
return absl::OkStatus();
}
#endif // __ANDROID__
#endif // defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
} // namespace
@ -225,7 +225,7 @@ absl::Status TFLiteGPURunner::InitializeOpenGL(
absl::Status TFLiteGPURunner::InitializeOpenCL(
std::unique_ptr<InferenceBuilder>* builder) {
#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
cl::InferenceEnvironmentOptions env_options;
if (!serialized_binary_cache_.empty()) {
env_options.serialized_binary_cache = serialized_binary_cache_;
@ -254,11 +254,12 @@ absl::Status TFLiteGPURunner::InitializeOpenCL(
return absl::OkStatus();
#else
return mediapipe::UnimplementedError("Currently only Android is supported");
#endif // __ANDROID__
return mediapipe::UnimplementedError(
"Currently only Android & ChromeOS are supported");
#endif // defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
}
#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
absl::Status TFLiteGPURunner::InitializeOpenCLFromSerializedModel(
std::unique_ptr<InferenceBuilder>* builder) {
@ -283,7 +284,7 @@ absl::StatusOr<std::vector<uint8_t>> TFLiteGPURunner::GetSerializedModel() {
return serialized_model;
}
#endif // __ANDROID__
#endif // defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
} // namespace gpu
} // namespace tflite

View File

@ -20,6 +20,7 @@
#include <vector>
#include "absl/status/status.h"
#include "mediapipe/framework/port.h"
#include "mediapipe/framework/port/status.h"
#include "mediapipe/framework/port/statusor.h"
#include "tensorflow/lite/core/api/op_resolver.h"
@ -28,9 +29,9 @@
#include "tensorflow/lite/delegates/gpu/gl/api2.h"
#include "tensorflow/lite/model.h"
#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
#include "tensorflow/lite/delegates/gpu/cl/api.h"
#endif // __ANDROID__
#endif // defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
namespace tflite {
namespace gpu {
@ -83,7 +84,7 @@ class TFLiteGPURunner {
return output_shape_from_model_;
}
#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
void SetSerializedBinaryCache(std::vector<uint8_t>&& cache) {
serialized_binary_cache_ = std::move(cache);
}
@ -98,26 +99,26 @@ class TFLiteGPURunner {
}
absl::StatusOr<std::vector<uint8_t>> GetSerializedModel();
#endif // __ANDROID__
#endif // defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
private:
absl::Status InitializeOpenGL(std::unique_ptr<InferenceBuilder>* builder);
absl::Status InitializeOpenCL(std::unique_ptr<InferenceBuilder>* builder);
#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
absl::Status InitializeOpenCLFromSerializedModel(
std::unique_ptr<InferenceBuilder>* builder);
#endif // __ANDROID__
#endif // defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
InferenceOptions options_;
std::unique_ptr<gl::InferenceEnvironment> gl_environment_;
#ifdef __ANDROID__
#if defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
std::unique_ptr<cl::InferenceEnvironment> cl_environment_;
std::vector<uint8_t> serialized_binary_cache_;
std::vector<uint8_t> serialized_model_;
bool serialized_model_used_ = false;
#endif // __ANDROID__
#endif // defined(__ANDROID__) || defined(MEDIAPIPE_CHROMIUMOS)
// graph_gl_ is maintained temporarily and becomes invalid after runner_ is
// ready