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

Reduce duplication within debug code #464

merged 9 commits into from
Sep 6, 2022

Conversation

cgmb
Copy link
Collaborator

@cgmb cgmb commented Aug 29, 2022

This change reduces duplication in the common host helpers by providing a fmt printer for rocblas_float_complex and rocblas_double_complex. If you have low-level functions specialized appropriately for both real and complex (like format or abs are), the higher level functions (like print_to_stream and print_host_matrix) don't need to be specialized themselves.

There were a couple fmtlib-related problems that I fixed at the same time.

  1. rocSOLVER is potentially affected by [PoC] Segmentation fault (possibly due to ODR violation) when mixing format.h with and without ostream.h in different cpp files fmtlib/fmt#2357. I've never actually seen it in rocSOLVER, so we may have gotten lucky with the way our headers are arranged, but it's possible to encounter this bug in fmtlib if <fmt/ostream.h> is only included in a subset of headers used in the library. This bug was fixed in fmt v9.0.0 but I'm having some trouble updating to that version. In previous versions, there is a simple workaround: either always include <fmt/ostream.h> whenever you include another fmtlib header, or never include <fmt/ostream.h>. The first of those two options was the easier one.
  2. It was a mistake for me to set a different default for DROCSOLVER_EMBED_FMT when building with CMake vs. install.sh.
  3. There are two different files named rocblascommon/utility.hpp and common/include/common_host_helpers.hpp was therefore including a different one when it was used in the library than when it was used in the client. This resulted in some very confusing behaviour. I've moved/renamed both headers and trimmed some unused stuff.

This whole thing is basically just me cleaning up some of the current debug code before submitting another PR with some additions.

Copy link
Collaborator

@tfalders tfalders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

cgmb added 9 commits September 6, 2022 09:13
Prior to fmt 9.0.0, the inclusion of fmt/ostream.h would cause fmt to
automatically use an existing ostream function to format the type.
However, this would cause subtle issues during compilation if
fmt/ostream.h were only sometimes included (as the definition of the
formatting would change between files, in violation of the
one-definition rule).

As long as rocSOLVER supports the use of fmt 7.x and 8.x and uses
fmt/ostream.h in any file, rocSOLVER should include fmt/ostream.h in
every file that includes another fmt header.
This matches the existing default when building with install.sh or
rmake.py. The difference was intended to provide different users with
the defaults they prefer, but in practice it mostly caused confusion.
Experience has shown that the defaults for directly using CMake and for
building with the user of the helper script should be as similar as
possible.
There is a clients/rocblascommon/utility.hpp and a
library/rocblascommon/utility.hpp and the identical names
cause confusion.

In particular, common_host_helpers.hpp includes utility.hpp, which
results in including a different file when the host helpers are used
in the library vs. when the host helpers are used in the clients.
A header in common/ cannot depend on a header in library/, but
common_host_helpers.hpp does. It only ever compiled because there were
two different headers called utility.hpp.

This is solved by moving the library/ utility.hpp to common/ and
renaming it to reflect that it is used for rocblas types.
@cgmb cgmb enabled auto-merge (squash) September 6, 2022 09:18
@cgmb cgmb disabled auto-merge September 6, 2022 16:25
@cgmb cgmb merged commit 55aff43 into ROCm:develop Sep 6, 2022
@cgmb cgmb deleted the fmt-complex branch September 6, 2022 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants