From 6f8b17dedb7b53b550e6210fd1c78c3a3e086271 Mon Sep 17 00:00:00 2001 From: Joseph Dobson Date: Tue, 11 Feb 2020 19:32:11 +0000 Subject: [ONCPUML-7] arm_compute support for ND parallelism Currently 1D ranges of work are specified by the scheduler via two integers, start and end. This limit opportunities for advance parallelism and scheduling This patch expands the interfaces to allow for ND parallism. `GemmCommon::get_window_size` now returns an `NDRange` specifying the work in N-dimensions rather than with the single integer it used prior (1D) Execute now takes an `NDCoordinate` which specifies an `NDRange` with a start position for that work along with an `NDCoordinate` to specify the thread location In addition to expanding the interface to enable this functionality, we have added the capability to SGEMM when the number of threads is high this has the effective of allowing a much greater degree of parallelism where te problem dimension would previously have limited the number of threads. Change-Id: I3e1a8b7276216627bec4ff6f24ac2147552ea9fb Signed-off-by: Joseph Dobson Reviewed-on: https://review.mlplatform.org/c/ml/ComputeLibrary/+/2962 Tested-by: Arm Jenkins Reviewed-by: Gian Marco Iodice Comments-Addressed: Arm Jenkins --- src/core/NEON/kernels/arm_gemm/ndrange.hpp | 85 ++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 4 deletions(-) (limited to 'src/core/NEON/kernels/arm_gemm/ndrange.hpp') diff --git a/src/core/NEON/kernels/arm_gemm/ndrange.hpp b/src/core/NEON/kernels/arm_gemm/ndrange.hpp index 20824dfc8b..0c068db011 100644 --- a/src/core/NEON/kernels/arm_gemm/ndrange.hpp +++ b/src/core/NEON/kernels/arm_gemm/ndrange.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019 Arm Limited. + * Copyright (c) 2019-2020 Arm Limited. * * SPDX-License-Identifier: MIT * @@ -23,16 +23,19 @@ */ #pragma once +#include #include #include +#include + namespace arm_gemm { template class NDRange { private: - unsigned int m_sizes[D]; - unsigned int m_totalsizes[D]; + std::array m_sizes {}; + std::array m_totalsizes {}; class NDRangeIterator { private: @@ -81,8 +84,25 @@ private: }; public: + NDRange& operator=(const NDRange& rhs)=default; + NDRange(const NDRange& rhs) =default; + template - NDRange(T... ts) : m_sizes{ts...} { + NDRange(T... ts) + : m_sizes{ts...} + { + unsigned int t=1; + + for (unsigned int i=0; i& n) + : m_sizes{n} + { unsigned int t=1; for (unsigned int i=0; i +class NDCoordinate : public NDRange { + using int_t =unsigned int; + using ndrange_t = NDRange; + + std::array m_positions {}; +public: + 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; + } + + //update the parents sizes + static_cast(*this) = ndrange_t(sizes); + } + + int_t get_position(int_t d) const { + assert(d < m_positions.size()); + 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)); + + m_positions[d] = v; + } + + int_t get_position_end(int_t d) const { + return get_position(d) + NDRange::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; +} + } // namespace arm_gemm -- cgit v1.2.1