|
Zip and Skip Tries
|
Implementation of CUDA-accelerated Most Significant Word finding algorithms. More...
#include <bit>#include <cstddef>#include <cstdint>#include <iostream>#include <stdio.h>#include "cuda_utils.cuh"
Go to the source code of this file.
Functions | |
| __global__ void | par_sig_sqrt (const uintmax_t *const p1, uintmax_t *p2, uintmax_t *sig_out, size_t n) |
| CUDA kernel that implements the first phase of the square root decomposition. | |
| __global__ void | naive_leftmost_prisoner (uintmax_t *p, size_t n) |
| Parallel kernel to find the leftmost non-zero element in an array. | |
| __global__ void | par_get_section_diff (uintmax_t *tree, uintmax_t *section, size_t n) |
| Parallel kernel to identify and record the index of the first non-zero element. | |
| size_t | seq_find_mismatch (const uintmax_t *const arr1, const uintmax_t *const arr2, size_t size) |
| Sequential implementation of finding the first mismatching word between two arrays. | |
| size_t | par_find_mismatch (const uintmax_t *const d_a, const uintmax_t *const b, uintmax_t *d_large_block, size_t n) |
| GPU-accelerated implementation of finding the first mismatching word with pre-allocated memory. | |
| uintmax_t * | alloc_large_block_to_device (size_t n) |
| Allocates a large block of device memory for parallel mismatch operations. | |
| size_t | par_find_mismatch (const uintmax_t *const a, const uintmax_t *const b, size_t n) |
| Convenience wrapper for GPU-accelerated mismatch finding. | |
Implementation of CUDA-accelerated Most Significant Word finding algorithms.
This file implements a parallel algorithm for finding the first mismatching word between two arrays using a two-phase square root decomposition approach:
Phase 1: Divide the arrays into sqrt(n) chunks and identify which chunk contains the first mismatch. Phase 2: Within the identified chunk, find the exact position of the first mismatch.
The implementation uses three key CUDA kernels:
This algorithm achieves O(n) work with O(1) span when sufficient threads are available, making it highly efficient for large arrays on GPU hardware.
Definition in file msw.cu.
Allocates a large block of device memory for parallel mismatch operations.
Calculates the required memory size based on the input size n and allocates a contiguous block of memory on the device. The size is calculated to accommodate:
| n | Number of elements to be processed |
Definition at line 256 of file msw.cu.
| __global__ void naive_leftmost_prisoner | ( | uintmax_t * | p, |
| size_t | n | ||
| ) |
Parallel kernel to find the leftmost non-zero element in an array.
Uses a tournament-style approach where each pair of elements is compared, and if a left element (lower index) is non-zero, it "eliminates" the right element by setting it to zero. After all comparisons, only the leftmost non-zero element remains. This kernel achieves O(n²) work in O(1) span when sufficient threads are available.
The algorithm distributes all n-choose-2 pairwise comparisons across available threads.
Definition at line 68 of file msw.cu.
Convenience wrapper for GPU-accelerated mismatch finding.
GPU-accelerated implementation of finding the first mismatching word.
This function handles all the device memory management, including:
This provides a simpler interface for callers who don't need to manage device memory themselves or reuse memory across multiple calls.
| a | First input array (host memory) |
| b | Second input array (host memory) |
| n | Number of elements in the arrays |
Definition at line 280 of file msw.cu.
| size_t par_find_mismatch | ( | const uintmax_t *const | d_a, |
| const uintmax_t *const | b, | ||
| uintmax_t * | d_large_block, | ||
| size_t | n | ||
| ) |
GPU-accelerated implementation of finding the first mismatching word with pre-allocated memory.
GPU-accelerated mismatch finding with pre-allocated device memory.
This function implements a two-phase square root decomposition algorithm:
The algorithm uses three CUDA kernels:
Time complexity: O(n) work with O(1) span when sufficient threads are available Space complexity: O(n + sqrt(n)) for temporary storage
| d_a | First input array (already in device memory) |
| b | Second input array (host memory, will be copied to device) |
| d_large_block | Pre-allocated device memory block for temporary storage |
| n | Number of elements in the arrays |
Definition at line 178 of file msw.cu.
| __global__ void par_get_section_diff | ( | uintmax_t * | tree, |
| uintmax_t * | section, | ||
| size_t | n | ||
| ) |
Parallel kernel to identify and record the index of the first non-zero element.
After the naive_leftmost_prisoner kernel has eliminated all non-leftmost elements, this kernel scans the array to find the remaining non-zero element and records its index. Multiple threads may write to the same location, but they'll all write the same value since only one element should remain non-zero after the elimination process.
This kernel is used in both phases of the square root algorithm:
| __global__ void par_sig_sqrt | ( | const uintmax_t *const | p1, |
| uintmax_t * | p2, | ||
| uintmax_t * | sig_out, | ||
| size_t | n | ||
| ) |
CUDA kernel that implements the first phase of the square root decomposition.
This kernel performs two critical operations:
Each thread processes multiple elements based on its thread ID. When a mismatch is found, the corresponding chunk in sig_out is marked with a 1.
Definition at line 41 of file msw.cu.
Sequential implementation of finding the first mismatching word between two arrays.
This is a simple linear scan through both arrays, comparing corresponding elements until a mismatch is found. This function serves as a baseline for comparison with the parallel implementation and is used for validation.
Time complexity: O(n) in the worst case Space complexity: O(1)
| arr1 | First input array |
| arr2 | Second input array |
| size | Number of elements in the arrays |