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

refactor: move tflite::Span to independent header #2638

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions codegen/runtime/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)
17 changes: 1 addition & 16 deletions codegen/runtime/micro_codegen_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
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<const size_t> inputs;
Span<const size_t> outputs;
Expand Down
6 changes: 6 additions & 0 deletions tensorflow/lite/micro/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -401,6 +401,12 @@ cc_library(
],
)

cc_library(
name = "span",
hdrs = ["span.h"],
copts = micro_copts(),
)

cc_library(
name = "system_setup",
srcs = [
Expand Down
41 changes: 41 additions & 0 deletions tensorflow/lite/micro/span.h
Original file line number Diff line number Diff line change
@@ -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 <cstddef>

namespace tflite {

// A poor man's std::span, we should consider using the Pigweed span instead.
template <typename T>
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_
Loading