From 5a15bf4c86fad79523517afff5f2df2f6298d8da Mon Sep 17 00:00:00 2001 From: Kristofer Jonsson Date: Thu, 27 Jan 2022 17:36:55 +0100 Subject: Set TFLu external context Remove PMU configuration from the InferenceJob struct and add an external context parameter intead. The external context is passed to the TFLu interpreter and will be returned in the ethosu_inference_begin() and ethosu_inference_end() callbacks. Change-Id: I6dab04c0ab5088b1325be365d77d65d1182e7441 --- .../include/inference_process.hpp | 12 +++----- .../inference_process/src/inference_process.cpp | 32 ++++++---------------- 2 files changed, 12 insertions(+), 32 deletions(-) (limited to 'applications') diff --git a/applications/inference_process/include/inference_process.hpp b/applications/inference_process/include/inference_process.hpp index 6ab453c..9635884 100644 --- a/applications/inference_process/include/inference_process.hpp +++ b/applications/inference_process/include/inference_process.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021 Arm Limited. All rights reserved. + * Copyright (c) 2019-2022 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -53,10 +53,7 @@ struct InferenceJob { std::vector output; std::vector expectedOutput; size_t numBytesToPrint; - std::vector pmuEventConfig; - bool pmuCycleCounterEnable; - std::vector pmuEventCount; - uint64_t pmuCycleCounterCount; + void *externalContext; InferenceJob(); InferenceJob(const std::string &name, @@ -64,9 +61,8 @@ struct InferenceJob { const std::vector &input, const std::vector &output, const std::vector &expectedOutput, - size_t numBytesToPrint, - const std::vector &pmuEventConfig, - const bool pmuCycleCounterEnable); + const size_t numBytesToPrint = 0, + void *externalContext = nullptr); void invalidate(); void clean(); diff --git a/applications/inference_process/src/inference_process.cpp b/applications/inference_process/src/inference_process.cpp index ebd9d6c..4c65005 100644 --- a/applications/inference_process/src/inference_process.cpp +++ b/applications/inference_process/src/inference_process.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2021 Arm Limited. All rights reserved. + * Copyright (c) 2019-2022 Arm Limited. All rights reserved. * * SPDX-License-Identifier: Apache-2.0 * @@ -100,20 +100,18 @@ char *DataPtr::end() const { return static_cast(data) + size; } -InferenceJob::InferenceJob() : numBytesToPrint(0) {} +InferenceJob::InferenceJob() : numBytesToPrint(0), externalContext(nullptr) {} InferenceJob::InferenceJob(const string &_name, const DataPtr &_networkModel, const vector &_input, const vector &_output, const vector &_expectedOutput, - size_t _numBytesToPrint, - const vector &_pmuEventConfig, - const bool _pmuCycleCounterEnable) : + const size_t _numBytesToPrint, + void *_externalContext) : name(_name), networkModel(_networkModel), input(_input), output(_output), expectedOutput(_expectedOutput), - numBytesToPrint(_numBytesToPrint), pmuEventConfig(_pmuEventConfig), pmuCycleCounterEnable(_pmuCycleCounterEnable), - pmuEventCount(), pmuCycleCounterCount(0) {} + numBytesToPrint(_numBytesToPrint), externalContext(_externalContext) {} void InferenceJob::invalidate() { networkModel.invalidate(); @@ -167,16 +165,14 @@ bool InferenceProcess::runJob(InferenceJob &job) { // Create the TFL micro interpreter tflite::AllOpsResolver resolver; -#ifdef LAYER_BY_LAYER_PROFILER - tflite::LayerByLayerProfiler profiler(job.pmuEventConfig, job.pmuCycleCounterEnable); -#else tflite::ArmProfiler profiler; -#endif - tflite::MicroErrorReporter errorReporter; tflite::MicroInterpreter interpreter( model, resolver, tensorArena, tensorArenaSize, &errorReporter, nullptr, &profiler); + // Set external context + interpreter.SetMicroExternalContext(job.externalContext); + // Allocate tensors TfLiteStatus status = interpreter.AllocateTensors(); if (status != kTfLiteOk) { @@ -196,14 +192,6 @@ bool InferenceProcess::runJob(InferenceJob &job) { return true; } -#ifdef LAYER_BY_LAYER_PROFILER - if (job.pmuCycleCounterEnable) { - job.pmuCycleCounterCount = profiler.GetPmuCycleCounterCount(); - } - - job.pmuEventCount.assign(profiler.GetPmuEventCount().begin(), profiler.GetPmuEventCount().end()); -#endif - LOG("Inference runtime: %" PRId32 " cycles\n", profiler.GetTotalTicks()); // Copy output data from TFLu arena to job descriptor @@ -333,10 +321,6 @@ bool InferenceProcess::compareOfm(InferenceJob &job, tflite::MicroInterpreter &i } void InferenceProcess::printJob(InferenceJob &job, tflite::MicroInterpreter &interpreter) { - for (size_t i = 0; i < job.pmuEventCount.size(); i++) { - LOG("ethosu_pmu_cntr%zu : %" PRIu32 "\n", i, job.pmuEventCount[i]); - } - LOG("arena_used_bytes : %zu\n", interpreter.arena_used_bytes()); // Print all of the output data, or the first NUM_BYTES_TO_PRINT bytes, -- cgit v1.2.1