diff options
author | Georgios Pinitas <georgios.pinitas@arm.com> | 2017-12-22 15:27:52 +0000 |
---|---|---|
committer | Anthony Barbier <anthony.barbier@arm.com> | 2018-11-02 16:49:16 +0000 |
commit | d8734b55d89f05901ba9a75349761a9c955d9243 (patch) | |
tree | e23d53a0fb73251f7416993e4d3a7241e533e79e /arm_compute/core/utils | |
parent | 7390e05561a5c49306ebbf2eb2dcb1848546f201 (diff) | |
download | ComputeLibrary-d8734b55d89f05901ba9a75349761a9c955d9243.tar.gz |
COMPMID-793 : Add graph intermediate representation
Change-Id: Ic1685de4e19e0ac79669ef2da64e1dc96c7ea0bf
Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/115248
Tested-by: Jenkins <bsgcomp@arm.com>
Reviewed-by: Anthony Barbier <anthony.barbier@arm.com>
Diffstat (limited to 'arm_compute/core/utils')
-rw-r--r-- | arm_compute/core/utils/logging/Types.h | 3 | ||||
-rw-r--r-- | arm_compute/core/utils/misc/CRTP.h | 54 | ||||
-rw-r--r-- | arm_compute/core/utils/misc/Cast.h | 76 | ||||
-rw-r--r-- | arm_compute/core/utils/misc/Iterable.h | 92 | ||||
-rw-r--r-- | arm_compute/core/utils/misc/ShapeCalculator.h | 18 | ||||
-rw-r--r-- | arm_compute/core/utils/misc/Utility.h (renamed from arm_compute/core/utils/misc/utility.h) | 1 | ||||
-rw-r--r-- | arm_compute/core/utils/strong_type/StrongType.h | 77 | ||||
-rw-r--r-- | arm_compute/core/utils/strong_type/StrongTypeAttributes.h | 64 |
8 files changed, 381 insertions, 4 deletions
diff --git a/arm_compute/core/utils/logging/Types.h b/arm_compute/core/utils/logging/Types.h index 171270d4ef..0b40e3d7a1 100644 --- a/arm_compute/core/utils/logging/Types.h +++ b/arm_compute/core/utils/logging/Types.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016, 2017 ARM Limited. + * Copyright (c) 2016-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -36,6 +36,7 @@ enum class LogLevel : unsigned int VERBOSE, /**< All logging messages */ INFO, /**< Information log level */ WARN, /**< Warning log level */ + ERROR, /**< Error log level */ OFF /**< No logging */ }; diff --git a/arm_compute/core/utils/misc/CRTP.h b/arm_compute/core/utils/misc/CRTP.h new file mode 100644 index 0000000000..9947312f95 --- /dev/null +++ b/arm_compute/core/utils/misc/CRTP.h @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2018 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_MISC_CRTP_H__ +#define __ARM_COMPUTE_MISC_CRTP_H__ + +namespace arm_compute +{ +namespace misc +{ +/** Curiously recurring template pattern Interface */ +template <typename T, template <typename> class Type> +struct CRTP +{ +public: + using ExactType = T; + +protected: + const T &impl() const + { + return static_cast<const T &>(*this); + } + T &impl() + { + return static_cast<T &>(*this); + } + +private: + CRTP() = default; + friend Type<T>; +}; +} // namespace misc +} // namespace arm_compute +#endif /* __ARM_COMPUTE_MISC_CRTP_H__ */ diff --git a/arm_compute/core/utils/misc/Cast.h b/arm_compute/core/utils/misc/Cast.h new file mode 100644 index 0000000000..f6c91dd2de --- /dev/null +++ b/arm_compute/core/utils/misc/Cast.h @@ -0,0 +1,76 @@ +/* + * Copyright (c) 2018 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_MISC_CAST_H__ +#define __ARM_COMPUTE_MISC_CAST_H__ + +#include "arm_compute/core/Error.h" + +namespace arm_compute +{ +namespace utils +{ +namespace cast +{ +/** Polymorphic cast between two types + * + * @warning Will throw an exception if cast cannot take place + * + * @tparam Target Target to cast type + * @tparam Source Source from cast type + * + * @param[in] v Value to cast + * + * @return The casted type + */ +template <typename Target, typename Source> +inline Target polymorphic_cast(Source *v) +{ + if(dynamic_cast<Target>(v) == nullptr) + { + throw std::bad_cast(); + } + return static_cast<Target>(v); +} + +/** Polymorphic down cast between two types + * + * @warning Will assert if cannot take place + * + * @tparam Target Target to cast type + * @tparam Source Source from cast type + * + * @param[in] v Value to cast + * + * @return The casted type + */ +template <typename Target, typename Source> +inline Target polymorphic_downcast(Source *v) +{ + ARM_COMPUTE_ERROR_ON(dynamic_cast<Target>(v) != static_cast<Target>(v)); + return static_cast<Target>(v); +} +} // namespace cast +} // namespace utils +} // namespace arm_compute +#endif /* __ARM_COMPUTE_MISC_CAST_H__ */ diff --git a/arm_compute/core/utils/misc/Iterable.h b/arm_compute/core/utils/misc/Iterable.h new file mode 100644 index 0000000000..96a650af35 --- /dev/null +++ b/arm_compute/core/utils/misc/Iterable.h @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2018 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_MISC_ITERABLE_H__ +#define __ARM_COMPUTE_MISC_ITERABLE_H__ + +#include <iterator> + +namespace arm_compute +{ +namespace utils +{ +namespace iterable +{ +/** Reverse range iterable class + * + * @tparam T Type to create a reverse range on + */ +template <typename T> +class reverse_iterable +{ +public: + /** Default constructor + * + * @param[in] it Value to reverse iterate on + */ + explicit reverse_iterable(T &it) + : _it(it) + { + } + + typename T::reverse_iterator begin() + { + return _it.rbegin(); + } + + typename T::reverse_iterator end() + { + return _it.rend(); + } + + typename T::const_reverse_iterator cbegin() + { + return _it.rbegin(); + } + + typename T::const_reverse_iterator cend() + { + return _it.rend(); + } + +private: + T &_it; +}; + +/** Creates a reverse iterable for a given type + * + * @tparam T Type to create a reverse iterable on + * + * @param[in] val Iterable input + * + * @return Reverse iterable container + */ +template <typename T> +reverse_iterable<T> reverse_iterate(T &val) +{ + return reverse_iterable<T>(val); +} +} // namespace iterable +} // namespace utils +} // namespace arm_compute +#endif /* __ARM_COMPUTE_MISC_ITERABLE_H__ */ diff --git a/arm_compute/core/utils/misc/ShapeCalculator.h b/arm_compute/core/utils/misc/ShapeCalculator.h index 2919625511..354f60d016 100644 --- a/arm_compute/core/utils/misc/ShapeCalculator.h +++ b/arm_compute/core/utils/misc/ShapeCalculator.h @@ -174,7 +174,6 @@ inline TensorShape compute_interleave_custom_shape(const TensorShape &input, con return output_shape; } - inline TensorShape compute_fully_connected_reshaped_weights_shape(const ITensorInfo *input, bool transpose_weights, bool is_batched_fc_layer, const int interleave) { TensorShape output_shape{ input->tensor_shape() }; @@ -194,7 +193,6 @@ inline TensorShape compute_fully_connected_reshaped_weights_shape(const ITensorI return output_shape; } - inline TensorShape compute_winograd_input_transform_shape(const ITensorInfo &input, const PadStrideInfo &conv_info, const Size2D &kernel_size) { // Compute height @@ -212,6 +210,22 @@ inline TensorShape compute_winograd_input_transform_shape(const ITensorInfo &inp return output_shape; } +inline TensorShape compute_deep_convolution_shape(const ITensorInfo &input, const ITensorInfo &weights, PadStrideInfo conv_info) +{ + const TensorShape input_shape{ input.tensor_shape() }; + const TensorShape weights_shape{ weights.tensor_shape() }; + + unsigned int output_width = 0; + unsigned int output_height = 0; + std::tie(output_width, output_height) = scaled_dimensions(input_shape.x(), input_shape.y(), weights_shape.x(), weights_shape.y(), conv_info); + + TensorShape output_shape{ input_shape }; + output_shape.set(0, output_width); + output_shape.set(1, output_height); + output_shape.set(2, weights_shape[3]); + + return output_shape; +} } // namespace shape_calculator } // namespace misc } // namespace arm_compute diff --git a/arm_compute/core/utils/misc/utility.h b/arm_compute/core/utils/misc/Utility.h index 8ba92310da..639f2e155d 100644 --- a/arm_compute/core/utils/misc/utility.h +++ b/arm_compute/core/utils/misc/Utility.h @@ -164,7 +164,6 @@ std::vector<size_t> sort_indices(const std::vector<T> &v) return idx; } - } // namespace utility } // namespace arm_compute #endif /* __ARM_COMPUTE_MISC_UTILITY_H__ */ diff --git a/arm_compute/core/utils/strong_type/StrongType.h b/arm_compute/core/utils/strong_type/StrongType.h new file mode 100644 index 0000000000..5a38edbbd6 --- /dev/null +++ b/arm_compute/core/utils/strong_type/StrongType.h @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2018 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_STRONG_TYPE_STRONG_TYPE_H__ +#define __ARM_COMPUTE_STRONG_TYPE_STRONG_TYPE_H__ + +#include <type_traits> + +namespace arm_compute +{ +namespace strong_type +{ +/** Strong type + * + * @tparam T Exact type of the Strong Type + * @tparam Tag Tag used to distinguish between types with same T + * @tparam Attributes Attributes of the Strong Type + */ +template <typename T, typename Tag, template <typename> class... Attributes> +class StrongType : public Attributes<StrongType<T, Tag, Attributes...>>... +{ +public: + /** Exact underlying type **/ + using ExactType = T; + +public: + /** Default Constructor + * + * @param[in] val Initialization value + */ + StrongType(T val) + : _val(val) + { + } + /** Accessor of the value of the exact type + * + * @return Exact type value + */ + T &get() + { + return _val; + } + /** Accessor of the value of the exact type + * + * @return Exact type value + */ + const T &get() const + { + return _val; + } + +private: + T _val = {}; +}; +} // namespace strong_type +} // namespace arm_compute +#endif /* __ARM_COMPUTE_STRONG_TYPE_STRONG_TYPE_H__ */ diff --git a/arm_compute/core/utils/strong_type/StrongTypeAttributes.h b/arm_compute/core/utils/strong_type/StrongTypeAttributes.h new file mode 100644 index 0000000000..b5ed48f5ce --- /dev/null +++ b/arm_compute/core/utils/strong_type/StrongTypeAttributes.h @@ -0,0 +1,64 @@ +/* + * Copyright (c) 2018 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_STRONG_TYPE_STRONG_TYPE_ATTRIBUTES_H__ +#define __ARM_COMPUTE_STRONG_TYPE_STRONG_TYPE_ATTRIBUTES_H__ + +#include "arm_compute/core/utils/misc/CRTP.h" + +namespace arm_compute +{ +namespace strong_type +{ +/** Comparable attribute */ +template <typename T> +struct Comparable : misc::CRTP<T, Comparable> +{ + bool operator==(T const &other) const + { + return this->impl().get() == other.get(); + } + bool operator!=(T const &other) const + { + return !(*this == other); + } + bool operator>(T const &other) const + { + return this->impl().get() > other.get(); + } + bool operator<(T const &other) const + { + return this->impl().get() < other.get(); + } + bool operator>=(T const &other) const + { + return !(*this < other); + } + bool operator<=(T const &other) const + { + return !(*this > other); + } +}; +} // namespace strong_type +} // namespace arm_compute +#endif /* __ARM_COMPUTE_STRONG_TYPE_STRONG_TYPE_ATTRIBUTES_H__ */ |