diff --git a/tests/unit_tests/sparse_blas/source/sparse_gemv_usm.cpp b/tests/unit_tests/sparse_blas/source/sparse_gemv_usm.cpp index e6b0520e1..873855ca9 100644 --- a/tests/unit_tests/sparse_blas/source/sparse_gemv_usm.cpp +++ b/tests/unit_tests/sparse_blas/source/sparse_gemv_usm.cpp @@ -61,25 +61,26 @@ int test(sycl::device *dev, intType nrows, intType ncols, double density_A_matri ia_host, ja_host, a_host); // Input and output dense vectors - // The host and device output are filled with a dummy value to spot mistakes. - std::vector x_host; - std::vector y_host(opa_nrows, fpType(2)); + // The input `x` and the input-output `y` are both initialized to random values on host and device. + std::vector x_host, y_host; rand_vector(x_host, opa_ncols); + rand_vector(y_host, opa_nrows); + std::vector y_ref_host(y_host); // Shuffle ordering of column indices/values to test sortedness shuffle_data(ia_host.data(), ja_host.data(), a_host.data(), static_cast(nrows)); auto ia_usm_uptr = malloc_device_uptr(main_queue, ia_host.size()); auto ja_usm_uptr = malloc_device_uptr(main_queue, ja_host.size()); + auto a_usm_uptr = malloc_device_uptr(main_queue, a_host.size()); auto x_usm_uptr = malloc_device_uptr(main_queue, x_host.size()); auto y_usm_uptr = malloc_device_uptr(main_queue, y_host.size()); - auto a_usm_uptr = malloc_device_uptr(main_queue, a_host.size()); intType *ia_usm = ia_usm_uptr.get(); intType *ja_usm = ja_usm_uptr.get(); + fpType *a_usm = a_usm_uptr.get(); fpType *x_usm = x_usm_uptr.get(); fpType *y_usm = y_usm_uptr.get(); - fpType *a_usm = a_usm_uptr.get(); std::vector mat_dependencies; std::vector gemv_dependencies; @@ -132,8 +133,6 @@ int test(sycl::device *dev, intType nrows, intType ncols, double density_A_matri } // Compute reference. - // The reference is filled with a dummy value to spot mistakes. - std::vector y_ref_host(opa_nrows, fpType(2)); prepare_reference_gemv_data(ia_host.data(), ja_host.data(), a_host.data(), nrows, ncols, nnz, int_index, transpose_val, alpha, beta, x_host.data(), y_ref_host.data()); @@ -148,6 +147,13 @@ int test(sycl::device *dev, intType nrows, intType ncols, double density_A_matri class SparseGemvUsmTests : public ::testing::TestWithParam {}; +/** + * Helper function to run tests in different configuration. + * + * @tparam fpType Complex or scalar, single or double precision type + * @param dev Device to test + * @param transpose_val Transpose value for the input matrix + */ template void test_helper(sycl::device *dev, oneapi::mkl::transpose transpose_val) { double density_A_matrix = 0.8;