Skip to content

Commit

Permalink
Apply the cuFile error work around to data_sink as well (#15335)
Browse files Browse the repository at this point in the history
Issue #14140

Follow-up on #15293

Moving the `cudaFree(0)` call to a function called both by file `datasource` and `data_sink`.

Authors:
  - Vukasin Milovanovic (https://github.com/vuule)

Approvers:
  - David Wendt (https://github.com/davidwendt)
  - Yunsong Wang (https://github.com/PointKernel)
  - Nghia Truong (https://github.com/ttnghia)

URL: #15335
  • Loading branch information
vuule authored Apr 1, 2024
1 parent aab6137 commit 0a8807e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 5 deletions.
1 change: 1 addition & 0 deletions cpp/src/io/utilities/data_sink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class file_sink : public data_sink {
public:
explicit file_sink(std::string const& filepath)
{
detail::force_init_cuda_context();
_output_stream.open(filepath, std::ios::out | std::ios::binary | std::ios::trunc);
if (!_output_stream.is_open()) { detail::throw_on_file_open_failure(filepath, true); }

Expand Down
6 changes: 1 addition & 5 deletions cpp/src/io/utilities/datasource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,8 @@ class file_source : public datasource {
public:
explicit file_source(char const* filepath) : _file(filepath, O_RDONLY)
{
detail::force_init_cuda_context();
if (detail::cufile_integration::is_kvikio_enabled()) {
// Workaround for https://github.com/rapidsai/cudf/issues/14140, where cuFileDriverOpen errors
// out if no CUDA calls have been made before it. This is a no-op if the CUDA context is
// already initialized
cudaFree(0);

_kvikio_file = kvikio::FileHandle(filepath);
CUDF_LOG_INFO("Reading a file using kvikIO, with compatibility mode {}.",
_kvikio_file.is_compat_mode_on() ? "on" : "off");
Expand Down
8 changes: 8 additions & 0 deletions cpp/src/io/utilities/file_io_utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ namespace cudf {
namespace io {
namespace detail {

void force_init_cuda_context()
{
// Workaround for https://github.com/rapidsai/cudf/issues/14140, where cuFileDriverOpen errors
// out if no CUDA calls have been made before it. This is a no-op if the CUDA context is already
// initialized.
cudaFree(0);
}

[[noreturn]] void throw_on_file_open_failure(std::string const& filepath, bool is_create)
{
// save errno because it may be overwritten by subsequent calls
Expand Down
3 changes: 3 additions & 0 deletions cpp/src/io/utilities/file_io_utilities.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ namespace detail {

[[noreturn]] void throw_on_file_open_failure(std::string const& filepath, bool is_create);

// Call before any cuFile API calls to ensure the CUDA context is initialized.
void force_init_cuda_context();

/**
* @brief Class that provides RAII for file handling.
*/
Expand Down

0 comments on commit 0a8807e

Please sign in to comment.