blob: d101d4a23cfb0801a9cbddb060917683ecc6c7b5 [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
Francis Murtaghbee4bc92019-06-18 12:30:37 +01008#include "CsvReader.hpp"
Jan Eilers45274902020-10-15 18:34:43 +01009#include <armnn/IRuntime.hpp>
10#include <armnn/Types.hpp>
Francis Murtaghbee4bc92019-06-18 12:30:37 +010011
James Ward6d9f5c52020-09-28 11:56:35 +010012#include <mapbox/variant.hpp>
Francis Murtaghbee4bc92019-06-18 12:30:37 +010013
14#include <iostream>
Francis Murtaghbee4bc92019-06-18 12:30:37 +010015
Francis Murtaghbee4bc92019-06-18 12:30:37 +010016
Jan Eilers45274902020-10-15 18:34:43 +010017std::vector<unsigned int> ParseArray(std::istream& stream);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010018
Jan Eilers45274902020-10-15 18:34:43 +010019/// Splits a given string at every accurance of delimiter into a vector of string
20std::vector<std::string> ParseStringList(const std::string& inputString, const char* delimiter);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010021
James Ward6d9f5c52020-09-28 11:56:35 +010022struct TensorPrinter
Francis Murtaghbee4bc92019-06-18 12:30:37 +010023{
Georgios Pinitas50311ba2020-02-18 13:25:23 +000024 TensorPrinter(const std::string& binding,
25 const armnn::TensorInfo& info,
26 const std::string& outputTensorFile,
Jan Eilers45274902020-10-15 18:34:43 +010027 bool dequantizeOutput);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010028
Jan Eilers45274902020-10-15 18:34:43 +010029 void operator()(const std::vector<float>& values);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010030
Jan Eilers45274902020-10-15 18:34:43 +010031 void operator()(const std::vector<uint8_t>& values);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010032
Jan Eilers45274902020-10-15 18:34:43 +010033 void operator()(const std::vector<int>& values);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010034
35private:
36 template<typename Container, typename Delegate>
Jan Eilers45274902020-10-15 18:34:43 +010037 void ForEachValue(const Container& c, Delegate delegate);
Francis Murtaghbee4bc92019-06-18 12:30:37 +010038
Sadik Armagan77086282019-09-02 11:46:28 +010039 template<typename T>
Jan Eilers45274902020-10-15 18:34:43 +010040 void WriteToFile(const std::vector<T>& values);
Sadik Armagan77086282019-09-02 11:46:28 +010041
Francis Murtaghbee4bc92019-06-18 12:30:37 +010042 std::string m_OutputBinding;
Jan Eilers45274902020-10-15 18:34:43 +010043 float m_Scale;
44 int m_Offset;
Sadik Armagan77086282019-09-02 11:46:28 +010045 std::string m_OutputTensorFile;
Jan Eilers45274902020-10-15 18:34:43 +010046 bool m_DequantizeOutput;
Francis Murtaghbee4bc92019-06-18 12:30:37 +010047};
48
James Ward6d9f5c52020-09-28 11:56:35 +010049using TContainer = mapbox::util::variant<std::vector<float>, std::vector<int>, std::vector<unsigned char>>;
Aron Virginas-Tarc82c8732019-10-24 17:07:43 +010050using QuantizationParams = std::pair<float, int32_t>;
51
52void PopulateTensorWithData(TContainer& tensorData,
53 unsigned int numElements,
54 const std::string& dataTypeStr,
55 const armnn::Optional<QuantizationParams>& qParams,
Jan Eilers45274902020-10-15 18:34:43 +010056 const armnn::Optional<std::string>& dataFile);
Aron Virginas-Tarc82c8732019-10-24 17:07:43 +010057
Jan Eilers45274902020-10-15 18:34:43 +010058/**
59 * Verifies if the given string is a valid path. Reports invalid paths to std::err.
60 * @param file string - A string containing the path to check
61 * @param expectFile bool - If true, checks for a regular file.
62 * @return bool - True if given string is a valid path., false otherwise.
63 * */
64bool ValidatePath(const std::string& file, const bool expectFile);
Aron Virginas-Tarc82c8732019-10-24 17:07:43 +010065
Jan Eilers45274902020-10-15 18:34:43 +010066/**
67 * Verifies if a given vector of strings are valid paths. Reports invalid paths to std::err.
68 * @param fileVec vector of string - A vector of string containing the paths to check
69 * @param expectFile bool - If true, checks for a regular file.
70 * @return bool - True if all given strings are valid paths., false otherwise.
71 * */
72bool ValidatePaths(const std::vector<std::string>& fileVec, const bool expectFile);