-
Notifications
You must be signed in to change notification settings - Fork 906
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
Generalized null support in user defined functions #8213
Generalized null support in user defined functions #8213
Conversation
cpp/include/cudf/transform.hpp
Outdated
@@ -53,6 +53,12 @@ std::unique_ptr<column> transform( | |||
bool is_ptx, | |||
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); | |||
|
|||
std::unique_ptr<column> generalized_masked_op( | |||
table_view data_view, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typically we pass in table_view const&
as copying it may involve recursively copying its children column_view which is more expensive.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may need to be modified to use table_view const&
(not just this, but in other places too).
* limitations under the License. | ||
*/ | ||
|
||
// Include Jitify's cstddef header first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why? The convention in cudf is to include from "near" to "far". So, you include <transform/...>
first, then <cudf/...>
, then <cuda/...>
, then std headers finally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the problem here is that technically when this file is runtime compilated later, transform/jit/operation-udf.hpp
gets string replaced by by an actual function definition that might contain the types in the std headers. So I think at least the order of those two headers is critical.
cpp/src/transform/transform.cpp
Outdated
@@ -15,6 +15,7 @@ | |||
*/ | |||
|
|||
#include <jit_preprocessed_files/transform/jit/kernel.cu.jit.hpp> | |||
#include <jit_preprocessed_files/transform/jit/masked_udf_kernel.cu.jit.hpp> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that jit headers should be included after cudf headers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
cpp/src/transform/transform.cpp
Outdated
template_types.reserve(data_view.num_columns() + 1); | ||
|
||
template_types.push_back(cudf::jit::get_type_name(outcol_view.type())); | ||
for (auto const& col : data_view) { | ||
template_types.push_back(cudf::jit::get_type_name(col.type()) + "*"); | ||
template_types.push_back(mskptr_type); | ||
template_types.push_back(offset_type); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait, I see that you call push_back
by 3*num_cols() + 1
times instead of num_cols() + 1
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nice catch - this was unsafe. Fixed
cpp/src/transform/transform.cpp
Outdated
rmm::cuda_stream_view generic_stream; | ||
cudf::jit::get_program_cache(*transform_jit_masked_udf_kernel_cu_jit) | ||
.get_kernel(generic_kernel_name, | ||
{}, | ||
{{"transform/jit/operation-udf.hpp", generic_cuda_source}}, | ||
{"-arch=sm_."}) // | ||
->configure_1d_max_occupancy(0, 0, 0, generic_stream.value()) // |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why generic_stream
is used without initialization? Are you using the default stream? If so, call default stream directly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be fixed.
cpp/src/transform/transform.cpp
Outdated
data_ptrs.push_back(cudf::jit::get_data_ptr(col)); | ||
mask_ptrs.push_back(col.null_mask()); | ||
offsets.push_back(col.offset()); | ||
|
||
kernel_args.push_back(&data_ptrs[col_idx]); | ||
kernel_args.push_back(&mask_ptrs[col_idx]); | ||
kernel_args.push_back(&offsets[col_idx]); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use some type of std::transform
instead? Using raw loop is discouraged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is difficult due to the 1->3 transform going on here. I kept trying to do the same, but couldn't get anything that was cleaner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using thrust::zip_iterator
(host callable)? You can output to 3 values at the same time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I managed to use zip_iterator
to replace about half the logic here. One loop though I did not see how to simplify, open to suggestions here.
cpp/src/transform/transform.cpp
Outdated
mutable_column_view outmsk_view, | ||
rmm::mr::device_memory_resource* mr) | ||
{ | ||
std::vector<std::string> template_types = make_template_types(outcol_view, data_view); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One more thing I want to note is that, you can use auto const
for declaring almost everything, instead of writing lengthy types like this. I.e.,
auto const template_types =...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Co-authored-by: Nghia Truong <[email protected]>
Co-authored-by: GALI PREM SAGAR <[email protected]>
I think this is ready for another look cc @ttnghia |
cpp/include/cudf/transform.hpp
Outdated
@@ -53,6 +53,12 @@ std::unique_ptr<column> transform( | |||
bool is_ptx, | |||
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); | |||
|
|||
std::unique_ptr<column> generalized_masked_op( | |||
table_view data_view, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You may need to be modified to use table_view const&
(not just this, but in other places too).
Co-authored-by: Nghia Truong <[email protected]>
rerun tests |
@gpucibot merge |
This PR removes the c++ side of the original masked UDF code introduced in #8213. These kernels had some limitations and are now superseded by the numba-generated versions we moved to in #9174. As far as I can tell, cuDF python was the only thing consuming this API for the short time it has existed. However I am marking this breaking just in case. Authors: - https://github.com/brandon-b-miller Approvers: - Mark Harris (https://github.com/harrism) - David Wendt (https://github.com/davidwendt) - Vyas Ramasubramani (https://github.com/vyasr) URL: #9792
Draft
DataFrame.apply
similar to Pandascudf.NA
in user defined functions explicitlyThis PR creates the following API: