Skip to content

Commit

Permalink
Disallow zero-size stream pools (#873)
Browse files Browse the repository at this point in the history
An exception is now thrown when zero is passed as the size parameter to the `cuda_stream_pool` constructor. Also adds a test for this exception.

Fixes #871

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

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

URL: #873
  • Loading branch information
harrism authored Sep 17, 2021
1 parent 20eb64a commit 8b9fac8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/rmm/cuda_stream_pool.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,15 @@ class cuda_stream_pool {
static constexpr std::size_t default_size{16}; ///< Default stream pool size

/**
* @brief Construct a new cuda stream pool object of the given size
* @brief Construct a new cuda stream pool object of the given non-zero size
*
* @throws logic_error if `pool_size` is zero
* @param pool_size The number of streams in the pool
*/
explicit cuda_stream_pool(std::size_t pool_size = default_size) : streams_(pool_size) {}
explicit cuda_stream_pool(std::size_t pool_size = default_size) : streams_(pool_size)
{
RMM_EXPECTS(pool_size > 0, "Stream pool size must be greater than zero");
}
~cuda_stream_pool() = default;

cuda_stream_pool(cuda_stream_pool&&) = delete;
Expand Down
5 changes: 5 additions & 0 deletions tests/cuda_stream_pool_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ struct CudaStreamPoolTest : public ::testing::Test {
rmm::cuda_stream_pool pool{};
};

TEST_F(CudaStreamPoolTest, ZeroSizePoolException)
{
EXPECT_THROW(rmm::cuda_stream_pool pool{0}, rmm::logic_error);
}

TEST_F(CudaStreamPoolTest, Unequal)
{
auto const stream_a = this->pool.get_stream();
Expand Down

0 comments on commit 8b9fac8

Please sign in to comment.