diff options
author | Felix Thomasmathibalan <felixjohnny.thomasmathibalan@arm.com> | 2023-09-27 17:46:17 +0100 |
---|---|---|
committer | felixjohnny.thomasmathibalan <felixjohnny.thomasmathibalan@arm.com> | 2023-09-28 12:08:05 +0000 |
commit | afd38f0c617d6f89b2b4532c6c44f116617e2b6f (patch) | |
tree | 03bc7d5a762099989b16a656fa8d397b490ed70e /support | |
parent | bdcb4c148ee2fdeaaddf4cf1e57bbb0de02bb894 (diff) | |
download | ComputeLibrary-afd38f0c617d6f89b2b4532c6c44f116617e2b6f.tar.gz |
Apply clang-format on repository
Code is formatted as per a revised clang format configuration
file(not part of this delivery). Version 14.0.6 is used.
Exclusion List:
- files with .cl extension
- files that are not strictly C/C++ (e.g. Android.bp, Sconscript ...)
And the following directories
- compute_kernel_writer/validation/
- tests/
- include/
- src/core/NEON/kernels/convolution/
- src/core/NEON/kernels/arm_gemm/
- src/core/NEON/kernels/arm_conv/
- data/
There will be a follow up for formatting of .cl files and the
files under tests/ and compute_kernel_writer/validation/.
Signed-off-by: Felix Thomasmathibalan <felixjohnny.thomasmathibalan@arm.com>
Change-Id: Ib7eb1fcf4e7537b9feaefcfc15098a804a3fde0a
Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/10391
Benchmark: Arm Jenkins <bsgcomp@arm.com>
Tested-by: Arm Jenkins <bsgcomp@arm.com>
Reviewed-by: Gunes Bayir <gunes.bayir@arm.com>
Diffstat (limited to 'support')
-rw-r--r-- | support/Bfloat16.h | 23 | ||||
-rw-r--r-- | support/Cast.h | 4 | ||||
-rw-r--r-- | support/DeepCopy.h | 56 | ||||
-rw-r--r-- | support/Half.h | 4 | ||||
-rw-r--r-- | support/Iterable.h | 3 | ||||
-rw-r--r-- | support/Mutex.h | 20 | ||||
-rw-r--r-- | support/Random.h | 7 | ||||
-rw-r--r-- | support/Rounding.h | 7 | ||||
-rw-r--r-- | support/SaturateCast.h | 1 | ||||
-rw-r--r-- | support/Semaphore.h | 16 | ||||
-rw-r--r-- | support/StringSupport.h | 14 | ||||
-rw-r--r-- | support/ToolchainSupport.h | 26 |
12 files changed, 81 insertions, 100 deletions
diff --git a/support/Bfloat16.h b/support/Bfloat16.h index e67c729a6c..17013294e2 100644 --- a/support/Bfloat16.h +++ b/support/Bfloat16.h @@ -43,18 +43,17 @@ inline uint16_t float_to_bf16(const float v) #if defined(ARM_COMPUTE_ENABLE_BF16) uint16_t res; - __asm __volatile( - "ldr s0, [%[fromptr]]\n" - ".inst 0x1e634000\n" // BFCVT h0, s0 - "str h0, [%[toptr]]\n" - : - : [fromptr] "r"(fromptr), [toptr] "r"(&res) - : "v0", "memory"); + __asm __volatile("ldr s0, [%[fromptr]]\n" + ".inst 0x1e634000\n" // BFCVT h0, s0 + "str h0, [%[toptr]]\n" + : + : [fromptr] "r"(fromptr), [toptr] "r"(&res) + : "v0", "memory"); #else /* defined(ARM_COMPUTE_ENABLE_BF16) */ uint16_t res = (*fromptr >> 16); const uint16_t error = (*fromptr & 0x0000ffff); uint16_t bf_l = res & 0x0001; - if((error > 0x8000) || ((error == 0x8000) && (bf_l != 0))) + if ((error > 0x8000) || ((error == 0x8000) && (bf_l != 0))) { res += 1; } @@ -75,23 +74,21 @@ inline float bf16_to_float(const uint16_t &v) memcpy(&fp, &lv, sizeof(lv)); return fp; } -} +} // namespace /** Brain floating point representation class */ class bfloat16 final { public: /** Default Constructor */ - bfloat16() - : value(0) + bfloat16() : value(0) { } /** Constructor * * @param[in] v Floating-point value */ - bfloat16(float v) - : value(float_to_bf16(v)) + bfloat16(float v) : value(float_to_bf16(v)) { } /** Assignment operator diff --git a/support/Cast.h b/support/Cast.h index 53d5f68065..5fd763690b 100644 --- a/support/Cast.h +++ b/support/Cast.h @@ -46,7 +46,7 @@ namespace cast template <typename Target, typename Source> inline Target polymorphic_cast(Source *v) { - if(dynamic_cast<Target>(v) == nullptr) + if (dynamic_cast<Target>(v) == nullptr) { ARM_COMPUTE_THROW(std::bad_cast()); } @@ -86,7 +86,7 @@ inline Target polymorphic_downcast(Source *v) template <typename Target, typename Source, typename Deleter> std::unique_ptr<Target, Deleter> polymorphic_cast_unique_ptr(std::unique_ptr<Source, Deleter> &&v) { - if(dynamic_cast<Target *>(v.get()) == nullptr) + if (dynamic_cast<Target *>(v.get()) == nullptr) { ARM_COMPUTE_THROW(std::bad_cast()); } diff --git a/support/DeepCopy.h b/support/DeepCopy.h index 0117897901..c0279284c0 100644 --- a/support/DeepCopy.h +++ b/support/DeepCopy.h @@ -40,9 +40,8 @@ namespace template <typename Base, typename Derived> Base *default_polymorphic_copy(const Base *ptr) { - static_assert(std::is_base_of<Base, Derived>::value, - "Derived is not a specialization of Base"); - if(ptr == nullptr) + static_assert(std::is_base_of<Base, Derived>::value, "Derived is not a specialization of Base"); + if (ptr == nullptr) { return nullptr; } @@ -62,25 +61,18 @@ class deep_unique_ptr public: using CopyFunc = std::function<Base *(const Base *)>; - deep_unique_ptr(std::nullptr_t val = nullptr) noexcept - : _val{ val }, - _copy{} + deep_unique_ptr(std::nullptr_t val = nullptr) noexcept : _val{val}, _copy{} { } template <typename Derived, typename CopyFuncDerived> - deep_unique_ptr(Derived *value, const CopyFuncDerived ©) noexcept - : _val{ value }, - _copy{ std::move(copy) } + deep_unique_ptr(Derived *value, const CopyFuncDerived ©) noexcept : _val{value}, _copy{std::move(copy)} { - static_assert(std::is_base_of<Base, Derived>::value, - "Derived is not a specialization of Base"); - static_assert( - std::is_constructible<CopyFunc, CopyFuncDerived>::value, - "CopyFuncDerived is not valid for a copy functor"); + static_assert(std::is_base_of<Base, Derived>::value, "Derived is not a specialization of Base"); + static_assert(std::is_constructible<CopyFunc, CopyFuncDerived>::value, + "CopyFuncDerived is not valid for a copy functor"); } - deep_unique_ptr(const deep_unique_ptr<Base> &ptr) - : deep_unique_ptr(ptr.clone()) + deep_unique_ptr(const deep_unique_ptr<Base> &ptr) : deep_unique_ptr(ptr.clone()) { } deep_unique_ptr &operator=(const deep_unique_ptr<Base> &ptr) @@ -90,7 +82,7 @@ public: return *this; } - deep_unique_ptr(deep_unique_ptr<Base> &&ptr) = default; + deep_unique_ptr(deep_unique_ptr<Base> &&ptr) = default; deep_unique_ptr &operator=(deep_unique_ptr<Base> &&ptr) = default; ~deep_unique_ptr() = default; friend void swap(deep_unique_ptr &ptr0, deep_unique_ptr<Base> &ptr1) noexcept @@ -135,11 +127,11 @@ public: bool operator==(const deep_unique_ptr<Base> &rhs) const { - if(rhs.get() == nullptr && _val == nullptr) + if (rhs.get() == nullptr && _val == nullptr) { return true; } - else if(rhs.get() == nullptr || _val == nullptr) + else if (rhs.get() == nullptr || _val == nullptr) { return false; } @@ -152,9 +144,9 @@ public: private: deep_unique_ptr clone() const { - return { _copy(_val.get()), CopyFunc(_copy) }; + return {_copy(_val.get()), CopyFunc(_copy)}; } - std::unique_ptr<Base> _val{ nullptr }; + std::unique_ptr<Base> _val{nullptr}; CopyFunc _copy{}; }; @@ -170,34 +162,26 @@ private: template <typename Base, typename Derived, typename CopyFunc> deep_unique_ptr<Base> make_deep_unique(Derived &&temp, CopyFunc copy) { - return - { - new Derived(std::move(temp)), - CopyFunc{ std::move(copy) } - }; + return {new Derived(std::move(temp)), CopyFunc{std::move(copy)}}; } template <typename Base, typename Derived> deep_unique_ptr<Base> make_deep_unique(Derived &&temp) { - static_assert(std::is_base_of<Base, Derived>::value, - "Derived is not a specialization of Base"); + static_assert(std::is_base_of<Base, Derived>::value, "Derived is not a specialization of Base"); - return make_deep_unique<Base, Derived>( - std::move(temp), default_polymorphic_copy<Base, Derived>); + return make_deep_unique<Base, Derived>(std::move(temp), default_polymorphic_copy<Base, Derived>); } template <typename Base, typename Derived, typename... Args> -deep_unique_ptr<Base> make_deep_unique(Args &&... args) +deep_unique_ptr<Base> make_deep_unique(Args &&...args) { - static_assert(std::is_constructible<Derived, Args...>::value, - "Cannot instantiate Derived from arguments"); + static_assert(std::is_constructible<Derived, Args...>::value, "Cannot instantiate Derived from arguments"); - return make_deep_unique<Base, Derived>( - std::move(Derived{ std::forward<Args>(args)... })); + return make_deep_unique<Base, Derived>(std::move(Derived{std::forward<Args>(args)...})); } } // namespace memory } // namespace utils } // namespace arm_compute -#endif // ARM_COMPUTE_MISC_ITERABLE_H
\ No newline at end of file +#endif // ARM_COMPUTE_MISC_ITERABLE_H diff --git a/support/Half.h b/support/Half.h index 081da5ebc1..f5c27da2d3 100644 --- a/support/Half.h +++ b/support/Half.h @@ -24,12 +24,12 @@ #ifndef __ARM_COMPUTE_HALF_H__ #define __ARM_COMPUTE_HALF_H__ -#if(BARE_METAL) +#if (BARE_METAL) #define HALF_ENABLE_CPP11_CMATH 0 #endif /* BARE_METAL */ // Set style to round to nearest -#define HALF_ROUND_STYLE 1 +#define HALF_ROUND_STYLE 1 #define HALF_ROUND_TIES_TO_EVEN 1 #include "half/half.hpp" diff --git a/support/Iterable.h b/support/Iterable.h index a0bafaf4ce..8d99e70196 100644 --- a/support/Iterable.h +++ b/support/Iterable.h @@ -44,8 +44,7 @@ public: * * @param[in] it Value to reverse iterate on */ - explicit reverse_iterable(T &it) - : _it(it) + explicit reverse_iterable(T &it) : _it(it) { } diff --git a/support/Mutex.h b/support/Mutex.h index 6e68fa5248..9c2b55c3ac 100644 --- a/support/Mutex.h +++ b/support/Mutex.h @@ -50,10 +50,10 @@ public: ~Mutex() = default; /** Lock */ - void lock() {}; + void lock(){}; /** Unlock */ - void unlock() {}; + void unlock(){}; /** Try the lock. * @@ -73,8 +73,7 @@ public: typedef Mutex mutex_type; public: - explicit lock_guard(Mutex &m_) - : m(m_) + explicit lock_guard(Mutex &m_) : m(m_) { } ~lock_guard() @@ -97,15 +96,14 @@ public: unique_lock() noexcept : m(nullptr) { } - explicit unique_lock(mutex_type &m) - : m(&m) + explicit unique_lock(mutex_type &m) : m(&m) { } - unique_lock(const unique_lock &) = delete; - unique_lock(unique_lock &&) = default; + unique_lock(const unique_lock &) = delete; + unique_lock(unique_lock &&) = default; unique_lock &operator=(const unique_lock &) = delete; - unique_lock &operator=(unique_lock &&) = default; - ~unique_lock() = default; + unique_lock &operator=(unique_lock &&) = default; + ~unique_lock() = default; void lock() { } @@ -121,5 +119,5 @@ private: mutex_type *m; }; #endif /* NO_MULTI_THREADING */ -} +} // namespace arm_compute #endif /* __ARM_COMPUTE_MUTEX_H__ */ diff --git a/support/Random.h b/support/Random.h index 7658e6d529..1a804d3290 100644 --- a/support/Random.h +++ b/support/Random.h @@ -25,6 +25,7 @@ #define ARM_COMPUTE_MISC_RANDOM_H #include "arm_compute/core/Error.h" + #include "utils/Utils.h" #include <random> @@ -47,7 +48,9 @@ public: static constexpr bool is_fp_16bit = std::is_same<T, half>::value || std::is_same<T, bfloat16>::value; static constexpr bool is_integral = std::is_integral<T>::value && !is_fp_16bit; - using fp_dist = typename std::conditional<is_fp_16bit, arm_compute::utils::uniform_real_distribution_16bit<T>, std::uniform_real_distribution<T>>::type; + using fp_dist = typename std::conditional<is_fp_16bit, + arm_compute::utils::uniform_real_distribution_16bit<T>, + std::uniform_real_distribution<T>>::type; using DT = typename std::conditional<is_integral, std::uniform_int_distribution<T>, fp_dist>::type; using result_type = T; using range_pair = std::pair<result_type, result_type>; @@ -62,7 +65,7 @@ public: : _distributions(), _selector() { result_type clow = low; - for(const auto &erange : exclude_ranges) + for (const auto &erange : exclude_ranges) { result_type epsilon = is_integral ? result_type(1) : result_type(std::numeric_limits<T>::epsilon()); diff --git a/support/Rounding.h b/support/Rounding.h index e2732dc459..5691a6680b 100644 --- a/support/Rounding.h +++ b/support/Rounding.h @@ -26,6 +26,7 @@ #include "arm_compute/core/Error.h" #include "arm_compute/core/utils/misc/Traits.h" + #include "support/AclRequires.h" #include "support/ToolchainSupport.h" @@ -153,10 +154,10 @@ inline T round_half_even(T value, T epsilon = std::numeric_limits<T>::epsilon()) T ipart = 0; std::modf(positive_value, &ipart); // If 'value' is exactly halfway between two integers - if(std::abs(positive_value - (ipart + 0.5f)) < epsilon) + if (std::abs(positive_value - (ipart + 0.5f)) < epsilon) { // If 'ipart' is even then return 'ipart' - if(std::fmod(ipart, 2.f) < epsilon) + if (std::fmod(ipart, 2.f) < epsilon) { return support::cpp11::copysign(ipart, value); } @@ -179,7 +180,7 @@ inline T round_half_even(T value, T epsilon = std::numeric_limits<T>::epsilon()) template <typename T, ARM_COMPUTE_REQUIRES_TA(traits::is_floating_point<T>::value)> inline T round(T value, RoundingMode rounding_mode) { - switch(rounding_mode) + switch (rounding_mode) { case RoundingMode::TO_ZERO: return round_to_zero(value); diff --git a/support/SaturateCast.h b/support/SaturateCast.h index a9982d8e96..7af9f983ed 100644 --- a/support/SaturateCast.h +++ b/support/SaturateCast.h @@ -26,6 +26,7 @@ #include "arm_compute/core/utils/misc/Traits.h" #include "arm_compute/core/utils/misc/Utility.h" + #include "support/Rounding.h" namespace arm_compute diff --git a/support/Semaphore.h b/support/Semaphore.h index e182b53a2d..f44179332b 100644 --- a/support/Semaphore.h +++ b/support/Semaphore.h @@ -24,8 +24,9 @@ #ifndef __ARM_COMPUTE_UTILS_SEMAMPHORE_H__ #define __ARM_COMPUTE_UTILS_SEMAMPHORE_H__ -#include "Mutex.h" #include "support/Mutex.h" + +#include "Mutex.h" #include <condition_variable> namespace arm_compute @@ -39,8 +40,7 @@ public: * * @param[in] value Semaphore initial value */ - Semaphore(int value = 0) - : _value(value), _m(), _cv() + Semaphore(int value = 0) : _value(value), _m(), _cv() { } /** Signals a semaphore */ @@ -56,10 +56,7 @@ public: inline void wait() { std::unique_lock<std::mutex> lock(_m); - _cv.wait(lock, [this]() - { - return _value > 0; - }); + _cv.wait(lock, [this]() { return _value > 0; }); --_value; } @@ -73,8 +70,7 @@ private: class Semaphore { public: - Semaphore(int value = 0) - : _value(value) + Semaphore(int value = 0) : _value(value) { (void)_value; } @@ -93,5 +89,5 @@ private: int _value; }; #endif /* NO_MULTI_THREADING */ -} // arm_compute +} // namespace arm_compute #endif /* __ARM_COMPUTE_UTILS_SEMAMPHORE_H__ */ diff --git a/support/StringSupport.h b/support/StringSupport.h index e8b3ca7ab3..7d1b5e7778 100644 --- a/support/StringSupport.h +++ b/support/StringSupport.h @@ -57,14 +57,14 @@ inline int stoi(const std::string &str, std::size_t *pos = 0, NumericBase base = assert(base == NumericBase::BASE_10 || base == NumericBase::BASE_16); unsigned int x; std::stringstream ss; - if(base == NumericBase::BASE_16) + if (base == NumericBase::BASE_16) { ss << std::hex; } ss << str; ss >> x; - if(pos) + if (pos) { std::string s; std::stringstream ss_p; @@ -93,14 +93,14 @@ inline unsigned long stoul(const std::string &str, std::size_t *pos = 0, Numeric assert(base == NumericBase::BASE_10 || base == NumericBase::BASE_16); std::stringstream stream; unsigned long value = 0; - if(base == NumericBase::BASE_16) + if (base == NumericBase::BASE_16) { stream << std::hex; } stream << str; stream >> value; - if(pos) + if (pos) { std::string s; std::stringstream ss_p; @@ -113,7 +113,7 @@ inline unsigned long stoul(const std::string &str, std::size_t *pos = 0, Numeric return value; } -#if(__ANDROID__ || BARE_METAL) +#if (__ANDROID__ || BARE_METAL) /** Convert integer and float values to string. * * @note This function implements the same behaviour as std::to_string. The @@ -124,7 +124,7 @@ inline unsigned long stoul(const std::string &str, std::size_t *pos = 0, Numeric * @return String representation of @p value. */ template <typename T, typename std::enable_if<std::is_arithmetic<typename std::decay<T>::type>::value, int>::type = 0> -inline std::string to_string(T && value) +inline std::string to_string(T &&value) { std::stringstream stream; stream << std::forward<T>(value); @@ -186,7 +186,7 @@ inline std::string to_string(const std::string &value) * @return Float representation of input string. */ template <typename... Ts> -int stof(Ts &&... args) +int stof(Ts &&...args) { return ::std::stof(std::forward<Ts>(args)...); } diff --git a/support/ToolchainSupport.h b/support/ToolchainSupport.h index 96826dad5e..4d394889c3 100644 --- a/support/ToolchainSupport.h +++ b/support/ToolchainSupport.h @@ -24,6 +24,9 @@ #ifndef ARM_COMPUTE_SUPPORT_TOOLCHAINSUPPORT #define ARM_COMPUTE_SUPPORT_TOOLCHAINSUPPORT +#include "support/Bfloat16.h" +#include "support/Half.h" + #include <cassert> #include <cmath> #include <cstddef> @@ -33,9 +36,6 @@ #include <string> #include <type_traits> -#include "support/Bfloat16.h" -#include "support/Half.h" - #ifndef M_PI #define M_PI (3.14159265358979323846) #endif // M_PI @@ -50,7 +50,7 @@ namespace support { namespace cpp11 { -#if(__ANDROID__ || BARE_METAL) +#if (__ANDROID__ || BARE_METAL) template <typename T> inline T nearbyint(T value) { @@ -129,11 +129,12 @@ inline T copysign(T x, T y) * * @return Result floating point value equal to (x*y) + z.c */ -template < typename T, typename = typename std::enable_if < std::is_floating_point<T>::value +template <typename T, + typename = typename std::enable_if<std::is_floating_point<T>::value #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC - || std::is_same<T, float16_t>::value + || std::is_same<T, float16_t>::value #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC - >::type > + >::type> inline T fma(T x, T y, T z) { return ::fma(x, y, z); @@ -151,7 +152,7 @@ inline T fma(T x, T y, T z) * if successful (not including the ending null character), or a negative value if an error occurred. */ template <typename... Ts> -inline int snprintf(char *s, size_t n, const char *fmt, Ts &&... args) +inline int snprintf(char *s, size_t n, const char *fmt, Ts &&...args) { return ::snprintf(s, n, fmt, std::forward<Ts>(args)...); } @@ -244,11 +245,12 @@ inline T copysign(T x, T y) * * @return Result floating point value equal to (x*y) + z. */ -template < typename T, typename = typename std::enable_if < std::is_floating_point<T>::value +template <typename T, + typename = typename std::enable_if<std::is_floating_point<T>::value #ifdef __ARM_FEATURE_FP16_VECTOR_ARITHMETIC - || std::is_same<T, float16_t>::value + || std::is_same<T, float16_t>::value #endif // __ARM_FEATURE_FP16_VECTOR_ARITHMETIC - >::type > + >::type> inline T fma(T x, T y, T z) { return std::fma(x, y, z); @@ -266,7 +268,7 @@ inline T fma(T x, T y, T z) * if successful (not including the ending null character), or a negative value if an error occurred. */ template <typename... Ts> -inline int snprintf(char *s, std::size_t n, const char *fmt, Ts &&... args) +inline int snprintf(char *s, std::size_t n, const char *fmt, Ts &&...args) { return std::snprintf(s, n, fmt, std::forward<Ts>(args)...); } |