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

Fixes issue with dependencies in nrm2 #451

Merged
merged 3 commits into from
Aug 10, 2023
Merged
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
4 changes: 2 additions & 2 deletions src/interface/blas1_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -332,10 +332,10 @@ typename sb_handle_t::event_t _nrm2(
const auto nWG = 2 * localSize;
auto assignOp =
make_assign_reduction<AddOperator>(rs, prdOp, localSize, localSize * nWG);
auto ret0 = sb_handle.execute(assignOp);
auto ret0 = sb_handle.execute(assignOp, _dependencies);
auto sqrtOp = make_op<UnaryOp, SqrtOperator>(rs);
auto assignOpFinal = make_op<Assign>(rs, sqrtOp);
auto ret1 = sb_handle.execute(assignOpFinal, _dependencies);
auto ret1 = sb_handle.execute(assignOpFinal, ret0);
return blas::concatenate_vectors(ret0, ret1);
}

Expand Down
4 changes: 2 additions & 2 deletions src/interface/blas2_interface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -661,8 +661,8 @@ typename sb_handle_t::event_t _tbmv_impl(
global_size, _dependencies);

auto assignOp = make_op<Assign>(vx, vres);
auto ret = concatenate_vectors(
tbmvEvent, sb_handle.execute(assignOp, local_range, _dependencies));
auto assignEvent = sb_handle.execute(assignOp, local_range, tbmvEvent);
auto ret = concatenate_vectors(tbmvEvent, assignEvent);

blas::helper::enqueue_deallocate(ret, res_buffer, sb_handle.get_queue());

Expand Down
2 changes: 1 addition & 1 deletion test/unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ set(SYCL_UNITTEST_SRCS
${SYCLBLAS_UNITTEST}/blas1/blas1_rotmg_test.cpp
${SYCLBLAS_UNITTEST}/blas1/blas1_rotg_test.cpp
${SYCLBLAS_UNITTEST}/blas1/blas1_sdsdot_test.cpp
${SYCLBLAS_UNITTEST}/blas1/blas1_nrm2_test.cpp
# # Blas 2 tests
${SYCLBLAS_UNITTEST}/blas2/blas2_gbmv_test.cpp
${SYCLBLAS_UNITTEST}/blas2/blas2_gemv_test.cpp
Expand Down Expand Up @@ -72,7 +73,6 @@ if(is_computecpp)
# Blas 1 tests
${SYCLBLAS_UNITTEST}/blas1/blas1_swap_test.cpp
${SYCLBLAS_UNITTEST}/blas1/blas1_dot_test.cpp
${SYCLBLAS_UNITTEST}/blas1/blas1_nrm2_test.cpp
${SYCLBLAS_UNITTEST}/blas1/blas1_iamax_test.cpp
${SYCLBLAS_UNITTEST}/blas1/blas1_iamin_test.cpp
# Blas 2 tests
Expand Down
36 changes: 25 additions & 11 deletions test/unittest/blas1/blas1_nrm2_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,35 +26,47 @@
#include "blas_test.hpp"

template <typename scalar_t>
using combination_t = std::tuple<std::string, api_type, int, int>;
using combination_t = std::tuple<std::string, api_type, int, int, scalar_t>;

template <typename scalar_t, helper::AllocType mem_alloc>
void run_test(const combination_t<scalar_t> combi) {
std::string alloc;
api_type api;
index_t size;
index_t incX;
std::tie(alloc, api, size, incX) = combi;
scalar_t unused;
std::tie(alloc, api, size, incX, unused) = combi;

auto vector_size = size * std::abs(incX);
// Input vectors
std::vector<scalar_t> x_v(size * incX);
std::vector<scalar_t> x_v(vector_size);
fill_random(x_v);

// Output scalar
scalar_t out_s = 10.0;
scalar_t out_cpu_s = 20.0;

// Reference implementation
auto out_cpu_s = reference_blas::nrm2(size, x_v.data(), incX);
if (incX < 0) {
// Some reference implementations of BLAS do not support negative
// increments for nrm2. To simulate what is specified in the
// oneAPI spec, invert the vector and use a positive increment.
std::vector<scalar_t> x_v_inv(vector_size);
std::reverse_copy(x_v.begin(), x_v.end() + (incX + 1), x_v_inv.begin());
out_cpu_s = reference_blas::nrm2(size, x_v_inv.data(), -incX);
} else {
out_cpu_s = reference_blas::nrm2(size, x_v.data(), incX);
}

// SYCL implementation
auto q = make_queue();
blas::SB_Handle sb_handle(q);

// Iterators
auto gpu_x_v = blas::helper::allocate<mem_alloc, scalar_t>(size * incX, q);
auto gpu_x_v = blas::helper::allocate<mem_alloc, scalar_t>(vector_size, q);

auto copy_x =
blas::helper::copy_to_device(q, x_v.data(), gpu_x_v, size * incX);
blas::helper::copy_to_device(q, x_v.data(), gpu_x_v, vector_size);

if (api == api_type::async) {
auto gpu_out_s = blas::helper::allocate<mem_alloc, scalar_t>(1, q);
Expand Down Expand Up @@ -84,7 +96,8 @@ void run_test(const combination_t<scalar_t> combi) {
api_type api;
index_t size;
index_t incX;
std::tie(alloc, api, size, incX) = combi;
scalar_t unused;
std::tie(alloc, api, size, incX, unused) = combi;

if (alloc == "usm") { // usm alloc
#ifdef SB_ENABLE_USM
Expand All @@ -98,20 +111,21 @@ void run_test(const combination_t<scalar_t> combi) {
}
template <typename scalar_t>
const auto combi =
::testing::Combine(::testing::Values("usm", "buf"), // allocation type
::testing::Combine(::testing::Values("usm", "buf"), // allocation type
::testing::Values(api_type::async,
api_type::sync), // Api
::testing::Values(11, 1002), // size
::testing::Values(1, 4) // incX
);
::testing::Values(1, 4, -3), // incX
::testing::Values(scalar_t{1}));

template <class T>
static std::string generate_name(
const ::testing::TestParamInfo<combination_t<T>>& info) {
std::string alloc;
api_type api;
int size, incX;
BLAS_GENERATE_NAME(info.param, alloc, api, size, incX);
T unused;
BLAS_GENERATE_NAME(info.param, alloc, api, size, incX, unused);
}

BLAS_REGISTER_TEST_ALL(Nrm2, combination_t, combi, generate_name);