You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2 KiB

#include <stdio.h>
#include <stdlib.h>
#include <ctime>
#include <iostream>
#include <ostream>
#include <arm_neon.h>
#define SIZE 1024
int main(){
void matmul_optimized(float **A,float **B,float **C,int n);
int i,j,n;
float **A=new float*[n];
float **B=new float*[n];
float **C=new float*[n];
for(i=0;i<n;i++){
A[i]=new float[n];
B[i]=new float[n];
C[i]=new float[n];
}
for(i=0;i<n;i++){
for(j=0;j<n;j++){
A[i][j]=rand()%100;
B[i][j]=rand()%100;
}
}
clock_t start=clock();
matmul_optimized(A,B,C,SIZE);
clock_t end=clock();
std::cout<<"优化稠密矩阵乘法时间:"<<double(end-start)/CLOCKS_PER_SEC<<""<<std::endl;
for(i=0;i<n;i++){
delete[] A[i];
delete[] B[i];
delete[] C[i];
}
delete[] A;
delete[] B;
delete[] C;
}
void matmul_optimized(float **A,float **B,float **C,int n){
int i,j,k;
for(i=0;i<n;i++){
for(j=0;j<n;j++){
float32x4_t vecC=vdupq_n_f32(0.0);
for(k=0;k<n;k+=4){
float32x4_t vecA=vld1q_f32(&A[i][j]);
float32x4_t vecB=vld1q_f32(&B[i][j]);
vecC=vmlap_f32(vecC,vecA,vecB);
C[i][j]=vgetq_lane_f32(vecC,0)+vgetq_lane_f32(vecC,1)+vgetq_lane_f32(vecC,2)+vgetq_lane_f32(vecC,3);
}
}
}
}