Files
project_6/cccl_upstream/docs/libcudacxx/runtime/algorithm.rst
muh-bot 2a7ca101d7 feat(cccl): integrate missing CCCL directories — python/, ci/, .agent/, docs/, test/
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
2026-08-07 02:34:33 +00:00

82 lines
3.0 KiB
ReStructuredText

.. _cccl-runtime-algorithm:
Algorithm
==========
The ``runtime`` part of the ``cuda/algorithm`` header provides stream-ordered, byte-wise primitives that operate on
:cpp:class:`cuda::std::span` and :cpp:class:`cuda::std::mdspan`-compatible types. They require a
:cpp:class:`cuda::stream_ref` to enqueue work.
:cpp:func:`cuda::copy_bytes`
-------------------------------
.. _cccl-runtime-algorithm-copy_bytes:
Launch a byte-wise copy from source to destination on the provided stream.
- Signature: :cpp:func:`cuda::copy_bytes`
- Overloads accept :cpp:class:`cuda::std::span`-convertible contiguous ranges or
:cpp:class:`cuda::std::mdspan`-convertible multi-dimensional views.
- Elements must be trivially copyable
- :cpp:class:`cuda::std::mdspan`-convertible types must convert to an mdspan that is exhaustive
- The optional ``config`` argument is a :cpp:struct:`cuda::copy_configuration` that controls source access order and
managed-memory location hints
Availability: CCCL 3.1.0 / CUDA 13.1
.. code:: cpp
#include <cuda/algorithm>
#include <cuda/stream>
#include <cuda/std/algorithm>
#include <cuda/std/span>
void copy_example(cuda::stream_ref s, cuda::std::span<const int> src, cuda::std::span<int> dst) {
// copy_bytes copies up to src.size_bytes(); dst can be larger.
auto n = cuda::std::min(src.size(), dst.size());
auto src_prefix = src.first(n / 2);
auto dst_prefix = dst.first(n / 2);
auto src_suffix = src.subspan(n / 2);
auto dst_suffix = dst.subspan(n / 2);
// Default behavior: enqueue a stream-ordered byte-wise copy on stream s.
cuda::copy_bytes(s, src_prefix, dst_prefix);
// Advanced behavior: customize source access order for this copy.
auto config = cuda::copy_configuration{
.src_access_order = cuda::source_access_order::during_api_call,
};
cuda::copy_bytes(s, src_suffix, dst_suffix, config);
}
:cpp:func:`cuda::fill_bytes`
-------------------------------
.. _cccl-runtime-algorithm-fill_bytes:
Launch a byte-wise fill of the destination on the provided stream.
- Overloads accept :cpp:class:`cuda::std::span`-convertible or :cpp:class:`cuda::std::mdspan`-convertible destinations.
- Elements must be trivially copyable
- :cpp:class:`cuda::std::mdspan`-convertible types must convert to an mdspan that is exhaustive
Availability: CCCL 3.1.0 / CUDA 13.1
.. code:: cpp
#include <cuda/algorithm>
#include <cuda/stream>
#include <cuda/std/algorithm>
#include <cuda/std/span>
void fill_example(cuda::stream_ref s, cuda::std::span<unsigned char> dst) {
// Reserve 16-byte red zones at both ends and clear the payload in between.
auto guard = cuda::std::min(static_cast<decltype(dst.size())>(16), dst.size() / 2);
auto head = dst.first(guard);
auto body = dst.subspan(guard, dst.size() - 2 * guard);
auto tail = dst.last(guard);
cuda::fill_bytes(s, head, 0xCD); // debug guard pattern
cuda::fill_bytes(s, body, 0x00); // initialize payload
cuda::fill_bytes(s, tail, 0xCD); // debug guard pattern
}