Sparse-checkout from NVIDIA/cccl main branch to complete cccl_upstream: Added: - python/cuda_cccl/ (226 files) — Python bindings for device-level algorithms Critical for muh toolchain: cuda.compute.reduce_into, scan, radix_sort, etc. Includes 204 .py files with full test coverage for all 27 algorithms - ci/ (163 files) — Build/test infrastructure build_cub.sh, test_cub.sh, build_and_test_targets.sh, matrix.yaml Directly maps to our [INFRA-CI] and [INFRA-BUILD] items - .agent/skills/ (7 files) — NVIDIA's own agent skills for CCCL cccl-style/SKILL.md, cccl-test/SKILL.md, sass-diff/SKILL.md - docs/ (491 files) — Official CCCL documentation CI references, CMake guides, Python compute docs, libcudacxx PTX docs - test/ (12 files) — Top-level integration tests (cuda_smoke, stdpar) - Root configs: .clang-format, .clang-tidy, CONTRIBUTING.md, pyproject.toml - CLAUDE.md symlink → AGENTS.md (NVIDIA's standard) cccl_upstream now mirrors full NVIDIA/cccl structure: Before: 42M (cub + thrust + libcudacxx + cudax + c + examples + benchmarks) After: 53M (+python +ci +docs +.agent +test +configs) This completes the CCCL base needed for: - [muh-bench] items: ci/util/build_and_test_targets.sh for targeted builds - [CCCL-verify] items: python/cuda_cccl/tests/ as reference implementations - [CCCL-test] items: ci/test_cub.sh, ci/test_thrust.sh - Agent workflow: .agent/skills/ for consistent style and test patterns
75 lines
1.7 KiB
ReStructuredText
75 lines
1.7 KiB
ReStructuredText
.. _libcudacxx-extended-api-bit-bitmask:
|
|
|
|
``cuda::bitmask``
|
|
=================
|
|
|
|
Defined in the ``<cuda/bit>`` header.
|
|
|
|
.. code:: cuda
|
|
|
|
namespace cuda {
|
|
|
|
template <typename T = uint32_t>
|
|
[[nodiscard]] __host__ __device__ constexpr
|
|
T bitmask(int start, int width) noexcept;
|
|
|
|
} // namespace cuda
|
|
|
|
The function generates a bitmask of size ``width`` starting at position ``start``.
|
|
|
|
**Parameters**
|
|
|
|
- ``start``: starting position of the bitmask.
|
|
- ``width``: width of the bitmask.
|
|
|
|
**Return value**
|
|
|
|
- Bitmask of size ``width`` starting at position``start``.
|
|
|
|
**Constraints**
|
|
|
|
- ``T`` is an unsigned integral type.
|
|
|
|
**Preconditions**
|
|
|
|
- ``start >= 0 && start <= num_bits(T)``.
|
|
- ``width >= 0 && width <= num_bits(T)``.
|
|
- ``start + width <= num_bits(T)``.
|
|
|
|
**Performance considerations**
|
|
|
|
The function performs the following operations in device code:
|
|
|
|
- ``uint8_t``, ``uint16_t``, ``uint32_t``: ``BMSK``.
|
|
- ``uint64_t``: ``SHL`` x4, ``ADD`` x2.
|
|
|
|
.. note::
|
|
|
|
When the input values are run-time values that the compiler can resolve at compile-time, e.g. an index of a loop with a fixed number of iterations, using the function could not be optimal.
|
|
|
|
.. note::
|
|
|
|
GCC <= 8 uses a slow path with more instructions even in CUDA.
|
|
|
|
Example
|
|
-------
|
|
|
|
.. code:: cuda
|
|
|
|
#include <cuda/bit>
|
|
#include <cuda/std/cassert>
|
|
#include <cuda/std/cstdint>
|
|
|
|
__global__ void bitmask_kernel() {
|
|
assert(cuda::bitmask(2, 4) == 0b111100u);
|
|
assert(cuda::bitmask<uint64_t>(1, 3) == uint64_t{0b1110});
|
|
}
|
|
|
|
int main() {
|
|
bitmask_kernel<<<1, 1>>>();
|
|
cudaDeviceSynchronize();
|
|
return 0;
|
|
}
|
|
|
|
`See it on Godbolt 🔗 <https://godbolt.org/z/habGohz7T>`__
|