AVX指令集矩阵乘向量算法

#include <stdio.h>
#include <time.h>
#include <x86intrin.h>


void matmul_avx(const float *x, const float **w,float *y,const int col,const int row){
    const int col_reduced_8 = col - col % 8;
    float scratchpad[8];
    __m256 op0, op1, tgt, tmp_vec;
    for (int i = 0; i < row; i++) {
        float res = 0;

        tgt = _mm256_setzero_ps();
        for (int j = 0; j < col_reduced_8; j += 8) {
            op0 = __builtin_ia32_loadups256(&x[j]);
            op1 = __builtin_ia32_loadups256(&w[i][j]);
            tmp_vec = __builtin_ia32_mulps256(op0, op1);
            tgt = __builtin_ia32_addps256(tmp_vec, tgt);
        }

        __builtin_ia32_storeups256(scratchpad, tgt);
        for (int k = 0; k < 8; k++)
            res += scratchpad[k];

        for (int l = col_reduced_8; l < col; l++) {
            res += w[i][l] *
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值