Skip to content

Commit

Permalink
WINDOWS: removing the dependency of the samples to the clients object…
Browse files Browse the repository at this point in the history
… files. (#305)

* removing the dependency of the samples to the clients object files.
To this end, a very short file 'clients/samples/utils.hpp' has been created.
Each cpp sample must include this file.

* still unrelated test failures on CI I cannot reproduce, my suspicion is something is going on with matrix files
  • Loading branch information
YvanMokwinski authored Feb 26, 2022
1 parent 86e897e commit 020c70c
Show file tree
Hide file tree
Showing 16 changed files with 541 additions and 181 deletions.
27 changes: 2 additions & 25 deletions clients/samples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,6 @@
#
# ########################################################################

set(ROCSPARSE_CLIENTS_COMMON
../common/rocsparse_init.cpp
../common/utility.cpp
../common/rocsparse_matrix_factory.cpp
../common/rocsparse_matrix_factory_laplace2d.cpp
../common/rocsparse_matrix_factory_laplace3d.cpp
../common/rocsparse_matrix_factory_zero.cpp
../common/rocsparse_matrix_factory_random.cpp
../common/rocsparse_matrix_factory_file.cpp
../common/rocsparse_importer.cpp
../common/rocsparse_importer_matrixmarket.cpp
../common/rocsparse_importer_rocsparseio.cpp
../common/rocsparse_importer_rocalution.cpp)


add_library(rocsparse_common_samples ${ROCSPARSE_CLIENTS_COMMON})
target_compile_options(rocsparse_common_samples PRIVATE -Wno-unused-command-line-argument)
target_include_directories(rocsparse_common_samples PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)
target_link_libraries(rocsparse_common_samples PRIVATE roc::rocsparse hip::host hip::device)
set_target_properties(rocsparse_common_samples PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging")

# Function to add rocsparse examples
function(add_rocsparse_example EXAMPLE_SOURCE)
get_filename_component(EXAMPLE_TARGET ${EXAMPLE_SOURCE} NAME_WE)
Expand All @@ -54,8 +33,7 @@ function(add_rocsparse_example EXAMPLE_SOURCE)
target_include_directories(${EXAMPLE_TARGET} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)

# Linker dependencies
target_link_libraries(${EXAMPLE_TARGET} PRIVATE roc::rocsparse hip::host hip::device rocsparse_common_samples)

target_link_libraries(${EXAMPLE_TARGET} PRIVATE roc::rocsparse hip::host hip::device)
# Target properties
set_target_properties(${EXAMPLE_TARGET} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/staging")
endfunction()
Expand Down Expand Up @@ -129,8 +107,7 @@ if(TARGET rocsparse)
target_include_directories(${EXAMPLE_TARGET} PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/../include>)

# Linker dependencies
target_link_libraries(${EXAMPLE_TARGET} PRIVATE roc::rocsparse hip::host rocsparse_common_samples)

target_link_libraries(${EXAMPLE_TARGET} PRIVATE roc::rocsparse hip::host)
if (BUILD_CODE_COVERAGE)
target_link_libraries(${EXAMPLE_TARGET} PRIVATE -lgcov)
endif()
Expand Down
17 changes: 7 additions & 10 deletions clients/samples/example_coomv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
*
* ************************************************************************ */

#include "rocsparse_init.hpp"
#include "rocsparse_random.hpp"
#include "utility.hpp"
#include "utils.hpp"

#include <hip/hip_runtime_api.h>
#include <iomanip>
Expand Down Expand Up @@ -94,17 +92,16 @@ int main(int argc, char* argv[])
rocsparse_int n;
rocsparse_int nnz;

rocsparse_init_coo_laplace2d(
hArow, hAcol, hAval, ndim, ndim, m, n, nnz, rocsparse_index_base_zero);
utils_init_coo_laplace2d(hArow, hAcol, hAval, ndim, ndim, m, n, nnz, rocsparse_index_base_zero);

// Sample some random data
rocsparse_seedrand();
utils_seedrand();

double halpha = random_generator<double>();
double halpha = utils_random<double>();
double hbeta = 0.0;

std::vector<double> hx(n);
rocsparse_init<double>(hx, 1, n, 1);
utils_init<double>(hx, 1, n, 1);

// Matrix descriptor
rocsparse_mat_descr descrA;
Expand Down Expand Up @@ -151,7 +148,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());

// Start time measurement
double time = get_time_us();
double time = utils_time_us();

// COO matrix vector multiplication
for(int i = 0; i < trials; ++i)
Expand All @@ -178,7 +175,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());
}

time = (get_time_us() - time) / (trials * batch_size * 1e3);
time = (utils_time_us() - time) / (trials * batch_size * 1e3);
double bandwidth
= static_cast<double>(sizeof(double) * (4 * m + nnz) + sizeof(rocsparse_int) * (2 * nnz))
/ time / 1e6;
Expand Down
19 changes: 7 additions & 12 deletions clients/samples/example_csrmv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@
* THE SOFTWARE.
*
* ************************************************************************ */

#include "rocsparse_init.hpp"
#include "rocsparse_random.hpp"
#include "utility.hpp"

#include "utils.hpp"
#include <hip/hip_runtime_api.h>
#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -94,11 +90,10 @@ int main(int argc, char* argv[])
rocsparse_int n;
rocsparse_int nnz;

rocsparse_init_csr_laplace2d(
hAptr, hAcol, hAval, ndim, ndim, m, n, nnz, rocsparse_index_base_zero);
utils_init_csr_laplace2d(hAptr, hAcol, hAval, ndim, ndim, m, n, nnz, rocsparse_index_base_zero);

std::vector<double> hx(n);
rocsparse_init<double>(hx, 1, n, 1);
utils_init<double>(hx, 1, n, 1);

// Offload data to device
rocsparse_int* dAptr = NULL;
Expand Down Expand Up @@ -150,7 +145,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());

// Start time measurement
double time = get_time_us();
double time = utils_time_us();

// CSR matrix vector multiplication
for(int i = 0; i < trials; ++i)
Expand Down Expand Up @@ -178,7 +173,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());
}

time = (get_time_us() - time) / (trials * batch_size * 1e3);
time = (utils_time_us() - time) / (trials * batch_size * 1e3);
double bandwidth = static_cast<double>(sizeof(double) * (2 * m + nnz)
+ sizeof(rocsparse_int) * (m + 1 + nnz))
/ time / 1e6;
Expand Down Expand Up @@ -227,7 +222,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());

// Start time measurement
time = get_time_us();
time = utils_time_us();

// CSR matrix vector multiplication
for(int i = 0; i < trials; ++i)
Expand Down Expand Up @@ -255,7 +250,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());
}

time = (get_time_us() - time) / (trials * batch_size * 1e3);
time = (utils_time_us() - time) / (trials * batch_size * 1e3);
bandwidth = static_cast<double>(sizeof(double) * (2 * m + nnz)
+ sizeof(rocsparse_int) * (m + 1 + nnz))
/ time / 1e6;
Expand Down
17 changes: 7 additions & 10 deletions clients/samples/example_csrmv_managed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
*
* ************************************************************************ */

#include "rocsparse_init.hpp"
#include "rocsparse_random.hpp"
#include "utility.hpp"

#include "utils.hpp"
#include <hip/hip_runtime_api.h>
#include <iomanip>
#include <iostream>
Expand Down Expand Up @@ -94,11 +91,11 @@ int main(int argc, char* argv[])
rocsparse_int n;
rocsparse_int nnz;

rocsparse_init_csr_laplace2d(
utils_init_csr_laplace2d(
Aptr_temp, Acol_temp, Aval_temp, ndim, ndim, m, n, nnz, rocsparse_index_base_zero);

std::vector<double> x_temp(n);
rocsparse_init<double>(x_temp, 1, n, 1);
utils_init<double>(x_temp, 1, n, 1);

rocsparse_int* Aptr = NULL;
rocsparse_int* Acol = NULL;
Expand Down Expand Up @@ -160,7 +157,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());

// Start time measurement
double time = get_time_us();
double time = utils_time_us();

// CSR matrix vector multiplication
for(int i = 0; i < trials; ++i)
Expand Down Expand Up @@ -188,7 +185,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());
}

time = (get_time_us() - time) / (trials * batch_size * 1e3);
time = (utils_time_us() - time) / (trials * batch_size * 1e3);
double bandwidth = static_cast<double>(sizeof(double) * (2 * m + nnz)
+ sizeof(rocsparse_int) * (m + 1 + nnz))
/ time / 1e6;
Expand Down Expand Up @@ -237,7 +234,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());

// Start time measurement
time = get_time_us();
time = utils_time_us();

// CSR matrix vector multiplication
for(int i = 0; i < trials; ++i)
Expand Down Expand Up @@ -265,7 +262,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());
}

time = (get_time_us() - time) / (trials * batch_size * 1e3);
time = (utils_time_us() - time) / (trials * batch_size * 1e3);
bandwidth = static_cast<double>(sizeof(double) * (2 * m + nnz)
+ sizeof(rocsparse_int) * (m + 1 + nnz))
/ time / 1e6;
Expand Down
15 changes: 5 additions & 10 deletions clients/samples/example_csrsv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,14 @@
* THE SOFTWARE.
*
* ************************************************************************ */

#include "rocsparse_init.hpp"
#include "rocsparse_random.hpp"
#include "utility.hpp"

#include "utils.hpp"
#include <hip/hip_runtime_api.h>
#include <iomanip>
#include <iostream>
#include <rocsparse.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

#define HIP_CHECK(stat) \
{ \
if(stat != hipSuccess) \
Expand Down Expand Up @@ -103,12 +98,12 @@ int main(int argc, char* argv[])
rocsparse_int nnz;
double alpha = 1.0f;

rocsparse_init_csr_laplace2d(
utils_init_csr_laplace2d(
hcsr_row_ptr, hcsr_col_ind, hcsr_val, ndim, ndim, m, m, nnz, rocsparse_index_base_zero);

std::vector<double> hx(m);
std::vector<double> hy(m);
rocsparse_init<double>(hx, 1, m, 1);
utils_init<double>(hx, 1, m, 1);

rocsparse_int* dcsr_row_ptr = NULL;
rocsparse_int* dcsr_col_ind = NULL;
Expand Down Expand Up @@ -193,7 +188,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());

// Start time measurement
double time = get_time_us();
double time = utils_time_us();

// Call dcsrsv to perform lower triangular solve Ly = x
for(int i = 0; i < trials; ++i)
Expand All @@ -220,7 +215,7 @@ int main(int argc, char* argv[])
}
}

double solve_time = (get_time_us() - time) / (trials * batch_size * 1e3);
double solve_time = (utils_time_us() - time) / (trials * batch_size * 1e3);
double bandwidth = ((m + 1 + nnz) * sizeof(rocsparse_int) + (m + m + nnz) * sizeof(double))
/ solve_time / 1e6;

Expand Down
30 changes: 13 additions & 17 deletions clients/samples/example_csrsv_managed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,14 @@
*
* ************************************************************************ */

#include "rocsparse_init.hpp"
#include "rocsparse_random.hpp"
#include "utility.hpp"

#include "utils.hpp"
#include <hip/hip_runtime_api.h>
#include <iomanip>
#include <iostream>
#include <rocsparse.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

#define HIP_CHECK(stat) \
{ \
if(stat != hipSuccess) \
Expand Down Expand Up @@ -103,18 +99,18 @@ int main(int argc, char* argv[])
rocsparse_int nnz;
double alpha = 1.0f;

rocsparse_init_csr_laplace2d(csr_row_ptr_temp,
csr_col_ind_temp,
csr_val_temp,
ndim,
ndim,
m,
m,
nnz,
rocsparse_index_base_zero);
utils_init_csr_laplace2d(csr_row_ptr_temp,
csr_col_ind_temp,
csr_val_temp,
ndim,
ndim,
m,
m,
nnz,
rocsparse_index_base_zero);

std::vector<double> x_temp(m);
rocsparse_init<double>(x_temp, 1, m, 1);
utils_init<double>(x_temp, 1, m, 1);

rocsparse_int* csr_row_ptr = NULL;
rocsparse_int* csr_col_ind = NULL;
Expand Down Expand Up @@ -207,7 +203,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());

// Start time measurement
double time = get_time_us();
double time = utils_time_us();

// Call dcsrsv to perform lower triangular solve Ly = x
for(int i = 0; i < trials; ++i)
Expand All @@ -234,7 +230,7 @@ int main(int argc, char* argv[])
}
}

double solve_time = (get_time_us() - time) / (trials * batch_size * 1e3);
double solve_time = (utils_time_us() - time) / (trials * batch_size * 1e3);
double bandwidth = ((m + 1 + nnz) * sizeof(rocsparse_int) + (m + m + nnz) * sizeof(double))
/ solve_time / 1e6;

Expand Down
17 changes: 7 additions & 10 deletions clients/samples/example_ellmv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@
*
* ************************************************************************ */

#include "rocsparse_init.hpp"
#include "rocsparse_random.hpp"
#include "utility.hpp"
#include "utils.hpp"

#include <hip/hip_runtime_api.h>
#include <iomanip>
Expand Down Expand Up @@ -94,17 +92,16 @@ int main(int argc, char* argv[])
rocsparse_int n;
rocsparse_int nnz;

rocsparse_init_csr_laplace2d(
hAptr, hAcol, hAval, ndim, ndim, m, n, nnz, rocsparse_index_base_zero);
utils_init_csr_laplace2d(hAptr, hAcol, hAval, ndim, ndim, m, n, nnz, rocsparse_index_base_zero);

// Sample some random data
rocsparse_seedrand();
utils_seedrand();

double halpha = random_generator<double>();
double halpha = utils_random<double>();
double hbeta = 0.0;

std::vector<double> hx(n);
rocsparse_init<double>(hx, 1, n, 1);
utils_init<double>(hx, 1, n, 1);

// Matrix descriptors
rocsparse_mat_descr descrA;
Expand Down Expand Up @@ -175,7 +172,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());

// Start time measurement
double time = get_time_us();
double time = utils_time_us();

// ELL matrix vector multiplication
for(int i = 0; i < trials; ++i)
Expand All @@ -201,7 +198,7 @@ int main(int argc, char* argv[])
HIP_CHECK(hipDeviceSynchronize());
}

time = (get_time_us() - time) / (trials * batch_size * 1e3);
time = (utils_time_us() - time) / (trials * batch_size * 1e3);
double bandwidth
= static_cast<double>(sizeof(double) * (2 * m + nnz) + sizeof(rocsparse_int) * (nnz)) / time
/ 1e6;
Expand Down
Loading

0 comments on commit 020c70c

Please sign in to comment.