diff --git a/tensorflow/lite/micro/tools/benchmarking/generic_model_benchmark.cc b/tensorflow/lite/micro/tools/benchmarking/generic_model_benchmark.cc index 1c2f4b9791d..c1db8fa9cf3 100644 --- a/tensorflow/lite/micro/tools/benchmarking/generic_model_benchmark.cc +++ b/tensorflow/lite/micro/tools/benchmarking/generic_model_benchmark.cc @@ -13,6 +13,7 @@ See the License for the specific language governing permissions and limitations under the License. ==============================================================================*/ +#include #include #include @@ -76,37 +77,20 @@ void SetRandomInput(const uint32_t random_seed, } bool ReadFile(const char* file_name, void* buffer, size_t buffer_size) { - // Obtain the file size using fstat, or report an error if that fails. std::unique_ptr file(fopen(file_name, "rb"), fclose); - struct stat sb; - -// For CMSIS_NN, the compilation is failing with the following error -// 'fileno' was not declared in this scope -// TODO(b/290988791): Investigate why fileno is not defined in arm toolchain. -#if defined(CMSIS_NN) - if (fstat(file.get()->_file, &sb) != 0) { -#else - if (fstat(fileno(file.get()), &sb) != 0) { -#endif - MicroPrintf("Failed to get file size of: %s\n", file_name); - return false; - } - if (!buffer) { - MicroPrintf("Malloc of buffer to hold copy of '%s' failed\n", file_name); + const size_t bytes_read = + fread(buffer, sizeof(char), buffer_size, file.get()); + if (ferror(file.get())) { + MicroPrintf("Unable to read model file: %d\n", ferror(file.get())); return false; } - - if (S_ISREG(sb.st_mode) != 0 && - (sb.st_size < 0 || (static_cast(sb.st_size) > buffer_size))) { - MicroPrintf( - "Buffer size (%ld) to hold the model is less than required %ld.\n", - buffer_size, sb.st_size); + if (!feof(file.get())) { + MicroPrintf("Model buffer is too small for the model.\n"); return false; } - - if (!fread(buffer, sizeof(char), sb.st_size, file.get())) { - MicroPrintf("Unable to read the model file or the model file is empty.\n"); + if (bytes_read == 0) { + MicroPrintf("No bytes read from model file.\n"); return false; } @@ -173,4 +157,4 @@ int Benchmark(const char* model_file_name) { } // namespace } // namespace tflite -int main(int argc, char** argv) { return tflite::Benchmark(argv[1]); } \ No newline at end of file +int main(int argc, char** argv) { return tflite::Benchmark(argv[1]); } diff --git a/tensorflow/lite/micro/tools/benchmarking/log_utils.cc b/tensorflow/lite/micro/tools/benchmarking/log_utils.cc index 8ac4ca39071..808e465b514 100644 --- a/tensorflow/lite/micro/tools/benchmarking/log_utils.cc +++ b/tensorflow/lite/micro/tools/benchmarking/log_utils.cc @@ -15,6 +15,7 @@ limitations under the License. #include "tensorflow/lite/micro/tools/benchmarking/log_utils.h" +#include #include #include @@ -90,11 +91,7 @@ void PrettyPrintTableHeader(PrettyPrintType type, const char* table_name) { template <> void FormatNumber(char* output, int32_t value) { -#if defined(HEXAGON) || defined(CMSIS_NN) - sprintf(output, "%ld", value); // NOLINT: sprintf required. -#else - sprintf(output, "%d", value); // NOLINT: sprintf required. -#endif + sprintf(output, "%" PRId32, value); // NOLINT: sprintf required. } template <>