Skip to content

Commit

Permalink
column_view: add owner
Browse files Browse the repository at this point in the history
This is a hack we have to remove before merging this PR.
  • Loading branch information
madsbk committed Aug 22, 2022
1 parent 7322070 commit 9da6b5b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 14 deletions.
23 changes: 19 additions & 4 deletions cpp/include/cudf/column/column_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include <cudf/utilities/type_dispatcher.hpp>

#include <limits>
#include <memory>
#include <type_traits>
#include <vector>

Expand Down Expand Up @@ -239,6 +240,8 @@ class column_view_base {
mutable size_type _null_count{}; ///< The number of null elements
size_type _offset{}; ///< Index position of the first element.
///< Enables zero-copy slicing
std::shared_ptr<void> _owner; ///< Pointer to the owner (if any) of the device
///< memory allocation.

column_view_base() = default;
~column_view_base() = default;
Expand Down Expand Up @@ -282,15 +285,19 @@ class column_view_base {
* @param data Pointer to device memory containing the column elements
* @param null_mask Optional, pointer to device memory containing the null
* indicator bitmask
* @param null_count Optional, the number of null elements.
* @param null_count Optional, the number of null elements
* @param offset optional, index of the first element
* @param owner optional, object to which the lifetime of the device memory
* allocation is tied. If provided, a reference to this object is kept until
* destruction
*/
column_view_base(data_type type,
size_type size,
void const* data,
bitmask_type const* null_mask = nullptr,
size_type null_count = UNKNOWN_NULL_COUNT,
size_type offset = 0);
size_type offset = 0,
std::shared_ptr<void> owner = nullptr);
};

class mutable_column_view_base : public column_view_base {
Expand Down Expand Up @@ -376,14 +383,18 @@ class column_view : public detail::column_view_base {
* @param offset optional, index of the first element
* @param children optional, depending on the element type, child columns may
* contain additional data
* @param owner optional, object to which the lifetime of the device memory
* allocation is tied. If provided, a reference to this object is kept until
* destruction
*/
column_view(data_type type,
size_type size,
void const* data,
bitmask_type const* null_mask = nullptr,
size_type null_count = UNKNOWN_NULL_COUNT,
size_type offset = 0,
std::vector<column_view> const& children = {});
std::vector<column_view> const& children = {},
std::shared_ptr<void> owner = nullptr);

/**
* @brief Returns the specified child
Expand Down Expand Up @@ -531,14 +542,18 @@ class mutable_column_view : public detail::column_view_base {
* @param offset optional, index of the first element
* @param children optional, depending on the element type, child columns may
* contain additional data
* @param owner optional, object to which the lifetime of the device memory
* allocation is tied. If provided, a reference to this object is kept until
* destruction
*/
mutable_column_view(data_type type,
size_type size,
void* data,
bitmask_type* null_mask = nullptr,
size_type null_count = cudf::UNKNOWN_NULL_COUNT,
size_type offset = 0,
std::vector<mutable_column_view> const& children = {});
std::vector<mutable_column_view> const& children = {},
std::shared_ptr<void> owner = nullptr);

/**
* @brief Returns pointer to the base device memory allocation casted to
Expand Down
17 changes: 11 additions & 6 deletions cpp/src/column/column_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ column_view_base::column_view_base(data_type type,
void const* data,
bitmask_type const* null_mask,
size_type null_count,
size_type offset)
size_type offset,
std::shared_ptr<void> owner)
: _type{type},
_size{size},
_data{data},
_null_mask{null_mask},
_null_count{null_count},
_offset{offset}
_offset{offset},
_owner{owner}
{
CUDF_EXPECTS(size >= 0, "Column size cannot be negative.");

Expand Down Expand Up @@ -143,8 +145,10 @@ column_view::column_view(data_type type,
bitmask_type const* null_mask,
size_type null_count,
size_type offset,
std::vector<column_view> const& children)
: detail::column_view_base{type, size, data, null_mask, null_count, offset}, _children{children}
std::vector<column_view> const& children,
std::shared_ptr<void> owner)
: detail::column_view_base{type, size, data, null_mask, null_count, offset, owner},
_children{children}
{
if (type.id() == type_id::EMPTY) {
CUDF_EXPECTS(num_children() == 0, "EMPTY column cannot have children.");
Expand All @@ -158,8 +162,9 @@ mutable_column_view::mutable_column_view(data_type type,
bitmask_type* null_mask,
size_type null_count,
size_type offset,
std::vector<mutable_column_view> const& children)
: detail::column_view_base{type, size, data, null_mask, null_count, offset},
std::vector<mutable_column_view> const& children,
std::shared_ptr<void> owner)
: detail::column_view_base{type, size, data, null_mask, null_count, offset, owner},
mutable_children{children}
{
if (type.id() == type_id::EMPTY) {
Expand Down
35 changes: 31 additions & 4 deletions python/cudf/cudf/_lib/cpp/column/column_view.pxd
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright (c) 2020, NVIDIA CORPORATION.
# Copyright (c) 2020-2022, NVIDIA CORPORATION.

from libcpp cimport bool
from libcpp.memory cimport shared_ptr
from libcpp.vector cimport vector

from cudf._lib.cpp.types cimport bitmask_type, data_type, size_type
Expand Down Expand Up @@ -54,6 +55,17 @@ cdef extern from "cudf/column/column_view.hpp" namespace "cudf" nogil:
vector[column_view] children
) except +

column_view(
data_type type,
size_type size,
const void* data,
const bitmask_type* null_mask,
size_type null_count,
size_type offset,
vector[column_view] children,
shared_ptr[void] owner
) except +

const T* data[T]() except +
const T* head[T]() except +
const bitmask_type* null_mask() except +
Expand Down Expand Up @@ -102,9 +114,24 @@ cdef extern from "cudf/column/column_view.hpp" namespace "cudf" nogil:
) except +

mutable_column_view(
data_type type, size_type size, const void* data,
const bitmask_type* null_mask, size_type null_count,
size_type offset, vector[mutable_column_view] children
data_type type,
size_type size,
const void* data,
const bitmask_type* null_mask,
size_type null_count,
size_type offset,
vector[mutable_column_view] children
) except +

mutable_column_view(
data_type type,
size_type size,
const void* data,
const bitmask_type* null_mask,
size_type null_count,
size_type offset,
vector[mutable_column_view] children,
shared_ptr[void] owner
) except +

T* data[T]() except +
Expand Down

0 comments on commit 9da6b5b

Please sign in to comment.