Repository navigation
Optimize FP64 fabs on GPUs with low FP64 performance #12294
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
Merged
davebayer
merged 8 commits into
NVIDIA:main
from
lennartvoelz:libcudacxx/feat/fp64_fabs_int_path
Nov 6, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a623b37
Add fabs integer path for fp64 slow targets
lennartvoelz 94c6c30
Add tests for fabs integer device and host path; exclude fast path fp…
lennartvoelz c5844b8
Loosen fabs NaN tests to only check for NaN
lennartvoelz cf44ee6
Merge branch 'main' into libcudacxx/feat/fp64_fabs_int_path
lennartvoelz 9664a31
Clean up fabs integer path
lennartvoelz 43c1c39
Merge branch 'main' into libcudacxx/feat/fp64_fabs_int_path
lennartvoelz 0133ad4
Use 120 column limit for comments in fp64 fabs integer path
lennartvoelz 56ecf2d
Merge branch 'main' into libcudacxx/feat/fp64_fabs_int_path
lennartvoelz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,47 @@ | ||
| //===----------------------------------------------------------------------===// | ||
| // | ||
| // Part of libcu++, the C++ Standard Library for your entire system, | ||
| // under the Apache License v2.0 with LLVM Exceptions. | ||
| // See https://llvm.org/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
| // SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. | ||
| // | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #include <cuda/std/__floating_point/storage.h> | ||
| #include <cuda/std/bit> | ||
| #include <cuda/std/cmath> | ||
|
|
||
| #include <cuda_runtime_api.h> | ||
| #include <device_side_benchmark.cuh> | ||
|
|
||
| #include <nvbench/nvbench.cuh> | ||
|
|
||
| struct benchmark_op_t | ||
| { | ||
| __device__ __forceinline__ double operator()(double value) const | ||
| { | ||
| // storage is used to prevent code elimination by the compiler (adapted from isnan benchmark) | ||
| // the rotation moves a mantissa bit into the sign bit, so the next input can be negative again | ||
| // __fp_get_storage and __fp_from_storage are no op | ||
| const auto storage = cuda::std::__fp_get_storage(value); | ||
| const auto result = cuda::std::__fp_get_storage(cuda::std::fabs(value)); | ||
| return cuda::std::__fp_from_storage<double>(result ^ cuda::std::rotr(storage, 7)); | ||
| } | ||
| }; | ||
|
|
||
| void fabs_bench(nvbench::state& state) | ||
| { | ||
| constexpr int block_size = 256; | ||
| constexpr int unroll_factor = 1024; | ||
| const auto& kernel = benchmark_kernel<block_size, unroll_factor, benchmark_op_t, double, false>; | ||
| const int num_SMs = state.get_device().value().get_number_of_sms(); // NOLINT(bugprone-unchecked-optional-access) | ||
| int max_blocks_per_SM = 0; | ||
| NVBENCH_CUDA_CALL_NOEXCEPT(cudaOccupancyMaxActiveBlocksPerMultiprocessor(&max_blocks_per_SM, kernel, block_size, 0)); | ||
| const int grid_size = max_blocks_per_SM * num_SMs; | ||
| state.exec(nvbench::exec_tag::gpu | nvbench::exec_tag::no_batch, [&](nvbench::launch&) { | ||
| kernel<<<grid_size, block_size>>>(benchmark_op_t{}); | ||
| }); | ||
| } | ||
|
|
||
| NVBENCH_BENCH(fabs_bench).set_name("base"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.