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

Improve cudf::cuda_error #10630

Merged
merged 12 commits into from
Apr 14, 2022
17 changes: 10 additions & 7 deletions cpp/include/cudf/utilities/error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,20 @@ struct cuda_error : public std::runtime_error {
: std::runtime_error(message), _cudaError(error)
{
}

public:
cudaError_t error_code() { return _cudaError; }

protected:
cudaError_t _cudaError;
};

struct cudart_error : public cuda_error {
cudart_error(std::string const& message, cudaError_t const& error) : cuda_error(message, error) {}
using cuda_error::cuda_error;
};

struct sticky_cuda_error : public cuda_error {
sticky_cuda_error(std::string const& message, cudaError_t const& error)
: cuda_error(message, error)
{
}
struct fatal_cuda_error : public cuda_error {
using cuda_error::cuda_error;
};
/** @} */

Expand Down Expand Up @@ -119,13 +118,17 @@ namespace detail {

inline void throw_cuda_error(cudaError_t error, const char* file, unsigned int line)
{
// Calls cudaGetLastError twice. It is nearly certain that a fatal error occurred if the second
// call doesn't return with cudaSuccess.
cudaGetLastError();
jrhemstad marked this conversation as resolved.
Show resolved Hide resolved
auto const last = cudaGetLastError();
auto const msg = std::string{"CUDA error encountered at: " + std::string{file} + ":" +
std::to_string(line) + ": " + std::to_string(error) + " " +
cudaGetErrorName(error) + " " + cudaGetErrorString(error)};
// Calls cudaDeviceSynchronize to make sure that there is no other asynchronize error occurs
sperlingxx marked this conversation as resolved.
Show resolved Hide resolved
// between two calls.
if (error == last && last == cudaDeviceSynchronize()) {
throw sticky_cuda_error{"Sticky " + msg, error};
throw fatal_cuda_error{"Sticky " + msg, error};
jrhemstad marked this conversation as resolved.
Show resolved Hide resolved
} else {
throw cudart_error{msg, error};
}
Expand Down