blob: 9d9e616e98bd9ea243b3d4a81d28c1e3bfb50295 [file] [log] [blame]
Laurent Carlier749294b2020-06-01 09:03:17 +01001//
Sadik Armagana9c2ce12020-07-14 10:02:22 +01002// Copyright © 2017 Arm Ltd and Contributors. All rights reserved.
Francis Murtaghbee4bc92019-06-18 12:30:37 +01003// SPDX-License-Identifier: MIT
4//
Francis Murtaghbee4bc92019-06-18 12:30:37 +01005
Jan Eilers45274902020-10-15 18:34:43 +01006#pragma once
7
Jan Eilers45274902020-10-15 18:34:43 +01008#include <armnn/IRuntime.hpp>
9#include <armnn/Types.hpp>
Francis Murtaghbee4bc92019-06-18 12:30:37 +010010
James Ward6d9f5c52020-09-28 11:56:35 +010011#include <mapbox/variant.hpp>
Francis Murtaghbee4bc92019-06-18 12:30:37 +010012
13#include <iostream>
Francis Murtaghbee4bc92019-06-18 12:30:37 +010014
Francis Murtaghbee4bc92019-06-18 12:30:37 +010015
Jan Eilers45274902020-10-15 18:34:43 +010016std::vector<unsigned int> ParseArray(std::istream& stream);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010017
Jan Eilers45274902020-10-15 18:34:43 +010018/// Splits a given string at every accurance of delimiter into a vector of string
19std::vector<std::string> ParseStringList(const std::string& inputString, const char* delimiter);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010020
James Ward6d9f5c52020-09-28 11:56:35 +010021struct TensorPrinter
Francis Murtaghbee4bc92019-06-18 12:30:37 +010022{
Georgios Pinitas50311ba2020-02-18 13:25:23 +000023 TensorPrinter(const std::string& binding,
24 const armnn::TensorInfo& info,
25 const std::string& outputTensorFile,
Jan Eilers45274902020-10-15 18:34:43 +010026 bool dequantizeOutput);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010027
Jan Eilers45274902020-10-15 18:34:43 +010028 void operator()(const std::vector<float>& values);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010029
Jan Eilers45274902020-10-15 18:34:43 +010030 void operator()(const std::vector<uint8_t>& values);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010031
Jan Eilers45274902020-10-15 18:34:43 +010032 void operator()(const std::vector<int>& values);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010033
34private:
35 template<typename Container, typename Delegate>
Jan Eilers45274902020-10-15 18:34:43 +010036 void ForEachValue(const Container& c, Delegate delegate);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010037
Sadik Armagan77086282019-09-02 11:46:28 +010038 template<typename T>
Jan Eilers45274902020-10-15 18:34:43 +010039 void WriteToFile(const std::vector<T>& values);
Sadik Armagan77086282019-09-02 11:46:28 +010040
Francis Murtaghbee4bc92019-06-18 12:30:37 +010041 std::string m_OutputBinding;
Jan Eilers45274902020-10-15 18:34:43 +010042 float m_Scale;
43 int m_Offset;
Sadik Armagan77086282019-09-02 11:46:28 +010044 std::string m_OutputTensorFile;
Jan Eilers45274902020-10-15 18:34:43 +010045 bool m_DequantizeOutput;
Francis Murtaghbee4bc92019-06-18 12:30:37 +010046};
47
James Ward6d9f5c52020-09-28 11:56:35 +010048using TContainer = mapbox::util::variant<std::vector<float>, std::vector<int>, std::vector<unsigned char>>;
Aron Virginas-Tarc82c8732019-10-24 17:07:43 +010049using QuantizationParams = std::pair<float, int32_t>;
50
51void PopulateTensorWithData(TContainer& tensorData,
52 unsigned int numElements,
53 const std::string& dataTypeStr,
54 const armnn::Optional<QuantizationParams>& qParams,
Jan Eilers45274902020-10-15 18:34:43 +010055 const armnn::Optional<std::string>& dataFile);
Aron Virginas-Tarc82c8732019-10-24 17:07:43 +010056
Jan Eilers45274902020-10-15 18:34:43 +010057/**
58 * Verifies if the given string is a valid path. Reports invalid paths to std::err.
59 * @param file string - A string containing the path to check
60 * @param expectFile bool - If true, checks for a regular file.
61 * @return bool - True if given string is a valid path., false otherwise.
62 * */
63bool ValidatePath(const std::string& file, const bool expectFile);
Aron Virginas-Tarc82c8732019-10-24 17:07:43 +010064
Jan Eilers45274902020-10-15 18:34:43 +010065/**
66 * Verifies if a given vector of strings are valid paths. Reports invalid paths to std::err.
67 * @param fileVec vector of string - A vector of string containing the paths to check
68 * @param expectFile bool - If true, checks for a regular file.
69 * @return bool - True if all given strings are valid paths., false otherwise.
70 * */
71bool ValidatePaths(const std::vector<std::string>& fileVec, const bool expectFile);