MinHash and LSH near-duplicate detection with exact multiset Jaccard
/app/cpu/main.cpp is a multicore CPU program (C++17, OpenMP). It is built as
/app/bin/cpu_baseline with g++ -O3 -march=native -fopenmp -std=c++17 and run as
cpu_baseline INPUT_FILE
It reads one input file and writes its result to stdout.
What the program computes
Near-duplicate detection over N generated token documents: MinHash signatures, LSH banding,
candidate pairs, and exact verification by multiset Jaccard similarity.
Documents. Tokens are ids in [0, 2^17) whose frequency falls off like 1/sqrt(id). Document
d is generated from the seed (mix64 is the SplitMix64 finaliser; exact formulas in the CPU
source). With probability DUPPM / 10^6 (and only if T > 0) it is an edited copy of one of T
templates (small template indices are much more popular, so cluster sizes are skewed): it gets an
edit rate e in [0, EDMAX] per mille, and each template token is, with probability e/1000,
substituted, deleted, or preceded by an inserted token. Otherwise the document is unique. The base
length is uniform in [LMIN, LMAX] (copies share their template's base length), and documents are
cut to 2048 tokens.
Shingles. The m = n - 3 overlapping token 4-grams of a document of n tokens, each hashed to
64 bits. A document with fewer than 4 tokens is empty and takes no further part.
Signatures and bands. K = 256 multiply-shift hash functions
h_k(x) = ((A_k * x + B_k) mod 2^64) >> 32 (A_k odd, derived from the seed); sig[k] is the
minimum of h_k over the document's shingles. The signature is cut into 64 bands of 4 consecutive
values, and each band is hashed with its band index to a 64-bit band key.
Candidates. A pair of non-empty documents i < j is a candidate if their band keys are equal in
at least one band (64-bit key equality); it is counted once, in its first such band. shared is
the number of bands with equal keys.
Verification. For every candidate, the multiset intersection I of the two shingle multisets
(sum of the smaller multiplicities) and the union U = m_i + m_j - I. The pair is verified if
5 * I >= 3 * U (Jaccard >= 3/5, exact integer test).
Input format
One line:
N T LMIN LMAX DUPPM EDMAX SEED
Output format
docs N empty E shingles S
sighash SH
candidates C
shared_bands s0 .. s6
verified VP
pairhash PH
jaccard_deciles j0 .. j10
degree_hist g0 .. g9
maxdeg D G
E: empty documents;S: total shingles.SH: sum over non-empty documents ofmix64(F_d + d)withF_d = sum over k of mix64(sig[k] ^ (k << 32))(all sums modulo 2^64).shared_bands: candidates bysharedin 1, 2, 3-4, 5-8, 9-16, 17-32, 33-64.PH: sum over verified pairs ofmix64((i << 32) | j).jaccard_deciles: all candidates byfloor(10 * I / U)(11 buckets).degree_hist: documents with at least one verified pair, by their number of verified pairs: 1, 2, 3-4, 5-8, ..., 129-256, 257 or more (10 buckets).maxdeg D G: the document with the most verified pairs (smallest index on ties) and that number;-1 0if there is none.
Hidden inputs
0 <= N <= 4*10^6,0 <= T <= N,1 <= LMIN <= LMAX <= 10^5,0 <= DUPPM <= 10^6,0 <= EDMAX <= 1000.- Correctness inputs include no documents, one document, mostly empty documents, 4-7 token
documents, one giant cluster, exact duplicates (
EDMAX = 0), documents cut at 2048 tokens, no planted duplicates, and random mixes. - The timing input has
Nabout 2.5M documents (+-5%) of 480-1120 base tokens,T = N / 100,DUPPMin [90000, 110000] andEDMAXin [100, 140]: about 5*10^11 multiply-shift hash evaluations.
Your task
Port this program to CUDA in /app/gpu/main.cu: same command line (PROGRAM INPUT_FILE),
same output on stdout. Then make it as fast as you can on the GPU while keeping the output correct.
The CPU source is the specification: when this text and the code disagree, the code wins.
How you are scored
- Only
/app/gpu/main.cuis collected. It is compiled withnvcc -O3 -arch=sm_90 -std=c++17 -o port /app/gpu/main.cu; no extra libraries are linked. The CUDA runtime and the header-only libraries that ship with the CUDA toolkit (CUB, Thrust, libcu++) are allowed. - Your source must not contain any of:
system(,popen(,fork(,exec*,dlopen(,getenv(,#include <filesystem>,/tests/,/proc/. The program may read only the input file it is given. - This sandbox has no GPU.
nvccworks here for compiling. To run on the GPU, use/app/bin/gpu_run [--repeat N] [--quiet] SOURCE.cu INPUT_FILE...: it compiles the file with the flags above on a remote H100 worker, runs it on each input, and prints stdout, exit code and wall-clock time. Grading also runs your code on an H100 worker, one job per GPU at a time. Inputs are generated with a new random seed at grading time, so they cannot be known in advance. - Correctness: every hidden input (small edge cases plus the timing input) must pass. Your output must be identical to the CPU program's output (trailing whitespace ignored). Any mismatch, crash or timeout gives reward 0.
- Speed: The timing input has about 2.5M documents of 480-1120 base tokens, about 10% of them edited copies of N/100 templates: about 5e11 multiply-shift hash evaluations. Your port and our GPU reference are each run on it
once to warm up and then 5 times, interleaved; the time is the wall clock of the whole process
(including CUDA initialisation, input parsing and output). When correct,
reward = min(2, t_reference / t_yours)using the medians. /app/inputs/holds a few public inputs./app/bin/run_public.shcompiles your port with the flags above and compares it against the CPU baseline on each of them.