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

[FEA] Add ssize() members to device_buffer/device_uvector that returns a signed integer #927

Closed
jrhemstad opened this issue Dec 1, 2021 · 2 comments · Fixed by #966
Closed
Assignees
Labels
feature request New feature or request good first issue Good for newcomers improvement Improvement / enhancement to an existing function

Comments

@jrhemstad
Copy link
Contributor

Mixing signed and unsigned types cause annoying compiler warnings necessitating a lot of casts. A common source of this problem is from the fact that size() functions return size_t which is unsigned.

C++20 addressed this by adding a signed size function ssize.

See https://stackoverflow.com/questions/56217283/why-is-stdssize-introduced-in-c20

We should add

int64_t ssize() const noexcept{
   return static_cast<int64_t>(size());
}

to device_buffer and `device_uvector

@jrhemstad jrhemstad added feature request New feature or request improvement Improvement / enhancement to an existing function good first issue Good for newcomers labels Dec 1, 2021
@jrhemstad
Copy link
Contributor Author

We could maybe add an assert in there for debugging potential overflows.

assert(size() < std::numeric_limits<int64_t>::max());

@jakirkham
Copy link
Member

This is also relevant for Python where Py_ssize_t is used a lot for sizes, but is also a signed integer

@harrism harrism self-assigned this Feb 2, 2022
@rapids-bot rapids-bot bot closed this as completed in #966 Feb 4, 2022
rapids-bot bot pushed a commit that referenced this issue Feb 4, 2022
Fixes  #927.

Adds signed size accessors (`ssize()`) to `rmm::device_buffer` and `rmm::device_uvector`.

Authors:
  - Mark Harris (https://github.com/harrism)

Approvers:
  - Rong Ou (https://github.com/rongou)
  - Mike Wilson (https://github.com/hyperbolic2346)
  - Jake Hemstad (https://github.com/jrhemstad)

URL: #966
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature request New feature or request good first issue Good for newcomers improvement Improvement / enhancement to an existing function
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants