Skip to content

Disable column_view data accessors for unsupported types - #7725

Merged
rapids-bot[bot] merged 43 commits into
NVIDIA:branch-0.19from
jrhemstad:disable_column_view_begin
Mar 30, 2021
Merged

Disable column_view data accessors for unsupported types#7725
rapids-bot[bot] merged 43 commits into
NVIDIA:branch-0.19from
jrhemstad:disable_column_view_begin

Conversation

@jrhemstad

@jrhemstad jrhemstad commented Mar 25, 2021

Copy link
Copy Markdown
Contributor

Fixes #7712

column_view provides data accessors like column_view::data<T> and column_view::begin<T>. These accessors are only valid for fixed-width primitive types that can be constructed by simply casting the underlying void* to T*.

However, the accessors never actually enforced this rule, e.g., column_view::data<struct_view> should fail to compile.

This PR disables these accessors for invalid types.

This uncovered a number of places that were erroneously instantiating column_view accessors, which would lead to silent failures (e.g., scatter was failing silently for struct columns).

I added a few new things to aid me in this effort:

  • CUDF_ENABLE_IF macro to make it easier to SFINAE.
  • is_rep_layout_compatbile<T>() to identify types that are layout compatible with their rep (e.g., duration_ns is layout compatible with its int64_t rep. The decimal32 type is not layout compatible with it's int32_t rep).
  • column_device_view::has_element_accessor<T>() identifies if column_device_view::element<T>() has a valid overload.

Scatter was erroneously instantiating things like
column_view::begin<struct_view>().

Updated the specializations to ensure that unsupported types throw an
exception.
@github-actions github-actions Bot added the libcudf Affects libcudf (C++/CUDA) code. label Mar 25, 2021
@jrhemstad

Copy link
Copy Markdown
Contributor Author

The following tests are now failing as a result of this change:

	 19 - FIXED_POINT_TEST (Failed)
	 20 - UNARY_TEST (Failed)
	 21 - ROUND_TEST (Failed)
	 22 - BINARY_TEST (Failed)

I suspect this is all due to the erroneous code paths taken in the JIT code.

@jrhemstad jrhemstad added non-breaking Non-breaking change bug Something isn't working labels Mar 25, 2021
@jrhemstad
jrhemstad requested a review from codereport March 25, 2021 21:09
@jrhemstad

Copy link
Copy Markdown
Contributor Author

So the fixed_point_binary_operation ultimately calls into the "regular" binary_operation API here:
https://github.com/rapidsai/cudf/blob/20509d0b75cf33e0597325fe17426766ed366eb3/cpp/src/binaryop/binaryop.cpp#L620
which calls into: https://github.com/rapidsai/cudf/blob/20509d0b75cf33e0597325fe17426766ed366eb3/cpp/src/binaryop/binaryop.cpp#L226-L230
which calls get_data_ptr<decimal32/64>
https://github.com/rapidsai/cudf/blob/20509d0b75cf33e0597325fe17426766ed366eb3/cpp/src/binaryop/binaryop.cpp#L248-L251
and in my PR, that lands you here: https://github.com/rapidsai/cudf/blob/f99318eba0b09149fbed5ddcee35a6f98581b0b2/cpp/src/jit/type.cpp#L36-L41

The binop API only knows how to access data through the column_view::data<T>(), but that doesn't work for decimalXX. It needs to go through the column_device_view::element<T> or operate on the device_storage_type<T>.

get_data_ptr was erroneously invoking
column_view::data<decimal32/64>().

As it happens, this ended up being okay
when the column did not have any offset as
column_view::data<int32>() and
column_view::data<decimal32>() will
return the same initial pointer when the
offset is zero. The problem occurs when you
attempt to advance this pointer, or if the
column had an offset (which internally will advance the pointer).
@jrhemstad

Copy link
Copy Markdown
Contributor Author

The fix in a4788a0 was to just use dispatch_storage_type.

@codecov

codecov Bot commented Mar 26, 2021

Copy link
Copy Markdown

Codecov Report

Merging #7725 (4571a03) into branch-0.19 (7871e7a) will increase coverage by 0.65%.
The diff coverage is n/a.

❗ Current head 4571a03 differs from pull request most recent head f92d462. Consider uploading reports for the commit f92d462 to get more accurate results
Impacted file tree graph

@@               Coverage Diff               @@
##           branch-0.19    #7725      +/-   ##
===============================================
+ Coverage        81.86%   82.52%   +0.65%     
===============================================
  Files              101      101              
  Lines            16884    17458     +574     
===============================================
+ Hits             13822    14407     +585     
+ Misses            3062     3051      -11     
Impacted Files Coverage Δ
python/cudf/cudf/utils/gpu_utils.py 53.65% <0.00%> (-4.88%) ⬇️
python/cudf/cudf/core/column/lists.py 87.68% <0.00%> (-3.72%) ⬇️
python/cudf/cudf/core/column/decimal.py 92.95% <0.00%> (-1.92%) ⬇️
python/cudf/cudf/core/abc.py 87.23% <0.00%> (-1.14%) ⬇️
python/cudf/cudf/core/column/numerical.py 94.83% <0.00%> (-0.20%) ⬇️
python/cudf/cudf/core/column/column.py 87.61% <0.00%> (-0.15%) ⬇️
python/cudf/cudf/utils/utils.py 85.36% <0.00%> (-0.07%) ⬇️
python/cudf/cudf/io/feather.py 100.00% <0.00%> (ø)
python/cudf/cudf/utils/ioutils.py 78.71% <0.00%> (ø)
python/cudf/cudf/comm/serialize.py 0.00% <0.00%> (ø)
... and 45 more

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 e73fff0...f92d462. Read the comment docs.

@jrhemstad
jrhemstad marked this pull request as ready for review March 29, 2021 17:39
@jrhemstad
jrhemstad requested a review from a team as a code owner March 29, 2021 17:39
@jrhemstad
jrhemstad requested a review from trxcllnt March 29, 2021 17:39
@jrhemstad

Copy link
Copy Markdown
Contributor Author

I'm calling this "non-breaking" in that it doesn't change any external APIs. It technically could change externally visible behavior where some code will throw where it used to "work", but those use cases were broken code to begin with.

Comment thread cpp/benchmarks/type_dispatcher/type_dispatcher_benchmark.cu Outdated
#include <type_traits>
#include "../fixture/benchmark_fixture.hpp"
#include "../synchronization/synchronization.hpp"
#include "cudf/utilities/traits.hpp"

@mythrocks mythrocks Mar 29, 2021

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.

Nitpick: Aren't we enforcing angle brackets <> for includes that aren't in the current directory?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah, something in my vscode auto includes headers and uses " instead of <>. I'll need to see if I can change that.

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.

It's clangd IWYU.

Comment thread cpp/include/cudf/column/column_device_view.cuh Outdated

@cwharris cwharris 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.

nice!

@vyasr vyasr 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.

Looks good to me. One request (if you don't want to do it then just re-request my review and I can approve): it seems like there are a number of places in this PR that are still using the raw std::enable_if_t<...>* = nullptr to disable implementations (where it's using an non-type template parameter that's unused AFAICT). Since any code patterns introduced here will inevitably be copied into other places and your new CUDF_ENABLE_IF macro is a bit cleaner, it would be nice to use it consistently everywhere as much as possible.

Co-authored-by: Paul Taylor <paul.e.taylor@me.com>
Comment thread cpp/include/cudf/column/column_device_view.cuh
@jrhemstad

jrhemstad commented Mar 29, 2021

Copy link
Copy Markdown
Contributor Author

Looks good to me. One request (if you don't want to do it then just re-request my review and I can approve): it seems like there are a number of places in this PR that are still using the raw std::enable_if_t<...>* = nullptr to disable implementations (where it's using an non-type template parameter that's unused AFAICT). Since any code patterns introduced here will inevitably be copied into other places and your new CUDF_ENABLE_IF macro is a bit cleaner, it would be nice to use it consistently everywhere as much as possible.

Yeah, I got half way through and got sick of typing, so I made the macro. I was hoping reviewers would just let me be lazy :) But I agree, I'll go make stuff in this PR consistent.

@codereport codereport 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.

Looks awesome! Small header things but not a big deal.

Comment thread cpp/src/copying/copy.cu Outdated
Comment thread cpp/src/interop/dlpack.cpp Outdated
Comment thread cpp/src/jit/type.cpp Outdated
Comment thread cpp/tests/copying/copy_tests.cu Outdated
#include <cudf/scalar/scalar.hpp>

#include <rmm/cuda_stream_view.hpp>
#include "cudf/utilities/traits.hpp"

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.

Suggested change
#include "cudf/utilities/traits.hpp"
#include <cudf/utilities/traits.hpp>

jrhemstad and others added 6 commits March 29, 2021 16:31
Co-authored-by: Conor Hoekstra <36027403+codereport@users.noreply.github.com>
Co-authored-by: Conor Hoekstra <36027403+codereport@users.noreply.github.com>
@jrhemstad
jrhemstad requested a review from vyasr March 29, 2021 21:38

@vyasr vyasr 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.

Looks good!

@harrism harrism added the 5 - Ready to Merge Testing and reviews complete, ready to merge label Mar 30, 2021
@harrism

harrism commented Mar 30, 2021

Copy link
Copy Markdown
Contributor

@gpucibot merge

@rapids-bot
rapids-bot Bot merged commit 2d24a9b into NVIDIA:branch-0.19 Mar 30, 2021
rapids-bot Bot pushed a commit that referenced this pull request Apr 1, 2021
In #7725 I updated some of the fall through error cases to use old, [C-style ellipsis variadics ](https://github.com/jrhemstad/cudf/blob/f92d4626c7a4296075c5aa6240d6e3b88049abe6/cpp/include/cudf/detail/gather.cuh#L145 
)since we don't care about the parameters in the error case. Turns out C++ forbids passing "non-POD" types through this kind of variadic ellipsis, which ends up generating a compiler warning:

> warning: non-POD class type passed through ellipsis

Authors:
  - Jake Hemstad (https://github.com/jrhemstad)

Approvers:
  - David Wendt (https://github.com/davidwendt)
  - Nghia Truong (https://github.com/ttnghia)
  - Mark Harris (https://github.com/harrism)

URL: #7781
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

5 - Ready to Merge Testing and reviews complete, ready to merge bug Something isn't working libcudf Affects libcudf (C++/CUDA) code. non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Templated data accessors in column_view should not work with non-fixed-width types.

8 participants