Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy_if integer overflow for sizes > 2^31 #747

Closed
RAMitchell opened this issue Oct 5, 2020 · 5 comments
Closed

copy_if integer overflow for sizes > 2^31 #747

RAMitchell opened this issue Oct 5, 2020 · 5 comments
Assignees
Labels
thrust For all items related to Thrust.

Comments

@RAMitchell
Copy link

RAMitchell commented Oct 5, 2020

For sizes > 2^31 we get an integer overflow with copy_if using the device backend. This results in out of memory:

terminate called after throwing an instance of 'thrust::system::detail::bad_alloc'
  what():  std::bad_alloc: temporary_buffer::allocate: get_temporary_buffer failed

MRE:

#include <thrust/copy.h>
#include <thrust/device_vector.h>
#include <limits>

int main() {
  // size_t n = std::numeric_limits<int>::max() - 1000ll; // Works
  size_t n = std::numeric_limits<int>::max() + 1ll; // Error
  std::cout << "n size: " << n << std::endl;
  thrust::device_vector<int> v(n);
  thrust::device_vector<int> result(n);
  thrust::copy_if(v.begin(), v.end(), result.begin(), thrust::identity<int>());
}

Suspected cause:
https://github.com/NVIDIA/thrust/blob/e4d96a2ecaae1fb2964be8caace289e3c314ac7b/thrust/system/cuda/detail/copy_if.h#L704
Custom cub-like backend, still using int size type.

@alliepiper
Copy link
Collaborator

We should triage this by using THRUST_INDEX_TYPE_DISPATCH .

@alliepiper
Copy link
Collaborator

Related to #744.

@seunghwak
Copy link

I am seeing a similar issue with thrust::remove & thrust::remove_if. Sounds related and better be fixed together.

rapids-bot bot referenced this issue in rapidsai/cudf Nov 10, 2022
Workaround for limitation in `thrust::copy_if` which fails if the input-iterator spans more than int-max.
The `thrust::copy_if` hardcodes the iterator distance type to be an int
https://github.com/NVIDIA/thrust/blob/dbd144ed543b60c4ff9d456edd19869e82fe8873/thrust/system/cuda/detail/copy_if.h#L699-L708

Found existing thrust issue: https://github.com/NVIDIA/thrust/issues/1302

This calls the `copy_if` in chunks if the iterator can span greater than int-max.

Closes #12058

Authors:
  - David Wendt (https://github.com/davidwendt)

Approvers:
  - Alessandro Bellina (https://github.com/abellina)
  - Robert Maynard (https://github.com/robertmaynard)
  - Nghia Truong (https://github.com/ttnghia)

URL: #12079
@elstehle elstehle self-assigned this Nov 22, 2022
rapids-bot bot referenced this issue in rapidsai/cudf Nov 28, 2022
Workaround in nvtext's wordpiece-tokenizer due to limitation in `thrust::copy_if` which fails if the input-iterator spans more than int-max.

Found existing thrust issue: https://github.com/NVIDIA/thrust/issues/1302
This calls the `thrust::copy_if` in chunks if the iterator can span greater than int-max.

Found while working on #12079

Authors:
  - David Wendt (https://github.com/davidwendt)

Approvers:
  - Nghia Truong (https://github.com/ttnghia)
  - Vyas Ramasubramani (https://github.com/vyasr)

URL: #12168
rapids-bot bot referenced this issue in rapidsai/cudf Dec 6, 2022
Workaround in json's get_tree_representation due to limitation in `thrust::copy_if` which fails if the input-iterator spans more than int-max.

Found existing thrust issue: https://github.com/NVIDIA/thrust/issues/1302
This calls the thrust::copy_if in chunks if the iterator can span greater than int-max.

Found while working on #12079

Authors:
  - David Wendt (https://github.com/davidwendt)

Approvers:
  - Elias Stehle (https://github.com/elstehle)
  - Mike Wilson (https://github.com/hyperbolic2346)

URL: #12190
@jrhemstad jrhemstad added the thrust For all items related to Thrust. label Feb 22, 2023
@jarmak-nv jarmak-nv transferred this issue from NVIDIA/thrust Nov 8, 2023
@jrhemstad
Copy link
Collaborator

Closing in favor of #744

@jrhemstad jrhemstad closed this as not planned Won't fix, can't repro, duplicate, stale Nov 8, 2023
@elstehle
Copy link
Collaborator

We have just merged PR #1379 that addresses this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
thrust For all items related to Thrust.
Projects
Archived in project
Development

No branches or pull requests

5 participants