NVIDIA / NVIDIA/cccl

[BUG]: thrust::min_element / max_element fail with numItems close to int_max

Open
#330 2 comments 1 reaction 0 assignees View on GitHub
cub thrust
Dominant language
C++
Stars
2.5k
Forks
487
Avg merge
2d 7h
Merged PRs (30d)
296

Description

### Is this a duplicate?

- [X] I confirmed there appear to be no [duplicate issues](https://github.com/NVIDIA/cccl/issues) for this bug and that I agree to the [Code of Conduct](CODE_OF_CONDUCT.md)

### Type of Bug

Runtime Error

### Component

Thrust

### Describe the bug

terminate called after throwing an instance of 'thrust::system::system_error'
what(): extrema failed to synchronize: cudaErrorIllegalAddress: an illegal memory access was encountered
Aborted (core dumped)

I assume it happens because the sum in this loop overflows for int.
https://github.com/NVIDIA/cccl/blob/4d01371f49ac9f30d5057f819b13df664e9ef945/thrust/thrust/system/cuda/detail/reduce.h#L541

### How to Reproduce

```
#include
#include

int main() {
size_t N = std::numeric_limits::max();
thrust::device_vector dArr(N, 1);
thrust::max_element(dArr.begin(),dArr.end());
return 0;
}
```

### Expected behavior

No error

### Reproduction link

_No response_

### Operating System

_No response_

### nvidia-smi output

_No response_

### NVCC version

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.