-
Notifications
You must be signed in to change notification settings - Fork 1k
Add conversions between column_view and device_span<T const>. #10302
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
Merged
rapids-bot
merged 18 commits into
rapidsai:branch-22.04
from
bdice:column_view-to-device_span-implicit-conversion
Feb 17, 2022
Merged
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
8e7c738
Add implicit conversion operator from column_view to device_span<T>.
bdice 9e4010b
Add documentation about errors.
bdice d87fed0
Add tparam.
bdice 1e936ae
Add column_view constructor from device_span<T>.
bdice 94bbfab
Ensure device_span is const, add draft of tests.
bdice c575f57
Ensure device_span size is smaller than maximum size_type.
bdice dfda8da
Clarify error messages.
bdice 61d786e
Add device_span constructor from data pointer and size.
bdice 0da5d77
Update conversion operators and tests.
bdice 5d597ae
Remove device_span constructor.
bdice 8b1d02c
Disallow conversion from nullable column view.
bdice b15bdff
Enable test for all fixed-width types except fixed-point.
bdice 2b92966
Cleanup.
bdice 8f87857
Cleanup.
bdice 04131d9
Remove [[nodiscard]].
bdice 8c4783a
Update cpp/include/cudf/column/column_view.hpp
bdice 62ee87b
Apply suggestions from code review
bdice 82b44b7
Add tests for column_view failing to convert to device_span.
bdice File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| /* | ||
| * Copyright (c) 2022, NVIDIA CORPORATION. | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| #include <cudf/column/column_view.hpp> | ||
| #include <cudf/null_mask.hpp> | ||
| #include <cudf/types.hpp> | ||
| #include <cudf/utilities/span.hpp> | ||
| #include <cudf/utilities/traits.hpp> | ||
|
|
||
| #include <cudf_test/base_fixture.hpp> | ||
| #include <cudf_test/column_utilities.hpp> | ||
| #include <cudf_test/column_wrapper.hpp> | ||
| #include <cudf_test/cudf_gtest.hpp> | ||
| #include <cudf_test/type_lists.hpp> | ||
|
|
||
| #include <thrust/iterator/counting_iterator.h> | ||
|
|
||
| #include <memory> | ||
|
|
||
| template <typename T, CUDF_ENABLE_IF(cudf::is_numeric<T>() or cudf::is_chrono<T>())> | ||
| std::unique_ptr<cudf::column> example_column() | ||
| { | ||
| auto begin = thrust::make_counting_iterator(1); | ||
| auto end = thrust::make_counting_iterator(16); | ||
| return cudf::test::fixed_width_column_wrapper<T>(begin, end).release(); | ||
| } | ||
|
|
||
| template <typename T> | ||
| struct ColumnViewDeviceSpanTests : public cudf::test::BaseFixture { | ||
| }; | ||
|
|
||
| using DeviceSpanTypes = cudf::test::FixedWidthTypesWithoutFixedPoint; | ||
| TYPED_TEST_SUITE(ColumnViewDeviceSpanTests, DeviceSpanTypes); | ||
|
|
||
| TYPED_TEST(ColumnViewDeviceSpanTests, conversion_round_trip) | ||
| { | ||
| auto col = example_column<TypeParam>(); | ||
| auto col_view = cudf::column_view{*col}; | ||
|
|
||
| // Test implicit conversion, round trip | ||
| cudf::device_span<const TypeParam> device_span_from_col_view = col_view; | ||
| cudf::column_view col_view_from_device_span = device_span_from_col_view; | ||
| CUDF_TEST_EXPECT_COLUMNS_EQUAL(col_view, col_view_from_device_span); | ||
| } | ||
|
|
||
| struct ColumnViewDeviceSpanErrorTests : public cudf::test::BaseFixture { | ||
| }; | ||
|
|
||
| TEST_F(ColumnViewDeviceSpanErrorTests, type_mismatch) | ||
| { | ||
| auto col = example_column<int32_t>(); | ||
| auto col_view = cudf::column_view{*col}; | ||
| EXPECT_THROW((void)cudf::device_span<const float>{col_view}, cudf::logic_error); | ||
| } | ||
|
|
||
| TEST_F(ColumnViewDeviceSpanErrorTests, nullable_column) | ||
| { | ||
| auto col = example_column<int32_t>(); | ||
| col->set_null_mask(cudf::create_null_mask(col->size(), cudf::mask_state::ALL_NULL), col->size()); | ||
| auto col_view = cudf::column_view{*col}; | ||
| EXPECT_THROW((void)cudf::device_span<const int32_t>{col_view}, cudf::logic_error); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.