chore: import upstream snapshot with attribution
cffconvert / validate (push) Has been skipped
License Check / license-check (push) Failing after 2s

This commit is contained in:
wehub-resource-sync
2026-07-13 12:14:16 +08:00
commit 8a852e4b4e
36502 changed files with 9277225 additions and 0 deletions
+41
View File
@@ -0,0 +1,41 @@
load("@rules_cc//cc:cc_test.bzl", "cc_test")
# Description:
#
# This package contains shim library targets for the Async C package.
load("//tensorflow/lite/core/shims:cc_library_with_tflite.bzl", "cc_library_with_tflite")
package(
# copybara:uncomment default_applicable_licenses = ["//tensorflow:LICENSE"],
default_visibility = [
"//visibility:private",
],
licenses = ["notice"],
)
cc_library_with_tflite(
name = "backend_async_kernel_interface",
srcs = ["backend_async_kernel_interface.cc"],
hdrs = ["backend_async_kernel_interface.h"],
tflite_deps = [
"//tensorflow/lite/async/c:async_kernel",
"//tensorflow/lite/async/c:types",
"//tensorflow/lite/c:c_api_types",
"//tensorflow/lite/c:common",
],
visibility = ["//visibility:public"],
)
cc_test(
name = "backend_async_kernel_interface_test",
srcs = ["backend_async_kernel_interface_test.cc"],
deps = [
":backend_async_kernel_interface",
"//tensorflow/lite/async/c:types",
"//tensorflow/lite/c:c_api_types",
"//tensorflow/lite/c:common",
"//tensorflow/lite/core/async:async_kernel_internal",
"//tensorflow/lite/core/async/testing:mock_async_kernel",
"@com_google_googletest//:gtest_main",
],
)
@@ -0,0 +1,198 @@
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/lite/async/backend_async_kernel_interface.h"
#include <cstddef>
#include <vector>
#include "tensorflow/lite/async/c/async_kernel.h"
#include "tensorflow/lite/async/c/types.h"
namespace tflite {
namespace delegates {
namespace internal {
TfLiteStatus RegisterBuffer(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context, TfLiteIoType io_type,
const TfLiteBackendBuffer* buffer,
const TfLiteAttributeMap* attrs,
TfLiteBufferHandle handle) {
return reinterpret_cast<BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->RegisterBuffer(context, io_type, buffer, attrs, handle);
}
// Registers a buffer slice from a previously registered memory.
// `attrs` contains the information of the memory, but also additional slice
// information.
TfLiteStatus RegisterBufferSlice(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context,
TfLiteBufferHandle buffer,
const TfLiteAttributeMap* attrs,
TfLiteBufferHandle handle) {
return reinterpret_cast<BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->RegisterBufferSlice(context, buffer, attrs, handle);
}
// Unregisters a buffer or a buffer slice.
TfLiteStatus UnregisterBuffer(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context,
const TfLiteBufferHandle handle) {
return reinterpret_cast<BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->UnregisterBuffer(context, handle);
}
// Reconciliations
// ===================
// Inspects the buffer / sync implementation types supported by the backend.
void SupportedBufferTypes(const TfLiteAsyncKernel* async_kernel,
TfLiteIoType io_type, const char* const** types,
size_t* n_types) {
if (types == nullptr || n_types == nullptr) return;
const auto& buf_types = reinterpret_cast<const BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->SupportedBufferTypes(io_type);
*types = buf_types.data();
*n_types = buf_types.size();
}
void SupportedSynchronizations(const TfLiteAsyncKernel* async_kernel,
TfLiteIoType io_type, const char* const** types,
size_t* n_types) {
if (types == nullptr || n_types == nullptr) return;
const auto& sync_types = reinterpret_cast<const BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->SupportedSynchronizations(io_type);
*types = sync_types.data();
*n_types = sync_types.size();
}
// Reconciles buffer or sync attributes for tensor at tensor_index.
// Fills `merged` with reconciled attributes.
// If `conflict` is provided, conflicting attributes will be provided there.
// Returns true if there's no conflict.
bool ReconcileRestrictions(const TfLiteAsyncKernel* async_kernel,
const TfLiteOpaqueContext* context,
const TfLiteOpaqueNode* node, int tensor_index,
const TfLiteAttributeMap* user_provided_attributes,
TfLiteAttributeMap* merged,
TfLiteAttributeMap* conflict) {
return reinterpret_cast<const BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->ReconcileRestrictions(context, node, tensor_index,
user_provided_attributes, merged, conflict);
}
// Sets the input / output buffer / sync attributes.
// Backend kernel will check the input attributes covers all the requirements.
// A typical workflow is for callers call Reconcile*Restrictions method
// above to have a merged attribute list, check all restrictions are met
// and set input / output attribute here.
// Returns TfLiteOk if provided `attrs` covers all requirements.
TfLiteStatus SetAttributes(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context, TfLiteOpaqueNode* node,
int tensor_index, const TfLiteAttributeMap* attrs) {
return reinterpret_cast<BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->SetAttributes(context, node, tensor_index, attrs);
}
// Prepares the kernel using the information from Set[In|Out]putAttributes
// call above.
TfLiteStatus Prepare(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context, TfLiteOpaqueNode* node) {
return reinterpret_cast<BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->Prepare(context, node);
}
// Execution methods
// =============================
// Schedules an execution with the information provided in task.
// The application is responsible for filling out buffer and sync mappings
// to tensors.
// Backend will set the sync ptr for related tensors if requested.
// i.e. SetOutputAttributes has sync implementation requested, and
// the TfLiteSynchronization is not null for the tensor in `task`.
// Returns TfLiteOk if the execution is successfully scheduled.
TfLiteStatus Eval(TfLiteAsyncKernel* async_kernel, TfLiteOpaqueContext* context,
TfLiteOpaqueNode* node, TfLiteExecutionTask* task) {
return reinterpret_cast<BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->Eval(context, node, task);
}
// Waits on the execution scheduled using the task to finish.
TfLiteStatus Wait(TfLiteAsyncKernel* async_kernel, TfLiteOpaqueContext* context,
TfLiteExecutionTask* task) {
return reinterpret_cast<BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->Wait(context, task);
}
// Finishes the task and clean up allocated resources for the task.
TfLiteStatus Finish(TfLiteAsyncKernel* async_kernel,
TfLiteOpaqueContext* context, TfLiteExecutionTask* task) {
return reinterpret_cast<BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->Finish(context, task);
}
TfLiteStatus SetBufferAttributes(TfLiteAsyncKernel* async_kernel,
const TfLiteBackendBuffer* buffer,
const TfLiteAttributeMap* attrs) {
return reinterpret_cast<BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->SetBufferAttributes(buffer, attrs);
}
TfLiteStatus GetBufferAttributes(TfLiteAsyncKernel* async_kernel,
const TfLiteBackendBuffer* buffer,
TfLiteAttributeMap* attrs) {
return reinterpret_cast<BackendAsyncKernelInterface*>(
TfLiteAsyncKernelGetKernelData(async_kernel))
->GetBufferAttributes(buffer, attrs);
}
} // namespace internal
BackendAsyncKernelInterface::BackendAsyncKernelInterface() {
kernel_ = TfLiteAsyncKernelCreate(this);
TfLiteAsyncKernelSetRegisterBuffer(kernel_, internal::RegisterBuffer);
TfLiteAsyncKernelSetRegisterBufferSlice(kernel_,
internal::RegisterBufferSlice);
TfLiteAsyncKernelSetUnregisterBuffer(kernel_, internal::UnregisterBuffer);
TfLiteAsyncKernelSetSupportedBufferTypes(kernel_,
internal::SupportedBufferTypes);
TfLiteAsyncKernelSetSupportedSynchronizations(
kernel_, internal::SupportedSynchronizations);
TfLiteAsyncKernelSetReconcileRestrictions(kernel_,
internal::ReconcileRestrictions);
TfLiteAsyncKernelSetSetAttributes(kernel_, internal::SetAttributes);
TfLiteAsyncKernelSetSetBufferAttributes(kernel_,
internal::SetBufferAttributes);
TfLiteAsyncKernelSetGetBufferAttributes(kernel_,
internal::GetBufferAttributes);
TfLiteAsyncKernelSetPrepare(kernel_, internal::Prepare);
TfLiteAsyncKernelSetEval(kernel_, internal::Eval);
TfLiteAsyncKernelSetWait(kernel_, internal::Wait);
TfLiteAsyncKernelSetFinish(kernel_, internal::Finish);
}
} // namespace delegates
} // namespace tflite
@@ -0,0 +1,214 @@
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_ASYNC_BACKEND_ASYNC_KERNEL_INTERFACE_H_
#define TENSORFLOW_LITE_ASYNC_BACKEND_ASYNC_KERNEL_INTERFACE_H_
#include <vector>
#include "tensorflow/lite/async/c/async_kernel.h"
#include "tensorflow/lite/async/c/types.h"
#include "tensorflow/lite/c/c_api_types.h"
#include "tensorflow/lite/c/common.h"
namespace tflite {
namespace delegates {
// A C++ wrapper around TfLiteAsyncKernel C API that delegate developers
// can use to add support for asynchronous execution.
// The implementation of `BackendAsyncKernelInterface` must be thread safe.
class BackendAsyncKernelInterface {
public:
BackendAsyncKernelInterface();
virtual ~BackendAsyncKernelInterface() { TfLiteAsyncKernelDelete(kernel_); }
// Returns the TfLiteAsyncKernel instance.
// kernel_ will be filled with the implementation of the class.
virtual TfLiteAsyncKernel* kernel() { return kernel_; }
// The following methods should be implemented to support buffer interop
// and asynchronous execution.
// Buffer operations
// ======================
// Registers the TfLiteBackendBuffer to `handle`.
// `TfLiteBackendBuffer` is a wrapper around a platform-specific buffer
// object (e.g. AHardwareBuffer).
// `buffer` and `attrs` lifespan is not guaranteed after the function call.
// kernels should read the stored attributes instead of caching the
// attribute map.
// `io_type` specifies whether this buffer is used as an input buffer
// or an output buffer. If a buffer is both used as input and output,
// specify it as output. Not null.
// `attrs` describes the attributes of the buffer. It's guaranteed to be
// of kTfLiteAttrMapTypeBuffer type and not null.
// `handle` is the buffer handle assigned by TfLite runtime to recognize
// this piece of buffer.
// In `attrs`, the application must provide the type of the buffer.
// If additional attributes (e.g. padding, size) are provided, the backend
// is responsible for validating those attributes to be compatible.
// The backend will not own the actual buffer wrapped in `buffer`, but the
// backend can choose to increase the ref count if underlying implementation
// supports that.
virtual TfLiteStatus RegisterBuffer(TfLiteOpaqueContext* context,
TfLiteIoType io_type,
const TfLiteBackendBuffer* buffer,
const TfLiteAttributeMap* attrs,
TfLiteBufferHandle handle) = 0;
// Registers a buffer slice from a previously registered memory.
// `buffer` is the handle of the buffer pool previously registered.
// `attrs` contains the information of the buffer slice.
// `handle` is the buffer handle assigned by TfLite runtime to recognize
// this piece of buffer.
// NOTE: The backend is responsible to validate the slicing is "valid":
// * The slicing is not nested from another slice. (i.e. the `buffer_pool` is
// a handle returned by `RegisterBuffer`.)
// * The attributes of the slice (e.g. size, offset) is of valid values
// from the buffer pool.
// If the `handle` is not recognized, returns error.
virtual TfLiteStatus RegisterBufferSlice(TfLiteOpaqueContext* context,
TfLiteBufferHandle buffer_pool,
const TfLiteAttributeMap* attrs,
TfLiteBufferHandle handle) = 0;
// Unregisters a buffer or a buffer slice.
// `handle` is a buffer handle previously assigned via register_* calls.
// If the `handle` is not recognized, returns error.
// Unregistering the buffer does not mean deallocating the buffer. However
// the backend need to reduce the ref-count if ref counting is performed
// during `Register*` calls.
virtual TfLiteStatus UnregisterBuffer(TfLiteOpaqueContext* context,
TfLiteBufferHandle handle) = 0;
// Reconciliations
// ===================
// Inspects the buffer object types supported by the backend.
// `io_type` specify whether the call returns supported input or output
// buffer.
virtual const std::vector<const char*>& SupportedBufferTypes(
TfLiteIoType io_type) const = 0;
// Inspects the sync object types supported by the backend.
// `io_type` specify whether the call returns supported input or output
// sync object.
virtual const std::vector<const char*>& SupportedSynchronizations(
TfLiteIoType io_type) const = 0;
// Reconciles buffer or sync attributes for tensor at tensor_index.
// Fills `merged` with reconciled attributes.
// If `conflict` is provided, conflicting attributes will be provided there.
// If the type of the `user_provided_attributes` is not recognizable, returns
// error.
// If any of the attribute in the `user_provided_attributes` is not
// recognizable skip this attribute.
// Returns true if the attribute map type is recognizable and there's no
// conflicting attribute.
virtual bool ReconcileRestrictions(
const TfLiteOpaqueContext* context, const TfLiteOpaqueNode* node,
int tensor_index, const TfLiteAttributeMap* user_provided_attributes,
TfLiteAttributeMap* merged, TfLiteAttributeMap* conflict) const = 0;
// Sets the input / output buffer / sync attributes.
// Backend kernel will check the input attributes covers all the requirements.
// A typical workflow is for callers call Reconcile*Restrictions method
// above to have a merged attribute list, check all restrictions are met
// and set input / output attribute here.
// Returns TfLiteOk if provided `attrs` covers all requirements.
virtual TfLiteStatus SetAttributes(TfLiteOpaqueContext* context,
TfLiteOpaqueNode* node, int tensor_index,
const TfLiteAttributeMap* attrs) = 0;
// Set buffer's attributes. Backend will check if the buffer has been
// registered. And return TfLiteOk if the `attrs` for the `buffer` could be
// set in the corresponding async kernel.
virtual TfLiteStatus SetBufferAttributes(const TfLiteBackendBuffer* buffer,
const TfLiteAttributeMap* attrs) = 0;
// Get buffer's attributes. Backend will check if the buffer has been
// registered. And return TfLiteOk if provided `attrs` for the `buffer` could
// be found in the registration pool in corresponding async kernel. If `attrs`
// is a non-empty map, it will be overwritten by the attributes of the
// `buffer`.
virtual TfLiteStatus GetBufferAttributes(const TfLiteBackendBuffer* buffer,
TfLiteAttributeMap* attrs) = 0;
// Prepares the kernel using the information from Set[In|Out]putAttributes
// call above.
virtual TfLiteStatus Prepare(TfLiteOpaqueContext* context,
TfLiteOpaqueNode* node) = 0;
// Execution methods
// =============================
// Schedules an execution with the information provided in task.
// The application is responsible for filling out buffer and sync mappings
// to tensors.
// Backend will set the sync ptr for related tensors if requested.
// i.e. SetOutputAttributes has sync implementation requested, and
// the TfLiteSynchronization is not null for the tensor in `task`.
//
// TfLite runtime guarantees that the task is in ready state (i.e. no
// un-ended execution for this task).
//
// Input synchronizations:
// If the synchronization of a input tensor is `kTfLiteSyncTypeNoSyncObj`
// type or it's nullptr, it means the data is ready during Eval call.
// If not, data will be available when the synchronization signals and the
// backend is responsible for closing the underlying synchronization.
// The backend is responsible for dedupping the input sync.
//
// Output synchronizations:
// If the synchronization type is `kTfLiteSyncTypeNoSyncObj` or is nullptr,
// the backend does not need to provide synchronization objects to the user.
// Otherwise, the backend need to provide the sync according to the sync type
// provided. The underlying sync object will be closed by the app (or
// downstream components).
// If there are multiple non-nullptr kTfLiteSynchronization provided for
// different output tensors, the backend is responsible for duplicating the
// synchronization.
// TODO(b/191883048): What if the sync fence is not dup-able?
//
// Returns kTfLiteOk if the execution is successfully scheduled.
virtual TfLiteStatus Eval(TfLiteOpaqueContext* context,
TfLiteOpaqueNode* node,
TfLiteExecutionTask* task) = 0;
// Waits on the execution scheduled using the task to finish.
// TfLite runtime guarantees that the task has an un-ended execution.
//
// Callers should be able to call `Wait` on the same task from multiple
// threads, and those calls should return the same status (i.e. if the backend
// failed to successfully wait on the task, all `Wait` to the task should
// return the same error before a new invocation is scheduled). Returns
// kTfLiteOk if the task is finished (w/ or w/o blocking).
virtual TfLiteStatus Wait(TfLiteOpaqueContext* context,
TfLiteExecutionTask* task) = 0;
// Finishes the task and clean up allocated resources for the task.
// May block if there's pending executions.
// This function will be called once and only once for individual task.
// Returns kTfLiteOk if there's no error. The backend is responsible to
// clean up task resources regardless there's error or not.
virtual TfLiteStatus Finish(TfLiteOpaqueContext* context,
TfLiteExecutionTask* task) = 0;
protected:
TfLiteAsyncKernel* kernel_ = nullptr;
};
} // namespace delegates
} // namespace tflite
#endif // TENSORFLOW_LITE_ASYNC_BACKEND_ASYNC_KERNEL_INTERFACE_H_
@@ -0,0 +1,63 @@
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#include "tensorflow/lite/async/backend_async_kernel_interface.h"
#include <gmock/gmock.h>
#include <gtest/gtest.h>
#include "tensorflow/lite/async/c/types.h"
#include "tensorflow/lite/c/c_api_types.h"
#include "tensorflow/lite/c/common.h"
#include "tensorflow/lite/core/async/async_kernel_internal.h"
#include "tensorflow/lite/core/async/testing/mock_async_kernel.h"
using ::testing::_;
namespace tflite::delegates {
namespace {
TEST(BackendAsyncKernelInterfaceTest, BasicTest) {
testing::StrictMock<async::testing::MockAsyncKernel> kernel;
EXPECT_CALL(kernel, RegisterBuffer(_, _, _, _, _));
EXPECT_CALL(kernel, RegisterBufferSlice(_, _, _, _));
EXPECT_CALL(kernel, UnregisterBuffer(_, _));
EXPECT_CALL(kernel, ReconcileRestrictions(_, _, _, _, _, _));
EXPECT_CALL(kernel, SetAttributes(_, _, _, _));
EXPECT_CALL(kernel, SetBufferAttributes(_, _));
EXPECT_CALL(kernel, GetBufferAttributes(_, _));
EXPECT_CALL(kernel, Prepare(_, _));
EXPECT_CALL(kernel, Eval(_, _, _));
EXPECT_CALL(kernel, Wait(_, _));
EXPECT_CALL(kernel, Finish(_, _));
auto* tflite_kernel = kernel.kernel();
tflite_kernel->register_buffer(tflite_kernel, nullptr, kTfLiteIoTypeInput,
nullptr, nullptr, 0);
tflite_kernel->register_buffer_slice(tflite_kernel, nullptr, 0, nullptr, 0);
tflite_kernel->unregister_buffer(tflite_kernel, nullptr, 0);
tflite_kernel->reconcile_restrictions(tflite_kernel, nullptr, nullptr, 0,
nullptr, nullptr, nullptr);
tflite_kernel->set_attributes(tflite_kernel, nullptr, nullptr, 0, nullptr);
tflite_kernel->set_buffer_attributes(tflite_kernel, nullptr, nullptr);
tflite_kernel->get_buffer_attributes(tflite_kernel, nullptr, nullptr);
tflite_kernel->prepare(tflite_kernel, nullptr, nullptr);
tflite_kernel->eval(tflite_kernel, nullptr, nullptr, nullptr);
tflite_kernel->wait(tflite_kernel, nullptr, nullptr);
tflite_kernel->finish(tflite_kernel, nullptr, nullptr);
}
} // namespace
} // namespace tflite::delegates
+45
View File
@@ -0,0 +1,45 @@
# This package contains shim library targets for the Async C package,
# that forward to the TF Lite C and C++ API targets.
load("//tensorflow/lite:build_def.bzl", "tflite_copts", "tflite_copts_warnings")
load("//tensorflow/lite/core/shims:cc_library_with_tflite.bzl", "cc_library_with_tflite")
package(
# copybara:uncomment default_applicable_licenses = ["//tensorflow:LICENSE"],
default_visibility = [
"//visibility:private",
],
licenses = ["notice"],
)
cc_library_with_tflite(
name = "task",
hdrs = ["task.h"],
copts = tflite_copts() + tflite_copts_warnings(),
visibility = ["//visibility:public"],
deps = ["//tensorflow/lite/core/async/c:task"],
)
cc_library_with_tflite(
name = "types",
hdrs = ["types.h"],
copts = tflite_copts() + tflite_copts_warnings(),
visibility = ["//visibility:public"],
deps = ["//tensorflow/lite/core/async/c:types"],
)
cc_library_with_tflite(
name = "async_signature_runner",
hdrs = ["async_signature_runner.h"],
copts = tflite_copts() + tflite_copts_warnings(),
visibility = ["//visibility:public"],
deps = ["//tensorflow/lite/core/async/c:async_signature_runner"],
)
cc_library_with_tflite(
name = "async_kernel",
hdrs = ["async_kernel.h"],
copts = tflite_copts() + tflite_copts_warnings(),
visibility = ["//visibility:public"],
deps = ["//tensorflow/lite/core/async/c:async_kernel"],
)
+20
View File
@@ -0,0 +1,20 @@
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_ASYNC_C_ASYNC_KERNEL_H_
#define TENSORFLOW_LITE_ASYNC_C_ASYNC_KERNEL_H_
/// For documentation, see
/// third_party/tensorflow/lite/core/async/c/async_kernel.h.
#include "tensorflow/lite/core/async/c/async_kernel.h" // IWYU pragma: export
#endif // TENSORFLOW_LITE_ASYNC_C_ASYNC_KERNEL_H_
@@ -0,0 +1,20 @@
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_ASYNC_C_ASYNC_SIGNATURE_RUNNER_H_
#define TENSORFLOW_LITE_ASYNC_C_ASYNC_SIGNATURE_RUNNER_H_
/// For documentation, see
/// third_party/tensorflow/lite/core/async/c/async_signature_runner.h.
#include "tensorflow/lite/core/async/c/async_signature_runner.h" // IWYU pragma: export
#endif // TENSORFLOW_LITE_ASYNC_C_ASYNC_SIGNATURE_RUNNER_H_
+21
View File
@@ -0,0 +1,21 @@
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_ASYNC_C_TASK_H_
#define TENSORFLOW_LITE_ASYNC_C_TASK_H_
/// For documentation, see
/// third_party/tensorflow/lite/core/async/c/task.h.
#include "tensorflow/lite/core/async/c/task.h" // IWYU pragma: export
#endif // TENSORFLOW_LITE_ASYNC_C_TASK_H_
+20
View File
@@ -0,0 +1,20 @@
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_ASYNC_C_TYPES_H_
#define TENSORFLOW_LITE_ASYNC_C_TYPES_H_
/// For documentation, see
/// tensorflow/lite/core/async/c/types.h.
#include "tensorflow/lite/core/async/c/types.h" // IWYU pragma: export
#endif // TENSORFLOW_LITE_ASYNC_C_TYPES_H_
+36
View File
@@ -0,0 +1,36 @@
# This package contains shim library targets for the Async interop package,
# that forward to the TF Lite C and C++ API targets.
load("//tensorflow/lite:build_def.bzl", "tflite_copts", "tflite_copts_warnings")
cc_library(
name = "attribute_map",
hdrs = ["attribute_map.h"],
copts = tflite_copts() + tflite_copts_warnings(),
visibility = [
"//visibility:public",
],
deps = ["//tensorflow/lite/core/async/interop/c:attribute_map"],
)
cc_library(
name = "types",
hdrs = ["types.h"],
copts = tflite_copts() + tflite_copts_warnings(),
visibility = [
"//visibility:public",
],
deps = ["//tensorflow/lite/core/async/interop/c:types"],
)
cc_library(
name = "constants",
hdrs = ["constants.h"],
copts = tflite_copts() + tflite_copts_warnings(),
visibility = [
"//visibility:public",
],
deps = [
"//tensorflow/lite/core/async/interop/c:constants",
],
)
@@ -0,0 +1,20 @@
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_ASYNC_INTEROP_C_ATTRIBUTE_MAP_H_
#define TENSORFLOW_LITE_ASYNC_INTEROP_C_ATTRIBUTE_MAP_H_
/// For documentation, see
/// tensorflow/lite/core/async/interop/c/attribute_map.h.
#include "tensorflow/lite/core/async/interop/c/attribute_map.h" // IWYU pragma: export
#endif // TENSORFLOW_LITE_ASYNC_INTEROP_C_ATTRIBUTE_MAP_H_
@@ -0,0 +1,20 @@
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_ASYNC_INTEROP_C_CONSTANTS_H_
#define TENSORFLOW_LITE_ASYNC_INTEROP_C_CONSTANTS_H_
/// For documentation, see
/// third_party/tensorflow/lite/core/async/interop/c/constants.h
#include "tensorflow/lite/core/async/interop/c/constants.h" // IWYU pragma: export
#endif // TENSORFLOW_LITE_ASYNC_INTEROP_C_CONSTANTS_H_
+20
View File
@@ -0,0 +1,20 @@
/* Copyright 2023 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_ASYNC_INTEROP_C_TYPES_H_
#define TENSORFLOW_LITE_ASYNC_INTEROP_C_TYPES_H_
/// For documentation, see
/// tensorflow/lite/core/async/interop/c/types.h.
#include "tensorflow/lite/core/async/interop/c/types.h" // IWYU pragma: export
#endif // TENSORFLOW_LITE_ASYNC_INTEROP_C_TYPES_H_
+24
View File
@@ -0,0 +1,24 @@
# Test utilities for TFLite async execution.
load("//tensorflow/lite/core/shims:cc_library_with_tflite.bzl", "cc_library_with_tflite")
package(
# copybara:uncomment default_applicable_licenses = ["//tensorflow:LICENSE"],
default_visibility = [
"//visibility:private",
],
licenses = ["notice"],
)
cc_library_with_tflite(
name = "mock_async_kernel",
testonly = 1,
hdrs = ["mock_async_kernel.h"],
tflite_deps = [
"//tensorflow/lite/async:backend_async_kernel_interface",
"//tensorflow/lite/async/c:types",
],
visibility = ["//visibility:public"],
deps = [
"@com_google_googletest//:gtest",
],
)
@@ -0,0 +1,84 @@
/* Copyright 2022 The TensorFlow Authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==============================================================================*/
#ifndef TENSORFLOW_LITE_ASYNC_TESTING_MOCK_ASYNC_KERNEL_H_
#define TENSORFLOW_LITE_ASYNC_TESTING_MOCK_ASYNC_KERNEL_H_
#include <vector>
#include <gmock/gmock.h>
#include "tensorflow/lite/async/backend_async_kernel_interface.h"
#include "tensorflow/lite/async/c/types.h"
namespace tflite {
namespace async {
namespace testing {
// A fully mocked out async kernel.
// Mocked TfLiteAsyncKernel can be retreived by `MockAsyncKernel::kernel()`.
class MockAsyncKernel : public delegates::BackendAsyncKernelInterface {
public:
MOCK_METHOD(TfLiteStatus, RegisterBuffer,
(TfLiteOpaqueContext*, TfLiteIoType, const TfLiteBackendBuffer*,
const TfLiteAttributeMap*, TfLiteBufferHandle),
(override));
MOCK_METHOD(TfLiteStatus, RegisterBufferSlice,
(TfLiteOpaqueContext*, TfLiteBufferHandle,
const TfLiteAttributeMap*, TfLiteBufferHandle),
(override));
MOCK_METHOD(TfLiteStatus, UnregisterBuffer,
(TfLiteOpaqueContext*, TfLiteBufferHandle), (override));
MOCK_METHOD(bool, ReconcileRestrictions,
(const TfLiteOpaqueContext*, const TfLiteOpaqueNode*, int,
const TfLiteAttributeMap*, TfLiteAttributeMap*,
TfLiteAttributeMap*),
(const, override));
MOCK_METHOD(TfLiteStatus, SetAttributes,
(TfLiteOpaqueContext*, TfLiteOpaqueNode*, int,
const TfLiteAttributeMap*),
(override));
MOCK_METHOD(TfLiteStatus, SetBufferAttributes,
(const TfLiteBackendBuffer*, const TfLiteAttributeMap*),
(override));
MOCK_METHOD(TfLiteStatus, GetBufferAttributes,
(const TfLiteBackendBuffer*, TfLiteAttributeMap*), (override));
MOCK_METHOD(TfLiteStatus, Prepare, (TfLiteOpaqueContext*, TfLiteOpaqueNode*),
(override));
MOCK_METHOD(TfLiteStatus, Eval,
(TfLiteOpaqueContext*, TfLiteOpaqueNode*, TfLiteExecutionTask*),
(override));
MOCK_METHOD(TfLiteStatus, Wait, (TfLiteOpaqueContext*, TfLiteExecutionTask*),
(override));
MOCK_METHOD(TfLiteStatus, Finish,
(TfLiteOpaqueContext*, TfLiteExecutionTask*), (override));
const std::vector<const char*>& SupportedBufferTypes(
TfLiteIoType io_type) const override {
return buffer_types_;
}
const std::vector<const char*>& SupportedSynchronizations(
TfLiteIoType io_type) const override {
return sync_types_;
}
private:
const std::vector<const char*> buffer_types_{"buffer_type"};
const std::vector<const char*> sync_types_{"sync_type"};
};
} // namespace testing
} // namespace async
} // namespace tflite
#endif // TENSORFLOW_LITE_ASYNC_TESTING_MOCK_ASYNC_KERNEL_H_