Warp Ballot Mask: Active Count, Leader Lane and Lane Ranks

Last updated: November 29, 2026

Quick Overview

Given a 32-bit ballot mask where bit i is set if lane i of a warp has a true predicate, return the number of set lanes, the lowest set lane (the leader), and for each set lane its rank among set lanes counting from lane 0.

NVIDIA
Coding & Algorithms
Software Engineer
NVIDIA
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a 32-bit ballot mask where bit i is set if lane i of a warp has a true predicate, return the number of set lanes, the lowest set lane (the leader), and for each set lane its rank among set lanes counting from lane 0.

A bit manipulation screen used by NVIDIA CUDA and compiler teams because it mirrors warp-aggregated atomics: one leader lane reserves space for the whole warp and every active lane computes its own offset with popcount of the lanes below it. The interviewer checks clean bit tricks and an explanation of why this cuts atomic traffic by up to 32x.

What the Interviewer Expects
  • Counts set bits correctly and handles an all-zero mask
  • Isolates the lowest set bit with mask & -mask
  • Computes rank as popcount(mask & ((1 << lane) - 1))
  • Masks input to 32 bits to avoid Python's unbounded integers surprising the caller
  • Explains the warp-aggregated atomic use case
Key Topics to Cover
bit manipulation
popcount
lowest set bit
CUDA warps
stream compaction
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you compute popcount without a built-in?
  • How do you find the highest set lane instead of the lowest?
  • Write the CUDA-side logic for appending matching elements to an output buffer with one atomicAdd per warp.
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input: an integer mask holding 32 lane bits. Output: (count, leader, rank) where leader is -1 for an empty mask and rank maps each active lane to its 0-based index among active lanes. This is ...

High-Level Design

Popcount gives how many slots the warp needs. mask & -mask keeps only the lowest set bit; its bit_length() - 1 is the lane index. For each active lane, the lanes strictly below it are `(1 << lane)...


Submit Your Answer
Markdown supported