cuDDL
Loading...
Searching...
No Matches
construction.cuh
Go to the documentation of this file.
1#pragma once
2
3#include <cuda_runtime.h>
4#include <cuda/devices>
5#include <cuda/std/cstddef>
6#include <cuda/std/cstdint>
7
10#include <cuddl/error.hpp>
11
12namespace cuddl::detail {
13
16template <size_t BucketCount, typename Layout = default_register_layout>
20 cuda::stream_ref stream,
21 cuda::std::optional<blacklist_view> blacklist = cuda::std::nullopt
22) {
23 if (input.empty()) {
24 return {};
25 }
26 return cuda_try([&] {
27 auto const multiprocessors =
28 stream.device().attribute(cuda::device_attributes::multiprocessor_count);
29 auto const vector_input = (reinterpret_cast<uintptr_t>(input.data()) & 31U) == 0U;
30 // Two CTAs per SM; the grid-stride loop covers the remaining inputs.
31 auto const capacity = static_cast<size_t>(shared_construction_block_size) * 4U;
32 auto const needed = input.size() / capacity + (input.size() % capacity != 0U);
33 auto const blocks =
34 static_cast<uint32_t>(cuda::std::min<size_t>(multiprocessors * 2U, needed));
35 auto launch = [&]<bool Filter>() {
36 add_shared_kernel<BucketCount, Layout, Filter>
37 <<<blocks, shared_construction_block_size, 0, stream.get()>>>(
38 input.data(),
39 input.size(),
40 registers.data(),
42 blacklist.value_or(blacklist_view{})
43 );
44 };
45 if (blacklist) {
46 launch.template operator()<true>();
47 } else {
48 launch.template operator()<false>();
49 }
50 return cudaGetLastError();
51 });
52}
53
54} // namespace cuddl::detail
__global__ size_t uint32_t bool blacklist_view blacklist
Definition kernels.cuh:96
constexpr uint32_t shared_construction_block_size
Threads per CTA for the CTA-local construction kernel.
Definition kernels.cuh:78
__host__ Result< void > launch_construction(device_span< uint64_t const > input, device_span< uint32_t > registers, cuda::stream_ref stream, cuda::std::optional< blacklist_view > blacklist=cuda::std::nullopt)
Launches construction of a sketch through a CTA-local shared register array merged into registers (ad...
__global__ size_t uint32_t * registers
Definition kernels.cuh:94
__global__ size_t uint32_t bool vector_input
Definition kernels.cuh:95
Result< void > cuda_try(cudaError_t error, std::source_location location=std::source_location::current())
Checks a CUDA runtime call and returns an error on failure.
Definition error.hpp:187
Fallible API result: cuda::std::expected<T, Error> with cuDDL factories.
Definition error.hpp:118
Exact membership within the candidate's destination bucket.
Definition blacklist.cuh:33
A span that is assumed to point to device-accessible memory.