diff options
author | Kaizen <kaizen@arm.com> | 2017-10-12 14:26:51 +0100 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2017-10-12 15:42:58 +0100 |
commit | bf8b01dfbfdca124673ade33c5eac8f3748d7abd (patch) | |
tree | 9504f134ca292b988e7065b22229e9bbe0493d00 /utils | |
parent | 8938bd3f40ea62ff56d6ed4e2db0a8aee34dd64a (diff) | |
download | armcl-bf8b01dfbfdca124673ade33c5eac8f3748d7abd.tar.gz armcl-bf8b01dfbfdca124673ade33c5eac8f3748d7abd.tar.bz2 armcl-bf8b01dfbfdca124673ade33c5eac8f3748d7abd.zip |
arm_compute v17.10
Change-Id: If1489af40eccd0219ede8946577afbf04db31b29
Diffstat (limited to 'utils')
-rw-r--r-- | utils/GraphTypePrinter.h | 63 | ||||
-rw-r--r-- | utils/GraphUtils.cpp | 114 | ||||
-rw-r--r-- | utils/GraphUtils.h | 34 | ||||
-rw-r--r-- | utils/TypePrinter.h | 71 | ||||
-rw-r--r-- | utils/Utils.h | 8 |
5 files changed, 282 insertions, 8 deletions
diff --git a/utils/GraphTypePrinter.h b/utils/GraphTypePrinter.h new file mode 100644 index 000000000..be56d5985 --- /dev/null +++ b/utils/GraphTypePrinter.h @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2017 ARM Limited. + * + * SPDX-License-Identifier: MIT + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to + * deal in the Software without restriction, including without limitation the + * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or + * sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +#ifndef __ARM_COMPUTE_TEST_GRAPH_TYPE_PRINTER_H__ +#define __ARM_COMPUTE_TEST_GRAPH_TYPE_PRINTER_H__ + +#include "arm_compute/graph/Types.h" + +#include <ostream> +#include <sstream> +#include <string> + +namespace arm_compute +{ +namespace graph +{ +/** Formatted output of the @ref ConvolutionMethodHint type. */ +inline ::std::ostream &operator<<(::std::ostream &os, const ConvolutionMethodHint &conv_method) +{ + switch(conv_method) + { + case ConvolutionMethodHint::DIRECT: + os << "DIRECT"; + break; + case ConvolutionMethodHint::GEMM: + os << "GEMM"; + break; + default: + ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); + } + + return os; +} + +inline std::string to_string(const ConvolutionMethodHint &conv_method) +{ + std::stringstream str; + str << conv_method; + return str.str(); +} +} // namespace graph +} // namespace arm_compute +#endif /* __ARM_COMPUTE_TEST_GRAPH_TYPE_PRINTER_H__ */ diff --git a/utils/GraphUtils.cpp b/utils/GraphUtils.cpp index d76360686..bdd831075 100644 --- a/utils/GraphUtils.cpp +++ b/utils/GraphUtils.cpp @@ -31,8 +31,10 @@ #endif /* ARM_COMPUTE_CL */ #include "arm_compute/core/Error.h" +#include "arm_compute/core/PixelValue.h" #include "libnpy/npy.hpp" +#include <random> #include <sstream> using namespace arm_compute::graph_utils; @@ -85,6 +87,116 @@ bool DummyAccessor::access_tensor(ITensor &tensor) return ret; } +RandomAccessor::RandomAccessor(PixelValue lower, PixelValue upper, std::random_device::result_type seed) + : _lower(lower), _upper(upper), _seed(seed) +{ +} + +template <typename T, typename D> +void RandomAccessor::fill(ITensor &tensor, D &&distribution) +{ + std::mt19937 gen(_seed); + + if(tensor.info()->padding().empty()) + { + for(size_t offset = 0; offset < tensor.info()->total_size(); offset += tensor.info()->element_size()) + { + const T value = distribution(gen); + *reinterpret_cast<T *>(tensor.buffer() + offset) = value; + } + } + else + { + // If tensor has padding accessing tensor elements through execution window. + Window window; + window.use_tensor_dimensions(tensor.info()->tensor_shape()); + + execute_window_loop(window, [&](const Coordinates & id) + { + const T value = distribution(gen); + *reinterpret_cast<T *>(tensor.ptr_to_element(id)) = value; + }); + } +} + +bool RandomAccessor::access_tensor(ITensor &tensor) +{ + switch(tensor.info()->data_type()) + { + case DataType::U8: + { + std::uniform_int_distribution<uint8_t> distribution_u8(_lower.get<uint8_t>(), _upper.get<uint8_t>()); + fill<uint8_t>(tensor, distribution_u8); + break; + } + case DataType::S8: + case DataType::QS8: + { + std::uniform_int_distribution<int8_t> distribution_s8(_lower.get<int8_t>(), _upper.get<int8_t>()); + fill<int8_t>(tensor, distribution_s8); + break; + } + case DataType::U16: + { + std::uniform_int_distribution<uint16_t> distribution_u16(_lower.get<uint16_t>(), _upper.get<uint16_t>()); + fill<uint16_t>(tensor, distribution_u16); + break; + } + case DataType::S16: + case DataType::QS16: + { + std::uniform_int_distribution<int16_t> distribution_s16(_lower.get<int16_t>(), _upper.get<int16_t>()); + fill<int16_t>(tensor, distribution_s16); + break; + } + case DataType::U32: + { + std::uniform_int_distribution<uint32_t> distribution_u32(_lower.get<uint32_t>(), _upper.get<uint32_t>()); + fill<uint32_t>(tensor, distribution_u32); + break; + } + case DataType::S32: + { + std::uniform_int_distribution<int32_t> distribution_s32(_lower.get<int32_t>(), _upper.get<int32_t>()); + fill<int32_t>(tensor, distribution_s32); + break; + } + case DataType::U64: + { + std::uniform_int_distribution<uint64_t> distribution_u64(_lower.get<uint64_t>(), _upper.get<uint64_t>()); + fill<uint64_t>(tensor, distribution_u64); + break; + } + case DataType::S64: + { + std::uniform_int_distribution<int64_t> distribution_s64(_lower.get<int64_t>(), _upper.get<int64_t>()); + fill<int64_t>(tensor, distribution_s64); + break; + } + case DataType::F16: + { + std::uniform_real_distribution<float> distribution_f16(_lower.get<float>(), _upper.get<float>()); + fill<float>(tensor, distribution_f16); + break; + } + case DataType::F32: + { + std::uniform_real_distribution<float> distribution_f32(_lower.get<float>(), _upper.get<float>()); + fill<float>(tensor, distribution_f32); + break; + } + case DataType::F64: + { + std::uniform_real_distribution<double> distribution_f64(_lower.get<double>(), _upper.get<double>()); + fill<double>(tensor, distribution_f64); + break; + } + default: + ARM_COMPUTE_ERROR("NOT SUPPORTED!"); + } + return true; +} + NumPyBinLoader::NumPyBinLoader(std::string filename) : _filename(std::move(filename)) { @@ -162,4 +274,4 @@ bool NumPyBinLoader::access_tensor(ITensor &tensor) }); } return true; -} +}
\ No newline at end of file diff --git a/utils/GraphUtils.h b/utils/GraphUtils.h index a19f7e510..5c370e5eb 100644 --- a/utils/GraphUtils.h +++ b/utils/GraphUtils.h @@ -24,9 +24,12 @@ #ifndef __ARM_COMPUTE_GRAPH_UTILS_H__ #define __ARM_COMPUTE_GRAPH_UTILS_H__ +#include "arm_compute/core/PixelValue.h" #include "arm_compute/graph/ITensorAccessor.h" #include "arm_compute/graph/Types.h" +#include <random> + namespace arm_compute { namespace graph_utils @@ -54,7 +57,7 @@ private: }; /** Dummy accessor class */ -class DummyAccessor : public graph::ITensorAccessor +class DummyAccessor final : public graph::ITensorAccessor { public: /** Constructor @@ -73,8 +76,33 @@ private: unsigned int _maximum; }; +/** Random accessor class */ +class RandomAccessor final : public graph::ITensorAccessor +{ +public: + /** Constructor + * + * @param[in] lower Lower bound value. + * @param[in] upper Upper bound value. + * @param[in] seed (Optional) Seed used to initialise the random number generator. + */ + RandomAccessor(PixelValue lower, PixelValue upper, const std::random_device::result_type seed = 0); + /** Allows instances to move constructed */ + RandomAccessor(RandomAccessor &&) = default; + + // Inherited methods overriden: + bool access_tensor(ITensor &tensor) override; + +private: + template <typename T, typename D> + void fill(ITensor &tensor, D &&distribution); + PixelValue _lower; + PixelValue _upper; + std::random_device::result_type _seed; +}; + /** Numpy Binary loader class*/ -class NumPyBinLoader : public graph::ITensorAccessor +class NumPyBinLoader final : public graph::ITensorAccessor { public: /** Default Constructor @@ -91,7 +119,7 @@ public: private: const std::string _filename; }; -} // namespace graph +} // namespace graph_utils } // namespace arm_compute #endif /* __ARM_COMPUTE_GRAPH_UTILS_H__ */ diff --git a/utils/TypePrinter.h b/utils/TypePrinter.h index d0c568922..d6e3bdda8 100644 --- a/utils/TypePrinter.h +++ b/utils/TypePrinter.h @@ -26,8 +26,11 @@ #include "arm_compute/core/Dimensions.h" #include "arm_compute/core/Error.h" +#include "arm_compute/core/Strides.h" #include "arm_compute/core/Types.h" +#include "tests/Types.h" + #include <ostream> #include <sstream> #include <string> @@ -147,6 +150,45 @@ inline ::std::ostream &operator<<(::std::ostream &os, const ROIPoolingLayerInfo return os; } +inline ::std::ostream &operator<<(::std::ostream &os, const FixedPointOp &op) +{ + switch(op) + { + case FixedPointOp::ADD: + os << "ADD"; + break; + case FixedPointOp::SUB: + os << "SUB"; + break; + case FixedPointOp::MUL: + os << "MUL"; + break; + case FixedPointOp::EXP: + os << "EXP"; + break; + case FixedPointOp::LOG: + os << "LOG"; + break; + case FixedPointOp::INV_SQRT: + os << "INV_SQRT"; + break; + case FixedPointOp::RECIPROCAL: + os << "RECIPROCAL"; + break; + default: + ARM_COMPUTE_ERROR("NOT_SUPPORTED!"); + } + + return os; +} + +inline std::string to_string(const FixedPointOp &op) +{ + std::stringstream str; + str << op; + return str.str(); +} + /** Formatted output of the activation function type. */ inline ::std::ostream &operator<<(::std::ostream &os, const ActivationLayerInfo::ActivationFunction &act_function) { @@ -233,6 +275,13 @@ inline std::string to_string(const arm_compute::NormalizationLayerInfo &info) return str.str(); } +/** Formatted output of @ref NormalizationLayerInfo. */ +inline ::std::ostream &operator<<(::std::ostream &os, const NormalizationLayerInfo &info) +{ + os << info.type(); + return os; +} + /** Formatted output of the PoolingType type. */ inline ::std::ostream &operator<<(::std::ostream &os, const PoolingType &pool_type) { @@ -505,6 +554,13 @@ inline std::string to_string(const Dimensions<T> &dimensions) return str.str(); } +inline std::string to_string(const Strides &stride) +{ + std::stringstream str; + str << stride; + return str.str(); +} + /** Formatted output of the TensorShape type. */ inline std::string to_string(const TensorShape &shape) { @@ -513,6 +569,14 @@ inline std::string to_string(const TensorShape &shape) return str.str(); } +/** Formatted output of the Coordinates type. */ +inline std::string to_string(const Coordinates &coord) +{ + std::stringstream str; + str << coord; + return str.str(); +} + /** Formatted output of the Rectangle type. */ inline ::std::ostream &operator<<(::std::ostream &os, const Rectangle &rect) { @@ -546,6 +610,13 @@ inline std::string to_string(const BorderMode &mode) return str.str(); } +inline std::string to_string(const BorderSize &border) +{ + std::stringstream str; + str << border; + return str.str(); +} + inline std::string to_string(const InterpolationPolicy &policy) { std::stringstream str; diff --git a/utils/Utils.h b/utils/Utils.h index 47a352e90..b0e1abeb5 100644 --- a/utils/Utils.h +++ b/utils/Utils.h @@ -86,7 +86,7 @@ std::tuple<unsigned int, unsigned int, int> parse_ppm_header(std::ifstream &fs); * @param[in] blocking Specified if map is blocking or not */ template <typename T> -void map(T &tensor, bool blocking) +inline void map(T &tensor, bool blocking) { ARM_COMPUTE_UNUSED(tensor); ARM_COMPUTE_UNUSED(blocking); @@ -97,7 +97,7 @@ void map(T &tensor, bool blocking) * @param tensor Tensor to be unmapped */ template <typename T> -void unmap(T &tensor) +inline void unmap(T &tensor) { ARM_COMPUTE_UNUSED(tensor); } @@ -108,7 +108,7 @@ void unmap(T &tensor) * @param[in] tensor Tensor to be mapped * @param[in] blocking Specified if map is blocking or not */ -void map(CLTensor &tensor, bool blocking) +inline void map(CLTensor &tensor, bool blocking) { tensor.map(blocking); } @@ -117,7 +117,7 @@ void map(CLTensor &tensor, bool blocking) * * @param tensor Tensor to be unmapped */ -void unmap(CLTensor &tensor) +inline void unmap(CLTensor &tensor) { tensor.unmap(); } |