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

Avoid using cudf_helpers.pyx to copy a cuDF DataFrame #1945

Closed
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
3 changes: 2 additions & 1 deletion .github/workflows/ci_pipe.yml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ jobs:
test:
name: Test
runs-on: linux-amd64-gpu-v100-latest-1
timeout-minutes: 60
# Consider lowering this back down to 60 minutes per https://github.com/nv-morpheus/Morpheus/issues/1948
timeout-minutes: 90
container:
credentials:
username: '$oauthtoken'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ struct MORPHEUS_EXPORT TableInfoBase
*/
bool has_sliceable_index() const;

const std::shared_ptr<const IDataTable>& get_parent() const;

protected:
TableInfoBase() = default;

TableInfoBase(std::shared_ptr<const IDataTable> parent, TableInfoData data);

const std::shared_ptr<const IDataTable>& get_parent() const;

TableInfoData& get_data();
const TableInfoData& get_data() const;

Expand Down
18 changes: 13 additions & 5 deletions python/morpheus/morpheus/_lib/src/messages/meta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@
#include <pybind11/gil.h>
#include <pybind11/pybind11.h>
#include <pybind11/pytypes.h>
#include <pyerrors.h> // for PyExc_DeprecationWarning
#include <warnings.h> // for PyErr_WarnEx
#include <pybind11/stl.h> // IWYU pragma: keep
#include <pyerrors.h> // for PyExc_DeprecationWarning
#include <warnings.h> // for PyErr_WarnEx

#include <cstddef> // for size_t
#include <cstdint> // for uint8_t
Expand Down Expand Up @@ -444,17 +445,24 @@ std::vector<std::string> MessageMetaInterfaceProxy::get_column_names(MessageMeta

py::object MessageMetaInterfaceProxy::get_data_frame(MessageMeta& self)
{
namespace py = pybind11;
TableInfo info;

{
// Need to release the GIL before calling `get_meta()`
pybind11::gil_scoped_release no_gil;
// Need to release the GIL before calling `get_info()`
py::gil_scoped_release no_gil;

// Get the column and convert to cudf
info = self.get_info();
}

return CudfHelper::table_from_table_info(info);
auto column_names = info.get_column_names();
auto py_df = info.get_parent()->get_py_object();

py::gil_scoped_acquire gil;
auto py_column_names = py::cast(column_names);
py::object py_df_slice = py_df[py_column_names];
return py_df_slice.attr("copy")("deep"_a = true);
}

py::object MessageMetaInterfaceProxy::df_property(MessageMeta& self)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,22 @@
#include "morpheus/objects/tensor.hpp" // for Tensor
#include "morpheus/types.hpp" // for RangeType

#include <gtest/gtest.h> // for TestInfo, TEST_F
#include <pybind11/gil.h> // for gil_scoped_release
#include <gtest/gtest.h> // for TestInfo, TEST_F
#include <pybind11/gil.h> // for gil_scoped_release
#include <pybind11/pybind11.h>
#include <pybind11/pytypes.h>
#include <rmm/cuda_stream_view.hpp> // for cuda_stream_per_thread
#include <rmm/device_buffer.hpp> // for device_buffer

#include <cstdint> // for int64_t
#include <filesystem> // for operator/, path
#include <memory> // for allocator, __shared_ptr_access, shared_ptr, make_shared
#include <utility> // for move
#include <vector> // for vector

using namespace morpheus;
using namespace morpheus::test;
using namespace pybind11::literals;

using TestMessageMeta = morpheus::test::TestMessages; // NOLINT(readability-identifier-naming)

Expand Down Expand Up @@ -82,3 +86,25 @@ TEST_F(TestMessageMeta, CopyRangeAndSlicing)
assert_eq_device_to_host(sliced_meta->get_info().get_column(0), sliced_expected_int);
assert_eq_device_to_host(sliced_meta->get_info().get_column(1), sliced_expected_double);
}

TEST_F(TestMessageMeta, Issue1934)
{
// Reproduce issue 1934 (https://github.com/nv-morpheus/Morpheus/issues/1934)
// The bug causes a segfault when calling `get_data_frame` on a message meta object
namespace py = pybind11;
py::gil_scoped_acquire gil;

auto cudf_mod = py::module_::import("cudf");
auto a_col = py::list();
auto v1 = py::list();
v1.append(py::str("a"));
a_col.attr("append")(std::move(v1));
a_col.attr("append")(py::none());

auto df = cudf_mod.attr("DataFrame")(py::dict("a"_a = std::move(a_col)));
df.attr("drop")(0, "inplace"_a = true);

auto msg = MessageMetaInterfaceProxy::init_python(std::move(df));

auto df_copy = MessageMetaInterfaceProxy::get_data_frame(*msg);
}
1 change: 0 additions & 1 deletion tests/_utils/test_directories.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ def __init__(self, tests_dir) -> None:
self.tests_data_dir = os.path.join(self.tests_dir, 'tests_data')
self.mock_triton_servers_dir = os.path.join(self.tests_dir, 'mock_triton_server')
self.mock_rest_server = os.path.join(self.tests_dir, 'mock_rest_server')
print(self)
Loading