Compare commits
3
Commits
bf65e37202
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5cb0ad82bd
|
||
|
|
948d16d378 | ||
|
|
f9ee622fb8 |
No files matched your search
@@ -0,0 +1,5 @@
|
|||||||
|
myexp
|
||||||
|
test_auto_vectorize
|
||||||
|
**/*.s
|
||||||
|
**/*.o
|
||||||
|
**/*.swp
|
||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
+72
-2
@@ -49,8 +49,63 @@ void clampedExpVector(float *values, int *exponents, float *output, int N)
|
|||||||
// Your solution should work for any value of
|
// Your solution should work for any value of
|
||||||
// N and VECTOR_WIDTH, not just when VECTOR_WIDTH divides N
|
// N and VECTOR_WIDTH, not just when VECTOR_WIDTH divides N
|
||||||
//
|
//
|
||||||
|
__pp_vec_float x;
|
||||||
|
__pp_vec_int y;
|
||||||
|
__pp_vec_float result;
|
||||||
|
__pp_vec_int zero = _pp_vset_int(0);
|
||||||
|
__pp_vec_float cap = _pp_vset_float(9.999999f);
|
||||||
|
__pp_vec_int one = _pp_vset_int(1);
|
||||||
|
__pp_mask maskAll, maskNonZero, maskGreater;
|
||||||
|
maskAll = _pp_init_ones();
|
||||||
|
|
||||||
for (int i = 0; i < N; i += VECTOR_WIDTH)
|
for (int i = 0; i < N; i += VECTOR_WIDTH)
|
||||||
{
|
{
|
||||||
|
if (i + VECTOR_WIDTH > N) {
|
||||||
|
float *tmp = new float[VECTOR_WIDTH];
|
||||||
|
for (int j = 0; i + j < N; j++)
|
||||||
|
tmp[j] = values[i+j];
|
||||||
|
for (int j = N % VECTOR_WIDTH; j < VECTOR_WIDTH; j++)
|
||||||
|
tmp[j] = 0;
|
||||||
|
_pp_vload_float(x, tmp, maskAll);
|
||||||
|
delete []tmp;
|
||||||
|
} else {
|
||||||
|
_pp_vload_float(x, values + i, maskAll); // x = values[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i + VECTOR_WIDTH > N) {
|
||||||
|
int *tmp = new int[VECTOR_WIDTH];
|
||||||
|
for (int j = 0; i + j < N; j++)
|
||||||
|
tmp[j] = exponents[i+j];
|
||||||
|
for (int j = N % VECTOR_WIDTH; j < VECTOR_WIDTH; j++)
|
||||||
|
tmp[j] = 0;
|
||||||
|
_pp_vload_int(y, tmp, maskAll);
|
||||||
|
delete []tmp;
|
||||||
|
} else {
|
||||||
|
_pp_vload_int(y, exponents + i, maskAll); // y = exponents[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
_pp_vset_float(result, 1.f, maskAll);
|
||||||
|
maskNonZero = _pp_init_ones();
|
||||||
|
while (_pp_cntbits(maskNonZero) > 0) {
|
||||||
|
_pp_veq_int(maskNonZero, y, zero, maskAll);
|
||||||
|
maskNonZero = _pp_mask_not(maskNonZero);
|
||||||
|
|
||||||
|
_pp_vmult_float(result, result, x, maskNonZero);
|
||||||
|
_pp_vsub_int(y, y, one, maskNonZero);
|
||||||
|
}
|
||||||
|
|
||||||
|
_pp_vgt_float(maskGreater, result, cap, maskAll);
|
||||||
|
_pp_vset_float(result, 9.999999f, maskGreater);
|
||||||
|
|
||||||
|
if (i + VECTOR_WIDTH > N) {
|
||||||
|
float *tmp = new float[VECTOR_WIDTH];
|
||||||
|
_pp_vstore_float(tmp, result, maskAll);
|
||||||
|
for (int j = 0; i + j < N; j++)
|
||||||
|
output[i+j] = tmp[j];
|
||||||
|
delete []tmp;
|
||||||
|
} else {
|
||||||
|
_pp_vstore_float(output + i, result, maskAll);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,10 +118,25 @@ float arraySumVector(float *values, int N)
|
|||||||
//
|
//
|
||||||
// PP STUDENTS TODO: Implement your vectorized version of arraySumSerial here
|
// PP STUDENTS TODO: Implement your vectorized version of arraySumSerial here
|
||||||
//
|
//
|
||||||
|
__pp_vec_float x;
|
||||||
|
__pp_mask maskAll;
|
||||||
|
maskAll = _pp_init_ones();
|
||||||
|
|
||||||
|
float total = 0.f;
|
||||||
for (int i = 0; i < N; i += VECTOR_WIDTH)
|
for (int i = 0; i < N; i += VECTOR_WIDTH)
|
||||||
{
|
{
|
||||||
|
_pp_vload_float(x, values + i, maskAll);
|
||||||
|
|
||||||
|
for (int n = VECTOR_WIDTH; n > 1; n >>= 1) {
|
||||||
|
_pp_hadd_float(x, x);
|
||||||
|
_pp_interleave_float(x, x);
|
||||||
|
}
|
||||||
|
|
||||||
|
float *tmp = new float[VECTOR_WIDTH];
|
||||||
|
_pp_vstore_float(tmp, x, maskAll);
|
||||||
|
total += tmp[0];
|
||||||
|
delete []tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0.0;
|
return total;
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
RUNS=${1:-5}
|
||||||
|
median() { sort -n | awk '{a[NR]=$1} END{print (NR%2)?a[(NR+1)/2]:(a[NR/2]+a[NR/2+1])/2}'; }
|
||||||
|
for cfg in "novec:" "vec:VECTORIZE=1" "avx2:VECTORIZE=1 AVX2=1"; do
|
||||||
|
name=${cfg%%:*}; flags=${cfg#*:}
|
||||||
|
make -s clean; make -s $flags >/dev/null 2>&1 || { echo "build $name failed"; exit 1; }
|
||||||
|
t=$(for r in $(seq $RUNS); do ./test_auto_vectorize -t 1 | grep -oE '^[0-9.]+'; done | median)
|
||||||
|
echo "$name $t"; eval "T_$name=$t"
|
||||||
|
done
|
||||||
|
awk -v n=$T_novec -v v=$T_vec -v a=$T_avx2 'BEGIN{printf "vec/novec speedup: %.2fx\navx2/vec speedup: %.2fx\navx2/novec speedup: %.2fx\n", n/v, v/a, n/a}'
|
||||||
+4
-1
@@ -1,7 +1,10 @@
|
|||||||
#include "test.h"
|
#include "test.h"
|
||||||
|
|
||||||
void test1(float *a, float *b, float *c, int N) {
|
void test1(float *__restrict a, float *__restrict b, float *__restrict c, int N) {
|
||||||
__builtin_assume(N == 1024);
|
__builtin_assume(N == 1024);
|
||||||
|
a = (float *)__builtin_assume_aligned(a, 32);
|
||||||
|
b = (float *)__builtin_assume_aligned(b, 32);
|
||||||
|
c = (float *)__builtin_assume_aligned(c, 32);
|
||||||
|
|
||||||
for (int i=0; i<I; i++) {
|
for (int i=0; i<I; i++) {
|
||||||
for (int j=0; j<N; j++) {
|
for (int j=0; j<N; j++) {
|
||||||
|
|||||||
+2
-3
@@ -11,9 +11,8 @@ void test2(float *__restrict a, float *__restrict b, float *__restrict c, int N)
|
|||||||
for (int j = 0; j < N; j++)
|
for (int j = 0; j < N; j++)
|
||||||
{
|
{
|
||||||
/* max() */
|
/* max() */
|
||||||
c[j] = a[j];
|
if (b[j] > a[j]) c[j] = b[j];
|
||||||
if (b[j] > a[j])
|
else c[j] = a[j];
|
||||||
c[j] = b[j];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
#include "test.h"
|
||||||
|
|
||||||
|
void test2(float *__restrict a, float *__restrict b, float *__restrict c, int N)
|
||||||
|
{
|
||||||
|
__builtin_assume(N == 1024);
|
||||||
|
a = (float *)__builtin_assume_aligned(a, 16);
|
||||||
|
b = (float *)__builtin_assume_aligned(b, 16);
|
||||||
|
|
||||||
|
for (int i = 0; i < I; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < N; j++)
|
||||||
|
{
|
||||||
|
/* max() */
|
||||||
|
c[j] = a[j];
|
||||||
|
if (b[j] > a[j])
|
||||||
|
c[j] = b[j];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user