Skip to content

Commit

Permalink
Execution policy class (#816)
Browse files Browse the repository at this point in the history
Changes currently planned for the RAFT code include updating the RAFT handle for it to store a singleton of a thrust execution policy. An execution policy class would prove useful to write a clearer code. This PR is a proof of concept for it.

cc @divyegala

Authors:
  - Victor Lafargue (https://github.com/viclafargue)

Approvers:
  - Divye Gala (https://github.com/divyegala)
  - Mark Harris (https://github.com/harrism)

URL: #816
  • Loading branch information
viclafargue authored Aug 13, 2021
1 parent 23bbe74 commit 570de8f
Showing 1 changed file with 15 additions and 7 deletions.
22 changes: 15 additions & 7 deletions include/rmm/exec_policy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,22 @@

namespace rmm {

using thrust_exec_policy_t =
thrust::detail::execute_with_allocator<rmm::mr::thrust_allocator<char>,
thrust::cuda_cub::execute_on_stream_base>;

/**
* @brief Returns a Thrust CUDA execution policy that uses RMM for temporary memory allocation on
* the specified stream.
* @brief Helper class usable as a Thrust CUDA execution policy
* that uses RMM for temporary memory allocation on the specified stream.
*/
inline auto exec_policy(cuda_stream_view stream = cuda_stream_default,
rmm::mr::device_memory_resource* mr = mr::get_current_device_resource())
{
return thrust::cuda::par(rmm::mr::thrust_allocator<char>(stream, mr)).on(stream.value());
}
class exec_policy : public thrust_exec_policy_t {
public:
explicit exec_policy(cuda_stream_view stream = cuda_stream_default,
rmm::mr::device_memory_resource* mr = mr::get_current_device_resource())
: thrust_exec_policy_t(
thrust::cuda::par(rmm::mr::thrust_allocator<char>(stream, mr)).on(stream.value()))
{
}
};

} // namespace rmm

0 comments on commit 570de8f

Please sign in to comment.