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

[BUG] pinned_host_vector can cause abrupt program termination #14165

Closed
jlowe opened this issue Sep 21, 2023 · 2 comments · Fixed by #14251
Closed

[BUG] pinned_host_vector can cause abrupt program termination #14165

jlowe opened this issue Sep 21, 2023 · 2 comments · Fixed by #14251
Labels
1 - On Deck To be worked on next bug Something isn't working libcudf Affects libcudf (C++/CUDA) code. Spark Functionality that helps Spark RAPIDS

Comments

@jlowe
Copy link
Member

jlowe commented Sep 21, 2023

Describe the bug
pinned_host_vector can throw from within it's destructor, causing the application process to terminate abruptly. For example, this is causing abnormal termination of Spark executors when a GPU illegal access occurs during a Parquet read. Since the executor process is abruptly terminated via low-level abort(), there's no chance to convey a useful message from the driver to the executor otherwise try to handle at the application level the cudf::fatal_cuda_error exception that is being thrown.

Steps/Code to reproduce bug
Compile and run the following program:

#include <stdexcept>
#include <cudf/detail/utilities/pinned_host_vector.hpp>

__global__ void crash(int *x) {
  int *y = NULL;
  *x = y[12345678];
}

int main() {
  int *x;
  try {
    auto p = cudf::detail::pinned_host_vector<uint8_t>(4096);
    cudaMalloc(&x, sizeof(*x));
    crash<<<1,1>>>(x);
    cudaDeviceSynchronize();
  } catch (std::exception const& e) {
  }
  return 0;
}

which will produce the following output:

terminate called after throwing an instance of 'cudf::fatal_cuda_error'
  what():  Fatal CUDA error encountered at: /home/jlowe/src/spark-rapids-jni/target/libcudf-install/include/cudf/detail/utilities/pinned_host_vector.hpp:172: 700 cudaErrorIllegalAddress an illegal memory access was encountered
Aborted (core dumped)

Expected behavior
Exceptions should not be thrown from destructors and cause an application to be terminated abruptly with no chance for the application to shutdown gracefully.

@jlowe jlowe added bug Something isn't working Needs Triage Need team to review and classify libcudf Affects libcudf (C++/CUDA) code. Spark Functionality that helps Spark RAPIDS labels Sep 21, 2023
@GregoryKimball
Copy link
Contributor

I believe this example hits the pinned_allocator deallocate function here.

We could adjust deallocate to not throw, catch the exception in the destructor (which is currently empty), or perhaps choose another option that we haven't yet considered.

@jlowe
Copy link
Member Author

jlowe commented Sep 22, 2023

We could adjust deallocate to not throw

This is what RMM's memory allocators do. Allocate functions always check, but deallocate is a debug assert that does nothing in a release build. See https://github.com/rapidsai/rmm/blob/branch-23.10/include/rmm/mr/device/cuda_memory_resource.hpp#L69-L88 as an example.

@GregoryKimball GregoryKimball added 1 - On Deck To be worked on next and removed Needs Triage Need team to review and classify labels Sep 22, 2023
robertmaynard added a commit to robertmaynard/cudf that referenced this issue Oct 5, 2023
Fixes rapidsai#14165

The deallocate function is called by the `pinned_host_vector`.
Throwing from destructors is bad since they can't be caught,
and generally get converted into runtime sig aborts.
rapids-bot bot pushed a commit that referenced this issue Oct 6, 2023
Fixes #14165

The deallocate function is called by the `pinned_host_vector`. Throwing from destructors is bad since they can't be caught, and generally get converted into runtime sig aborts.

Authors:
  - Robert Maynard (https://github.com/robertmaynard)

Approvers:
  - David Wendt (https://github.com/davidwendt)
  - Divye Gala (https://github.com/divyegala)
  - Mike Wilson (https://github.com/hyperbolic2346)

URL: #14251
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
1 - On Deck To be worked on next bug Something isn't working libcudf Affects libcudf (C++/CUDA) code. Spark Functionality that helps Spark RAPIDS
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants