From 5aa1a0b7ca5eed010e4b297a95b1c4851f741328 Mon Sep 17 00:00:00 2001 From: Georgios Pinitas Date: Thu, 2 Jul 2020 20:02:20 +0100 Subject: COMPID-3324: Clean GEMM kernels Signed-off-by: Georgios Pinitas Change-Id: I170de1671e061a78740caee31fb4a1b8642c1369 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3505 Tested-by: Arm Jenkins Comments-Addressed: Arm Jenkins Reviewed-by: Michele Di Giorgio --- src/core/NEON/kernels/assembly/ndrange.hpp | 158 ++++++++++++++++------------- 1 file changed, 86 insertions(+), 72 deletions(-) (limited to 'src/core/NEON/kernels/assembly/ndrange.hpp') diff --git a/src/core/NEON/kernels/assembly/ndrange.hpp b/src/core/NEON/kernels/assembly/ndrange.hpp index d082a3e9b8..86638298ab 100644 --- a/src/core/NEON/kernels/assembly/ndrange.hpp +++ b/src/core/NEON/kernels/assembly/ndrange.hpp @@ -23,104 +23,123 @@ */ #pragma once -#include #include -#include - +#include #include +#include -namespace arm_gemm { - -template -class NDRange { +namespace arm_gemm +{ +template +class NDRange +{ private: - std::array m_sizes {}; - std::array m_totalsizes {}; + std::array m_sizes{}; + std::array m_totalsizes{}; - class NDRangeIterator { + class NDRangeIterator + { private: const NDRange &m_parent; - unsigned int m_pos = 0; - unsigned int m_end = 0; + unsigned int m_pos = 0; + unsigned int m_end = 0; public: - NDRangeIterator(const NDRange &p, unsigned int s, unsigned int e) : m_parent(p), m_pos(s), m_end(e) { } + NDRangeIterator(const NDRange &p, unsigned int s, unsigned int e) + : m_parent(p), m_pos(s), m_end(e) + { + } - bool done() const { + bool done() const + { return (m_pos >= m_end); } - unsigned int dim(unsigned int d) const { + unsigned int dim(unsigned int d) const + { unsigned int r = m_pos; - if (d < (D - 1)) { + if(d < (D - 1)) + { r %= m_parent.m_totalsizes[d]; } - if (d > 0) { - r /= m_parent.m_totalsizes[d-1]; + if(d > 0) + { + r /= m_parent.m_totalsizes[d - 1]; } return r; } - bool next_dim0() { + bool next_dim0() + { m_pos++; return !done(); } - bool next_dim1() { + bool next_dim1() + { m_pos += m_parent.m_sizes[0] - dim(0); return !done(); } - unsigned int dim0_max() const { + unsigned int dim0_max() const + { unsigned int offset = std::min(m_end - m_pos, m_parent.m_sizes[0] - dim(0)); return dim(0) + offset; } }; -public: - NDRange& operator=(const NDRange& rhs)=default; - NDRange(const NDRange& rhs) =default; - - template - NDRange(T... ts) - : m_sizes{ts...} + void set_totalsizes() { - unsigned int t=1; + unsigned int t = 1; + + for(unsigned int i = 0; i < D; i++) + { + if(m_sizes[i] == 0) + { + m_sizes[i] = 1; + } - for (unsigned int i=0; i& n) - : m_sizes(n) - { - unsigned int t=1; +public: + NDRange &operator=(const NDRange &rhs) = default; + NDRange(const NDRange &rhs) = default; - for (unsigned int i=0; i + NDRange(T... ts) + : m_sizes{ ts... } + { + set_totalsizes(); + } - m_totalsizes[i] = t; - } + NDRange(const std::array &n) + : m_sizes(n) + { + set_totalsizes(); } - NDRangeIterator iterator(unsigned int start, unsigned int end) const { + NDRangeIterator iterator(unsigned int start, unsigned int end) const + { return NDRangeIterator(*this, start, end); } - unsigned int total_size() const { + unsigned int total_size() const + { return m_totalsizes[D - 1]; } - unsigned int get_size(unsigned int v) const { + unsigned int get_size(unsigned int v) const + { return m_sizes[v]; } }; @@ -128,58 +147,53 @@ public: /** NDCoordinate builds upon a range, but specifies a starting position * in addition to a size which it inherits from NDRange */ -template -class NDCoordinate : public NDRange { - using int_t =unsigned int; +template +class NDCoordinate : public NDRange +{ + using int_t = unsigned int; using ndrange_t = NDRange; - std::array m_positions {}; + std::array m_positions{}; + public: - NDCoordinate& operator=(const NDCoordinate& rhs)=default; - NDCoordinate(const NDCoordinate& rhs) =default; - NDCoordinate(const std::initializer_list>& list) + NDCoordinate &operator=(const NDCoordinate &rhs) = default; + NDCoordinate(const NDCoordinate &rhs) = default; + NDCoordinate(const std::initializer_list> &list) { std::array sizes{}; std::size_t i = 0; - for(auto& p : list) { - m_positions[i]= p.first; - sizes[i++] = p.second; + for(auto &p : list) + { + m_positions[i] = p.first; + sizes[i++] = p.second; } //update the parents sizes - static_cast(*this) = ndrange_t(sizes); + static_cast(*this) = ndrange_t(sizes); } - int_t get_position(int_t d) const { - assert(d < m_positions.size()); + int_t get_position(int_t d) const + { + assert(d < N); + return m_positions[d]; } - void set_position(int_t d, int_t v) { - assert(d < size(m_positions)); - assert(v < ndrange_t::get_size(d)); + void set_position(int_t d, int_t v) + { + assert(d < N); m_positions[d] = v; } - int_t get_position_end(int_t d) const { - return get_position(d) + NDRange::get_size(d); + int_t get_position_end(int_t d) const + { + return get_position(d) + ndrange_t::get_size(d); } }; //class NDCoordinate -/** @returns the number of dimensions in the NDRange which have none-1 values - * IE there is actual work in these dimensions that can be broken up - */ -template -std::size_t ndrange_popcount(const NDRange& ndr) { - std::size_t count = 0; - - for(unsigned int d = 0; d != N; ++d) { - if(ndr.get_size(d) != 1) - ++count; - } - return count; -} +using ndrange_t = NDRange<6>; +using ndcoord_t = NDCoordinate<6>; } // namespace arm_gemm -- cgit v1.2.1