diff options
Diffstat (limited to 'runtime/libs/tflite/port/1.13.1/include/tflite/ext')
7 files changed, 433 insertions, 0 deletions
diff --git a/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/Abs.h b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/Abs.h new file mode 100644 index 000000000..697ba33e9 --- /dev/null +++ b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/Abs.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. 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 __NNFW_TFLITE_EXT_KERNELS_ABS_H__ +#define __NNFW_TFLITE_EXT_KERNELS_ABS_H__ + +#include "tensorflow/lite/context.h" + +namespace nnfw +{ +namespace tflite +{ +namespace custom +{ +namespace Abs +{ + +void *InitAbs(TfLiteContext *context, const char *buffer, size_t length); +void FreeAbs(TfLiteContext *context, void *buffer); +TfLiteStatus PrepareAbs(TfLiteContext *context, TfLiteNode *node); +TfLiteStatus EvalAbs(TfLiteContext *context, TfLiteNode *node); + +} // namespace Abs +} // namespace custom +} // namespace tflite +} // namespace nnfw + +#endif // __NNFW_TFLITE_EXT_KERNELS_ABS_H__ diff --git a/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/CustomOps.h b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/CustomOps.h new file mode 100644 index 000000000..3370db778 --- /dev/null +++ b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/CustomOps.h @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. 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. + */ + +/** + * @file CustomOps.h + * @brief This file contains registration of custom operands + * @ingroup COM_AI_RUNTIME + */ + +#ifndef __NNFW_TFLITE_EXT_KERNELS_CUSTOM_OP_H__ +#define __NNFW_TFLITE_EXT_KERNELS_CUSTOM_OP_H__ + +#include "tensorflow/lite/context.h" +#include "tflite/ext/kernels/TensorFlowMax.h" +#include "tflite/ext/kernels/SquaredDifference.h" +#include "tflite/ext/kernels/TensorFlowSum.h" +#include "tflite/ext/kernels/Abs.h" + +namespace nnfw +{ +namespace tflite +{ +namespace custom +{ + +#define REGISTER_FUNCTION(Name) \ + TfLiteRegistration *Register_##Name(void) \ + { \ + static TfLiteRegistration r = {}; \ + r.init = Name::Init##Name; \ + r.free = Name::Free##Name; \ + r.prepare = Name::Prepare##Name; \ + r.invoke = Name::Eval##Name; \ + r.custom_name = #Name; \ + return &r; \ + } + +REGISTER_FUNCTION(TensorFlowMax) +REGISTER_FUNCTION(SquaredDifference) +REGISTER_FUNCTION(TensorFlowSum) +REGISTER_FUNCTION(Abs) + +#undef REGISTER_FUNCTION + +} // namespace custom +} // namespace tflite +} // namespace nnfw + +#endif // __NNFW_TFLITE_EXT_KERNELS_CUSTOM_OP_H__ diff --git a/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/SquaredDifference.h b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/SquaredDifference.h new file mode 100644 index 000000000..5512ead78 --- /dev/null +++ b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/SquaredDifference.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. 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. + */ + +/** + * @file SquaredDifference.h + * @brief This file contains SquaredDifference namespace and SquaredDifference function + * definitions + * @ingroup COM_AI_RUNTIME + */ + +#ifndef __NNFW_TFLITE_EXT_KERNELS_SQUARED_DIFFERENCE_H__ +#define __NNFW_TFLITE_EXT_KERNELS_SQUARED_DIFFERENCE_H__ + +#include "tensorflow/lite/context.h" + +namespace nnfw +{ +namespace tflite +{ +namespace custom +{ +namespace SquaredDifference +{ + +/** + * @brief Initialize SquaredDifference operand using the contents of buffer + * @param[in] context The TfLite context + * @param[in] buffer The buffer with contents + * @param[in] length The buffer length + * @return The void pointer for user data + */ +void *InitSquaredDifference(TfLiteContext *context, const char *buffer, size_t length); + +/** + * @brief Release any memory it might have allocated via 'InitSquaredDifference' + * @param[in] context The TfLite context + * @param[in] buffer The buffer with contents + * @return N/A + */ +void FreeSquaredDifference(TfLiteContext *context, void *buffer); + +/** + * @brief Prepare the SquaredDifference operand for execution + * @param[in] context The TfLite context + * @param[in] node The operand node + * @return The TfLite status + */ +TfLiteStatus PrepareSquaredDifference(TfLiteContext *context, TfLiteNode *node); + +/** + * @brief Evaluation the SquaredDifference operand for execution + * @param[in] context The TfLite context + * @param[in] node The operand node + * @return The TfLite status + */ +TfLiteStatus EvalSquaredDifference(TfLiteContext *context, TfLiteNode *node); + +} // namespace SquaredDifference +} // namespace custom +} // namespace tflite +} // namespace nnfw + +#endif // __NNFW_TFLITE_EXT_KERNELS_SQUARED_DIFFERENCE_H__ diff --git a/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/TensorFlowMax.h b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/TensorFlowMax.h new file mode 100644 index 000000000..d573308ed --- /dev/null +++ b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/TensorFlowMax.h @@ -0,0 +1,75 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. 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. + */ + +/** + * @file TensorFlowMax.h + * @brief This file contains TensorFlowMax namespace and TensorFlowMax function definitions + * @ingroup COM_AI_RUNTIME + */ + +#ifndef __NNFW_TFLITE_EXT_KERNELS_TENSORFLOW_MAX_H__ +#define __NNFW_TFLITE_EXT_KERNELS_TENSORFLOW_MAX_H__ + +#include "tensorflow/lite/context.h" + +namespace nnfw +{ +namespace tflite +{ +namespace custom +{ +namespace TensorFlowMax +{ + +/** + * @brief Initialize TensorFlowMax operand using the contents of buffer + * @param[in] context The TfLite context + * @param[in] buffer The buffer with contents + * @param[in] length The buffer length + * @return The void pointer for user data + */ +void *InitTensorFlowMax(TfLiteContext *context, const char *buffer, size_t length); + +/** + * @brief Release any memory it might have allocated via 'InitTensorFlowMax' + * @param[in] context The TfLite context + * @param[in] buffer The buffer with contents + * @return N/A + */ +void FreeTensorFlowMax(TfLiteContext *context, void *buffer); + +/** + * @brief Prepare the TensorFlowMax operand for execution + * @param[in] context The TfLite context + * @param[in] node The operand node + * @return The TfLite status + */ +TfLiteStatus PrepareTensorFlowMax(TfLiteContext *context, TfLiteNode *node); + +/** + * @brief Evaluation the TensorFlowMax operand for execution + * @param[in] context The TfLite context + * @param[in] node The operand node + * @return The TfLite status + */ +TfLiteStatus EvalTensorFlowMax(TfLiteContext *context, TfLiteNode *node); + +} // namespace TensorFlowMax +} // namespace custom +} // namespace tflite +} // namespace nnfw + +#endif // __NNFW_TFLITE_EXT_KERNELS_TENSORFLOW_MAX_H__ diff --git a/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/TensorFlowSum.h b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/TensorFlowSum.h new file mode 100644 index 000000000..29455aac5 --- /dev/null +++ b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/TensorFlowSum.h @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd. 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 __NNFW_TFLITE_EXT_KERNELS_TENSORFLOW_SUM_H__ +#define __NNFW_TFLITE_EXT_KERNELS_TENSORFLOW_SUM_H__ + +#include "tensorflow/lite/context.h" + +namespace nnfw +{ +namespace tflite +{ +namespace custom +{ +namespace TensorFlowSum +{ + +void *InitTensorFlowSum(TfLiteContext *context, const char *buffer, size_t length); +void FreeTensorFlowSum(TfLiteContext *context, void *buffer); +TfLiteStatus PrepareTensorFlowSum(TfLiteContext *context, TfLiteNode *node); +TfLiteStatus EvalTensorFlowSum(TfLiteContext *context, TfLiteNode *node); + +} // namespace TensorFlowSum +} // namespace custom +} // namespace tflite +} // namespace nnfw + +#endif // __NNFW_TFLITE_EXT_KERNELS_TENSORFLOW_SUM_H__ diff --git a/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/register.h b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/register.h new file mode 100644 index 000000000..6e32b35fb --- /dev/null +++ b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/kernels/register.h @@ -0,0 +1,46 @@ +/* Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + Copyright 2017 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. +==============================================================================*/ + +// NOTE To minimize diff with upstream tensorflow, disable clang-format +// clang-format off + +// NOTE This header is derived from the following file (in TensorFlow v1.13.1) +// 'externals/tensorflow/tensorflow/lite/kernels/register.h' +#ifndef __NNFW_TFLITE_EXT_KERNELS_REGISTER_H__ +#define __NNFW_TFLITE_EXT_KERNELS_REGISTER_H__ + +#include <unordered_map> +#include "tensorflow/lite/context.h" +#include "tensorflow/lite/model.h" + +namespace nnfw { +namespace tflite { + +class BuiltinOpResolver : public ::tflite::MutableOpResolver { + public: + BuiltinOpResolver(); + + const TfLiteRegistration* FindOp(::tflite::BuiltinOperator op, + int version) const override; + const TfLiteRegistration* FindOp(const char* op, int version) const override; +}; + +} // namespace tflite +} // namespace nnfw + +#endif // __NNFW_TFLITE_EXT_KERNELS_REGISTER_H__ + +// clang-format on diff --git a/runtime/libs/tflite/port/1.13.1/include/tflite/ext/nnapi_delegate.h b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/nnapi_delegate.h new file mode 100644 index 000000000..231baa25c --- /dev/null +++ b/runtime/libs/tflite/port/1.13.1/include/tflite/ext/nnapi_delegate.h @@ -0,0 +1,92 @@ +/* Copyright (c) 2018 Samsung Electronics Co., Ltd. All Rights Reserved + Copyright 2017 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. +==============================================================================*/ + +// NOTE To minimize diff with upstream tensorflow, disable clang-format +// clang-format off + +// NOTE This header is derived from the following file (in TensorFlow v1.13.1) +// 'externals/tensorflow/tensorflow/lite/nnapi_delegate.h' +#ifndef __NNFW_TFLITE_EXT_NNAPI_DELEGATE_H__ +#define __NNFW_TFLITE_EXT_NNAPI_DELEGATE_H__ + +#include "tensorflow/lite/allocation.h" +#include "tensorflow/lite/c/c_api_internal.h" +#include "tensorflow/lite/core/api/error_reporter.h" +#include "tensorflow/lite/core/subgraph.h" +#include "tensorflow/lite/interpreter.h" + +struct ANeuralNetworksModel; +struct ANeuralNetworksMemory; +struct ANeuralNetworksCompilation; + +namespace nnfw { +namespace tflite { + +class NNAPIAllocation : public ::tflite::MMAPAllocation { + public: + NNAPIAllocation(const char* filename, ::tflite::ErrorReporter* error_reporter); + ~NNAPIAllocation(); + + size_t offset(const void* ptr) const { + auto signed_offset = reinterpret_cast<const uint8_t*>(ptr) - + reinterpret_cast<const uint8_t*>(mmapped_buffer_); + + return static_cast<size_t>(signed_offset); + } + + ANeuralNetworksMemory* memory() const { return handle_; } + bool valid() const override { return handle_ != nullptr; } + + private: + mutable ANeuralNetworksMemory* handle_ = nullptr; +}; + +class NNAPIDelegate { + public: + ~NNAPIDelegate(); + + // Convert a tflite graph to NNAPI + TfLiteStatus BuildGraph(::tflite::Subgraph* subgraph); + + // Run + TfLiteStatus Invoke(::tflite::Subgraph* subgraph); + + // Whether the current platform supports NNAPI delegation. + static bool IsSupported(); + + private: + // The NN API model handle + ANeuralNetworksModel* nn_model_ = nullptr; + // The NN API compilation handle + ANeuralNetworksCompilation* nn_compiled_model_ = nullptr; + // Model status + TfLiteStatus model_status_ = kTfLiteOk; + + // List of state tensors for LSTM, RNN, SVDF. + // NN API does not allow ops to maintain states across multiple + // invocations. We need to manually create state input tensors from + // corresponding state output tensors of TFLite operations, and map them + // correctly. + std::vector<int> model_states_inputs_; // holds NNAPI operand ids + std::vector<int> model_states_outputs_; // holds TFLite tensor ids +}; + +} // namespace tflite +} // namespace nnfw + +#endif // __NNFW_TFLITE_EXT_NNAPI_DELEGATE_H__ + +// clang-format on |