From 077ae1003f8e65fbb97f82d34ee6f643d57afde8 Mon Sep 17 00:00:00 2001 From: Advait Jain Date: Fri, 4 Jun 2021 11:58:23 -0700 Subject: [PATCH] Revert https://github.com/tensorflow/tensorflow/pull/47935 (#127) * Revert "Disable currently failing test to make the Xtensa build green. (#124)" This reverts commit 20cdd3fb004ce7818be2bca94c414214b775834a. * Cherry pick https://github.com/tensorflow/tensorflow/pull/50072 * clang-formatting fix. --- .../lite/experimental/microfrontend/lib/BUILD | 45 ------------ .../experimental/microfrontend/lib/fft_io.c | 26 +++---- .../microfrontend/lib/fft_util.cc | 29 ++++---- .../microfrontend/lib/filterbank_io.c | 39 +++++------ .../microfrontend/lib/filterbank_util.c | 68 ++++++++----------- .../microfrontend/lib/fprintf_shim.h | 37 ---------- .../microfrontend/lib/frontend_io.c | 40 +++++------ .../microfrontend/lib/frontend_main.c | 6 +- .../lib/frontend_memmap_generator.c | 13 ++-- .../microfrontend/lib/frontend_memmap_main.c | 4 +- .../microfrontend/lib/frontend_util.c | 15 ++-- .../microfrontend/lib/log_scale_io.c | 6 +- .../microfrontend/lib/memory_util.h | 34 ---------- .../lib/memory_util_fixed_pool.c | 44 ------------ .../microfrontend/lib/memory_util_stdlib.c | 25 ------- .../microfrontend/lib/memory_util_test.cc | 31 --------- .../microfrontend/lib/noise_reduction_io.c | 22 +++--- .../microfrontend/lib/noise_reduction_util.c | 13 ++-- .../microfrontend/lib/pcan_gain_control.c | 1 - .../lib/pcan_gain_control_util.c | 11 ++- .../microfrontend/lib/window_io.c | 33 ++++----- .../microfrontend/lib/window_util.c | 23 +++---- .../micro/examples/micro_speech/Makefile.inc | 35 +++------- .../simple_features_generator_test.cc | 35 ---------- .../tools/make/targets/bluepill_makefile.inc | 5 +- 25 files changed, 162 insertions(+), 478 deletions(-) delete mode 100644 tensorflow/lite/experimental/microfrontend/lib/fprintf_shim.h delete mode 100644 tensorflow/lite/experimental/microfrontend/lib/memory_util.h delete mode 100644 tensorflow/lite/experimental/microfrontend/lib/memory_util_fixed_pool.c delete mode 100644 tensorflow/lite/experimental/microfrontend/lib/memory_util_stdlib.c delete mode 100644 tensorflow/lite/experimental/microfrontend/lib/memory_util_test.cc delete mode 100644 tensorflow/lite/micro/examples/micro_speech/simple_features/bluepill/simple_features_generator_test.cc diff --git a/tensorflow/lite/experimental/microfrontend/lib/BUILD b/tensorflow/lite/experimental/microfrontend/lib/BUILD index 4ad9d683..8ba5f9a2 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/BUILD +++ b/tensorflow/lite/experimental/microfrontend/lib/BUILD @@ -20,8 +20,6 @@ cc_library( "fft_util.h", ], deps = [ - ":fprintf_shim", - ":memory_util", "@kissfft//:kiss_fftr_16", ], ) @@ -39,19 +37,9 @@ cc_library( deps = [ ":bits", ":fft", - ":fprintf_shim", - ":memory_util", ], ) -cc_library( - name = "fprintf_shim", - hdrs = [ - "fprintf_shim.h", - ], - defines = ["MICROFRONTEND_USE_FPRINTF"], -) - cc_library( name = "frontend", srcs = [ @@ -66,7 +54,6 @@ cc_library( ":bits", ":fft", ":filterbank", - ":fprintf_shim", ":log_scale", ":noise_reduction", ":pcan_gain_control", @@ -91,16 +78,6 @@ cc_library( ], ) -cc_library( - name = "memory_util", - srcs = [ - "memory_util_stdlib.c", - ], - hdrs = [ - "memory_util.h", - ], -) - cc_library( name = "noise_reduction", srcs = [ @@ -111,10 +88,6 @@ cc_library( "noise_reduction.h", "noise_reduction_util.h", ], - deps = [ - ":fprintf_shim", - ":memory_util", - ], ) cc_library( @@ -129,8 +102,6 @@ cc_library( ], deps = [ ":bits", - ":fprintf_shim", - ":memory_util", ], ) @@ -144,10 +115,6 @@ cc_library( "window.h", "window_util.h", ], - deps = [ - "fprintf_shim", - ":memory_util", - ], ) cc_test( @@ -195,18 +162,6 @@ cc_test( ], ) -cc_test( - name = "memory_util_test", - srcs = ["memory_util_test.cc"], - # Setting copts for experimental code to [], but this code should be fixed - # to build with the default copts (micro_copts()) - copts = [], - deps = [ - ":memory_util", - "//tensorflow/lite/micro/testing:micro_test", - ], -) - cc_test( name = "noise_reduction_test", srcs = ["noise_reduction_test.cc"], diff --git a/tensorflow/lite/experimental/microfrontend/lib/fft_io.c b/tensorflow/lite/experimental/microfrontend/lib/fft_io.c index 0d2fb187..820221c1 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/fft_io.c +++ b/tensorflow/lite/experimental/microfrontend/lib/fft_io.c @@ -15,23 +15,19 @@ limitations under the License. #include "tensorflow/lite/experimental/microfrontend/lib/fft_io.h" void FftWriteMemmapPreamble(FILE* fp, const struct FftState* state) { - MICROFRONTEND_FPRINTF(fp, "static int16_t fft_input[%zu];\n", - state->fft_size); - MICROFRONTEND_FPRINTF(fp, "static struct complex_int16_t fft_output[%zu];\n", - state->fft_size / 2 + 1); - MICROFRONTEND_FPRINTF(fp, "static char fft_scratch[%zu];\n", - state->scratch_size); - MICROFRONTEND_FPRINTF(fp, "\n"); + fprintf(fp, "static int16_t fft_input[%zu];\n", state->fft_size); + fprintf(fp, "static struct complex_int16_t fft_output[%zu];\n", + state->fft_size / 2 + 1); + fprintf(fp, "static char fft_scratch[%zu];\n", state->scratch_size); + fprintf(fp, "\n"); } void FftWriteMemmap(FILE* fp, const struct FftState* state, const char* variable) { - MICROFRONTEND_FPRINTF(fp, "%s->input = fft_input;\n", variable); - MICROFRONTEND_FPRINTF(fp, "%s->output = fft_output;\n", variable); - MICROFRONTEND_FPRINTF(fp, "%s->fft_size = %zu;\n", variable, state->fft_size); - MICROFRONTEND_FPRINTF(fp, "%s->input_size = %zu;\n", variable, - state->input_size); - MICROFRONTEND_FPRINTF(fp, "%s->scratch = fft_scratch;\n", variable); - MICROFRONTEND_FPRINTF(fp, "%s->scratch_size = %zu;\n", variable, - state->scratch_size); + fprintf(fp, "%s->input = fft_input;\n", variable); + fprintf(fp, "%s->output = fft_output;\n", variable); + fprintf(fp, "%s->fft_size = %zu;\n", variable, state->fft_size); + fprintf(fp, "%s->input_size = %zu;\n", variable, state->input_size); + fprintf(fp, "%s->scratch = fft_scratch;\n", variable); + fprintf(fp, "%s->scratch_size = %zu;\n", variable, state->scratch_size); } diff --git a/tensorflow/lite/experimental/microfrontend/lib/fft_util.cc b/tensorflow/lite/experimental/microfrontend/lib/fft_util.cc index 190935f4..d516b464 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/fft_util.cc +++ b/tensorflow/lite/experimental/microfrontend/lib/fft_util.cc @@ -14,11 +14,11 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/lite/experimental/microfrontend/lib/fft_util.h" +#include + #define FIXED_POINT 16 #include "kiss_fft.h" #include "tools/kiss_fftr.h" -#include "tensorflow/lite/experimental/microfrontend/lib/fprintf_shim.h" -#include "tensorflow/lite/experimental/microfrontend/lib/memory_util.h" int FftPopulateState(struct FftState* state, size_t input_size) { state->input_size = input_size; @@ -28,16 +28,16 @@ int FftPopulateState(struct FftState* state, size_t input_size) { } state->input = reinterpret_cast( - microfrontend_alloc(state->fft_size * sizeof(*state->input))); + malloc(state->fft_size * sizeof(*state->input))); if (state->input == nullptr) { - MICROFRONTEND_FPRINTF(stderr, "Failed to alloc fft input buffer\n"); + fprintf(stderr, "Failed to alloc fft input buffer\n"); return 0; } - state->output = reinterpret_cast(microfrontend_alloc( - (state->fft_size / 2 + 1) * sizeof(*state->output) * 2)); + state->output = reinterpret_cast( + malloc((state->fft_size / 2 + 1) * sizeof(*state->output) * 2)); if (state->output == nullptr) { - MICROFRONTEND_FPRINTF(stderr, "Failed to alloc fft output buffer\n"); + fprintf(stderr, "Failed to alloc fft output buffer\n"); return 0; } @@ -46,12 +46,12 @@ int FftPopulateState(struct FftState* state, size_t input_size) { kiss_fftr_cfg kfft_cfg = kiss_fftr_alloc( state->fft_size, 0, nullptr, &scratch_size); if (kfft_cfg != nullptr) { - MICROFRONTEND_FPRINTF(stderr, "Kiss memory sizing failed.\n"); + fprintf(stderr, "Kiss memory sizing failed.\n"); return 0; } - state->scratch = microfrontend_alloc(scratch_size); + state->scratch = malloc(scratch_size); if (state->scratch == nullptr) { - MICROFRONTEND_FPRINTF(stderr, "Failed to alloc fft scratch buffer\n"); + fprintf(stderr, "Failed to alloc fft scratch buffer\n"); return 0; } state->scratch_size = scratch_size; @@ -59,15 +59,14 @@ int FftPopulateState(struct FftState* state, size_t input_size) { kfft_cfg = kiss_fftr_alloc(state->fft_size, 0, state->scratch, &scratch_size); if (kfft_cfg != state->scratch) { - MICROFRONTEND_FPRINTF(stderr, - "Kiss memory preallocation strategy failed.\n"); + fprintf(stderr, "Kiss memory preallocation strategy failed.\n"); return 0; } return 1; } void FftFreeStateContents(struct FftState* state) { - microfrontend_free(state->input); - microfrontend_free(state->output); - microfrontend_free(state->scratch); + free(state->input); + free(state->output); + free(state->scratch); } diff --git a/tensorflow/lite/experimental/microfrontend/lib/filterbank_io.c b/tensorflow/lite/experimental/microfrontend/lib/filterbank_io.c index c6873adf..6ce4c7c7 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/filterbank_io.c +++ b/tensorflow/lite/experimental/microfrontend/lib/filterbank_io.c @@ -16,15 +16,15 @@ limitations under the License. static void PrintArray(FILE* fp, const char* name, const int16_t* values, size_t size) { - MICROFRONTEND_FPRINTF(fp, "static int16_t filterbank_%s[] = {", name); + fprintf(fp, "static int16_t filterbank_%s[] = {", name); int i; for (i = 0; i < size; ++i) { - MICROFRONTEND_FPRINTF(fp, "%d", values[i]); + fprintf(fp, "%d", values[i]); if (i < size - 1) { - MICROFRONTEND_FPRINTF(fp, ", "); + fprintf(fp, ", "); } } - MICROFRONTEND_FPRINTF(fp, "};\n"); + fprintf(fp, "};\n"); } void FilterbankWriteMemmapPreamble(FILE* fp, @@ -44,31 +44,24 @@ void FilterbankWriteMemmapPreamble(FILE* fp, PrintArray(fp, "weights", state->weights, num_weights); PrintArray(fp, "unweights", state->unweights, num_weights); - MICROFRONTEND_FPRINTF(fp, "static uint64_t filterbank_work[%d];\n", - num_channels_plus_1); - MICROFRONTEND_FPRINTF(fp, "\n"); + fprintf(fp, "static uint64_t filterbank_work[%d];\n", num_channels_plus_1); + fprintf(fp, "\n"); } void FilterbankWriteMemmap(FILE* fp, const struct FilterbankState* state, const char* variable) { - MICROFRONTEND_FPRINTF(fp, "%s->num_channels = %d;\n", variable, - state->num_channels); - MICROFRONTEND_FPRINTF(fp, "%s->start_index = %d;\n", variable, - state->start_index); - MICROFRONTEND_FPRINTF(fp, "%s->end_index = %d;\n", variable, - state->end_index); + fprintf(fp, "%s->num_channels = %d;\n", variable, state->num_channels); + fprintf(fp, "%s->start_index = %d;\n", variable, state->start_index); + fprintf(fp, "%s->end_index = %d;\n", variable, state->end_index); - MICROFRONTEND_FPRINTF( + fprintf( fp, "%s->channel_frequency_starts = filterbank_channel_frequency_starts;\n", variable); - MICROFRONTEND_FPRINTF( - fp, "%s->channel_weight_starts = filterbank_channel_weight_starts;\n", - variable); - MICROFRONTEND_FPRINTF(fp, "%s->channel_widths = filterbank_channel_widths;\n", - variable); - MICROFRONTEND_FPRINTF(fp, "%s->weights = filterbank_weights;\n", variable); - MICROFRONTEND_FPRINTF(fp, "%s->unweights = filterbank_unweights;\n", - variable); - MICROFRONTEND_FPRINTF(fp, "%s->work = filterbank_work;\n", variable); + fprintf(fp, "%s->channel_weight_starts = filterbank_channel_weight_starts;\n", + variable); + fprintf(fp, "%s->channel_widths = filterbank_channel_widths;\n", variable); + fprintf(fp, "%s->weights = filterbank_weights;\n", variable); + fprintf(fp, "%s->unweights = filterbank_unweights;\n", variable); + fprintf(fp, "%s->work = filterbank_work;\n", variable); } diff --git a/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.c b/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.c index 84f2a74a..f18ebf54 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.c +++ b/tensorflow/lite/experimental/microfrontend/lib/filterbank_util.c @@ -16,10 +16,7 @@ limitations under the License. #include #include -#include - -#include "tensorflow/lite/experimental/microfrontend/lib/fprintf_shim.h" -#include "tensorflow/lite/experimental/microfrontend/lib/memory_util.h" +#include #define kFilterbankIndexAlignment 4 #define kFilterbankChannelBlockSize 4 @@ -68,29 +65,29 @@ int FilterbankPopulateState(const struct FilterbankConfig* config, ? 1 : kFilterbankIndexAlignment / sizeof(int16_t)); - state->channel_frequency_starts = microfrontend_alloc( - num_channels_plus_1 * sizeof(*state->channel_frequency_starts)); - state->channel_weight_starts = microfrontend_alloc( - num_channels_plus_1 * sizeof(*state->channel_weight_starts)); + state->channel_frequency_starts = + malloc(num_channels_plus_1 * sizeof(*state->channel_frequency_starts)); + state->channel_weight_starts = + malloc(num_channels_plus_1 * sizeof(*state->channel_weight_starts)); state->channel_widths = - microfrontend_alloc(num_channels_plus_1 * sizeof(*state->channel_widths)); - state->work = microfrontend_alloc(num_channels_plus_1 * sizeof(*state->work)); + malloc(num_channels_plus_1 * sizeof(*state->channel_widths)); + state->work = malloc(num_channels_plus_1 * sizeof(*state->work)); float* center_mel_freqs = - microfrontend_alloc(num_channels_plus_1 * sizeof(*center_mel_freqs)); + malloc(num_channels_plus_1 * sizeof(*center_mel_freqs)); int16_t* actual_channel_starts = - microfrontend_alloc(num_channels_plus_1 * sizeof(*actual_channel_starts)); + malloc(num_channels_plus_1 * sizeof(*actual_channel_starts)); int16_t* actual_channel_widths = - microfrontend_alloc(num_channels_plus_1 * sizeof(*actual_channel_widths)); + malloc(num_channels_plus_1 * sizeof(*actual_channel_widths)); if (state->channel_frequency_starts == NULL || state->channel_weight_starts == NULL || state->channel_widths == NULL || center_mel_freqs == NULL || actual_channel_starts == NULL || actual_channel_widths == NULL) { - microfrontend_free(center_mel_freqs); - microfrontend_free(actual_channel_starts); - microfrontend_free(actual_channel_widths); - MICROFRONTEND_FPRINTF(stderr, "Failed to allocate channel buffers\n"); + free(center_mel_freqs); + free(actual_channel_starts); + free(actual_channel_widths); + fprintf(stderr, "Failed to allocate channel buffers\n"); return 0; } @@ -163,19 +160,15 @@ int FilterbankPopulateState(const struct FilterbankConfig* config, // Allocate the two arrays to store the weights - weight_index_start contains // the index of what would be the next set of weights that we would need to // add, so that's how many weights we need to allocate. - state->weights = - microfrontend_alloc(weight_index_start * sizeof(*state->weights)); - memset(state->weights, 0, (weight_index_start * sizeof(*state->weights))); - state->unweights = - microfrontend_alloc(weight_index_start * sizeof(*state->unweights)); - memset(state->unweights, 0, (weight_index_start * sizeof(*state->unweights))); + state->weights = calloc(weight_index_start, sizeof(*state->weights)); + state->unweights = calloc(weight_index_start, sizeof(*state->unweights)); // If the alloc failed, we also need to nuke the arrays. if (state->weights == NULL || state->unweights == NULL) { - microfrontend_free(center_mel_freqs); - microfrontend_free(actual_channel_starts); - microfrontend_free(actual_channel_widths); - MICROFRONTEND_FPRINTF(stderr, "Failed to allocate weights or unweights\n"); + free(center_mel_freqs); + free(actual_channel_starts); + free(actual_channel_widths); + fprintf(stderr, "Failed to allocate weights or unweights\n"); return 0; } @@ -207,22 +200,21 @@ int FilterbankPopulateState(const struct FilterbankConfig* config, } } - microfrontend_free(center_mel_freqs); - microfrontend_free(actual_channel_starts); - microfrontend_free(actual_channel_widths); + free(center_mel_freqs); + free(actual_channel_starts); + free(actual_channel_widths); if (state->end_index >= spectrum_size) { - MICROFRONTEND_FPRINTF(stderr, - "Filterbank end_index is above spectrum size.\n"); + fprintf(stderr, "Filterbank end_index is above spectrum size.\n"); return 0; } return 1; } void FilterbankFreeStateContents(struct FilterbankState* state) { - microfrontend_free(state->channel_frequency_starts); - microfrontend_free(state->channel_weight_starts); - microfrontend_free(state->channel_widths); - microfrontend_free(state->weights); - microfrontend_free(state->unweights); - microfrontend_free(state->work); + free(state->channel_frequency_starts); + free(state->channel_weight_starts); + free(state->channel_widths); + free(state->weights); + free(state->unweights); + free(state->work); } diff --git a/tensorflow/lite/experimental/microfrontend/lib/fprintf_shim.h b/tensorflow/lite/experimental/microfrontend/lib/fprintf_shim.h deleted file mode 100644 index e293db7b..00000000 --- a/tensorflow/lite/experimental/microfrontend/lib/fprintf_shim.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright 2021 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_EXPERIMENTAL_MICROFRONTEND_LIB_FPRINTF_SHIM_H_ -#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_FPRINTF_SHIM_H_ - -// This code is shared between the TensorFlow training environment and -// the embedded Micro codebase. On Micro, many platforms don't support -// stdio, so we stub out the fprintf call so it does nothing. In the -// Bazel build files for the training ops, we enable this macro so that -// useful debug logging will still be output. -#ifdef MICROFRONTEND_USE_FPRINTF - -#include - -// Redirect to the real fprintf. -#define MICROFRONTEND_FPRINTF fprintf - -#else // MICROFRONTEND_USE_FPRINTF - -// Stub out calls to fprintf so they do nothing. -#define MICROFRONTEND_FPRINTF(stream, format, ...) - -#endif // MICROFRONTEND_USE_FPRINTF - -#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_MEMORY_UTIL_H_ diff --git a/tensorflow/lite/experimental/microfrontend/lib/frontend_io.c b/tensorflow/lite/experimental/microfrontend/lib/frontend_io.c index 333f4433..b422d078 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/frontend_io.c +++ b/tensorflow/lite/experimental/microfrontend/lib/frontend_io.c @@ -27,47 +27,43 @@ int WriteFrontendStateMemmap(const char* header, const char* source, // Write a header that just has our init function. FILE* fp = fopen(header, "w"); if (!fp) { - MICROFRONTEND_FPRINTF(stderr, "Failed to open header '%s' for write\n", - header); + fprintf(stderr, "Failed to open header '%s' for write\n", header); return 0; } - MICROFRONTEND_FPRINTF(fp, "#ifndef FRONTEND_STATE_MEMMAP_H_\n"); - MICROFRONTEND_FPRINTF(fp, "#define FRONTEND_STATE_MEMMAP_H_\n"); - MICROFRONTEND_FPRINTF(fp, "\n"); - MICROFRONTEND_FPRINTF(fp, "#include \"frontend.h\"\n"); - MICROFRONTEND_FPRINTF(fp, "\n"); - MICROFRONTEND_FPRINTF(fp, - "struct FrontendState* GetFrontendStateMemmap();\n"); - MICROFRONTEND_FPRINTF(fp, "\n"); - MICROFRONTEND_FPRINTF(fp, "#endif // FRONTEND_STATE_MEMMAP_H_\n"); + fprintf(fp, "#ifndef FRONTEND_STATE_MEMMAP_H_\n"); + fprintf(fp, "#define FRONTEND_STATE_MEMMAP_H_\n"); + fprintf(fp, "\n"); + fprintf(fp, "#include \"frontend.h\"\n"); + fprintf(fp, "\n"); + fprintf(fp, "struct FrontendState* GetFrontendStateMemmap();\n"); + fprintf(fp, "\n"); + fprintf(fp, "#endif // FRONTEND_STATE_MEMMAP_H_\n"); fclose(fp); // Write out the source file that actually has everything in it. fp = fopen(source, "w"); if (!fp) { - MICROFRONTEND_FPRINTF(stderr, "Failed to open source '%s' for write\n", - source); + fprintf(stderr, "Failed to open source '%s' for write\n", source); return 0; } - MICROFRONTEND_FPRINTF(fp, "#include \"%s\"\n", header); - MICROFRONTEND_FPRINTF(fp, "\n"); + fprintf(fp, "#include \"%s\"\n", header); + fprintf(fp, "\n"); WindowWriteMemmapPreamble(fp, &state->window); FftWriteMemmapPreamble(fp, &state->fft); FilterbankWriteMemmapPreamble(fp, &state->filterbank); NoiseReductionWriteMemmapPreamble(fp, &state->noise_reduction); - MICROFRONTEND_FPRINTF(fp, "static struct FrontendState state;\n"); - MICROFRONTEND_FPRINTF(fp, - "struct FrontendState* GetFrontendStateMemmap() {\n"); + fprintf(fp, "static struct FrontendState state;\n"); + fprintf(fp, "struct FrontendState* GetFrontendStateMemmap() {\n"); WindowWriteMemmap(fp, &state->window, " (&state.window)"); FftWriteMemmap(fp, &state->fft, " (&state.fft)"); FilterbankWriteMemmap(fp, &state->filterbank, " (&state.filterbank)"); NoiseReductionWriteMemmap(fp, &state->noise_reduction, " (&state.noise_reduction)"); LogScaleWriteMemmap(fp, &state->log_scale, " (&state.log_scale)"); - MICROFRONTEND_FPRINTF(fp, " FftInit(&state.fft);\n"); - MICROFRONTEND_FPRINTF(fp, " FrontendReset(&state);\n"); - MICROFRONTEND_FPRINTF(fp, " return &state;\n"); - MICROFRONTEND_FPRINTF(fp, "}\n"); + fprintf(fp, " FftInit(&state.fft);\n"); + fprintf(fp, " FrontendReset(&state);\n"); + fprintf(fp, " return &state;\n"); + fprintf(fp, "}\n"); fclose(fp); return 1; } diff --git a/tensorflow/lite/experimental/microfrontend/lib/frontend_main.c b/tensorflow/lite/experimental/microfrontend/lib/frontend_main.c index b377263a..861778c7 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/frontend_main.c +++ b/tensorflow/lite/experimental/microfrontend/lib/frontend_main.c @@ -26,14 +26,14 @@ int main(int argc, char** argv) { struct FrontendState frontend_state; if (!FrontendPopulateState(&frontend_config, &frontend_state, sample_rate)) { - MICROFRONTEND_FPRINTF(stderr, "Failed to populate frontend state\n"); + fprintf(stderr, "Failed to populate frontend state\n"); FrontendFreeStateContents(&frontend_state); return 1; } FILE* fp = fopen(filename, "r"); if (fp == NULL) { - MICROFRONTEND_FPRINTF(stderr, "Failed to open %s for read\n", filename); + fprintf(stderr, "Failed to open %s for read\n", filename); return 1; } fseek(fp, 0L, SEEK_END); @@ -43,7 +43,7 @@ int main(int argc, char** argv) { int16_t* original_audio_data = audio_data; if (audio_file_size != fread(audio_data, sizeof(int16_t), audio_file_size, fp)) { - MICROFRONTEND_FPRINTF(stderr, "Failed to read in all audio data\n"); + fprintf(stderr, "Failed to read in all audio data\n"); fclose(fp); return 1; } diff --git a/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_generator.c b/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_generator.c index 262a67b1..d62433a5 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_generator.c +++ b/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_generator.c @@ -20,11 +20,10 @@ limitations under the License. int main(int argc, char** argv) { if (argc != 3) { - MICROFRONTEND_FPRINTF( - stderr, - "%s requires exactly two parameters - the names of the header and " - "source files to save\n", - argv[0]); + fprintf(stderr, + "%s requires exactly two parameters - the names of the header and " + "source files to save\n", + argv[0]); return 1; } struct FrontendConfig frontend_config; @@ -33,13 +32,13 @@ int main(int argc, char** argv) { int sample_rate = 16000; struct FrontendState frontend_state; if (!FrontendPopulateState(&frontend_config, &frontend_state, sample_rate)) { - MICROFRONTEND_FPRINTF(stderr, "Failed to populate frontend state\n"); + fprintf(stderr, "Failed to populate frontend state\n"); FrontendFreeStateContents(&frontend_state); return 1; } if (!WriteFrontendStateMemmap(argv[1], argv[2], &frontend_state)) { - MICROFRONTEND_FPRINTF(stderr, "Failed to write memmap\n"); + fprintf(stderr, "Failed to write memmap\n"); FrontendFreeStateContents(&frontend_state); return 1; } diff --git a/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_main.c b/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_main.c index d70ade31..e9c89b56 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_main.c +++ b/tensorflow/lite/experimental/microfrontend/lib/frontend_memmap_main.c @@ -23,7 +23,7 @@ int main(int argc, char** argv) { char* filename = argv[1]; FILE* fp = fopen(filename, "r"); if (fp == NULL) { - MICROFRONTEND_FPRINTF(stderr, "Failed to open %s for read\n", filename); + fprintf(stderr, "Failed to open %s for read\n", filename); return 1; } fseek(fp, 0L, SEEK_END); @@ -33,7 +33,7 @@ int main(int argc, char** argv) { int16_t* original_audio_data = audio_data; if (audio_file_size != fread(audio_data, sizeof(int16_t), audio_file_size, fp)) { - MICROFRONTEND_FPRINTF(stderr, "Failed to read in all audio data\n"); + fprintf(stderr, "Failed to read in all audio data\n"); fclose(fp); return 1; } diff --git a/tensorflow/lite/experimental/microfrontend/lib/frontend_util.c b/tensorflow/lite/experimental/microfrontend/lib/frontend_util.c index d7db9fb8..27224f6d 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/frontend_util.c +++ b/tensorflow/lite/experimental/microfrontend/lib/frontend_util.c @@ -14,10 +14,10 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/lite/experimental/microfrontend/lib/frontend_util.h" +#include #include #include "tensorflow/lite/experimental/microfrontend/lib/bits.h" -#include "tensorflow/lite/experimental/microfrontend/lib/fprintf_shim.h" void FrontendFillConfigWithDefaults(struct FrontendConfig* config) { WindowFillConfigWithDefaults(&config->window); @@ -32,26 +32,26 @@ int FrontendPopulateState(const struct FrontendConfig* config, memset(state, 0, sizeof(*state)); if (!WindowPopulateState(&config->window, &state->window, sample_rate)) { - MICROFRONTEND_FPRINTF(stderr, "Failed to populate window state\n"); + fprintf(stderr, "Failed to populate window state\n"); return 0; } if (!FftPopulateState(&state->fft, state->window.size)) { - MICROFRONTEND_FPRINTF(stderr, "Failed to populate fft state\n"); + fprintf(stderr, "Failed to populate fft state\n"); return 0; } FftInit(&state->fft); if (!FilterbankPopulateState(&config->filterbank, &state->filterbank, sample_rate, state->fft.fft_size / 2 + 1)) { - MICROFRONTEND_FPRINTF(stderr, "Failed to populate filterbank state\n"); + fprintf(stderr, "Failed to populate filterbank state\n"); return 0; } if (!NoiseReductionPopulateState(&config->noise_reduction, &state->noise_reduction, state->filterbank.num_channels)) { - MICROFRONTEND_FPRINTF(stderr, "Failed to populate noise reduction state\n"); + fprintf(stderr, "Failed to populate noise reduction state\n"); return 0; } @@ -61,13 +61,12 @@ int FrontendPopulateState(const struct FrontendConfig* config, &config->pcan_gain_control, &state->pcan_gain_control, state->noise_reduction.estimate, state->filterbank.num_channels, state->noise_reduction.smoothing_bits, input_correction_bits)) { - MICROFRONTEND_FPRINTF(stderr, - "Failed to populate pcan gain control state\n"); + fprintf(stderr, "Failed to populate pcan gain control state\n"); return 0; } if (!LogScalePopulateState(&config->log_scale, &state->log_scale)) { - MICROFRONTEND_FPRINTF(stderr, "Failed to populate log scale state\n"); + fprintf(stderr, "Failed to populate log scale state\n"); return 0; } diff --git a/tensorflow/lite/experimental/microfrontend/lib/log_scale_io.c b/tensorflow/lite/experimental/microfrontend/lib/log_scale_io.c index 91807227..a04760de 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/log_scale_io.c +++ b/tensorflow/lite/experimental/microfrontend/lib/log_scale_io.c @@ -16,8 +16,6 @@ limitations under the License. void LogScaleWriteMemmap(FILE* fp, const struct LogScaleState* state, const char* variable) { - MICROFRONTEND_FPRINTF(fp, "%s->enable_log = %d;\n", variable, - state->enable_log); - MICROFRONTEND_FPRINTF(fp, "%s->scale_shift = %d;\n", variable, - state->scale_shift); + fprintf(fp, "%s->enable_log = %d;\n", variable, state->enable_log); + fprintf(fp, "%s->scale_shift = %d;\n", variable, state->scale_shift); } diff --git a/tensorflow/lite/experimental/microfrontend/lib/memory_util.h b/tensorflow/lite/experimental/microfrontend/lib/memory_util.h deleted file mode 100644 index b1239639..00000000 --- a/tensorflow/lite/experimental/microfrontend/lib/memory_util.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright 2021 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_EXPERIMENTAL_MICROFRONTEND_LIB_MEMORY_UTIL_H_ -#define TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_MEMORY_UTIL_H_ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -// On platforms that support dynamic memory allocation, these just call into -// malloc and free, but for embedded systems with no heap we have an alternate -// implementation that allocates linearly from a fixed-size arena. -void* microfrontend_alloc(size_t size); -void microfrontend_free(void* ptr); - -#ifdef __cplusplus -} // extern "C" -#endif - -#endif // TENSORFLOW_LITE_EXPERIMENTAL_MICROFRONTEND_LIB_MEMORY_UTIL_H_ diff --git a/tensorflow/lite/experimental/microfrontend/lib/memory_util_fixed_pool.c b/tensorflow/lite/experimental/microfrontend/lib/memory_util_fixed_pool.c deleted file mode 100644 index b0a666d0..00000000 --- a/tensorflow/lite/experimental/microfrontend/lib/memory_util_fixed_pool.c +++ /dev/null @@ -1,44 +0,0 @@ -/* Copyright 2021 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. -==============================================================================*/ - -// This version of the allocation utilities uses a fixed pool of memory so that -// a standard library heap isn't required. Include this in the list of files to -// compile instead of the memory_util_stdlib.c version if your platform doesn't -// have a heap available. - -#include "tensorflow/lite/experimental/microfrontend/lib/memory_util.h" - -// This size has been determined by experimentation, based on the largest -// allocations used by the micro speech example and tests. -#define FIXED_POOL_SIZE (30 * 1024) - -void* microfrontend_alloc(size_t size) { - static unsigned char fixed_pool[FIXED_POOL_SIZE]; - static int fixed_pool_used = 0; - - int next_used = fixed_pool_used + size; - if (next_used > FIXED_POOL_SIZE) { - return 0; - } - - void* result = &fixed_pool[fixed_pool_used]; - fixed_pool_used += size; - - return result; -} - -void microfrontend_free(void* ptr) { - // Do nothing. -} diff --git a/tensorflow/lite/experimental/microfrontend/lib/memory_util_stdlib.c b/tensorflow/lite/experimental/microfrontend/lib/memory_util_stdlib.c deleted file mode 100644 index af5a56f3..00000000 --- a/tensorflow/lite/experimental/microfrontend/lib/memory_util_stdlib.c +++ /dev/null @@ -1,25 +0,0 @@ -/* Copyright 2021 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. -==============================================================================*/ - -// This version of the allocation utilities uses standard malloc/free -// implementations for the memory required by the frontend. - -#include - -#include "tensorflow/lite/experimental/microfrontend/lib/memory_util.h" - -void* microfrontend_alloc(size_t size) { return malloc(size); } - -void microfrontend_free(void* ptr) { free(ptr); } diff --git a/tensorflow/lite/experimental/microfrontend/lib/memory_util_test.cc b/tensorflow/lite/experimental/microfrontend/lib/memory_util_test.cc deleted file mode 100644 index 4118d483..00000000 --- a/tensorflow/lite/experimental/microfrontend/lib/memory_util_test.cc +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright 2021 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/experimental/microfrontend/lib/memory_util.h" - -#include "tensorflow/lite/micro/testing/micro_test.h" - -TF_LITE_MICRO_TESTS_BEGIN - -TF_LITE_MICRO_TEST(MemoryUtil_CheckAlloc) { - TF_LITE_MICRO_EXPECT_NE(nullptr, microfrontend_alloc(256)); -} - -TF_LITE_MICRO_TEST(MemoryUtil_CheckFree) { - void* ptr = microfrontend_alloc(128); - TF_LITE_MICRO_EXPECT_NE(nullptr, ptr); - microfrontend_free(ptr); -} - -TF_LITE_MICRO_TESTS_END diff --git a/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.c b/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.c index dc3b7b24..19c32b32 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.c +++ b/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_io.c @@ -16,23 +16,19 @@ limitations under the License. void NoiseReductionWriteMemmapPreamble( FILE* fp, const struct NoiseReductionState* state) { - MICROFRONTEND_FPRINTF(fp, "static uint32_t noise_reduction_estimate[%zu];\n", - state->num_channels); - MICROFRONTEND_FPRINTF(fp, "\n"); + fprintf(fp, "static uint32_t noise_reduction_estimate[%zu];\n", + state->num_channels); + fprintf(fp, "\n"); } void NoiseReductionWriteMemmap(FILE* fp, const struct NoiseReductionState* state, const char* variable) { - MICROFRONTEND_FPRINTF(fp, "%s->even_smoothing = %d;\n", variable, - state->even_smoothing); - MICROFRONTEND_FPRINTF(fp, "%s->odd_smoothing = %d;\n", variable, - state->odd_smoothing); - MICROFRONTEND_FPRINTF(fp, "%s->min_signal_remaining = %d;\n", variable, - state->min_signal_remaining); - MICROFRONTEND_FPRINTF(fp, "%s->num_channels = %d;\n", variable, - state->num_channels); + fprintf(fp, "%s->even_smoothing = %d;\n", variable, state->even_smoothing); + fprintf(fp, "%s->odd_smoothing = %d;\n", variable, state->odd_smoothing); + fprintf(fp, "%s->min_signal_remaining = %d;\n", variable, + state->min_signal_remaining); + fprintf(fp, "%s->num_channels = %d;\n", variable, state->num_channels); - MICROFRONTEND_FPRINTF(fp, "%s->estimate = noise_reduction_estimate;\n", - variable); + fprintf(fp, "%s->estimate = noise_reduction_estimate;\n", variable); } diff --git a/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.c b/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.c index 760f6752..a6c9234e 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.c +++ b/tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.c @@ -14,10 +14,7 @@ limitations under the License. ==============================================================================*/ #include "tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.h" -#include - -#include "tensorflow/lite/experimental/microfrontend/lib/fprintf_shim.h" -#include "tensorflow/lite/experimental/microfrontend/lib/memory_util.h" +#include void NoiseReductionFillConfigWithDefaults(struct NoiseReductionConfig* config) { config->smoothing_bits = 10; @@ -35,16 +32,14 @@ int NoiseReductionPopulateState(const struct NoiseReductionConfig* config, state->min_signal_remaining = config->min_signal_remaining * (1 << kNoiseReductionBits); state->num_channels = num_channels; - state->estimate = - microfrontend_alloc(state->num_channels * sizeof(*state->estimate)); - memset(state->estimate, 0, (state->num_channels * sizeof(*state->estimate))); + state->estimate = calloc(state->num_channels, sizeof(*state->estimate)); if (state->estimate == NULL) { - MICROFRONTEND_FPRINTF(stderr, "Failed to alloc estimate buffer\n"); + fprintf(stderr, "Failed to alloc estimate buffer\n"); return 0; } return 1; } void NoiseReductionFreeStateContents(struct NoiseReductionState* state) { - microfrontend_free(state->estimate); + free(state->estimate); } diff --git a/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.c b/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.c index 6b11de69..22d58767 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.c +++ b/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.c @@ -15,7 +15,6 @@ limitations under the License. #include "tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h" #include "tensorflow/lite/experimental/microfrontend/lib/bits.h" -#include "tensorflow/lite/experimental/microfrontend/lib/fprintf_shim.h" int16_t WideDynamicFunction(const uint32_t x, const int16_t* lut) { if (x <= 2) { diff --git a/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.c b/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.c index f4bbfffe..e850d439 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.c +++ b/tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.c @@ -15,9 +15,7 @@ limitations under the License. #include "tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control_util.h" #include - -#include "tensorflow/lite/experimental/microfrontend/lib/fprintf_shim.h" -#include "tensorflow/lite/experimental/microfrontend/lib/memory_util.h" +#include #define kint16max 0x00007FFF @@ -54,10 +52,9 @@ int PcanGainControlPopulateState(const struct PcanGainControlConfig* config, } state->noise_estimate = noise_estimate; state->num_channels = num_channels; - state->gain_lut = - microfrontend_alloc(kWideDynamicFunctionLUTSize * sizeof(int16_t)); + state->gain_lut = malloc(kWideDynamicFunctionLUTSize * sizeof(int16_t)); if (state->gain_lut == NULL) { - MICROFRONTEND_FPRINTF(stderr, "Failed to allocate gain LUT\n"); + fprintf(stderr, "Failed to allocate gain LUT\n"); return 0; } state->snr_shift = config->gain_bits - input_correction_bits - kPcanSnrBits; @@ -91,5 +88,5 @@ int PcanGainControlPopulateState(const struct PcanGainControlConfig* config, } void PcanGainControlFreeStateContents(struct PcanGainControlState* state) { - microfrontend_free(state->gain_lut); + free(state->gain_lut); } diff --git a/tensorflow/lite/experimental/microfrontend/lib/window_io.c b/tensorflow/lite/experimental/microfrontend/lib/window_io.c index 0f2ee7b9..d12cac2c 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/window_io.c +++ b/tensorflow/lite/experimental/microfrontend/lib/window_io.c @@ -15,32 +15,29 @@ limitations under the License. #include "tensorflow/lite/experimental/microfrontend/lib/window_io.h" void WindowWriteMemmapPreamble(FILE* fp, const struct WindowState* state) { - MICROFRONTEND_FPRINTF(fp, "static int16_t window_coefficients[] = {\n"); + fprintf(fp, "static int16_t window_coefficients[] = {\n"); int i; for (i = 0; i < state->size; ++i) { - MICROFRONTEND_FPRINTF(fp, "%d", state->coefficients[i]); + fprintf(fp, "%d", state->coefficients[i]); if (i < state->size - 1) { - MICROFRONTEND_FPRINTF(fp, ", "); + fprintf(fp, ", "); } } - MICROFRONTEND_FPRINTF(fp, "};\n"); - MICROFRONTEND_FPRINTF(fp, "static int16_t window_input[%zu];\n", state->size); - MICROFRONTEND_FPRINTF(fp, "static int16_t window_output[%zu];\n", - state->size); - MICROFRONTEND_FPRINTF(fp, "\n"); + fprintf(fp, "};\n"); + fprintf(fp, "static int16_t window_input[%zu];\n", state->size); + fprintf(fp, "static int16_t window_output[%zu];\n", state->size); + fprintf(fp, "\n"); } void WindowWriteMemmap(FILE* fp, const struct WindowState* state, const char* variable) { - MICROFRONTEND_FPRINTF(fp, "%s->size = %zu;\n", variable, state->size); - MICROFRONTEND_FPRINTF(fp, "%s->coefficients = window_coefficients;\n", - variable); - MICROFRONTEND_FPRINTF(fp, "%s->step = %zu;\n", variable, state->step); + fprintf(fp, "%s->size = %zu;\n", variable, state->size); + fprintf(fp, "%s->coefficients = window_coefficients;\n", variable); + fprintf(fp, "%s->step = %zu;\n", variable, state->step); - MICROFRONTEND_FPRINTF(fp, "%s->input = window_input;\n", variable); - MICROFRONTEND_FPRINTF(fp, "%s->input_used = %zu;\n", variable, - state->input_used); - MICROFRONTEND_FPRINTF(fp, "%s->output = window_output;\n", variable); - MICROFRONTEND_FPRINTF(fp, "%s->max_abs_output_value = %d;\n", variable, - state->max_abs_output_value); + fprintf(fp, "%s->input = window_input;\n", variable); + fprintf(fp, "%s->input_used = %zu;\n", variable, state->input_used); + fprintf(fp, "%s->output = window_output;\n", variable); + fprintf(fp, "%s->max_abs_output_value = %d;\n", variable, + state->max_abs_output_value); } diff --git a/tensorflow/lite/experimental/microfrontend/lib/window_util.c b/tensorflow/lite/experimental/microfrontend/lib/window_util.c index f3ace6a9..eee6e7b5 100644 --- a/tensorflow/lite/experimental/microfrontend/lib/window_util.c +++ b/tensorflow/lite/experimental/microfrontend/lib/window_util.c @@ -15,12 +15,10 @@ limitations under the License. #include "tensorflow/lite/experimental/microfrontend/lib/window_util.h" #include +#include #include #include -#include "tensorflow/lite/experimental/microfrontend/lib/fprintf_shim.h" -#include "tensorflow/lite/experimental/microfrontend/lib/memory_util.h" - // Some platforms don't have M_PI #ifndef M_PI #define M_PI 3.14159265358979323846 @@ -36,10 +34,9 @@ int WindowPopulateState(const struct WindowConfig* config, state->size = config->size_ms * sample_rate / 1000; state->step = config->step_size_ms * sample_rate / 1000; - state->coefficients = - microfrontend_alloc(state->size * sizeof(*state->coefficients)); + state->coefficients = malloc(state->size * sizeof(*state->coefficients)); if (state->coefficients == NULL) { - MICROFRONTEND_FPRINTF(stderr, "Failed to allocate window coefficients\n"); + fprintf(stderr, "Failed to allocate window coefficients\n"); return 0; } @@ -54,15 +51,15 @@ int WindowPopulateState(const struct WindowConfig* config, } state->input_used = 0; - state->input = microfrontend_alloc(state->size * sizeof(*state->input)); + state->input = malloc(state->size * sizeof(*state->input)); if (state->input == NULL) { - MICROFRONTEND_FPRINTF(stderr, "Failed to allocate window input\n"); + fprintf(stderr, "Failed to allocate window input\n"); return 0; } - state->output = microfrontend_alloc(state->size * sizeof(*state->output)); + state->output = malloc(state->size * sizeof(*state->output)); if (state->output == NULL) { - MICROFRONTEND_FPRINTF(stderr, "Failed to allocate window output\n"); + fprintf(stderr, "Failed to allocate window output\n"); return 0; } @@ -70,7 +67,7 @@ int WindowPopulateState(const struct WindowConfig* config, } void WindowFreeStateContents(struct WindowState* state) { - microfrontend_free(state->coefficients); - microfrontend_free(state->input); - microfrontend_free(state->output); + free(state->coefficients); + free(state->input); + free(state->output); } diff --git a/tensorflow/lite/micro/examples/micro_speech/Makefile.inc b/tensorflow/lite/micro/examples/micro_speech/Makefile.inc index beb93a8b..a4ec24f4 100644 --- a/tensorflow/lite/micro/examples/micro_speech/Makefile.inc +++ b/tensorflow/lite/micro/examples/micro_speech/Makefile.inc @@ -63,7 +63,6 @@ tensorflow/lite/experimental/microfrontend/lib/frontend_util.c \ tensorflow/lite/experimental/microfrontend/lib/log_lut.c \ tensorflow/lite/experimental/microfrontend/lib/log_scale.c \ tensorflow/lite/experimental/microfrontend/lib/log_scale_util.c \ -tensorflow/lite/experimental/microfrontend/lib/memory_util_fixed_pool.c \ tensorflow/lite/experimental/microfrontend/lib/noise_reduction.c \ tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.c \ tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.c \ @@ -78,13 +77,11 @@ tensorflow/lite/experimental/microfrontend/lib/fft.h \ tensorflow/lite/experimental/microfrontend/lib/fft_util.h \ tensorflow/lite/experimental/microfrontend/lib/filterbank.h \ tensorflow/lite/experimental/microfrontend/lib/filterbank_util.h \ -tensorflow/lite/experimental/microfrontend/lib/fprintf_shim.h \ tensorflow/lite/experimental/microfrontend/lib/frontend.h \ tensorflow/lite/experimental/microfrontend/lib/frontend_util.h \ tensorflow/lite/experimental/microfrontend/lib/log_lut.h \ tensorflow/lite/experimental/microfrontend/lib/log_scale.h \ tensorflow/lite/experimental/microfrontend/lib/log_scale_util.h \ -tensorflow/lite/experimental/microfrontend/lib/memory_util.h \ tensorflow/lite/experimental/microfrontend/lib/noise_reduction.h \ tensorflow/lite/experimental/microfrontend/lib/noise_reduction_util.h \ tensorflow/lite/experimental/microfrontend/lib/pcan_gain_control.h \ @@ -93,13 +90,6 @@ tensorflow/lite/experimental/microfrontend/lib/window.h \ tensorflow/lite/experimental/microfrontend/lib/window_util.h \ $(KISSFFT_LIB_HDRS) -MICRO_FEATURES_LIB_MEMORY_UTIL_TEST_SRCS := \ -tensorflow/lite/experimental/microfrontend/lib/memory_util_test.c \ -$(MICRO_FEATURES_LIB_SRCS) - -MICRO_FEATURES_LIB_MEMORY_UTIL_TEST_HDRS := \ -$(MICRO_FEATURES_LIB_HDRS) - MICRO_FEATURES_GENERATOR_SRCS := \ tensorflow/lite/micro/examples/micro_speech/micro_features/micro_features_generator.cc \ tensorflow/lite/micro/examples/micro_speech/micro_features/micro_model_settings.cc \ @@ -251,27 +241,10 @@ include $(wildcard tensorflow/lite/micro/examples/micro_speech/*/Makefile.inc) # way to build third_party code with a reduced list of CFLAGS. CCFLAGS := $(filter-out $(CC_WARNINGS),$(CCFLAGS)) -# Test the code for feature generation. -$(eval $(call microlite_test,micro_features_lib_memory_util_test,\ -$(MICRO_FEATURES_LIB_MEMORY_UTIL_TEST_SRCS), $(MICRO_FEATURES_LIB_MEMORY_UTIL_TEST_HDRS))) - - -# TODO(#123): enable micro_features_generator_test once it passes for the Xtensa -# target. -ifneq ($(TARGET),xtensa) # Test the code for feature generation. $(eval $(call microlite_test,micro_features_generator_test,\ $(MICRO_FEATURES_GENERATOR_TEST_SRCS), $(MICRO_FEATURES_GENERATOR_TEST_HDRS))) -# Tests the feature provider module. -$(eval $(call microlite_test,feature_provider_test,\ -$(FEATURE_PROVIDER_TEST_SRCS),$(FEATURE_PROVIDER_TEST_HDRS))) - -# Tests the feature provider module using the mock audio provider. -$(eval $(call microlite_test,feature_provider_mock_test,\ -$(FEATURE_PROVIDER_MOCK_TEST_SRCS),$(FEATURE_PROVIDER_MOCK_TEST_HDRS))) -endif - # Tests loading and running a speech model. $(eval $(call microlite_test,micro_speech_test,\ $(MICRO_SPEECH_TEST_SRCS),$(MICRO_SPEECH_TEST_HDRS))) @@ -288,6 +261,14 @@ $(AUDIO_PROVIDER_TEST_SRCS),$(AUDIO_PROVIDER_TEST_HDRS))) $(eval $(call microlite_test,audio_provider_mock_test,\ $(AUDIO_PROVIDER_MOCK_TEST_SRCS),$(AUDIO_PROVIDER_MOCK_TEST_HDRS))) +# Tests the feature provider module. +$(eval $(call microlite_test,feature_provider_test,\ +$(FEATURE_PROVIDER_TEST_SRCS),$(FEATURE_PROVIDER_TEST_HDRS))) + +# Tests the feature provider module using the mock audio provider. +$(eval $(call microlite_test,feature_provider_mock_test,\ +$(FEATURE_PROVIDER_MOCK_TEST_SRCS),$(FEATURE_PROVIDER_MOCK_TEST_HDRS))) + # Tests the command recognizer module. $(eval $(call microlite_test,recognize_commands_test,\ $(RECOGNIZE_COMMANDS_TEST_SRCS),$(RECOGNIZE_COMMANDS_TEST_HDRS))) diff --git a/tensorflow/lite/micro/examples/micro_speech/simple_features/bluepill/simple_features_generator_test.cc b/tensorflow/lite/micro/examples/micro_speech/simple_features/bluepill/simple_features_generator_test.cc deleted file mode 100644 index 28a101fb..00000000 --- a/tensorflow/lite/micro/examples/micro_speech/simple_features/bluepill/simple_features_generator_test.cc +++ /dev/null @@ -1,35 +0,0 @@ -/* Copyright 2021 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/micro/examples/micro_speech/simple_features/simple_features_generator.h" - -#include "tensorflow/lite/c/common.h" -#include "tensorflow/lite/micro/examples/micro_speech/no_30ms_sample_data.h" -#include "tensorflow/lite/micro/examples/micro_speech/simple_features/no_power_spectrum_data.h" -#include "tensorflow/lite/micro/examples/micro_speech/simple_features/yes_power_spectrum_data.h" -#include "tensorflow/lite/micro/examples/micro_speech/yes_30ms_sample_data.h" -#include "tensorflow/lite/micro/micro_error_reporter.h" -#include "tensorflow/lite/micro/testing/micro_test.h" - -TF_LITE_MICRO_TESTS_BEGIN - -TF_LITE_MICRO_TEST(TestSimpleFeaturesGenerator) { - tflite::MicroErrorReporter micro_error_reporter; - // This test times out on a Bluepill because of the very slow FFT - // calculations, so replace it with a version that does nothing for this - // platform. -} - -TF_LITE_MICRO_TESTS_END diff --git a/tensorflow/lite/micro/tools/make/targets/bluepill_makefile.inc b/tensorflow/lite/micro/tools/make/targets/bluepill_makefile.inc index 09ed6735..572b3898 100644 --- a/tensorflow/lite/micro/tools/make/targets/bluepill_makefile.inc +++ b/tensorflow/lite/micro/tools/make/targets/bluepill_makefile.inc @@ -69,10 +69,11 @@ EXCLUDED_TESTS := \ tensorflow/lite/micro/memory_arena_threshold_test.cc MICROLITE_TEST_SRCS := $(filter-out $(EXCLUDED_TESTS), $(MICROLITE_TEST_SRCS)) -EXCLUDED_EXAMPLE_TEST_MAKEFILES := \ +EXCLUDED_EXAMPLE_TESTS := \ tensorflow/lite/micro/examples/magic_wand/Makefile.inc \ + tensorflow/lite/micro/examples/micro_speech/Makefile.inc \ tensorflow/lite/micro/examples/image_recognition_experimental/Makefile.inc -MICRO_LITE_EXAMPLE_TESTS := $(filter-out $(EXCLUDED_EXAMPLE_TESTS), $(MICRO_LITE_EXAMPLE_TEST_MAKEFILES)) +MICRO_LITE_EXAMPLE_TESTS := $(filter-out $(EXCLUDED_EXAMPLE_TESTS), $(MICRO_LITE_EXAMPLE_TESTS)) TEST_SCRIPT := tensorflow/lite/micro/testing/test_with_renode.sh -- GitLab