Show
Ignore:
Timestamp:
06/03/08 21:24:57 (6 months ago)
Author:
pernet
Message:

* Change the design of fflas-bounds
* Modular<double> -> ModularBalanced?<double>
* Fix the winograd recursion issue (when some steps are done over the field)
* Fix a bunch of bugs
* Remove the template specialization by the Element (incompatible with the soon coming compressed representations over small fields)
* Create a randiter file, generic wrt the modular field

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • include/fflas-ffpack/fflas.h

    r59 r62  
    2424#include "linbox/config-blas.h" 
    2525#include "linbox/field/unparametric.h" 
    26  
     26#include "linbox/field/modular-double.h" 
     27#include "linbox/field/modular-float.h" 
    2728namespace LinBox { 
    2829#else 
    2930#include "config-blas.h" 
    30 #include "unparametric.h" 
     31#include "fflas-ffpack/unparametric.h" 
     32#include "fflas-ffpack/modular-positive.h" 
     33#include "fflas-ffpack/modular-balanced.h" 
    3134#endif 
    3235         
    3336#ifndef __LINBOX_STRASSEN_OPTIMIZATION 
    34 #define WINOTHRESHOLD 1000 
     37#define WINOTHRESHOLD 2000 
    3538#else 
    3639#define WINOTHRESHOLD __LINBOX_WINOTHRESHOLD 
     
    5861         * FflasDouble: to use the double precision BLAS 
    5962         * FflasFloat: to use the single precison BLAS 
    60          * FflasFloat: for any other domain, that can not be converted to floating point integers 
     63         * FflasGeneric: for any other domain, that can not be converted to floating point integers 
    6164         */ 
    6265        enum FFLAS_BASE      { FflasDouble = 151, FflasFloat = 152, FflasGeneric = 153}; 
     
    238241 
    239242                if (!(m && n && k)) return C; 
    240                  
    241                 FFLAS_BASE base = BaseCompute<typename Field::Element> ()(F, w); 
    242                 size_t d = DotProdBound (F, w, beta, base); 
    243                 //std::cerr<<"d = "<<d<<std::endl; 
     243 
     244                if (F.isZero (alpha)){ 
     245                        for (size_t i = 0; i<m; ++i) 
     246                                fscal(F, n, beta, C + i*ldc, 1); 
     247                        return C; 
     248                } 
     249                 
     250                size_t kmax = 0; 
     251                size_t winolevel = w; 
     252                FFLAS_BASE base; 
     253                MatMulParameters (F, MIN(MIN(m,n),k), beta, kmax, base, 
     254                                  winolevel, true); 
    244255                WinoMain (F, ta, tb, m, n, k, alpha, A, lda, B, ldb, beta, 
    245                                  C, ldc, d, w, base); 
     256                                 C, ldc, kmax, winolevel, base); 
    246257                return C; 
    247258                }; 
     
    262273               const size_t k, 
    263274               const typename Field::Element alpha, 
    264                const typename Field::Element* A,  
    265                const size_t lda, 
    266                const typename Field::Element* B, 
    267                const size_t ldb,  
     275               const typename Field::Element* A, const size_t lda, 
     276               const typename Field::Element* B, const size_t ldb,  
    268277               const typename Field::Element beta, 
    269                typename Field::Element* C,  
    270                const size_t ldc){ 
     278               typename Field::Element* C, const size_t ldc){ 
    271279 
    272280                if (!(m && n && k)) return C; 
    273  
    274                 size_t w, kmax=0; 
     281                if (F.isZero (alpha)){ 
     282                        for (size_t i = 0; i<m; ++i) 
     283                                fscal(F, n, beta, C + i*ldc, 1); 
     284                        return C; 
     285                } 
     286                 
     287                size_t w, kmax; 
    275288                FFLAS_BASE base; 
    276289 
    277                 setMatMulParam<typename Field::Element> ()(F, MIN(MIN(m,n),k), beta, 
    278                                                            w, base, kmax); 
     290                MatMulParameters (F, MIN(MIN(m,n),k), beta, kmax, base, w); 
    279291 
    280292                WinoMain (F, ta, tb, m, n, k, alpha, A, lda, B, ldb, beta, 
     
    447459        } 
    448460 
    449         /** @brief Bound for the delayed modulus matrix multiplication 
    450          * 
    451          *  @param F  - the finite field 
    452          *  @param w  - the number of recursive levels of Winograds algorithm being used 
    453          *  @param beta - for the computation of C <- AB + beta C 
    454          * 
    455          *  Compute the maximal dimension k, such that a matrix multiplication (m,k)x(k,n) 
    456          *  can be performed over Z without overflow of the 53 bits of the double 
    457          *  mantissa. 
    458          *  See [Dumas, Gautier, Pernet ISSAC'2002] 
     461        /** 
     462         * MatMulParameters 
     463         * 
     464         * \brief Computes the threshold parameters for the cascade 
     465         *        Matmul algorithm 
     466         * 
     467         *  
     468         * \param F Finite Field/Ring of the computation. 
     469         * \param k Common dimension of A and B, in the product A x B 
     470         * \param bet Computing AB + beta C 
     471         * \param delayedDim Returns the size of blocks that can be multiplied 
     472         *                   over Z with no overflow 
     473         * \param base Returns the type of BLAS representation to use 
     474         * \param winoRecLevel Returns the number of recursion levels of 
     475         *                     Strassen-Winograd's algorithm to perform 
     476         * \param winoLevelProvided tells whether the user forced the number of 
     477         *                          recursive level of Winograd's algorithm 
     478         * 
     479         * See [Dumas, Giorgi, Pernet, arXiv cs/0601133] 
     480         * http://arxiv.org/abs/cs.SC/0601133 
    459481         */ 
    460482        template <class Field> 
    461         static size_t DotProdBound (const Field& F, const size_t w, 
    462                                     const typename Field::Element& beta, 
    463                                     const FFLAS_BASE base); 
    464  
     483        static void MatMulParameters (const Field& F, 
     484                                      const size_t k, 
     485                                      const typename Field::Element& beta, 
     486                                      size_t& delayedDim, 
     487                                      FFLAS_BASE& base, 
     488                                      size_t& winoRecLevel, 
     489                                      bool winoLevelProvided=false); 
     490 
     491         
     492        /** 
     493         * DotprodBound 
     494         * 
     495         * \brief  computes the maximal size for delaying the modular reduction 
     496         *         in a dotproduct 
     497         * 
     498         * This is the default version assuming a conversion to a positive modular representation 
     499         *  
     500         * \param F Finite Field/Ring of the computation 
     501         * \param winoRecLevel Number of recusrive Strassen-Winograd levels (if any, 0 otherwise) 
     502         * \param beta Computing AB + beta C 
     503         * \param base Type of floating point representation for delayed modular computations 
     504         *  
     505         */ 
    465506        template <class Field> 
    466         static size_t DotProdBoundCompute (const Field& F, const size_t w, 
    467                                            const typename Field::Element& beta, 
    468                                            const FFLAS_BASE base); 
    469          
    470  
     507        static size_t DotProdBound (const Field& F, 
     508                             const size_t w,  
     509                             const typename Field::Element& beta, 
     510                             const FFLAS_BASE base); 
     511         
     512 
     513        /** 
     514         * Internal function for the bound computation 
     515         * Generic implementation for positive representations 
     516         */ 
     517        template <class Field> 
     518        static double computeFactor (const Field& F, const size_t w); 
     519         
     520 
     521        /** 
     522         * Winosteps 
     523         * 
     524         * \brief Computes the number of recursive levels to perform 
     525         * 
     526         * \param m the common dimension in the product AxB 
     527         */ 
    471528        static size_t WinoSteps (const size_t m); 
    472529         
    473         //      template <class Element> 
    474 //      class callDotProdBoundCompute; 
    475  
    476         /** @brief Bound for the delayed modulus triangular system solving 
    477          * 
    478          *  @param F  - the finite field 
     530        /** 
     531         * BaseCompute 
     532         * 
     533         * \brief Determines the type of floating point representation to convert to, 
     534         *        for BLAS computations 
     535         * \param F Finite Field/Ring of the computation 
     536         * \param w Number of recursive levels in Winograd's algorithm 
     537         */ 
     538        template <class Field> 
     539        static FFLAS_BASE BaseCompute (const Field& F, const size_t w); 
     540                 
     541        /** 
     542         * TRSMBound 
     543         * 
     544         * \brief  computes the maximal size for delaying the modular reduction 
     545         *         in a triangular system resolution 
    479546         * 
    480547         *  Compute the maximal dimension k, such that a unit diagonal triangular 
    481548         *  system of dimension k can be solved over Z without overflow of the 
    482          *  53 bits of the double mantissa. 
    483          *  See [Dumas, Giorgi, Pernet ISSAC'2004] 
     549         *  underlying floating point representation. 
     550         *  See [Dumas, Giorgi, Pernet 06, arXiv:cs/0601133 ] 
     551         *  
     552         * \param F Finite Field/Ring of the computation 
     553         *  
    484554         */ 
    485555        template <class Field> 
    486556        static size_t TRSMBound (const Field& F); 
    487  
    488         template <class Element> 
    489         class callTRSMBound; 
    490  
    491         /** @brief Set the optimal parameters for the Matrix Multiplication 
    492          */ 
    493         template <class Element> 
    494         class setMatMulParam; 
    495  
    496         template <class Element> 
    497         class BaseCompute; 
    498557 
    499558        template <class Field> 
     
    557616                              const size_t kmax, const size_t w, const FFLAS_BASE base); 
    558617 
    559  
    560         template<class Element> 
    561         class callWinoMain; 
    562  
    563         template<class Element> 
    564         class callClassicMatmul; 
    565  
    566         template<class Element> 
    567         class callFsquare; 
    568  
    569         template<class Element> 
    570         class callMatVectProd; 
    571                  
    572618        // Specialized routines for ftrsm 
    573619        template <class Element>