Switch TfLite benchmark from gl_delegate to delegate that combines OpenCL and OpenGL.
PiperOrigin-RevId: 270314075
This commit is contained in:
parent
c14495c8f6
commit
592d786f30
@ -138,7 +138,7 @@ cc_library(
|
||||
"//tensorflow/lite/tools:command_line_flags",
|
||||
] + select({
|
||||
"//tensorflow:android": [
|
||||
"//tensorflow/lite/delegates/gpu:gl_delegate",
|
||||
"//tensorflow/lite/delegates/gpu:delegate",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
|
@ -48,29 +48,7 @@ void MultiRunStatsRecorder::OnBenchmarkStart(const BenchmarkParams& params) {
|
||||
const bool allow_precision_loss =
|
||||
params.Get<bool>("gpu_precision_loss_allowed");
|
||||
const std::string precision_tag = allow_precision_loss ? "fp16" : "fp32";
|
||||
|
||||
const int32_t gl_obj_type = params.Get<int32_t>("gpu_gl_object_type");
|
||||
std::string gl_type;
|
||||
switch (gl_obj_type) {
|
||||
case TFLITE_GL_OBJECT_TYPE_FASTEST:
|
||||
gl_type = "fastest";
|
||||
break;
|
||||
case TFLITE_GL_OBJECT_TYPE_TEXTURE:
|
||||
gl_type = "texture";
|
||||
break;
|
||||
case TFLITE_GL_OBJECT_TYPE_BUFFER:
|
||||
gl_type = "buffer";
|
||||
break;
|
||||
default:
|
||||
gl_type = "unknown";
|
||||
break;
|
||||
}
|
||||
|
||||
if (allow_precision_loss && gl_obj_type == TFLITE_GL_OBJECT_TYPE_FASTEST) {
|
||||
current_run_name_ = "gpu(fp16, fastest)-default";
|
||||
return;
|
||||
}
|
||||
current_run_name_ = "gpu(" + precision_tag + ", " + gl_type + ")";
|
||||
current_run_name_ = "gpu(" + precision_tag + ")";
|
||||
#else
|
||||
current_run_name_ = "gpu(fp16, fastest)-default";
|
||||
#endif
|
||||
|
@ -24,7 +24,7 @@ limitations under the License.
|
||||
#include <vector>
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include "tensorflow/lite/delegates/gpu/gl_delegate.h"
|
||||
#include "tensorflow/lite/delegates/gpu/delegate.h"
|
||||
#include "tensorflow/lite/nnapi/nnapi_util.h"
|
||||
#endif
|
||||
|
||||
@ -218,9 +218,6 @@ BenchmarkParams BenchmarkTfLiteModel::DefaultParams() {
|
||||
#if defined(__ANDROID__)
|
||||
default_params.AddParam("gpu_precision_loss_allowed",
|
||||
BenchmarkParam::Create<bool>(true));
|
||||
default_params.AddParam(
|
||||
"gpu_gl_object_type",
|
||||
BenchmarkParam::Create<int32_t>(TFLITE_GL_OBJECT_TYPE_FASTEST));
|
||||
#endif
|
||||
default_params.AddParam("allow_fp16", BenchmarkParam::Create<bool>(false));
|
||||
default_params.AddParam("require_full_delegation",
|
||||
@ -588,37 +585,16 @@ TfLiteStatus BenchmarkTfLiteModel::Init() {
|
||||
return kTfLiteOk;
|
||||
}
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
bool IsValidGLObjectTypeInGPU(int32_t type) {
|
||||
if (type < TFLITE_GL_OBJECT_TYPE_FASTEST ||
|
||||
type > TFLITE_GL_OBJECT_TYPE_BUFFER) {
|
||||
TFLITE_LOG(WARN) << "The specified GL object type in GPU is invalid: "
|
||||
<< type;
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
BenchmarkTfLiteModel::TfLiteDelegatePtrMap BenchmarkTfLiteModel::GetDelegates()
|
||||
const {
|
||||
TfLiteDelegatePtrMap delegates;
|
||||
if (params_.Get<bool>("use_gpu")) {
|
||||
#if defined(__ANDROID__)
|
||||
TfLiteGpuDelegateOptions gpu_opts = TfLiteGpuDelegateOptionsDefault();
|
||||
gpu_opts.metadata =
|
||||
model_ ? TfLiteGpuDelegateGetModelMetadata(model_->GetModel())
|
||||
: nullptr;
|
||||
gpu_opts.compile_options.precision_loss_allowed =
|
||||
TfLiteGpuDelegateOptionsV2 gpu_opts = TfLiteGpuDelegateOptionsV2Default();
|
||||
gpu_opts.inference_preference =
|
||||
TFLITE_GPU_INFERENCE_PREFERENCE_SUSTAINED_SPEED;
|
||||
gpu_opts.is_precision_loss_allowed =
|
||||
params_.Get<bool>("gpu_precision_loss_allowed") ? 1 : 0;
|
||||
int32_t gl_obj_type = params_.Get<int32_t>("gpu_gl_object_type");
|
||||
// We overwrite the gl object type to the recommended value if the specified
|
||||
// isn't valid.
|
||||
if (!IsValidGLObjectTypeInGPU(gl_obj_type)) {
|
||||
gl_obj_type = TFLITE_GL_OBJECT_TYPE_FASTEST;
|
||||
}
|
||||
gpu_opts.compile_options.preferred_gl_object_type = gl_obj_type;
|
||||
gpu_opts.compile_options.dynamic_batch_enabled = 0;
|
||||
Interpreter::TfLiteDelegatePtr delegate =
|
||||
evaluation::CreateGPUDelegate(model_.get(), &gpu_opts);
|
||||
#else
|
||||
|
@ -45,7 +45,7 @@ cc_library(
|
||||
"//tensorflow/lite/delegates/nnapi:nnapi_delegate",
|
||||
] + select({
|
||||
"//tensorflow:android": [
|
||||
"//tensorflow/lite/delegates/gpu:gl_delegate",
|
||||
"//tensorflow/lite/delegates/gpu:delegate",
|
||||
],
|
||||
"//conditions:default": [],
|
||||
}),
|
||||
|
@ -99,22 +99,19 @@ Interpreter::TfLiteDelegatePtr CreateNNAPIDelegate(
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
Interpreter::TfLiteDelegatePtr CreateGPUDelegate(
|
||||
tflite::FlatBufferModel* model, TfLiteGpuDelegateOptions* options) {
|
||||
return Interpreter::TfLiteDelegatePtr(TfLiteGpuDelegateCreate(options),
|
||||
&TfLiteGpuDelegateDelete);
|
||||
tflite::FlatBufferModel* model, TfLiteGpuDelegateOptionsV2* options) {
|
||||
return Interpreter::TfLiteDelegatePtr(TfLiteGpuDelegateV2Create(options),
|
||||
&TfLiteGpuDelegateV2Delete);
|
||||
}
|
||||
#endif // defined(__ANDROID__)
|
||||
|
||||
Interpreter::TfLiteDelegatePtr CreateGPUDelegate(
|
||||
tflite::FlatBufferModel* model) {
|
||||
#if defined(__ANDROID__)
|
||||
TfLiteGpuDelegateOptions options = TfLiteGpuDelegateOptionsDefault();
|
||||
options.metadata =
|
||||
model ? TfLiteGpuDelegateGetModelMetadata(model->GetModel()) : nullptr;
|
||||
options.compile_options.precision_loss_allowed = 1;
|
||||
options.compile_options.preferred_gl_object_type =
|
||||
TFLITE_GL_OBJECT_TYPE_FASTEST;
|
||||
options.compile_options.dynamic_batch_enabled = 0;
|
||||
TfLiteGpuDelegateOptionsV2 options = TfLiteGpuDelegateOptionsV2Default();
|
||||
options.is_precision_loss_allowed = 1;
|
||||
options.inference_preference =
|
||||
TFLITE_GPU_INFERENCE_PREFERENCE_SUSTAINED_SPEED;
|
||||
|
||||
return CreateGPUDelegate(model, &options);
|
||||
#else
|
||||
|
@ -20,7 +20,7 @@ limitations under the License.
|
||||
#include <vector>
|
||||
|
||||
#if defined(__ANDROID__)
|
||||
#include "tensorflow/lite/delegates/gpu/gl_delegate.h"
|
||||
#include "tensorflow/lite/delegates/gpu/delegate.h"
|
||||
#endif
|
||||
|
||||
#include "tensorflow/lite/context.h"
|
||||
@ -45,7 +45,7 @@ Interpreter::TfLiteDelegatePtr CreateNNAPIDelegate(
|
||||
Interpreter::TfLiteDelegatePtr CreateGPUDelegate(FlatBufferModel* model);
|
||||
#if defined(__ANDROID__)
|
||||
Interpreter::TfLiteDelegatePtr CreateGPUDelegate(
|
||||
FlatBufferModel* model, TfLiteGpuDelegateOptions* options);
|
||||
FlatBufferModel* model, TfLiteGpuDelegateOptionsV2* options);
|
||||
#endif
|
||||
|
||||
} // namespace evaluation
|
||||
|
Loading…
Reference in New Issue
Block a user