diff --git a/codegen/runtime/BUILD b/codegen/runtime/BUILD index a1cb6c160bf..d23cb7078eb 100644 --- a/codegen/runtime/BUILD +++ b/codegen/runtime/BUILD @@ -14,5 +14,6 @@ cc_library( "//tensorflow/lite/micro:micro_context", "//tensorflow/lite/micro:micro_graph", "//tensorflow/lite/micro:micro_log", + "//tensorflow/lite/micro:span", ], ) diff --git a/codegen/runtime/micro_codegen_context.h b/codegen/runtime/micro_codegen_context.h index ca01a63bce4..3693ad27118 100644 --- a/codegen/runtime/micro_codegen_context.h +++ b/codegen/runtime/micro_codegen_context.h @@ -19,25 +19,10 @@ limitations under the License. #include "tensorflow/lite/c/common.h" #include "tensorflow/lite/micro/micro_context.h" #include "tensorflow/lite/micro/micro_graph.h" +#include "tensorflow/lite/micro/span.h" namespace tflite { -// A poor man's std::span, we should consider using the Pigweed span instead. -template -class Span { - public: - constexpr Span(T* data, size_t size) noexcept : data_(data), size_(size) {} - - constexpr T& operator[](size_t idx) const noexcept { return *(data_ + idx); } - - constexpr T* data() const noexcept { return data_; } - constexpr size_t size() const noexcept { return size_; } - - private: - T* data_; - size_t size_; -}; - struct Subgraph { Span inputs; Span outputs; diff --git a/tensorflow/lite/micro/BUILD b/tensorflow/lite/micro/BUILD index 60ace250631..527b85a8ea8 100644 --- a/tensorflow/lite/micro/BUILD +++ b/tensorflow/lite/micro/BUILD @@ -401,6 +401,12 @@ cc_library( ], ) +cc_library( + name = "span", + hdrs = ["span.h"], + copts = micro_copts(), +) + cc_library( name = "system_setup", srcs = [ diff --git a/tensorflow/lite/micro/span.h b/tensorflow/lite/micro/span.h new file mode 100644 index 00000000000..eeb4c0b6ac5 --- /dev/null +++ b/tensorflow/lite/micro/span.h @@ -0,0 +1,41 @@ +/* Copyright 2024 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_MICRO_SPAN_H_ +#define TENSORFLOW_LITE_MICRO_SPAN_H_ + +#include + +namespace tflite { + +// A poor man's std::span, we should consider using the Pigweed span instead. +template +class Span { + public: + constexpr Span(T* data, size_t size) noexcept : data_(data), size_(size) {} + + constexpr T& operator[](size_t idx) const noexcept { return *(data_ + idx); } + + constexpr T* data() const noexcept { return data_; } + constexpr size_t size() const noexcept { return size_; } + + private: + T* data_; + size_t size_; +}; + +} // end namespace tflite + +#endif // TENSORFLOW_LITE_MICRO_SPAN_H_