Skip to content
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: 4 additions & 0 deletions clients/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,10 @@ target_sources(test_main
test_functions_incomplete_LU_factorization_dense.cpp
test_functions_sptrsv.cpp
test_functions_spgeam.cpp
test_functions_axpy.cpp
test_functions_axpby.cpp
test_functions_axpbypgz.cpp
test_functions_dot_product.cpp
test_functions_transpose.cpp
test_functions_transpose_dense.cpp
test_functions_ruiz_scaling.cpp
Expand Down
51 changes: 51 additions & 0 deletions clients/testing/test_arguments.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,9 @@ namespace testing
int m;
int n;
double tol;
double alpha;
double beta;
double gamma;
double omega;

std::string generate_test_name() const
Expand Down Expand Up @@ -114,6 +117,54 @@ namespace testing
}
name += "_" + tol_str;
}
if(this->alpha >= -98.0)
{
std::string alpha_str = std::to_string(this->alpha);
for(size_t i = 0; i < alpha_str.length(); i++)
{
if(alpha_str[i] == '.')
{
alpha_str[i] = '_';
}
if(alpha_str[i] == '-')
{
alpha_str[i] = 'n';
}
}
name += "_" + alpha_str;
}
if(this->beta >= -98.0)
{
std::string beta_str = std::to_string(this->beta);
for(size_t i = 0; i < beta_str.length(); i++)
{
if(beta_str[i] == '.')
{
beta_str[i] = '_';
}
if(beta_str[i] == '-')
{
beta_str[i] = 'n';
}
}
name += "_" + beta_str;
}
if(this->gamma >= -98.0)
{
std::string gamma_str = std::to_string(this->gamma);
for(size_t i = 0; i < gamma_str.length(); i++)
{
if(gamma_str[i] == '.')
{
gamma_str[i] = '_';
}
if(gamma_str[i] == '-')
{
gamma_str[i] = 'n';
}
}
name += "_" + gamma_str;
}
if(this->omega >= 0)
{
std::string omega_str = std::to_string(this->omega);
Expand Down
12 changes: 12 additions & 0 deletions clients/testing/test_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ namespace testing
CSRILU0,
tridiagonal_solver,
exclusive_scan,
axpy,
axpby,
axpbypgz,
dot_product,
ruiz_scaling,
symmetric_ruiz_scaling,
unknown
Expand Down Expand Up @@ -218,6 +222,14 @@ namespace testing
return "tridiagonal_solver";
case fixture::exclusive_scan:
return "exclusive_scan";
case fixture::axpy:
return "axpy";
case fixture::axpby:
return "axpby";
case fixture::axpbypgz:
return "axpbypgz";
case fixture::dot_product:
return "dot_product";
case fixture::ruiz_scaling:
return "ruiz_scaling";
case fixture::symmetric_ruiz_scaling:
Expand Down
4 changes: 4 additions & 0 deletions clients/testing/test_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ namespace testing
bool test_tridiagonal_solver(Arguments arg);

// math testing
bool test_axpy(Arguments arg);
bool test_axpby(Arguments arg);
bool test_axpbypgz(Arguments arg);
bool test_dot_product(Arguments arg);
bool test_sptrsv(Arguments arg);
bool test_spgeam(Arguments arg);
bool test_csric0(Arguments arg);
Expand Down
107 changes: 107 additions & 0 deletions clients/testing/test_functions_axpby.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
//********************************************************************************
//
// MIT License
//
// Copyright(c) 2026 James Sandham
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this softwareand associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//********************************************************************************

#include "test_functions.h"
#include "utility.h"

#include <chrono>
#include <cmath>
#include <iostream>

#include "linalg.h"

bool testing::test_axpby(Arguments arg)
{
const size_t size = arg.m;

linalg::vector<double> x(size);
linalg::vector<double> y(size);
x.fill(2.0);
y.fill(3.0);

linalg::vector<double> y_copy(size);
y_copy.copy_from(y);

if(arg.backend == backend::GPU)
{
x.move_to_device();
y.move_to_device();
y_copy.move_to_device();
}

// Warmup
for(int i = 0; i < 4; i++)
{
linalg::axpby(arg.alpha, x, arg.beta, y);
}
y.copy_from(y_copy);
linalg::synchronize();

// Timed solve
auto t1 = std::chrono::high_resolution_clock::now();
for(int i = 0; i < 10; i++)
{
linalg::axpby(arg.alpha, x, arg.beta, y);
}
linalg::synchronize();
auto t2 = std::chrono::high_resolution_clock::now();

std::chrono::duration<double, std::milli> ms_float = t2 - t1;
std::cout << "Solve time: " << ms_float.count() << "ms" << std::endl;

y.copy_from(y_copy);
linalg::axpby(arg.alpha, x, arg.beta, y);

if(arg.backend == backend::GPU)
{
x.move_to_host();
y.move_to_host();
y_copy.move_to_host();
}

bool success = true;
for(size_t i = 0; i < size; ++i)
{
const double expected = arg.alpha * 2.0 + arg.beta * 3.0;
if(std::abs(y[i] - expected) > 1e-12)
{
std::cout << "axpby mismatch at index " << i << ": got " << y[i] << ", expected "
<< expected << std::endl;
success = false;
}
}

size_t total_bytes_read = sizeof(double) * ((arg.alpha != 0.0) ? size : 0)
+ sizeof(double) * ((arg.beta != 0.0) ? size : 0);
size_t total_bytes_written = sizeof(double) * size;
size_t total_bytes_read_write = total_bytes_read + total_bytes_written;
double total_gbytes = (double)10 * total_bytes_read_write / 1e9;
double bandwidth = total_gbytes / (ms_float.count() / 1e3);

std::cout << "Effective Bandwidth: " << bandwidth << " GB/s" << std::endl;

return success;
}
112 changes: 112 additions & 0 deletions clients/testing/test_functions_axpbypgz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
//********************************************************************************
//
// MIT License
//
// Copyright(c) 2026 James Sandham
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this softwareand associated documentation files(the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and /or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions :
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
//
//********************************************************************************

#include "test_functions.h"
#include "utility.h"

#include <chrono>
#include <cmath>
#include <iostream>

#include "linalg.h"

bool testing::test_axpbypgz(Arguments arg)
{
const size_t size = arg.m;

linalg::vector<double> x(size);
linalg::vector<double> y(size);
linalg::vector<double> z(size);
x.fill(2.0);
y.fill(3.0);
z.fill(4.0);

linalg::vector<double> z_copy(size);
z_copy.copy_from(z);

if(arg.backend == backend::GPU)
{
x.move_to_device();
y.move_to_device();
z.move_to_device();
z_copy.move_to_device();
}

// Warmup
for(int i = 0; i < 4; i++)
{
linalg::axpbypgz(arg.alpha, x, arg.beta, y, arg.gamma, z);
}
z.copy_from(z_copy);
linalg::synchronize();

// Timed solve
auto t1 = std::chrono::high_resolution_clock::now();
for(int i = 0; i < 10; i++)
{
linalg::axpbypgz(arg.alpha, x, arg.beta, y, arg.gamma, z);
}
linalg::synchronize();
auto t2 = std::chrono::high_resolution_clock::now();

std::chrono::duration<double, std::milli> ms_float = t2 - t1;
std::cout << "Solve time: " << ms_float.count() << "ms" << std::endl;

z.copy_from(z_copy);
linalg::axpbypgz(arg.alpha, x, arg.beta, y, arg.gamma, z);

if(arg.backend == backend::GPU)
{
x.move_to_host();
y.move_to_host();
z.move_to_host();
z_copy.move_to_host();
}

bool success = true;
for(size_t i = 0; i < size; ++i)
{
const double expected = arg.alpha * 2.0 + arg.beta * 3.0 + arg.gamma * 4.0;
if(std::abs(z[i] - expected) > 1e-12)
{
std::cout << "axpbypgz mismatch at index " << i << ": got " << z[i] << ", expected "
<< expected << std::endl;
success = false;
}
}

size_t total_bytes_read = sizeof(double) * ((arg.alpha != 0.0) ? size : 0)
+ sizeof(double) * ((arg.beta != 0.0) ? size : 0)
+ sizeof(double) * ((arg.gamma != 0.0) ? size : 0);
size_t total_bytes_written = sizeof(double) * size;
size_t total_bytes_read_write = total_bytes_read + total_bytes_written;
double total_gbytes = (double)10 * total_bytes_read_write / 1e9;
double bandwidth = total_gbytes / (ms_float.count() / 1e3);

std::cout << "Effective Bandwidth: " << bandwidth << " GB/s" << std::endl;

return success;
}
Loading
Loading