Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Windows shared library build for CMake #47621

Merged
merged 4 commits into from
Apr 8, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 5 additions & 0 deletions tensorflow/lite/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,11 @@ target_link_libraries(tensorflow-lite
ruy
${TFLITE_TARGET_DEPENDENCIES}
)

if (NOT BUILD_SHARED_LIBS)
list(APPEND TFLITE_TARGET_PUBLIC_OPTIONS "TFL_STATIC_LIBRARY_BUILD")
endif()

target_compile_options(tensorflow-lite
PUBLIC ${TFLITE_TARGET_PUBLIC_OPTIONS}
PRIVATE ${TFLITE_TARGET_PRIVATE_OPTIONS}
Expand Down
4 changes: 3 additions & 1 deletion tensorflow/lite/c/c_api_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ extern "C" {
// library.
#ifdef SWIG
#define TFL_CAPI_EXPORT
#else
#elif defined(TFL_STATIC_LIBRARY_BUILD)
#define TFL_CAPI_EXPORT
#else // not definded TFL_STATIC_LIBRARY_BUILD
terryheo marked this conversation as resolved.
Show resolved Hide resolved
#if defined(_WIN32)
#ifdef TFL_COMPILE_LIBRARY
terryheo marked this conversation as resolved.
Show resolved Hide resolved
#define TFL_CAPI_EXPORT __declspec(dllexport)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ limitations under the License.
namespace tflite {
namespace gpu {

using uint = unsigned int;

template <DataType S, typename T>
void RearrangeWeightsToOHWIOGroupI4O4(
const tflite::gpu::Tensor<OHWI, S>& weights, int out_group_size,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.

#include <math.h>

#include <cmath>
#include <set>
#include <vector>

Expand Down
40 changes: 19 additions & 21 deletions tensorflow/lite/delegates/gpu/delegate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ class Delegate {
public:
explicit Delegate(const TfLiteGpuDelegateOptionsV2* options)
: num_delegate_kernels_(0) {
delegate_.data_ = reinterpret_cast<void*>(this);
delegate_.Prepare = DelegatePrepare;
delegate_.CopyFromBufferHandle = nullptr;
delegate_.CopyToBufferHandle = nullptr;
delegate_.FreeBufferHandle = nullptr;
delegate_.flags = kTfLiteDelegateFlagsNone;
options_ = options ? *options : TfLiteGpuDelegateOptionsV2Default();
if (options_.max_delegated_partitions <= 0) {
options_.max_delegated_partitions = 1;
Expand All @@ -95,15 +101,7 @@ class Delegate {
int num_delegate_kernels() const { return num_delegate_kernels_; }

private:
TfLiteDelegate delegate_ = {
.data_ = reinterpret_cast<void*>(this),
.Prepare = DelegatePrepare,
.CopyFromBufferHandle = nullptr,
.CopyToBufferHandle = nullptr,
.FreeBufferHandle = nullptr,
.flags = kTfLiteDelegateFlagsNone,
};

TfLiteDelegate delegate_;
terryheo marked this conversation as resolved.
Show resolved Hide resolved
TfLiteGpuDelegateOptionsV2 options_;
int num_delegate_kernels_ = 0;

Expand Down Expand Up @@ -334,8 +332,10 @@ class DelegateKernel {
enforce_same_thread_ = true;
TFLITE_LOG_PROD_ONCE(tflite::TFLITE_LOG_INFO,
"Initialized OpenGL-based API.");
#endif
return absl::OkStatus();
#else
return absl::UnavailableError("OpenGL-based API disabled");
terryheo marked this conversation as resolved.
Show resolved Hide resolved
#endif
}

// The Delegate instance that's shared across all DelegateKernel instances.
Expand Down Expand Up @@ -440,17 +440,15 @@ TfLiteStatus DelegatePrepare(TfLiteContext* context, TfLiteDelegate* delegate) {
} // namespace tflite

TfLiteGpuDelegateOptionsV2 TfLiteGpuDelegateOptionsV2Default() {
TfLiteGpuDelegateOptionsV2 options = {
// set it to -1 to detect whether it was later adjusted.
.is_precision_loss_allowed = -1,
.inference_preference =
TFLITE_GPU_INFERENCE_PREFERENCE_FAST_SINGLE_ANSWER,
.inference_priority1 = TFLITE_GPU_INFERENCE_PRIORITY_MAX_PRECISION,
.inference_priority2 = TFLITE_GPU_INFERENCE_PRIORITY_AUTO,
.inference_priority3 = TFLITE_GPU_INFERENCE_PRIORITY_AUTO,
.experimental_flags = TFLITE_GPU_EXPERIMENTAL_FLAGS_ENABLE_QUANT,
.max_delegated_partitions = 1,
};
TfLiteGpuDelegateOptionsV2 options;
// set it to -1 to detect whether it was later adjusted.
options.is_precision_loss_allowed = -1;
options.inference_preference = TFLITE_GPU_INFERENCE_PREFERENCE_FAST_SINGLE_ANSWER;
options.inference_priority1 = TFLITE_GPU_INFERENCE_PRIORITY_MAX_PRECISION;
options.inference_priority2 = TFLITE_GPU_INFERENCE_PRIORITY_AUTO;
options.inference_priority3 = TFLITE_GPU_INFERENCE_PRIORITY_AUTO;
options.experimental_flags = TFLITE_GPU_EXPERIMENTAL_FLAGS_ENABLE_QUANT;
options.max_delegated_partitions = 1;
return options;
}

Expand Down