Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions kernel/riscv64/axpy_vector.c
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,17 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
j += gvl;
}
} else if( 0 == inc_y ) {
#if defined(RISCV64_ZVL256B)
/* Zero output stride is an ordered update of one scalar. Do not
broadcast its initial value into every reduction lane. */
for (BLASLONG k = 0; k < n; ++k) {
#if defined(DOUBLE)
y[0] = __builtin_fma(da, x[k * inc_x], y[0]);
#else
y[0] = __builtin_fmaf(da, x[k * inc_x], y[0]);
#endif
}
#else
BLASLONG stride_x = inc_x * sizeof(FLOAT);
size_t in_vl = VSETVL(n);
vy0 = VFMVVF_FLOAT( y[0], in_vl );
Expand All @@ -173,6 +184,8 @@ int CNAME(BLASLONG n, BLASLONG dummy0, BLASLONG dummy1, FLOAT da, FLOAT *x, BLAS
FLOAT_V_M1_T v_res = VFMVVF_FLOAT_M1( 0.0f, 1 );
v_res = VFREDSUMVS_FLOAT( vy0, v_res, in_vl );
y[0] = EXTRACT_FLOAT(v_res);
#endif

}else{
stride_x = inc_x * sizeof(FLOAT);
stride_y = inc_y * sizeof(FLOAT);
Expand Down
55 changes: 55 additions & 0 deletions utest/test_axpy.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,58 @@ CTEST(axpy,caxpy_incx_0)
}
#endif



#ifdef BUILD_DOUBLE
CTEST(axpy,daxpy_zero_output_stride)
{
const blasint lengths[] = {1, 2, 9, 17, 33};
const blasint strides[] = {1, 2, -1, -2};
const double seeds[] = {-2, 0, 2};
const double alphas[] = {0, 1, -1, 0.5};
int ni, si, yi, ai, k;
for (ni = 0; ni < 5; ++ni)
for (si = 0; si < 4; ++si)
for (yi = 0; yi < 3; ++yi)
for (ai = 0; ai < 4; ++ai) {
blasint n = lengths[ni], incx = strides[si], incy = 0;
double alpha = alphas[ai], x[65], y[3] = {99, 0, 99};
double expected = seeds[yi] + n * alpha;
y[1] = seeds[yi];
for (k = 0; k < 65; ++k) x[k] = 1;
BLASFUNC(daxpy)(&n, &alpha, x, &incx, y + 1, &incy);
ASSERT_DBL_NEAR_TOL(expected, y[1], DOUBLE_EPS);
ASSERT_DBL_NEAR_TOL(99, y[0], DOUBLE_EPS);
ASSERT_DBL_NEAR_TOL(99, y[2], DOUBLE_EPS);
for (k = 0; k < 65; ++k)
ASSERT_DBL_NEAR_TOL(1, x[k], DOUBLE_EPS);
}
}
#endif

#ifdef BUILD_SINGLE
CTEST(axpy,saxpy_zero_output_stride)
{
const blasint lengths[] = {1, 2, 9, 17, 33};
const blasint strides[] = {1, 2, -1, -2};
const float seeds[] = {-2, 0, 2};
const float alphas[] = {0, 1, -1, 0.5};
int ni, si, yi, ai, k;
for (ni = 0; ni < 5; ++ni)
for (si = 0; si < 4; ++si)
for (yi = 0; yi < 3; ++yi)
for (ai = 0; ai < 4; ++ai) {
blasint n = lengths[ni], incx = strides[si], incy = 0;
float alpha = alphas[ai], x[65], y[3] = {99, 0, 99};
float expected = seeds[yi] + n * alpha;
y[1] = seeds[yi];
for (k = 0; k < 65; ++k) x[k] = 1;
BLASFUNC(saxpy)(&n, &alpha, x, &incx, y + 1, &incy);
ASSERT_DBL_NEAR_TOL(expected, y[1], DOUBLE_EPS);
ASSERT_DBL_NEAR_TOL(99, y[0], DOUBLE_EPS);
ASSERT_DBL_NEAR_TOL(99, y[2], DOUBLE_EPS);
for (k = 0; k < 65; ++k)
ASSERT_DBL_NEAR_TOL(1, x[k], DOUBLE_EPS);
}
}
#endif