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

Reorder parameters in RMM_EXPECTS #1286

Merged
merged 1 commit into from
Jun 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/utilities/simulated_memory_resource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class simulated_memory_resource final : public device_memory_resource {
void* do_allocate(std::size_t bytes, cuda_stream_view) override
{
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
RMM_EXPECTS(begin_ + bytes <= end_, rmm::bad_alloc, "Simulated memory size exceeded");
RMM_EXPECTS(begin_ + bytes <= end_, "Simulated memory size exceeded", rmm::bad_alloc);
auto* ptr = static_cast<void*>(begin_);
begin_ += bytes; // NOLINT(cppcoreguidelines-pro-bounds-pointer-arithmetic)
return ptr;
Expand Down
10 changes: 5 additions & 5 deletions include/rmm/detail/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,27 +95,27 @@ class out_of_range : public std::out_of_range {
* RMM_EXPECTS(p != nullptr, "Unexpected null pointer");
*
* // throws std::runtime_error
* RMM_EXPECTS(p != nullptr, std::runtime_error, "Unexpected nullptr");
* RMM_EXPECTS(p != nullptr, "Unexpected nullptr", std::runtime_error);
* ```
* @param[in] _condition Expression that evaluates to true or false
* @param[in] _what String literal description of why the exception was
* thrown, i.e. why `_condition` was expected to be true.
* @param[in] _expection_type The exception type to throw; must inherit
* `std::exception`. If not specified (i.e. if only two macro
* arguments are provided), defaults to `rmm::logic_error`
* @param[in] _what String literal description of why the exception was
* thrown, i.e. why `_condition` was expected to be true.
* @throw `_exception_type` if the condition evaluates to 0 (false).
*/
#define RMM_EXPECTS(...) \
GET_RMM_EXPECTS_MACRO(__VA_ARGS__, RMM_EXPECTS_3, RMM_EXPECTS_2) \
(__VA_ARGS__)
#define GET_RMM_EXPECTS_MACRO(_1, _2, _3, NAME, ...) NAME
#define RMM_EXPECTS_3(_condition, _exception_type, _reason) \
#define RMM_EXPECTS_3(_condition, _reason, _exception_type) \
(!!(_condition)) ? static_cast<void>(0) \
: throw _exception_type /*NOLINT(bugprone-macro-parentheses)*/ \
{ \
"RMM failure at: " __FILE__ ":" RMM_STRINGIFY(__LINE__) ": " _reason \
}
#define RMM_EXPECTS_2(_condition, _reason) RMM_EXPECTS_3(_condition, rmm::logic_error, _reason)
#define RMM_EXPECTS_2(_condition, _reason) RMM_EXPECTS_3(_condition, _reason, rmm::logic_error)

/**
* @brief Indicates that an erroneous code path has been taken.
Expand Down
6 changes: 3 additions & 3 deletions include/rmm/device_uvector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class device_uvector {
cuda_stream_view stream)
{
RMM_EXPECTS(
element_index < size(), rmm::out_of_range, "Attempt to access out of bounds element.");
element_index < size(), "Attempt to access out of bounds element.", rmm::out_of_range);

if constexpr (std::is_same<value_type, bool>::value) {
RMM_CUDA_TRY(
Expand Down Expand Up @@ -256,7 +256,7 @@ class device_uvector {
void set_element_to_zero_async(std::size_t element_index, cuda_stream_view stream)
{
RMM_EXPECTS(
element_index < size(), rmm::out_of_range, "Attempt to access out of bounds element.");
element_index < size(), "Attempt to access out of bounds element.", rmm::out_of_range);
RMM_CUDA_TRY(
cudaMemsetAsync(element_ptr(element_index), 0, sizeof(value_type), stream.value()));
}
Expand Down Expand Up @@ -311,7 +311,7 @@ class device_uvector {
[[nodiscard]] value_type element(std::size_t element_index, cuda_stream_view stream) const
{
RMM_EXPECTS(
element_index < size(), rmm::out_of_range, "Attempt to access out of bounds element.");
element_index < size(), "Attempt to access out of bounds element.", rmm::out_of_range);
value_type value;
RMM_CUDA_TRY(cudaMemcpyAsync(
&value, element_ptr(element_index), sizeof(value), cudaMemcpyDefault, stream.value()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ class stream_ordered_memory_resource : public crtp<PoolResource>, public device_

size = rmm::detail::align_up(size, rmm::detail::CUDA_ALLOCATION_ALIGNMENT);
RMM_EXPECTS(size <= this->underlying().get_maximum_allocation_size(),
rmm::out_of_memory,
"Maximum allocation size exceeded");
"Maximum allocation size exceeded",
rmm::out_of_memory);
auto const block = this->underlying().get_block(size, stream_event);

RMM_LOG_TRACE("[A][stream {:p}][{}B][{:p}]",
Expand Down