cuDDL
Loading...
Searching...
No Matches
Classes | Namespaces | Functions | Variables
top_k.cuh File Reference
#include <cub/device/device_segmented_sort.cuh>
#include <cuda/buffer>
#include <cuda/iterator>
#include <cuda/std/bit>
#include <cuda/std/cstdint>
#include <cuda/stream>
#include <algorithm>
#include <span>
#include <vector>
#include <cuddl/error.hpp>
#include <cuddl/reference_database.cuh>

Go to the source code of this file.

Classes

struct  cuddl::detail::top_k_slots
 Each genome's k best neighbours so far: keys and packed counts in parallel rows of k, each row a min-heap of keys whose root is the row's worst key, zero while the row has room. More...
 
struct  cuddl::detail::top_k_row_offset
 Start of genome row i of a collector's heaps, rows of k slots. More...
 
class  cuddl::top_k_search
 Keeps each genome's k most similar genomes from search tiles on the device. More...
 

Namespaces

namespace  cuddl
 Batch operations over contiguous device rows.
 
namespace  cuddl::detail
 

Functions

__host__ __device__ constexpr uint64_t cuddl::detail::top_k_key (pairwise_counts const &counts, uint32_t id) noexcept
 Ranking key of a neighbour: its weighted k-mer identity above its complemented ID.
 
constexpr size_t cuddl::detail::top_k_heap_words (uint32_t k) noexcept
 Words of shared memory one heap takes: k keys, then their k packed counts.
 
__device__ void cuddl::detail::top_k_replace_root (uint64_t *heap, uint32_t k, uint64_t key, uint64_t value)
 Replaces the root of a min-heap of k keys at heap, whose values follow the keys, with key and value, and sifts it down.
 
template<bool Thresholded, bool UpperTriangle>
__device__ uint32_t cuddl::detail::top_k_word_bits (batch_result_tile const &tile, uint32_t query, uint32_t word, uint32_t words)
 The pass bits of word word of tile row query: the stored bits, or for exhaustive tiles every reference of the word.
 
template<bool UpperTriangle>
__device__ packed_pairwise_counts cuddl::detail::top_k_stored (batch_result_tile const &tile, uint32_t query, uint32_t reference)
 The stored result of tile row query and reference, which must pass.
 
__device__ uint32_t cuddl::detail::top_k_nth_bit (uint32_t mask, uint32_t n)
 Position of set bit n, counting from zero, of mask, which has more than n set bits.
 
template<typename Bits , typename Entry >
__device__ void cuddl::detail::top_k_warp_merge (uint64_t *heap, uint32_t k, uint32_t words, Bits bits_of, Entry entry_of)
 One warp merges the candidates of words bitmap words into the heap of k entries at heap, in shared memory, which only this warp updates, so it needs no lock.
 
template<bool ToShared>
__device__ void cuddl::detail::top_k_warp_copy (top_k_slots const &slots, size_t row, uint64_t *heap)
 Copies the k entries of global heap row into, or for ToShared false out of, the shared heap heap with the warp's lanes.
 
template<size_t BucketCount, typename QueryRow >
__global__ cuddl::detail::__launch_bounds__ (block_size) void count_batch_index_matches_kernel(QueryRow const *queries
 Counts index matches for every query/reference pair in one tile.
 
 cuddl::detail::if (query >=tile.query_count) return
 
 cuddl::detail::top_k_warp_copy< true > (slots, row, heap)
 
 cuddl::detail::top_k_warp_merge (heap, slots.k, words - cuda::std::min(skipped, words), [&](uint32_t word) { return top_k_word_bits< Thresholded, UpperTriangle >(tile, query, skipped+word, words);}, [&](uint32_t candidate, uint64_t &key, uint64_t &value) { auto const reference=skipped *32U+candidate;auto const stored=top_k_stored< UpperTriangle >(tile, query, reference);key=top_k_key(stored.unpack(tile.bucket_count), reference);value=stored.bits;})
 
 cuddl::detail::top_k_warp_copy< false > (slots, row, heap)
 
template<size_t BucketCount>
__global__ cuddl::detail::__launch_bounds__ (block_size) void build_score_planes_kernel(uint16_t const *rows
 Transposes compact score rows into the bit-plane layout of score_plane_index.
 
 cuddl::detail::if (block >=static_cast< uint64_t >(row_words) *word_count) return
 
 cuddl::detail::_Pragma ("unroll") for(uint32_t bit=0U
 
std::vector< batch_search_result > cuddl::select_top_k (std::vector< batch_search_result > rows, uint32_t k)
 The k best rows of each query among rows, as top_k_search ranks them, best first and query by query.
 

Variables

constexpr uint32_t cuddl::detail::top_k_warps = block_size / 32U
 Warps per merging block, each holding one heap; fewer when the heaps exceed shared memory.
 
__global__ top_k_slots cuddl::detail::slots
 
auto *const cuddl::detail::heap = heaps + warp * top_k_heap_words(slots.k)
 
auto const cuddl::detail::query_id = tile.first_query_id + query
 
auto const cuddl::detail::row = static_cast<size_t>(query_id - slots.first_genome_id)
 
auto const cuddl::detail::words = tile.words_per_query()
 
auto const cuddl::detail::skipped = UpperTriangle ? (query_id + 1U) / 32U : 0U
 
__global__ uint32_t * cuddl::detail::columns
 
__global__ uint32_t uint32_t cuddl::detail::first_word
 
auto const cuddl::detail::block = static_cast<uint64_t>(blockIdx.x) * (blockDim.x / 32U) + threadIdx.x / 32U
 
auto const cuddl::detail::word_count = words - first_word
 
auto const cuddl::detail::word = first_word + static_cast<uint32_t>(block % word_count)
 
auto const cuddl::detail::row_word = static_cast<uint32_t>(block / word_count)
 
uint32_t cuddl::detail::column = 0U