Skip to content

Commit

Permalink
Fill y with random values
Browse files Browse the repository at this point in the history
  • Loading branch information
Rbiessy committed Oct 18, 2023
1 parent 5341802 commit 543e55d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tests/unit_tests/sparse_blas/source/sparse_gemv_usm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<fpType> x_host;
std::vector<fpType> 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<fpType> x_host, y_host;
rand_vector(x_host, opa_ncols);
rand_vector(y_host, opa_nrows);
std::vector<fpType> 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<std::size_t>(nrows));

auto ia_usm_uptr = malloc_device_uptr<intType>(main_queue, ia_host.size());
auto ja_usm_uptr = malloc_device_uptr<intType>(main_queue, ja_host.size());
auto a_usm_uptr = malloc_device_uptr<fpType>(main_queue, a_host.size());
auto x_usm_uptr = malloc_device_uptr<fpType>(main_queue, x_host.size());
auto y_usm_uptr = malloc_device_uptr<fpType>(main_queue, y_host.size());
auto a_usm_uptr = malloc_device_uptr<fpType>(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<sycl::event> mat_dependencies;
std::vector<sycl::event> gemv_dependencies;
Expand Down Expand Up @@ -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<fpType> 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());
Expand All @@ -148,6 +147,13 @@ int test(sycl::device *dev, intType nrows, intType ncols, double density_A_matri

class SparseGemvUsmTests : public ::testing::TestWithParam<sycl::device *> {};

/**
* 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 <typename fpType>
void test_helper(sycl::device *dev, oneapi::mkl::transpose transpose_val) {
double density_A_matrix = 0.8;
Expand Down

0 comments on commit 543e55d

Please sign in to comment.