[BUG] illegal memory access due to negative offset in map_kernel on large array (1.8 billion elements)

Open
#2,683 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
45/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
cpp
Domain
performance

Research direction

Start at cpp/include/raft/linalg/detail/map.cuh around line 56, where map_kernel checks that the offset is below the length. Reproduce the issue with a roughly 1.8-billion-element array under compute-sanitizer, then verify the kernel handles the negative-offset case without illegal GPU memory access.

Written by the indexing model from the issue text.

Description

bug

Describe the bug

map_kernel multiplies the thread ID by 2, which causes integer overflow when the data size approaches INT_MAX. This results in negative array indexing, leading to illegal memory access errors on the GPU.

Steps/Code to reproduce bug
Run compute-sanitizer on code that involks the map_kernel on large array (e.g. 1.8 billion elements) in our case.
It seems an easy way to fix this is to check negative array index in the GPU kernel.

There is a checking already to ensure offset < len. Maybe also ensure offset >=0: https://github.com/rapidsai/raft/blob/cc165d9efc45962de90b15d1e29da849bb340ef9/cpp/include/raft/linalg/detail/map.cuh#L56

Expected behavior
1.8 billion is within range of int32.

Environment details (please complete the following information):
A100 GPU, 1.5TB CPU memory, rapids 25.04 environment.

Dominant language
Cuda
Stars
1.1k
Forks
260
Avg merge
1d 18h
Merged PRs (30d)
21

Getting set up

  • No Dockerfile or Docker Compose file
  • Has a pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from NVIDIA/raft

All issues in NVIDIA/raft

Similar issues

More Performance issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.