Skip to content

[REVIEW] Add new factory methods to include passing an existing null mask - #3252

Merged
jrhemstad merged 9 commits into
NVIDIA:branch-0.11from
davidwendt:fea-column-factory-existing-nullmask
Nov 6, 2019
Merged

jrhemstad merged 9 commits into
NVIDIA:branch-0.11from
davidwendt:fea-column-factory-existing-nullmask

Conversation

@davidwendt

Copy link
Copy Markdown
Contributor

Closes #3235

I have many functions where the output column's null mask should be the same (copy of) the input column's null mask. So the code just copies the null mask before calling the column constructor like this:

// copy null mask
rmm::device_buffer null_mask;
cudf::size_type null_count = input_column.null_count();
if( input_column.has_nulls() )
    null_mask = rmm::device_buffer( input_column.null_mask(),
                                    bitmask_allocation_size_bytes(input_column.size()),
                                    stream, mr);
// create output column
auto output_column = std::make_unique<cudf::column>( output_type, input_column.size(),
    rmm::device_buffer(input_column.size() * size_of(output_type), stream, mr),
    null_mask, null_count);

This PR will add new column factory methods to pass an existing null mask when building the column so the above code can be reduced to the following:

auto output_column = make_numeric_column( output_type, input_column.size(),
                                          input_column.null_mask() );

@davidwendt
davidwendt requested a review from a team as a code owner October 30, 2019 20:05
@jrhemstad

jrhemstad commented Oct 30, 2019 •

Copy link
Copy Markdown
Contributor

This API would be more generic if it accept a universal reference to a device buffer:

template <typename Buffer>
std::unique_ptr<column> make_numeric_column(
    data_type type, size_type size, Buffer&& null_mask,
    size_type null_count = cudf::UNKNOWN_NULL_COUNT, cudaStream_t stream = 0,
    rmm::mr::device_memory_resource* mr = rmm::mr::get_default_resource());

Which allows the following uses:

make_numeric_column(..., rmm::device_buffer(p, bitmask_allocation_size_bytes(size)), ...); // deep copies the mask from the raw pointer p

rmm::device_buffer null_mask = ....;
make_numeric_column(..., null_mask, ...); // deep copies the mask from the device_buffer null_mask

make_numeric_column(..., std::move(null_mask), ...); // moves contents of `null_mask` into new column

@kaatish is working on a utility function to make rmm::device_buffer(p, bitmask_allocation_size_bytes(size)) a little more convenient.

@davidwendt

Copy link
Copy Markdown
Contributor Author

So I don't want to have to know how to build a device_buffer from a bitmask_t* (returned from column::null_mask()) which requires knowing about bitmask_allocation_size_bytes and what include file that is in, etc. Also, if the bitmask_t* is null then an if-statement is required otherwise you get a "Invalid size" exception from the device_buffer constructor so you would need to know to pass 0 for the size instead.
I'd rather the factory just handle all these details.
Perhaps another factory method is needed in case you have a device_buffer of a null mask. Otherwise, creating a proper device_buffer from a column::null_mask() is still about the same amount of work that is in the description.

@codecov

codecov Bot commented Oct 30, 2019 •

Copy link
Copy Markdown

Codecov Report

Merging #3252 into branch-0.11 will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##           branch-0.11    #3252   +/-   ##
============================================
  Coverage        87.13%   87.13%           
============================================
  Files               49       49           
  Lines             9269     9269           
============================================
  Hits              8077     8077           
  Misses            1192     1192

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f601939...4ea5742. Read the comment docs.

@jrhemstad jrhemstad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While it may be more convenient, simply passing in a bitmask_type* can easily lead to shooting yourself in the foot. Consider if you're copying from a column_view::null_mask where the offset() !=0.

One solution is to instead accept a device_buffer in combination with #3262.

Which would look like:

make_numeric_column(..., copy_bitmask(view.null_mask(), view.offset(), view.size()), ...);

I admit that this leaves something to be desired.

Another option is to have the factory accept a column_view and then the implementation takes care of the offset bitmask.

std::unique_ptr<column> make_numeric_column(
    data_type type, size_type size, column_view const& view,
    size_type null_count = cudf::UNKNOWN_NULL_COUNT, cudaStream_t stream = 0,
    rmm::mr::device_memory_resource* mr = rmm::mr::get_default_resource());

This looks a little weird to me, but I could probably be convinced.

Comment thread cpp/src/column/column_factories.cpp Resolved
Comment thread cpp/src/column/column_factories.cpp Resolved
Comment thread cpp/src/column/column_factories.cpp Resolved
Comment thread cpp/src/column/column_factories.cpp Resolved
@davidwendt

Copy link
Copy Markdown
Contributor Author

I guess I like this option the best then.

make_numeric_column(..., copy_bitmask(view.null_mask(), view.offset(), view.size()), ...);

Could I have a copy_bitmask(column_view) method in #3262 as well which takes care of these parameters?

@jrhemstad

Copy link
Copy Markdown
Contributor

Could I have a copy_bitmask(column_view) method in #3262 as well which takes care of these parameters?

I like this. It should be a trivial extension to the other copy_bitmask API.

Comment thread cpp/src/column/column_factories.cpp Resolved
Comment thread cpp/src/column/column_factories.cpp Resolved
@davidwendt davidwendt self-assigned this Nov 1, 2019
@davidwendt davidwendt added 2 - In Progress Currently a work in progress libcudf++ labels Nov 1, 2019

@jrhemstad jrhemstad left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just needs some tests.

@devavret devavret left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to use this but it doesn't work. Needs these changes.

@sameerz sameerz added the Spark Functionality that helps Spark RAPIDS label Nov 4, 2019
@davidwendt davidwendt changed the title [WIP] Add new factory methods to include passing an existing null mask [REVIEW] Add new factory methods to include passing an existing null mask Nov 5, 2019
@davidwendt davidwendt added 3 - Ready for Review Ready for review by team and removed 2 - In Progress Currently a work in progress labels Nov 5, 2019
@jrhemstad
jrhemstad merged commit edecb21 into NVIDIA:branch-0.11 Nov 6, 2019
@davidwendt
davidwendt deleted the fea-column-factory-existing-nullmask branch November 6, 2019 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3 - Ready for Review Ready for review by team Spark Functionality that helps Spark RAPIDS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEA] Add column factories the allow passing in an existing null mask

5 participants