フロートのタブが2つあります。最初のタブの要素に2番目のタブの対応する要素を掛けて、結果を3番目のタブに保存する必要があります。
NEONを使用してfloat乗算を並列化したいと思います。1つではなく4つのfloat乗算を同時に実行します。
大幅な加速を期待していましたが、実行時間の短縮は約20%しか達成できませんでした。これは私のコードです:
#include <stdlib.h>
#include <iostream>
#include <arm_neon.h>
const int n = 100; // table size
/* fill a tab with random floats */
void rand_tab(float *t) {
for (int i = 0; i < n; i++)
t[i] = (float)rand()/(float)RAND_MAX;
}
/* Multiply elements of two tabs and store results in third tab
- STANDARD processing. */
void mul_tab_standard(float *t1, float *t2, float *tr) {
for (int i = 0; i < n; i++)
tr[i] = t1[i] * t2[i];
}
/* Multiply elements of two tabs and store results in third tab
- NEON processing. */
void mul_tab_neon(float *t1, float *t2, float *tr) {
for (int i = 0; i < n; i+=4)
vst1q_f32(tr+i, vmulq_f32(vld1q_f32(t1+i), vld1q_f32(t2+i)));
}
int main() {
float t1[n], t2[n], tr[n];
/* fill tables with random values */
srand(1); rand_tab(t1); rand_tab(t2);
// I repeat table multiplication function 1000000 times for measuring purposes:
for (int k=0; k < 1000000; k++)
mul_tab_standard(t1, t2, tr); // switch to next line for comparison:
//mul_tab_neon(t1, t2, tr);
return 1;
}
次のコマンドを実行してコンパイルします:g ++ -mfpu = neon -ffast-math neon_test.cpp
私のCPU:ARMv7プロセッサrev 0(v7l)
より大幅なスピードアップを実現する方法について何かアイデアはありますか?