Skip to content

Revert back from C/C++17 to C/C++11 #3095

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
21 changes: 0 additions & 21 deletions tensorflow/lite/micro/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -405,14 +405,6 @@ tflm_cc_library(
hdrs = ["span.h"],
)

tflm_cc_library(
name = "static_vector",
hdrs = ["static_vector.h"],
deps = [
"//tensorflow/lite/kernels:op_macros",
],
)

tflm_cc_library(
name = "system_setup",
srcs = [
Expand All @@ -434,7 +426,6 @@ tflm_cc_library(
deps = [
":debug_log",
":span",
":static_vector",
],
)

Expand Down Expand Up @@ -648,18 +639,6 @@ tflm_cc_test(
],
)

tflm_cc_test(
name = "static_vector_test",
size = "small",
srcs = [
"static_vector_test.cc",
],
deps = [
":static_vector",
"//tensorflow/lite/micro/testing:micro_test",
],
)

tflm_cc_test(
name = "hexdump_test",
size = "small",
Expand Down
4 changes: 2 additions & 2 deletions tensorflow/lite/micro/compression/metadata_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ metadata->subgraphs.push_back(std::move(subgraph0));
flatbuffers::FlatBufferBuilder builder;
auto root = Metadata::Pack(builder, metadata.get());
builder.Finish(root);
auto flatbuffer = tflite::Span<const std::byte>{
reinterpret_cast<const std::byte*>(builder.GetBufferPointer()),
auto flatbuffer = tflite::Span<const uint8_t>{
reinterpret_cast<const uint8_t*>(builder.GetBufferPointer()),
builder.GetSize()};

TF_LITE_MICRO_TEST(ReadbackEqualsWrite) {
Expand Down
15 changes: 8 additions & 7 deletions tensorflow/lite/micro/hexdump.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

#include <algorithm>
#include <cctype>
#include <cstdint>

#include "tensorflow/lite/micro/debug_log.h"
#include "tensorflow/lite/micro/static_vector.h"

namespace {

Expand Down Expand Up @@ -52,15 +52,16 @@ tflite::Span<char> output(const tflite::Span<char>& buf, const char* format,

} // end anonymous namespace

tflite::Span<char> tflite::hexdump(const tflite::Span<const std::byte> region,
tflite::Span<char> tflite::hexdump(const tflite::Span<const uint8_t> region,
const tflite::Span<char> out) {
tflite::Span<char> buffer{out};
std::size_t byte_nr = 0;
constexpr int per_line = 16;
const int lines = (region.size() + per_line - 1) / per_line; // round up

for (int line = 0; line < lines; ++line) {
tflite::StaticVector<char, per_line> ascii;
char ascii[per_line];
int ascii_nr = 0;

// print address
buffer = output(buffer, "%08X:", line);
Expand All @@ -76,7 +77,7 @@ tflite::Span<char> tflite::hexdump(const tflite::Span<const std::byte> region,
if (std::isprint(as_int)) {
c = static_cast<char>(as_int);
}
ascii.push_back(c);
ascii[ascii_nr++] = c;
} else {
buffer = output(buffer, " ");
}
Expand All @@ -89,15 +90,15 @@ tflite::Span<char> tflite::hexdump(const tflite::Span<const std::byte> region,

// print the ascii value
buffer = output(buffer, " ");
for (const auto& c : ascii) {
buffer = output(buffer, "%c", c);
for (int ascii_index = 0; ascii_index < ascii_nr; ascii_index++) {
buffer = output(buffer, "%c", ascii[ascii_index]);
}
buffer = output(buffer, "%c", '\n');
}

return {out.data(), out.size() - buffer.size()};
}

void tflite::hexdump(const tflite::Span<const std::byte> region) {
void tflite::hexdump(const tflite::Span<const uint8_t> region) {
hexdump(region, {nullptr, 0});
}
5 changes: 3 additions & 2 deletions tensorflow/lite/micro/hexdump.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@
#define TENSORFLOW_LITE_MICRO_HEXDUMP_H_

#include <cstddef>
#include <cstdint>

#include "tensorflow/lite/micro/span.h"

namespace tflite {

// Displays the contents of a memory region, formatted in hexadecimal and ASCII
// in a style matching Python's hexdump module, using DebugLog().
void hexdump(Span<const std::byte> region);
void hexdump(Span<const uint8_t> region);

// Writes the contents of a memory region, formatted in hexadecimal and ASCII
// in a style matching Python's hexdump module, to a buffer. Returns the portion
// of the buffer written.
Span<char> hexdump(Span<const std::byte> region, Span<char> buffer);
Span<char> hexdump(Span<const uint8_t> region, Span<char> buffer);

} // end namespace tflite

Expand Down
5 changes: 3 additions & 2 deletions tensorflow/lite/micro/hexdump_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
#include "tensorflow/lite/micro/hexdump.h"

#include <array>
#include <cstdint>

#include "tensorflow/lite/micro/span.h"
#include "tensorflow/lite/micro/testing/micro_test.h"

constexpr tflite::Span<const char> input{
"This is an input string for testing."};

const tflite::Span<const std::byte> region{
reinterpret_cast<const std::byte*>(input.data()), input.size()};
const tflite::Span<const uint8_t> region{
reinterpret_cast<const uint8_t*>(input.data()), input.size()};

// clang-format off
constexpr tflite::Span<const char> expected{
Expand Down
83 changes: 0 additions & 83 deletions tensorflow/lite/micro/static_vector.h
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd hate to see StaticVector go. We've used it a few times in code that hasn't yet been merged (e.g., unit test refactoring).

This file was deleted.

82 changes: 0 additions & 82 deletions tensorflow/lite/micro/static_vector_test.cc

This file was deleted.

9 changes: 6 additions & 3 deletions tensorflow/lite/micro/tools/make/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ ifeq ($(TARGET), $(HOST_OS))
endif

CXXFLAGS := \
-std=c++17 \
-std=c++11 \
-fno-rtti \
-fno-exceptions \
-fno-threadsafe-statics \
Expand All @@ -192,7 +192,7 @@ CXXFLAGS := \

CCFLAGS := \
-Wimplicit-function-declaration \
-std=c17 \
-std=c11 \
$(COMMON_FLAGS)

ARFLAGS := -r
Expand Down Expand Up @@ -258,6 +258,10 @@ else ifeq ($(BUILD_TYPE), no_tf_lite_static_memory)
# https://github.com/tensorflow/tensorflow/issues/43076
CXXFLAGS := $(filter-out -DTF_LITE_STATIC_MEMORY, $(CXXFLAGS))
CCFLAGS := $(filter-out -DTF_LITE_STATIC_MEMORY, $(CCFLAGS))

# array.h uses std::conditional_t, which is a C++14 feature
CXXFLAGS := $(filter-out -std=c++11, $(CXXFLAGS))
CXXFLAGS += -std=c++14
endif

# This library is the main target for this makefile. It will contain a minimal
Expand Down Expand Up @@ -346,7 +350,6 @@ $(TENSORFLOW_ROOT)tensorflow/lite/micro/micro_time_test.cc \
$(TENSORFLOW_ROOT)tensorflow/lite/micro/micro_utils_test.cc \
$(TENSORFLOW_ROOT)tensorflow/lite/micro/recording_micro_allocator_test.cc \
$(TENSORFLOW_ROOT)tensorflow/lite/micro/span_test.cc \
$(TENSORFLOW_ROOT)tensorflow/lite/micro/static_vector_test.cc \
$(TENSORFLOW_ROOT)tensorflow/lite/micro/arena_allocator/non_persistent_arena_buffer_allocator_test.cc \
$(TENSORFLOW_ROOT)tensorflow/lite/micro/arena_allocator/persistent_arena_buffer_allocator_test.cc \
$(TENSORFLOW_ROOT)tensorflow/lite/micro/arena_allocator/recording_single_arena_buffer_allocator_test.cc \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ endif
TARGET_ARCH_DEFINES := -D$(shell echo $(TARGET_ARCH) | tr [a-z] [A-Z])

PLATFORM_FLAGS = \
-stdlib=libc++ \
-DTF_LITE_MCU_DEBUG_LOG \
-DTF_LITE_USE_CTIME \
--xtensa-core=$(XTENSA_CORE) \
Expand Down
Loading