aboutsummaryrefslogtreecommitdiff
path: root/src/core/NEON/kernels/assembly/ndrange.hpp
diff options
context:
space:
mode:
authorGeorgios Pinitas <georgios.pinitas@arm.com>2020-07-02 20:02:20 +0100
committerGeorgios Pinitas <georgios.pinitas@arm.com>2020-07-06 16:51:32 +0000
commit5aa1a0b7ca5eed010e4b297a95b1c4851f741328 (patch)
treeba882de9e86589dfdd33937d538a89bbdf01c40e /src/core/NEON/kernels/assembly/ndrange.hpp
parent42550c039105597ff6acd4e5efc0ee3c7c20b08e (diff)
downloadComputeLibrary-5aa1a0b7ca5eed010e4b297a95b1c4851f741328.tar.gz
COMPID-3324: Clean GEMM kernels
Signed-off-by: Georgios Pinitas <georgios.pinitas@arm.com> Change-Id: I170de1671e061a78740caee31fb4a1b8642c1369 Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/3505 Tested-by: Arm Jenkins <bsgcomp@arm.com> Comments-Addressed: Arm Jenkins <bsgcomp@arm.com> Reviewed-by: Michele Di Giorgio <michele.digiorgio@arm.com>
Diffstat (limited to 'src/core/NEON/kernels/assembly/ndrange.hpp')
-rw-r--r--src/core/NEON/kernels/assembly/ndrange.hpp158
1 files changed, 86 insertions, 72 deletions
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 <array>
#include <algorithm>
-#include <initializer_list>
-
+#include <array>
#include <cassert>
+#include <initializer_list>
-namespace arm_gemm {
-
-template<unsigned int D>
-class NDRange {
+namespace arm_gemm
+{
+template <unsigned int D>
+class NDRange
+{
private:
- std::array<unsigned int, D> m_sizes {};
- std::array<unsigned int, D> m_totalsizes {};
+ std::array<unsigned int, D> m_sizes{};
+ std::array<unsigned int, D> 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 <typename... T>
- 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<D; i++) {
t *= m_sizes[i];
m_totalsizes[i] = t;
}
}
- NDRange(const std::array<unsigned int, D>& 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<D; i++) {
- t *= m_sizes[i];
+ template <typename... T>
+ NDRange(T... ts)
+ : m_sizes{ ts... }
+ {
+ set_totalsizes();
+ }
- m_totalsizes[i] = t;
- }
+ NDRange(const std::array<unsigned int, D> &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<unsigned int N>
-class NDCoordinate : public NDRange<N> {
- using int_t =unsigned int;
+template <unsigned int N>
+class NDCoordinate : public NDRange<N>
+{
+ using int_t = unsigned int;
using ndrange_t = NDRange<N>;
- std::array<int_t, N> m_positions {};
+ std::array<int_t, N> m_positions{};
+
public:
- NDCoordinate& operator=(const NDCoordinate& rhs)=default;
- NDCoordinate(const NDCoordinate& rhs) =default;
- NDCoordinate(const std::initializer_list<std::pair<int_t, int_t>>& list)
+ NDCoordinate &operator=(const NDCoordinate &rhs) = default;
+ NDCoordinate(const NDCoordinate &rhs) = default;
+ NDCoordinate(const std::initializer_list<std::pair<int_t, int_t>> &list)
{
std::array<int_t, N> 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<ndrange_t&>(*this) = ndrange_t(sizes);
+ static_cast<ndrange_t &>(*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<N>::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<unsigned int N>
-std::size_t ndrange_popcount(const NDRange<N>& 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