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

Avoid potential race conditions in device_scalar/device_uvector setters #725

Merged
merged 6 commits into from
Mar 18, 2021

Conversation

harrism
Copy link
Member

@harrism harrism commented Mar 10, 2021

There is a subtle problem with rmm::device_uvector::set_element_async and rmm::device_scalar::set_value. It's common to pass a literal (e.g. 0) to these functions. But these functions accept the parameter by reference, so if you pass a literal, it's possible for the temporary created to store the literal to be destroyed before the cudaMemcpyAsync is performed, resulting in a use after free. This PR:

  1. Disallows passing literals to these functions by deleting the rvalue reference (&&) overload. This is a breaking API change.
  2. In device_scalar, adds an optimization for bool types to always use cudaMemsetAsync.
  3. In device_scalar, add a new method set_value_zero for the common case of initialization to zero. Also uses cudaMemsetAsync.
  4. Improves documentation.

These changes will require PRs to fix up some uses in cudf, cuspatial, and cugraph.

@harrism harrism added 3 - Ready for review Ready for review by team breaking Breaking change improvement Improvement / enhancement to an existing function labels Mar 10, 2021
@harrism harrism self-assigned this Mar 10, 2021
@harrism harrism requested a review from a team as a code owner March 10, 2021 23:20
@harrism harrism added this to PR-WIP in v0.19 Release via automation Mar 10, 2021
@github-actions github-actions bot added the cpp Pertains to C++ code label Mar 10, 2021
include/rmm/device_scalar.hpp Outdated Show resolved Hide resolved
v0.19 Release automation moved this from PR-WIP to PR-Reviewer approved Mar 11, 2021
Copy link
Contributor

@codereport codereport left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, one minor change

include/rmm/device_scalar.hpp Outdated Show resolved Hide resolved
v0.19 Release automation moved this from PR-Reviewer approved to PR-Needs review Mar 15, 2021
@harrism
Copy link
Member Author

harrism commented Mar 16, 2021

I also expanded the device_scalar tests to exercise bool, float and double.

Copy link
Contributor

@codereport codereport left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm 👍

v0.19 Release automation moved this from PR-Needs review to PR-Reviewer approved Mar 17, 2021
rapids-bot bot pushed a commit to rapidsai/cugraph that referenced this pull request Mar 17, 2021
After rapidsai/rmm#725 is merged, this PR updates cuspatial to eliminate passing literal values to device_uvector::set_element_async.

Companion PR to rapidsai/cuspatial#367

Authors:
  - Mark Harris (@harrism)

Approvers:
  - Seunghwa Kang (@seunghwak)
  - Alex Fender (@afender)
  - Andrei Schaffer (@aschaffer)

URL: #1453
rapids-bot bot pushed a commit to rapidsai/cuspatial that referenced this pull request Mar 18, 2021
After rapidsai/rmm#725 is merged, this PR updates cuspatial to eliminate passing literal values to `device_uvector::set_element_async`.

Authors:
  - Mark Harris (@harrism)

Approvers:
  - Paul Taylor (@trxcllnt)
  - Christopher Harris (@cwharris)

URL: #367
@harrism
Copy link
Member Author

harrism commented Mar 18, 2021

@gpucibot merge

@rapids-bot rapids-bot bot merged commit dce33aa into rapidsai:branch-0.19 Mar 18, 2021
v0.19 Release automation moved this from PR-Reviewer approved to Done Mar 18, 2021
rapids-bot bot pushed a commit to rapidsai/cudf that referenced this pull request Mar 19, 2021
…_scalar::set_value (#7563)

After rapidsai/rmm#725 is merged, this PR updates cuspatial to eliminate passing literal values to `device_scalar::set_value`.

Note there are still similar issues with uses of `cudf::scalar` that need to be addressed. But I wanted to get this open before the end of the week. This can be merged after RMM 725 is merged to fix the build, so I think the `scalar` issues should be fixed separately.

Authors:
  - Mark Harris (@harrism)

Approvers:
  - Devavret Makkar (@devavret)
  - Paul Taylor (@trxcllnt)
  - Mike Wilson (@hyperbolic2346)

URL: #7563
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3 - Ready for review Ready for review by team breaking Breaking change cpp Pertains to C++ code improvement Improvement / enhancement to an existing function
Projects
No open projects
v0.19 Release
  
Done
Development

Successfully merging this pull request may close these issues.

None yet

3 participants