Skip to content
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
3 changes: 3 additions & 0 deletions clients/testing/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ 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_transpose.cpp
test_functions_transpose_dense.cpp
test_functions_ruiz_scaling.cpp
Expand Down
9 changes: 9 additions & 0 deletions clients/testing/test_enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ namespace testing
CSRILU0,
tridiagonal_solver,
exclusive_scan,
axpy,
axpby,
axpbypgz,
ruiz_scaling,
symmetric_ruiz_scaling,
unknown
Expand Down Expand Up @@ -218,6 +221,12 @@ 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::ruiz_scaling:
return "ruiz_scaling";
case fixture::symmetric_ruiz_scaling:
Expand Down
3 changes: 3 additions & 0 deletions clients/testing/test_functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ 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_sptrsv(Arguments arg);
bool test_spgeam(Arguments arg);
bool test_csric0(Arguments arg);
Expand Down
110 changes: 110 additions & 0 deletions clients/testing/test_functions_axpby.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
//********************************************************************************
//
// 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();
}

const double alpha = 1.5;
const double beta = -0.5;

// Warmup
for(int i = 0; i < 4; i++)
{
linalg::axpby(alpha, x, 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(alpha, x, 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(alpha, x, 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 = alpha * 2.0 + 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) * ((alpha != 0.0) ? size : 0)
+ sizeof(double) * ((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;
}
116 changes: 116 additions & 0 deletions clients/testing/test_functions_axpbypgz.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
//********************************************************************************
//
// 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();
}

const double alpha = 1.5;
const double beta = -0.5;
const double gamma = 2.0;

// Warmup
for(int i = 0; i < 4; i++)
{
linalg::axpbypgz(alpha, x, beta, y, 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(alpha, x, beta, y, 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(alpha, x, beta, y, 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 = alpha * 2.0 + beta * 3.0 + 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) * ((alpha != 0.0) ? size : 0)
+ sizeof(double) * ((beta != 0.0) ? size : 0)
+ sizeof(double) * ((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;
}
109 changes: 109 additions & 0 deletions clients/testing/test_functions_axpy.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
//********************************************************************************
//
// 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 <vector>

#include "linalg.h"

bool testing::test_axpy(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();
}

const double alpha = 1.5;

// Warmup
for(int i = 0; i < 4; i++)
{
linalg::axpy(alpha, x, 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::axpy(alpha, x, 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::axpy(alpha, x, 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 = alpha * 2.0 + 3.0;
if(std::abs(y[i] - expected) > 1e-12)
{
std::cout << "axpy mismatch at index " << i << ": got " << y[i] << ", expected "
<< expected << std::endl;
success = false;
}
}

size_t total_bytes_read = sizeof(double) * ((alpha != 0.0) ? size : 0) + sizeof(double) * size;
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;
}
6 changes: 6 additions & 0 deletions clients/testing/test_functions_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,12 @@ namespace testing
{
switch(arg.fixture)
{
case fixture::axpy:
return test_axpy(arg);
case fixture::axpby:
return test_axpby(arg);
case fixture::axpbypgz:
return test_axpbypgz(arg);
case fixture::SpTRSV:
return test_sptrsv(arg);
case fixture::SpGEAM:
Expand Down
Loading
Loading