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

Reduce duplication within debug code #464

Merged
merged 9 commits into from
Sep 6, 2022
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Full documentation for rocSOLVER is available at [rocsolver.readthedocs.io](http
### Added
### Optimized
### Changed
- Changed `ROCSOLVER_EMBED_FMT` default to `ON` for users building directly with CMake.
This matches the existing default when building with install.sh or rmake.py.
### Deprecated
### Removed
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_EXTENSIONS OFF)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(ROCSOLVER_EMBED_FMT "Hide libfmt symbols" OFF)
option(ROCSOLVER_EMBED_FMT "Hide libfmt symbols" ON)
option(OPTIMAL "Build specialized kernels for small matrix sizes" ON)
option(ROCSOLVER_FIND_PACKAGE_LAPACK_CONFIG "Skip module mode search for LAPACK" ON)

Expand Down
2 changes: 1 addition & 1 deletion clients/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ if(BUILD_CLIENTS_BENCHMARKS OR BUILD_CLIENTS_TESTS)
)
set(common_source_files
common/lapack_host_reference.cpp
rocblascommon/utility.cpp
rocblascommon/clients_utility.cpp
${explicit_inst_files}
)

Expand Down
3 changes: 2 additions & 1 deletion clients/gtest/rocsolver_gtest_main.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
/* ************************************************************************
* Copyright (c) 2020-2021 Advanced Micro Devices, Inc.
* Copyright (c) 2020-2022 Advanced Micro Devices, Inc.
* ************************************************************************ */

#include <cstdio>
#include <string>

#include <fmt/core.h>
#include <fmt/ostream.h>
#include <gtest/gtest.h>
#include <rocsolver/rocsolver.h>

Expand Down
2 changes: 1 addition & 1 deletion clients/include/clientcommon.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
#include "common_host_helpers.hpp"
#include "rocsolver_datatype2string.hpp"
// rocblas common
#include "rocblascommon/clients_utility.hpp"
#include "rocblascommon/rocblas_test.hpp"
#include "rocblascommon/rocblas_vector.hpp"
#include "rocblascommon/utility.hpp"
//#include "rocblascommon/device_vector.hpp"
//#include "rocblascommon/device_batch_vector.hpp"
//#include "rocblascommon/device_strided_batch_vector.hpp"
Expand Down
1 change: 1 addition & 0 deletions clients/include/rocsolver_arguments.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <set>

#include <fmt/format.h>
#include <fmt/ostream.h>
#include <fmt/ranges.h>
#include <rocblas/rocblas.h>

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
/* ************************************************************************
* Copyright (c) 2018-2021 Advanced Micro Devices, Inc.
* Copyright (c) 2018-2022 Advanced Micro Devices, Inc.
* ************************************************************************ */

#include <cstdlib>
#include <cstring>
#include <string>

#include <fmt/core.h>
#include <rocblas/rocblas.h>

#include "clients_utility.hpp"
#include "rocblas_random.hpp"
#include "utility.hpp"

// Random number generator
// Note: We do not use random_device to initialize the RNG, because we want
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ************************************************************************
* Copyright (c) 2018-2021 Advanced Micro Devices, Inc.
* Copyright (c) 2018-2022 Advanced Micro Devices, Inc.
* ************************************************************************ */

#pragma once
Expand Down
3 changes: 2 additions & 1 deletion clients/rocblascommon/d_vector.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ************************************************************************
* Copyright (c) 2018-2021 Advanced Micro Devices, Inc.
* Copyright (c) 2018-2022 Advanced Micro Devices, Inc.
* ************************************************************************ */

#pragma once
Expand All @@ -8,6 +8,7 @@
#include <cstdio>

#include <fmt/core.h>
#include <fmt/ostream.h>
#include <rocblas/rocblas.h>

#include "rocblas_init.hpp"
Expand Down
3 changes: 2 additions & 1 deletion clients/rocblascommon/rocblas_init.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ************************************************************************
* Copyright (c) 2018-2021 Advanced Micro Devices, Inc.
* Copyright (c) 2018-2022 Advanced Micro Devices, Inc.
* ************************************************************************ */

#pragma once
Expand All @@ -9,6 +9,7 @@
#include <vector>

#include <fmt/core.h>
#include <fmt/ostream.h>
#include <rocblas/rocblas.h>

#include "rocblas_math.hpp"
Expand Down
4 changes: 2 additions & 2 deletions clients/rocblascommon/rocblas_test.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* ************************************************************************
* Copyright (c) 2018-2021 Advanced Micro Devices, Inc.
* Copyright (c) 2018-2022 Advanced Micro Devices, Inc.
* ************************************************************************ */

#pragma once
Expand All @@ -9,14 +9,14 @@
#include <cstring>
#include <functional>
#include <iostream>
#include <rocblas/rocblas.h>
#include <sstream>
#include <string>
#include <type_traits>
#include <unordered_map>
#include <utility>

#include <fmt/core.h>
#include <fmt/ostream.h>
#include <rocblas/rocblas.h>

// Suppress warnings about hipMalloc(), hipFree() except in rocblas-test and
Expand Down
108 changes: 6 additions & 102 deletions common/include/common_host_helpers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
#include <fmt/ostream.h>
#include <hip/hip_runtime_api.h>

#include "rocblascommon/utility.hpp"
#include "fmt_rocblas_types.hpp"
#include "rocblas_utility.hpp"

/*
* ===========================================================================
Expand Down Expand Up @@ -81,8 +82,8 @@ void pairs_to_string(std::string& str, const char* sep, T1 arg1, T2 arg2, Ts...
/** Set of helpers to print out data hosted in the CPU and/or the GPU **/
/***********************************************************************/

/*! \brief Print provided data into specified stream (real case)*/
template <typename T, std::enable_if_t<!rocblas_is_complex<T>, int> = 0>
/*! \brief Print provided data into specified stream */
template <typename T>
void print_to_stream(std::ostream& os,
const std::string name,
const rocblas_int m,
Expand Down Expand Up @@ -148,73 +149,6 @@ void print_to_stream(std::ostream& os,
os.flush();
}

/*! \brief Print provided data into specified stream (complex cases)*/
template <typename T, std::enable_if_t<rocblas_is_complex<T>, int> = 0>
void print_to_stream(std::ostream& os,
const std::string name,
const rocblas_int m,
const rocblas_int n,
T* A,
const rocblas_int lda,
const rocblas_fill uplo)
{
std::string s;
bool empty = name.empty();
if(!empty)
s += fmt::format("{}-by-{} matrix: {}\n", m, n, name);

if(uplo == rocblas_fill_full)
{
// normal case
for(int i = 0; i < m; i++)
{
if(!empty)
s += " ";
for(int j = 0; j < n; j++)
{
s += fmt::format("{}+{}*i", A[j * lda + i].real(), A[j * lda + i].imag());
if(j < n - 1)
s += ", ";
}
s += '\n';
}
}
else
{
// symmetric case
for(int i = 0; i < min(m, n); i++)
{
if(!empty)
s += " ";
for(int j = 0; j < min(m, n); j++)
{
if(uplo == rocblas_fill_upper)
{
if(i < j)
s += fmt::format("{}+{}*i", A[j * lda + i].real(), A[j * lda + i].imag());
else
s += fmt::format("{}+{}*i", A[i * lda + j].real(), A[i * lda + j].imag());
}
else
{
if(i > j)
s += fmt::format("{}+{}*i", A[j * lda + i].real(), A[j * lda + i].imag());
else
s += fmt::format("{}+{}*i", A[i * lda + j].real(), A[i * lda + j].imag());
}

if(j < n - 1)
s += ", ";
}
s += '\n';
}
}

s += '\n';
os << s;
os.flush();
}

/*! \brief Print data from a normal or strided_batched array on the GPU to screen*/
template <typename T>
void print_device_matrix(std::ostream& os,
Expand Down Expand Up @@ -380,37 +314,7 @@ void print_host_matrix(std::ostream& os,
os.flush();
}

template <typename T, std::enable_if_t<!rocblas_is_complex<T>, int> = 0>
void print_host_matrix(std::ostream& os,
const std::string name,
const rocblas_int m,
const rocblas_int n,
T* CPU_result,
T* GPU_result,
const rocblas_int lda,
double error_tolerance)
{
std::string s;
bool empty = name.empty();
if(!empty)
s += fmt::format("{}-by-{} matrix: {}\n", m, n, name);

for(size_t j = 0; j < n; j++)
{
for(size_t i = 0; i < m; i++)
{
T comp = (CPU_result[j * lda + i] - GPU_result[j * lda + i]) / CPU_result[j * lda + i];
if(abs(comp) > error_tolerance)
s += fmt::format("matrix row {}, col {}, CPU result={}, GPU result={}\n", i, j,
CPU_result[j * lda + i], GPU_result[j * lda + i]);
}
}
s += '\n';
os << s;
os.flush();
}

template <typename T, std::enable_if_t<rocblas_is_complex<T>, int> = 0>
template <typename T>
void print_host_matrix(std::ostream& os,
const std::string name,
const rocblas_int m,
Expand All @@ -430,7 +334,7 @@ void print_host_matrix(std::ostream& os,
for(size_t i = 0; i < m; i++)
{
T comp = (CPU_result[j * lda + i] - GPU_result[j * lda + i]) / CPU_result[j * lda + i];
if(sqrt(comp.real() * comp.real() + comp.imag() * comp.imag()) > error_tolerance)
if(std::abs(comp) > error_tolerance)
s += fmt::format("matrix row {}, col {}, CPU result={}, GPU result={}\n", i, j,
CPU_result[j * lda + i], GPU_result[j * lda + i]);
}
Expand Down
34 changes: 34 additions & 0 deletions common/include/fmt_rocblas_types.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/* ************************************************************************
* Copyright (c) 2021-2022 Advanced Micro Devices, Inc.
* ************************************************************************ */

#pragma once

#include <fmt/format.h>
#include <fmt/ostream.h>
#include <rocblas/rocblas.h>

/* The format function for user-defined types cannot be const before fmt v8.0
but must be const in fmt v8.1 if the type is used in a tuple. */
#if FMT_VERSION < 80000
#define ROCSOLVER_FMT_CONST
#else
#define ROCSOLVER_FMT_CONST const
#endif

namespace fmt
{
template <typename T>
struct formatter<rocblas_complex_num<T>> : formatter<T>
{
template <typename FormatCtx>
auto format(const rocblas_complex_num<T>& value, FormatCtx& ctx) ROCSOLVER_FMT_CONST
{
formatter<T>::format(value.real(), ctx);
format_to(ctx.out(), "+");
formatter<T>::format(value.imag(), ctx);
format_to(ctx.out(), "*i");
return ctx.out();
}
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@

#pragma once

#include "definitions.hpp"
#include "rocblas/rocblas.h"
#include "rocsolver/rocsolver.h"
#include <cmath>
#include <complex>
#include <exception>
#include <hip/hip_runtime.h>
#include <new>
#include <type_traits>

#include <hip/hip_runtime.h>
#include <rocblas/rocblas.h>
#include <rocsolver/rocsolver.h>

#pragma STDC CX_LIMITED_RANGE ON

// half vectors
Expand Down
1 change: 0 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -540,7 +540,6 @@ cmake_common_options+=(
'-DCPACK_SET_DESTDIR=OFF'
"-DCMAKE_INSTALL_PREFIX=${lib_dir}"
"-DCPACK_PACKAGING_INSTALL_PREFIX=${install_dir}"
'-DROCSOLVER_EMBED_FMT=ON'
"-DCMAKE_BUILD_TYPE=${build_type}"
)

Expand Down
2 changes: 1 addition & 1 deletion library/src/common/rocsolver_logger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#include <iostream>
#include <string>

#include "rocblascommon/utility.hpp"
#include "rocblas_utility.hpp"
#include "rocsolver_logger.hpp"

#define STRINGIFY(s) STRINGIFY_HELPER(s)
Expand Down
5 changes: 3 additions & 2 deletions library/src/include/libcommon.hpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
/* ************************************************************************
* Copyright (c) 2019-2021 Advanced Micro Devices, Inc.
* Copyright (c) 2019-2022 Advanced Micro Devices, Inc.
* ************************************************************************ */

#pragma once

#include "rocblascommon/utility.hpp"
#include <string>
#include <vector>

#include "rocblas_utility.hpp"
10 changes: 2 additions & 8 deletions library/src/include/rocsolver_logvalue.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,11 @@
#pragma once

#include <fmt/format.h>
#include <fmt/ostream.h>

#include "fmt_rocblas_types.hpp"
#include "rocsolver_datatype2string.hpp"

/* The format function for user-defined types cannot be const before fmt v8.0
but must be const in fmt v8.1 if the type is used in a tuple. */
#if FMT_VERSION < 80000
#define ROCSOLVER_FMT_CONST
#else
#define ROCSOLVER_FMT_CONST const
#endif

/***************************************************************************
* Wrapper for types passed to logger, so we can more easily adjust the
* default way of printing built-in types without doing it globally. (e.g.
Expand Down
Loading