代码之家  ›  专栏  ›  技术社区  ›  NULL

为什么执行逐浮点矩阵乘法比逐整数乘法更快?

  •  25
  • NULL  · 技术社区  · 9 年前

    有两个int矩阵A和B,有1000多行和10K列,我经常需要将它们转换为浮点矩阵以获得加速(4x或更多)。

    2 回复  |  直到 5 年前
        1
  •  14
  •   chtz    9 年前

    #include <Eigen/Core>
    
    int mult_int(const Eigen::MatrixXi& A, Eigen::MatrixXi& B)
    {
        Eigen::MatrixXi C= A*B;
        return C(0,0);
    }
    
    int mult_float(const Eigen::MatrixXf& A, Eigen::MatrixXf& B)
    {
        Eigen::MatrixXf C= A*B;
        return C(0,0);
    }
    

    使用标志 -mavx2 -S -O3 然而,主要区别在于 vpmulld 延迟为的2-3倍,吞吐量仅为的1/2或1/4 vmulps (关于最近的Intel架构)

    参考: Intel Intrinsics Guide

        2
  •  14
  •   sascha    9 年前

    所有这些向量和矩阵向量运算都使用 BLAS

    Here is some branch of OpenBLAS tiny discussion at google-groups linking it ).

    might be working on integer-types too . This talk 看起来很有趣(在那个论坛中提到),虽然它很短,可能更接近