From eb82fd2aa786715c3b6a941dc6d6deac4ce8e2a0 Mon Sep 17 00:00:00 2001 From: Pablo Tello Date: Fri, 23 Feb 2018 13:43:50 +0000 Subject: COMPMID-881: RSH new arm_gemm interface. Change-Id: I1e2a1a77097d8017c274af3f97eba6964f80f5fa Reviewed-on: https://eu-gerrit-1.euhpc.arm.com/122592 Tested-by: Jenkins Reviewed-by: Anthony Barbier --- .../core/NEON/kernels/assembly/gemm_common.hpp | 79 ++++++++++++++++++++-- 1 file changed, 75 insertions(+), 4 deletions(-) (limited to 'arm_compute/core/NEON/kernels/assembly/gemm_common.hpp') diff --git a/arm_compute/core/NEON/kernels/assembly/gemm_common.hpp b/arm_compute/core/NEON/kernels/assembly/gemm_common.hpp index ef89e3aac3..7f47abcbb9 100644 --- a/arm_compute/core/NEON/kernels/assembly/gemm_common.hpp +++ b/arm_compute/core/NEON/kernels/assembly/gemm_common.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017 ARM Limited. + * Copyright (c) 2017-2018 ARM Limited. * * SPDX-License-Identifier: MIT * @@ -23,11 +23,82 @@ */ #pragma once -// Abstract class for a GEMM function +#include + +namespace arm_gemm { + +// Abstract class for the GEMM/GEMV functions. +// +// GEMM implementations may be "native" (never require any input +// permutation), "pretransposed" (require permutation up-front) or require +// working space (permute as they go along). This interface should support +// all of them. + template class GemmCommon { +protected: + const To *_Aptr=nullptr; + int _lda=0; + const To *_Bptr=nullptr; + int _ldb=0; + Tr *_Cptr=nullptr; + int _ldc=0; + public: - virtual size_t get_working_size() const = 0; - virtual void execute(const To *, const int, const To *, const int, Tr *, const int, const Tr, const Tr, void *working_space) const = 0; + /* Pass in the pointers to the arrays to be operated on and their + * strides. This has a default implementation that just captures them + * all in protected members. If B is pretransposed (see below) then the + * settings for B here are ignored. */ + virtual void set_arrays(const To *A, const int lda, const To *B, const int ldb, Tr *C, const int ldc) { + _Aptr = A; + _lda = lda; + _Bptr = B; + _ldb = ldb; + _Cptr = C; + _ldc = ldc; + } + + /* For threading, we divide the work into some number of units and work + * out internally what unit corresponds to what work. This returns the + * total number of units. */ + virtual unsigned int get_window_size() const = 0; + + /* The maximum thread count is specified when the GEMM is created. Some + * implementations need to know how many threads will actually run in + * order to work properly. + * + * In some cases, after creating the GEMM the number of threads needs to + * be reduced (e.g. not enough work to split across threads). This + * method allows the number of actual threads to be run to be set (must + * be equal or lower). + * + * This has an empty default implementation, as GEMMs which don't care + * about thread count can safely ignore this. + */ + virtual void set_nthreads(int nthreads) { }; + + /* Actually do the work. Provide a threadid to index any per-thread + * buffers, and a start/end range to indicate which work to do. */ + virtual void execute(unsigned int start, unsigned int end, int threadid) = 0; + + /*** Working space interface (optional) ***/ + /* Total number of bytes of temporary working space needed. If zero, it's not necessary to call set_working_space(). */ + virtual size_t get_working_size() const { return 0; } + /* Provide working space buffer - the void * passed in must remain allocated for the duration of any execute calls. */ + virtual void set_working_space(void *) { }; + + /*** "Pretransposed" interface (optional) ***/ + /* Is this object set up for pretranspose? If so, pretranspose_array() needs to be called before execute(); */ + virtual bool B_is_pretransposed() const { return false; } + /* Does pretranspose still need to be done? */ + virtual bool B_pretranspose_required() const { return false; } + /* Total number of bytes of space needed for pretransposed arrays. */ + virtual size_t get_B_pretransposed_array_size() const { return 0; } + /* Perform pretranspose - the void * passed in must remain allocated for the duration of any execute calls. */ + virtual void pretranspose_B_array(void *buffer, const To *, const int) { }; + + // Destructor virtual ~GemmCommon() { } }; + +} // namespace arm_gemm -- cgit v1.2.1