Skip to content

fix: use fabsf() consistently for float symmetry checks - #238

Open
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:fix/symmetry-check-abs-format
Open

fix: use fabsf() consistently for float symmetry checks#238
andrewwhitecdw wants to merge 1 commit into
NVIDIA:mainfrom
andrewwhitecdw:fix/symmetry-check-abs-format

Conversation

@andrewwhitecdw

@andrewwhitecdw andrewwhitecdw commented Jul 25, 2026

Copy link
Copy Markdown

Use fabsf() instead of abs() for the floating-point symmetry difference in all learner-facing locations.

abs() selects the integer overload, which truncates/rounds the float before comparing it against the 0.1 threshold. That can hide real asymmetry or report false positives.

The format specifier stays %d everywhere because temperature_grid_f uses cuda::std::dextents<int, 2>, so temp.extent(1) returns int, not size_t.

Files updated:

  • Solutions/symmetry-check.cpp
  • Sources/symmetry-check.cpp
  • Solutions/row-symmetry-check.cpp
  • Sources/row-symmetry-check.cpp
  • Sources/row-symmetry-check-assertions.cpp
  • Sources/row-symmetry-check-fixed.cpp
  • 03.02.02-Exercise-Symmetry.ipynb
  • 03.02.03-Exercise-Row-Symmetry.ipynb
  • 03.02.04-Dev-Tools.ipynb

@copy-pr-bot

copy-pr-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@github-actions

Copy link
Copy Markdown
Contributor

👋 Thank you for your contribution!

This pull request is from a forked repository so GitHub Actions will not be able to run CI. A maintainer will review your changes shortly and manually trigger the CI.

@maintainers Please review this PR when you have a chance and follow the instructions in the CONTRIBUTING.md file to trigger the CI.

@brycelelbach

Copy link
Copy Markdown
Collaborator

/ok to test a96f6f0

@github-actions

Copy link
Copy Markdown
Contributor

❌ Git Signature Check Failed

🔗 View workflow run logs

Found 1 unsigned commit(s):

Unsigned commits
  • 5a641d4: Fix float abs and size_t format specifier in symmetry-check solution (unsigned)

How to fix:

  1. Configure commit signing (if not already done):

    # For GPG signing
    git config --global commit.gpgsign true
    
    # Or for SSH signing (Git 2.34+)
    git config --global gpg.format ssh
    git config --global user.signingkey ~/.ssh/id_ed25519.pub
  2. Re-sign your commits:

    git fetch https://github.com/NVIDIA/accelerated-computing-hub.git main
    git rebase -i FETCH_HEAD --exec "git commit --amend --no-edit -S"
    git push --force-with-lease

📚 GitHub documentation on signing commits

@robobryce robobryce left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Changes requested for the format regression below. The floating-point change also needs to be applied consistently to the code the notebooks generate and to the closely related row-symmetry examples, rather than only to one linked solution.

Separately, the required git-signature check currently fails because commit 5a641d4 is unsigned.

if (abs(temp(row, column) - temp(temp.extent(0) - 1 - row, column)) > 0.1) {
printf("Error: asymmetry in %d / %d\n", column, temp.extent(1));
if (fabsf(temp(row, column) - temp(temp.extent(0) - 1 - row, column)) > 0.1) {
printf("Error: asymmetry in %d / %zu\n", column, temp.extent(1));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

temperature_grid_f is declared as cuda::std::mdspan<float, cuda::std::dextents<int, 2>> in Sources/ach.cuh, so its index_type—and therefore the return type of temp.extent(1)—is int, not size_t. %zu expects a size_t; passing an int through variadic printf is a format/argument mismatch and undefined behavior. Please retain %d here (or explicitly cast to size_t, though that is unnecessary).


if (abs(temp(row, column) - temp(temp.extent(0) - 1 - row, column)) > 0.1) {
printf("Error: asymmetry in %d / %d\n", column, temp.extent(1));
if (fabsf(temp(row, column) - temp(temp.extent(0) - 1 - row, column)) > 0.1) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Please apply this correctness fix to the code learners actually generate and to the related examples as well. 03.02.02-Exercise-Symmetry.ipynb still emits abs(...) in all three symmetry-check code cells, while Solutions/row-symmetry-check.cpp, Sources/row-symmetry-check-assertions.cpp, and the fixed-code cell in 03.02.04-Dev-Tools.ipynb retain the same expression. As written, the exercise continues teaching/executing the form this PR says is incorrect, and the linked solution silently differs. Keep the extent format as %d in those locations because the mdspan index type is int.

@andrewwhitecdw
andrewwhitecdw force-pushed the fix/symmetry-check-abs-format branch from a96f6f0 to 642490d Compare July 27, 2026 14:07
@andrewwhitecdw
andrewwhitecdw force-pushed the fix/symmetry-check-abs-format branch from 642490d to 0e915f1 Compare July 27, 2026 14:07
The review pointed out that temp.extent(1) returns int because the mdspan index type is int, so the original %zu change was a format/argument mismatch. Revert to %d and apply fabsf() across all symmetry-check examples, starter sources, row-symmetry sources/solutions, and the Dev-Tools fixed-code cell.

Signed-off-by: Andrew White <andrewh@cdw.com>
@github-actions

Copy link
Copy Markdown
Contributor

👋 Thank you for your contribution!

This pull request is from a forked repository so GitHub Actions will not be able to run CI. A maintainer will review your changes shortly and manually trigger the CI.

@maintainers Please review this PR when you have a chance and follow the instructions in the CONTRIBUTING.md file to trigger the CI.

@andrewwhitecdw andrewwhitecdw changed the title Fix float abs and size_t format specifier in symmetry-check solution fix: use fabsf() consistently for float symmetry checks Jul 27, 2026
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.

3 participants