Skip to content

Commit b854598

Browse files
authored
Convert cudf::concatenate APIs to use spans and device_uvector (#7621)
Contributes to #7287 This PR replaces `std::vector` with `host_span` in public and detail `cudf::contatenate` functions, and replaces `rmm::device_vector` with `rmm::device_uvector` in the concatenate implementations. It also strengthens the SFINAE restrictions on `cudf::host_span` and `cudf::device_span` so that they cannot be constructed from containers unless the container's value_type is the same as the span's value_type. This PR also - [x] Updates cython. - [x] benchmarks before and after Authors: - Mark Harris (@harrism) Approvers: - Jake Hemstad (@jrhemstad) - Vukasin Milovanovic (@vuule) - Ashwin Srinath (@shwina) URL: #7621
1 parent 3136124 commit b854598

File tree

25 files changed

+282
-200
lines changed

25 files changed

+282
-200
lines changed

cpp/include/cudf/column/column_factories.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#include <cudf/utilities/traits.hpp>
2222

2323
#include <rmm/cuda_stream_view.hpp>
24-
#include <rmm/device_vector.hpp>
2524

2625
namespace cudf {
2726
/**

cpp/include/cudf/concatenate.hpp

+8-10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,9 +17,9 @@
1717

1818
#include <cudf/column/column_view.hpp>
1919
#include <cudf/table/table_view.hpp>
20+
#include <cudf/utilities/span.hpp>
2021

2122
#include <memory>
22-
#include <vector>
2323

2424
namespace cudf {
2525
/**
@@ -36,13 +36,13 @@ namespace cudf {
3636
*
3737
* Returns empty `device_buffer` if the column is not nullable
3838
*
39-
* @param views Vector of column views whose bitmask will to be concatenated
39+
* @param views host_span of column views whose bitmask will to be concatenated
4040
* @param mr Device memory resource used for allocating the new device_buffer
4141
* @return rmm::device_buffer A `device_buffer` containing the bitmasks of all
4242
* the column views in the views vector
4343
*/
4444
rmm::device_buffer concatenate_masks(
45-
std::vector<column_view> const& views,
45+
host_span<column_view const> views,
4646
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
4747

4848
/**
@@ -51,14 +51,13 @@ rmm::device_buffer concatenate_masks(
5151
* @throws cudf::logic_error
5252
* If types of the input columns mismatch
5353
*
54-
* @param columns_to_concat The column views to be concatenated into a single
55-
* column
54+
* @param columns_to_concat host_span of column views to be concatenated into a single column
5655
* @param mr Device memory resource used to allocate the returned column's device memory.
5756
* @return Unique pointer to a single table having all the rows from the
5857
* elements of `columns_to_concat` respectively in the same order.
5958
*/
6059
std::unique_ptr<column> concatenate(
61-
std::vector<column_view> const& columns_to_concat,
60+
host_span<column_view const> columns_to_concat,
6261
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
6362

6463
/**
@@ -82,14 +81,13 @@ std::unique_ptr<column> concatenate(
8281
* @throws cudf::logic_error
8382
* If number of columns mismatch
8483
*
85-
* @param tables_to_concat The table views to be concatenated into a single
86-
* table
84+
* @param tables_to_concat host_span of table views to be concatenated into a single table
8785
* @param mr Device memory resource used to allocate the returned table's device memory.
8886
* @return Unique pointer to a single table having all the rows from the
8987
* elements of `tables_to_concat` respectively in the same order.
9088
*/
9189
std::unique_ptr<table> concatenate(
92-
std::vector<table_view> const& tables_to_concat,
90+
host_span<table_view const> tables_to_concat,
9391
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
9492

9593
/** @} */ // end of group

cpp/include/cudf/detail/concatenate.cuh

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,6 +20,7 @@
2020
#include <cudf/concatenate.hpp>
2121
#include <cudf/detail/concatenate.hpp>
2222
#include <cudf/table/table_view.hpp>
23+
#include <cudf/utilities/span.hpp>
2324

2425
#include <rmm/cuda_stream_view.hpp>
2526

@@ -34,8 +35,8 @@ namespace detail {
3435
*
3536
* @param stream CUDA stream used for device memory operations and kernel launches.
3637
*/
37-
void concatenate_masks(rmm::device_vector<column_device_view> const& d_views,
38-
rmm::device_vector<size_t> const& d_offsets,
38+
void concatenate_masks(device_span<column_device_view const> d_views,
39+
device_span<size_t const> d_offsets,
3940
bitmask_type* dest_mask,
4041
size_type output_size,
4142
rmm::cuda_stream_view stream);
@@ -45,7 +46,7 @@ void concatenate_masks(rmm::device_vector<column_device_view> const& d_views,
4546
*
4647
* @param stream CUDA stream used for device memory operations and kernel launches.
4748
*/
48-
void concatenate_masks(std::vector<column_view> const& views,
49+
void concatenate_masks(host_span<column_view const> views,
4950
bitmask_type* dest_mask,
5051
rmm::cuda_stream_view stream);
5152

cpp/include/cudf/detail/concatenate.hpp

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818
#include <cudf/column/column_view.hpp>
1919
#include <cudf/concatenate.hpp>
2020
#include <cudf/table/table_view.hpp>
21+
#include <cudf/utilities/span.hpp>
2122

2223
#include <rmm/cuda_stream_view.hpp>
2324

@@ -27,22 +28,22 @@ namespace cudf {
2728
//! Inner interfaces and implementations
2829
namespace detail {
2930
/**
30-
* @copydoc cudf::concatenate(std::vector<column_view> const&,rmm::mr::device_memory_resource*)
31+
* @copydoc cudf::concatenate(host_span<column_view const>,rmm::mr::device_memory_resource*)
3132
*
3233
* @param stream CUDA stream used for device memory operations and kernel launches.
3334
*/
3435
std::unique_ptr<column> concatenate(
35-
std::vector<column_view> const& columns_to_concat,
36+
host_span<column_view const> columns_to_concat,
3637
rmm::cuda_stream_view stream = rmm::cuda_stream_default,
3738
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
3839

3940
/**
40-
* @copydoc cudf::concatenate(std::vector<table_view> const&,rmm::mr::device_memory_resource*)
41+
* @copydoc cudf::concatenate(host_span<table_view const>,rmm::mr::device_memory_resource*)
4142
*
4243
* @param stream CUDA stream used for device memory operations and kernel launches.
4344
*/
4445
std::unique_ptr<table> concatenate(
45-
std::vector<table_view> const& tables_to_concat,
46+
host_span<table_view const> tables_to_concat,
4647
rmm::cuda_stream_view stream = rmm::cuda_stream_default,
4748
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
4849

cpp/include/cudf/dictionary/detail/concatenate.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -17,6 +17,7 @@
1717

1818
#include <cudf/column/column.hpp>
1919
#include <cudf/dictionary/dictionary_column_view.hpp>
20+
#include <cudf/utilities/span.hpp>
2021

2122
#include <rmm/cuda_stream_view.hpp>
2223

@@ -36,7 +37,7 @@ namespace detail {
3637
* @return New column with concatenated results.
3738
*/
3839
std::unique_ptr<column> concatenate(
39-
std::vector<column_view> const& columns,
40+
host_span<column_view const> columns,
4041
rmm::cuda_stream_view stream = rmm::cuda_stream_default,
4142
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
4243

cpp/include/cudf/lists/detail/concatenate.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818
#include <cudf/column/column.hpp>
1919
#include <cudf/lists/lists_column_view.hpp>
2020
#include <cudf/table/table_view.hpp>
21+
#include <cudf/utilities/span.hpp>
2122

2223
#include <rmm/cuda_stream_view.hpp>
2324

@@ -42,7 +43,7 @@ namespace detail {
4243
* @return New column with concatenated results.
4344
*/
4445
std::unique_ptr<column> concatenate(
45-
std::vector<column_view> const& columns,
46+
host_span<column_view const> columns,
4647
rmm::cuda_stream_view stream = rmm::cuda_stream_default,
4748
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
4849

cpp/include/cudf/strings/detail/concatenate.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2019-2020, NVIDIA CORPORATION.
2+
* Copyright (c) 2019-2021, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818
#include <cudf/column/column.hpp>
1919
#include <cudf/strings/strings_column_view.hpp>
2020
#include <cudf/table/table_view.hpp>
21+
#include <cudf/utilities/span.hpp>
2122

2223
#include <rmm/cuda_stream_view.hpp>
2324

@@ -41,7 +42,7 @@ namespace detail {
4142
* @return New column with concatenated results.
4243
*/
4344
std::unique_ptr<column> concatenate(
44-
std::vector<column_view> const& columns,
45+
host_span<column_view const> columns,
4546
rmm::cuda_stream_view stream = rmm::cuda_stream_default,
4647
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
4748

cpp/include/cudf/structs/detail/concatenate.hpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2020, NVIDIA CORPORATION.
2+
* Copyright (c) 2020-2021, NVIDIA CORPORATION.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,6 +18,7 @@
1818
#include <cudf/column/column.hpp>
1919
#include <cudf/structs/structs_column_view.hpp>
2020
#include <cudf/table/table_view.hpp>
21+
#include <cudf/utilities/span.hpp>
2122

2223
namespace cudf {
2324
namespace structs {
@@ -48,7 +49,7 @@ namespace detail {
4849
* @return New column with concatenated results.
4950
*/
5051
std::unique_ptr<column> concatenate(
51-
std::vector<column_view> const& columns,
52+
host_span<column_view const> columns,
5253
rmm::cuda_stream_view stream,
5354
rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource());
5455

cpp/include/cudf/utilities/span.hpp

+31-4
Original file line numberDiff line numberDiff line change
@@ -126,16 +126,31 @@ struct host_span : public cudf::detail::span_base<T, Extent, host_span<T, Extent
126126

127127
constexpr host_span() noexcept : base() {} // required to compile on centos
128128

129-
template <typename C, std::enable_if_t<is_host_span_supported_container<C>::value>* = nullptr>
129+
// Constructor from container
130+
template <
131+
typename C,
132+
// Only supported containers of types convertible to T
133+
std::enable_if_t<is_host_span_supported_container<C>::value &&
134+
std::is_convertible<std::remove_pointer_t<decltype(thrust::raw_pointer_cast(
135+
std::declval<C&>().data()))> (*)[],
136+
T (*)[]>::value>* = nullptr>
130137
constexpr host_span(C& in) : base(in.data(), in.size())
131138
{
132139
}
133140

134-
template <typename C, std::enable_if_t<is_host_span_supported_container<C>::value>* = nullptr>
141+
// Constructor from const container
142+
template <
143+
typename C,
144+
// Only supported containers of types convertible to T
145+
std::enable_if_t<is_host_span_supported_container<C>::value &&
146+
std::is_convertible<std::remove_pointer_t<decltype(thrust::raw_pointer_cast(
147+
std::declval<C&>().data()))> (*)[],
148+
T (*)[]>::value>* = nullptr>
135149
constexpr host_span(C const& in) : base(in.data(), in.size())
136150
{
137151
}
138152

153+
// Copy construction to support const conversion
139154
template <typename OtherT,
140155
std::size_t OtherExtent,
141156
typename std::enable_if<(Extent == OtherExtent || Extent == dynamic_extent) &&
@@ -175,12 +190,24 @@ struct device_span : public cudf::detail::span_base<T, Extent, device_span<T, Ex
175190

176191
constexpr device_span() noexcept : base() {} // required to compile on centos
177192

178-
template <typename C, std::enable_if_t<is_device_span_supported_container<C>::value>* = nullptr>
193+
template <
194+
typename C,
195+
// Only supported containers of types convertible to T
196+
std::enable_if_t<is_device_span_supported_container<C>::value &&
197+
std::is_convertible<std::remove_pointer_t<decltype(thrust::raw_pointer_cast(
198+
std::declval<C&>().data()))> (*)[],
199+
T (*)[]>::value>* = nullptr>
179200
constexpr device_span(C& in) : base(thrust::raw_pointer_cast(in.data()), in.size())
180201
{
181202
}
182203

183-
template <typename C, std::enable_if_t<is_device_span_supported_container<C>::value>* = nullptr>
204+
template <
205+
typename C,
206+
// Only supported containers of types convertible to T
207+
std::enable_if_t<is_device_span_supported_container<C>::value &&
208+
std::is_convertible<std::remove_pointer_t<decltype(thrust::raw_pointer_cast(
209+
std::declval<C&>().data()))> (*)[],
210+
T (*)[]>::value>* = nullptr>
184211
constexpr device_span(C const& in) : base(thrust::raw_pointer_cast(in.data()), in.size())
185212
{
186213
}

0 commit comments

Comments
 (0)