kikoland
kikoland

Reputation: 1

How to control GPU delegate fallback (C API)

I'm writing a program which relies on tensorflow lite GPU v2 capabilities link. At initialization step, I'm trying to create the GPU v2 delegate. However, on several devices the required OpenCL library is not available and I'd like to use the CPU delegate instead of automatic GPU v1 (GLES) fallback.

I've tried following code but the delegate is created (not null) even when OpenCL is not available.

TfLiteDelegate* delegate = TfLiteGpuDelegateV2Create(&optionsV2);

if (delegate == nullptr) LOGV("launchDelegate", "==> Failed to create GPU v2 delegate");
TfLiteInterpreterOptionsAddDelegate(options, delegate);

How do I detect that the GPU v2 delegate is not available at initialization so I can control the fallback options?

Upvotes: 0

Views: 367

Answers (2)

Terry Heo
Terry Heo

Reputation: 169

Or you can check libOpenCL.so availability by yourself.

https://github.com/tensorflow/tensorflow/blob/master/tensorflow/lite/delegates/gpu/cl/opencl_wrapper.cc#L81

Upvotes: 0

Taehee Jeong
Taehee Jeong

Reputation: 146

Can you share what options you've specified with optionsV2? enabling TFLITE_GPU_EXPERIMENTAL_FLAGS_CL_ONLY experimental flag might be worth trying.

https://github.com/tensorflow/tensorflow/blob/5874c1424db542293276cdaeb21f8de9febabd60/tensorflow/lite/delegates/gpu/delegate.h#L56

Upvotes: 1

Related Questions