Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add check for test_matrix_a in gbmv,tbmv,hbmv and sbmv #559

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 5 additions & 5 deletions include/clblast.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ StatusCode Gemv(const Layout layout, const Transpose a_transpose,
const cl_mem x_buffer, const size_t x_offset, const size_t x_inc,
const T beta,
cl_mem y_buffer, const size_t y_offset, const size_t y_inc,
cl_command_queue* queue, cl_event* event = nullptr);
cl_command_queue* queue, cl_event* event = nullptr, const bool do_test_matrix_a=true);

// General banded matrix-vector multiplication: SGBMV/DGBMV/CGBMV/ZGBMV/HGBMV
template <typename T>
Expand All @@ -292,7 +292,7 @@ StatusCode Gbmv(const Layout layout, const Transpose a_transpose,
const cl_mem x_buffer, const size_t x_offset, const size_t x_inc,
const T beta,
cl_mem y_buffer, const size_t y_offset, const size_t y_inc,
cl_command_queue* queue, cl_event* event = nullptr);
cl_command_queue* queue, cl_event* event = nullptr, const bool do_test_matrix_a=true);

// Hermitian matrix-vector multiplication: CHEMV/ZHEMV
template <typename T>
Expand All @@ -314,7 +314,7 @@ StatusCode Hbmv(const Layout layout, const Triangle triangle,
const cl_mem x_buffer, const size_t x_offset, const size_t x_inc,
const T beta,
cl_mem y_buffer, const size_t y_offset, const size_t y_inc,
cl_command_queue* queue, cl_event* event = nullptr);
cl_command_queue* queue, cl_event* event = nullptr, const bool do_test_matrix_a=true);

// Hermitian packed matrix-vector multiplication: CHPMV/ZHPMV
template <typename T>
Expand Down Expand Up @@ -347,7 +347,7 @@ StatusCode Sbmv(const Layout layout, const Triangle triangle,
const cl_mem x_buffer, const size_t x_offset, const size_t x_inc,
const T beta,
cl_mem y_buffer, const size_t y_offset, const size_t y_inc,
cl_command_queue* queue, cl_event* event = nullptr);
cl_command_queue* queue, cl_event* event = nullptr, const bool do_test_matrix_a=true);

// Symmetric packed matrix-vector multiplication: SSPMV/DSPMV/HSPMV
template <typename T>
Expand All @@ -374,7 +374,7 @@ StatusCode Tbmv(const Layout layout, const Triangle triangle, const Transpose a_
const size_t n, const size_t k,
const cl_mem a_buffer, const size_t a_offset, const size_t a_ld,
cl_mem x_buffer, const size_t x_offset, const size_t x_inc,
cl_command_queue* queue, cl_event* event = nullptr);
cl_command_queue* queue, cl_event* event = nullptr, const bool do_test_matrix_a=true);

// Triangular packed matrix-vector multiplication: STPMV/DTPMV/CTPMV/ZTPMV/HTPMV
template <typename T>
Expand Down
60 changes: 30 additions & 30 deletions src/clblast.cpp

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions src/clblast_c.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1145,7 +1145,7 @@ CLBlastStatusCode CLBlastSgbmv(const CLBlastLayout layout, const CLBlastTranspos
const cl_mem x_buffer, const size_t x_offset, const size_t x_inc,
const float beta,
cl_mem y_buffer, const size_t y_offset, const size_t y_inc,
cl_command_queue* queue, cl_event* event) {
cl_command_queue* queue, cl_event* event, const bool do_test_matrix_a) {
try {
return static_cast<CLBlastStatusCode>(
clblast::Gbmv(static_cast<clblast::Layout>(layout),
Expand All @@ -1156,7 +1156,7 @@ CLBlastStatusCode CLBlastSgbmv(const CLBlastLayout layout, const CLBlastTranspos
x_buffer, x_offset, x_inc,
beta,
y_buffer, y_offset, y_inc,
queue, event)
queue, event, do_test_matrix_a)
);
} catch (...) { return static_cast<CLBlastStatusCode>(clblast::DispatchExceptionForC()); }
}
Expand All @@ -1167,7 +1167,7 @@ CLBlastStatusCode CLBlastDgbmv(const CLBlastLayout layout, const CLBlastTranspos
const cl_mem x_buffer, const size_t x_offset, const size_t x_inc,
const double beta,
cl_mem y_buffer, const size_t y_offset, const size_t y_inc,
cl_command_queue* queue, cl_event* event) {
cl_command_queue* queue, cl_event* event, const bool do_test_matrix_a) {
try {
return static_cast<CLBlastStatusCode>(
clblast::Gbmv(static_cast<clblast::Layout>(layout),
Expand All @@ -1178,7 +1178,7 @@ CLBlastStatusCode CLBlastDgbmv(const CLBlastLayout layout, const CLBlastTranspos
x_buffer, x_offset, x_inc,
beta,
y_buffer, y_offset, y_inc,
queue, event)
queue, event, do_test_matrix_a)
);
} catch (...) { return static_cast<CLBlastStatusCode>(clblast::DispatchExceptionForC()); }
}
Expand All @@ -1189,7 +1189,7 @@ CLBlastStatusCode CLBlastCgbmv(const CLBlastLayout layout, const CLBlastTranspos
const cl_mem x_buffer, const size_t x_offset, const size_t x_inc,
const cl_float2 beta,
cl_mem y_buffer, const size_t y_offset, const size_t y_inc,
cl_command_queue* queue, cl_event* event) {
cl_command_queue* queue, cl_event* event, const bool do_test_matrix_a) {
try {
return static_cast<CLBlastStatusCode>(
clblast::Gbmv(static_cast<clblast::Layout>(layout),
Expand All @@ -1200,7 +1200,7 @@ CLBlastStatusCode CLBlastCgbmv(const CLBlastLayout layout, const CLBlastTranspos
x_buffer, x_offset, x_inc,
float2{beta.s[0], beta.s[1]},
y_buffer, y_offset, y_inc,
queue, event)
queue, event, do_test_matrix_a)
);
} catch (...) { return static_cast<CLBlastStatusCode>(clblast::DispatchExceptionForC()); }
}
Expand All @@ -1211,7 +1211,7 @@ CLBlastStatusCode CLBlastZgbmv(const CLBlastLayout layout, const CLBlastTranspos
const cl_mem x_buffer, const size_t x_offset, const size_t x_inc,
const cl_double2 beta,
cl_mem y_buffer, const size_t y_offset, const size_t y_inc,
cl_command_queue* queue, cl_event* event) {
cl_command_queue* queue, cl_event* event, const bool do_test_matrix_a) {
try {
return static_cast<CLBlastStatusCode>(
clblast::Gbmv(static_cast<clblast::Layout>(layout),
Expand All @@ -1222,7 +1222,7 @@ CLBlastStatusCode CLBlastZgbmv(const CLBlastLayout layout, const CLBlastTranspos
x_buffer, x_offset, x_inc,
double2{beta.s[0], beta.s[1]},
y_buffer, y_offset, y_inc,
queue, event)
queue, event, do_test_matrix_a)
);
} catch (...) { return static_cast<CLBlastStatusCode>(clblast::DispatchExceptionForC()); }
}
Expand All @@ -1233,7 +1233,7 @@ CLBlastStatusCode CLBlastHgbmv(const CLBlastLayout layout, const CLBlastTranspos
const cl_mem x_buffer, const size_t x_offset, const size_t x_inc,
const cl_half beta,
cl_mem y_buffer, const size_t y_offset, const size_t y_inc,
cl_command_queue* queue, cl_event* event) {
cl_command_queue* queue, cl_event* event, const bool do_test_matrix_a) {
try {
return static_cast<CLBlastStatusCode>(
clblast::Gbmv(static_cast<clblast::Layout>(layout),
Expand All @@ -1243,8 +1243,8 @@ CLBlastStatusCode CLBlastHgbmv(const CLBlastLayout layout, const CLBlastTranspos
a_buffer, a_offset, a_ld,
x_buffer, x_offset, x_inc,
beta,
y_buffer, y_offset, y_inc,
queue, event)
y_buffer, y_offset, y_inc,
queue, event, do_test_matrix_a)
);
} catch (...) { return static_cast<CLBlastStatusCode>(clblast::DispatchExceptionForC()); }
}
Expand Down
7 changes: 5 additions & 2 deletions src/routines/level2/xgbmv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@ void Xgbmv<T>::DoGbmv(const Layout layout, const Transpose a_transpose,
const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld,
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc,
const T beta,
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc) {
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc, const bool do_test_matrix_a) {

// Reverses the upper and lower band count
auto rotated = (layout == Layout::kRowMajor);
auto kl_real = (rotated) ? ku : kl;
auto ku_real = (rotated) ? kl : ku;

// The matrix A has different constraints compared to what is normally tested in MatVec below
TestMatrixBanded(n, kl, ku, a_buffer, a_offset, a_ld);

// Runs the generic matrix-vector multiplication, disabling the use of fast vectorized kernels.
// The specific hermitian matrix-accesses are implemented in the kernel guarded by the
// ROUTINE_GBMV define.
Expand All @@ -52,7 +55,7 @@ void Xgbmv<T>::DoGbmv(const Layout layout, const Transpose a_transpose,
x_buffer, x_offset, x_inc, beta,
y_buffer, y_offset, y_inc,
fast_kernels, fast_kernels,
0, false, kl_real, ku_real);
0, false, kl_real, ku_real,/*do_test_matrix_a=*/do_test_matrix_a);
}

// =================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/routines/level2/xgbmv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Xgbmv: public Xgemv<T> {
const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld,
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc,
const T beta,
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc);
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc, const bool do_test_matrix_a=true);
};

// =================================================================================================
Expand Down
9 changes: 5 additions & 4 deletions src/routines/level2/xgemv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void Xgemv<T>::DoGemv(const Layout layout, const Transpose a_transpose,
const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld,
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc,
const T beta,
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc) {
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc, const bool do_test_matrix_a) {

// Performs the matrix-vector multiplication
MatVec(layout, a_transpose,
Expand All @@ -48,7 +48,7 @@ void Xgemv<T>::DoGemv(const Layout layout, const Transpose a_transpose,
x_buffer, x_offset, x_inc, beta,
y_buffer, y_offset, y_inc,
true, true,
0, false, 0, 0); // N/A for this routine
0, false, 0, 0,do_test_matrix_a); // N/A for this routine
}

// =================================================================================================
Expand All @@ -64,7 +64,7 @@ void Xgemv<T>::MatVec(const Layout layout, const Transpose a_transpose,
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc,
bool fast_kernel, bool fast_kernel_rot,
const size_t parameter, const bool packed,
const size_t kl, const size_t ku) {
const size_t kl, const size_t ku,const bool do_test_matrix_a) {

// Makes sure all dimensions are larger than zero
if (m == 0 || n == 0) { throw BLASError(StatusCode::kInvalidDimension); }
Expand Down Expand Up @@ -92,7 +92,8 @@ void Xgemv<T>::MatVec(const Layout layout, const Transpose a_transpose,

// Tests the matrix and the vectors for validity
if (packed) { TestMatrixAP(n, a_buffer, a_offset); }
else { TestMatrixA(a_one, a_two, a_buffer, a_offset, a_ld); }
else if (do_test_matrix_a) { TestMatrixA(a_one, a_two, a_buffer, a_offset, a_ld); }

TestVectorX(n_real, x_buffer, x_offset, x_inc);
TestVectorY(m_real, y_buffer, y_offset, y_inc);

Expand Down
4 changes: 2 additions & 2 deletions src/routines/level2/xgemv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class Xgemv: public Routine {
const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld,
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc,
const T beta,
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc);
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc, const bool do_test_matrix_a=true);

// Generic version used also for other matrix-vector multiplications
void MatVec(const Layout layout, const Transpose a_transpose,
Expand All @@ -46,7 +46,7 @@ class Xgemv: public Routine {
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc,
bool fast_kernel, bool fast_kernel_rot,
const size_t parameter, const bool packed,
const size_t kl, const size_t ku);
const size_t kl, const size_t ku, const bool do_test_matrix_a = true);
};

// =================================================================================================
Expand Down
4 changes: 2 additions & 2 deletions src/routines/level2/xhbmv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Xhbmv<T>::DoHbmv(const Layout layout, const Triangle triangle,
const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld,
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc,
const T beta,
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc) {
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc, const bool do_test_matrix_a) {

// The data is either in the upper or lower triangle
size_t is_upper = ((triangle == Triangle::kUpper && layout != Layout::kRowMajor) ||
Expand All @@ -51,7 +51,7 @@ void Xhbmv<T>::DoHbmv(const Layout layout, const Triangle triangle,
x_buffer, x_offset, x_inc, beta,
y_buffer, y_offset, y_inc,
fast_kernels, fast_kernels,
is_upper, false, k, 0);
is_upper, false, k, 0,do_test_matrix_a);
}

// =================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/routines/level2/xhbmv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Xhbmv: public Xgemv<T> {
const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld,
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc,
const T beta,
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc);
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc, const bool do_test_matrix_a=true);
};

// =================================================================================================
Expand Down
4 changes: 2 additions & 2 deletions src/routines/level2/xsbmv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ void Xsbmv<T>::DoSbmv(const Layout layout, const Triangle triangle,
const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld,
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc,
const T beta,
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc) {
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc,const bool do_test_matrix_a) {

// The data is either in the upper or lower triangle
size_t is_upper = ((triangle == Triangle::kUpper && layout != Layout::kRowMajor) ||
Expand All @@ -51,7 +51,7 @@ void Xsbmv<T>::DoSbmv(const Layout layout, const Triangle triangle,
x_buffer, x_offset, x_inc, beta,
y_buffer, y_offset, y_inc,
fast_kernels, fast_kernels,
is_upper, false, k, 0);
is_upper, false, k, 0,do_test_matrix_a);
}

// =================================================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/routines/level2/xsbmv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Xsbmv: public Xgemv<T> {
const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld,
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc,
const T beta,
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc);
const Buffer<T> &y_buffer, const size_t y_offset, const size_t y_inc, const bool do_test_matrix_a);
};

// =================================================================================================
Expand Down
4 changes: 2 additions & 2 deletions src/routines/level2/xtbmv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ void Xtbmv<T>::DoTbmv(const Layout layout, const Triangle triangle,
const Transpose a_transpose, const Diagonal diagonal,
const size_t n, const size_t k,
const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld,
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc) {
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc,const bool do_test_matrix_a ) {

// Creates a copy of X: a temporary scratch buffer
const auto x_size = (1 + (n - 1) * x_inc) + x_offset;
Expand All @@ -58,7 +58,7 @@ void Xtbmv<T>::DoTbmv(const Layout layout, const Triangle triangle,
scratch_buffer, x_offset, x_inc, ConstantZero<T>(),
x_buffer, x_offset, x_inc,
fast_kernels, fast_kernels,
parameter, false, k, 0);
parameter, false, k, 0,do_test_matrix_a);
} catch (BLASError &e) {
// Returns the proper error code (renames vector Y to X)
switch (e.status()) {
Expand Down
2 changes: 1 addition & 1 deletion src/routines/level2/xtbmv.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class Xtbmv: public Xgemv<T> {
const Transpose a_transpose, const Diagonal diagonal,
const size_t n, const size_t k,
const Buffer<T> &a_buffer, const size_t a_offset, const size_t a_ld,
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc);
const Buffer<T> &x_buffer, const size_t x_offset, const size_t x_inc, const bool do_test_matrix_a = true);
};

// =================================================================================================
Expand Down
10 changes: 10 additions & 0 deletions src/utilities/buffer_test.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,16 @@

namespace clblast {
// =================================================================================================
// Tests matrix 'A' (for banded matrix-vector computations) for validity
template <typename T>
void TestMatrixBanded(const size_t n, const size_t kl, const size_t ku, const Buffer<T> &buffer,
const size_t offset, const size_t ld, const bool test_lead_dim = true) {
if (test_lead_dim && ld < kl + ku) { throw BLASError(StatusCode::kInvalidLeadDimA); }
try {
const auto required_size = (ld * n + offset) * sizeof(T);
if (buffer.GetSize() < required_size) { throw BLASError(StatusCode::kInsufficientMemoryA); }
} catch (const Error<std::runtime_error> &e) { throw BLASError(StatusCode::kInvalidMatrixA, e.what()); }
}

// Tests matrix 'A' for validity
template <typename T>
Expand Down
Loading