Skip to content

Commit 2b73f2e

Browse files
davidwendtshrshi
authored andcommitted
Move table_device_view function definitions from .cuh to .cu (rapidsai#22354)
Moves member functions from .cuh to .cu and refactors the `create()` implementations to better use the renamed `create_column_device_views` utility. Follow on to changes in rapidsai#22321 Authors: - David Wendt (https://github.com/davidwendt) Approvers: - Bradley Dice (https://github.com/bdice) - Vyas Ramasubramani (https://github.com/vyasr) URL: rapidsai#22354
1 parent 52b9245 commit 2b73f2e

6 files changed

Lines changed: 64 additions & 52 deletions

File tree

cpp/include/cudf/table/table_device_view.cuh

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -131,15 +131,13 @@ class table_device_view_base {
131131

132132
protected:
133133
/**
134-
* @brief Construct a new table device view base object from host table_view
134+
* @brief Constructor for subclasses to create a table device view from a host table view
135135
*
136136
* @param source_view The host table_view to create table device view from
137-
* @param stream The CUDA stream to use for device memory allocation
137+
* @param columns Pointer to the array of column device views in device memory corresponding to
138+
* the columns of `source_view`
138139
*/
139-
table_device_view_base(HostTableView source_view, rmm::cuda_stream_view stream);
140-
141-
/// Pointer to device memory holding the descendant storage
142-
rmm::device_buffer* _descendant_storage{};
140+
table_device_view_base(HostTableView source_view, ColumnDeviceView* columns);
143141
};
144142
} // namespace detail
145143

@@ -162,19 +160,11 @@ class table_device_view : public detail::table_device_view_base<column_device_vi
162160
* @return A `unique_ptr` to a `table_device_view` that makes the data from `source_view`
163161
* available in device memory
164162
*/
165-
static auto create(table_view source_view,
166-
rmm::cuda_stream_view stream = cudf::get_default_stream())
167-
{
168-
auto deleter = [](table_device_view* t) { t->destroy(); };
169-
return std::unique_ptr<table_device_view, decltype(deleter)>{
170-
new table_device_view(source_view, stream), deleter};
171-
}
163+
static std::unique_ptr<table_device_view, std::function<void(table_device_view*)>> create(
164+
table_view source_view, rmm::cuda_stream_view stream = cudf::get_default_stream());
172165

173166
private:
174-
table_device_view(table_view source_view, rmm::cuda_stream_view stream)
175-
: detail::table_device_view_base<column_device_view, table_view>(source_view, stream)
176-
{
177-
}
167+
table_device_view(table_view source_view, column_device_view* columns);
178168
};
179169

180170
/**
@@ -199,20 +189,11 @@ class mutable_table_device_view
199189
* @return A `unique_ptr` to a `mutable_table_device_view` that makes the data from `source_view`
200190
* available in device memory
201191
*/
202-
static auto create(mutable_table_view source_view,
203-
rmm::cuda_stream_view stream = cudf::get_default_stream())
204-
{
205-
auto deleter = [](mutable_table_device_view* t) { t->destroy(); };
206-
return std::unique_ptr<mutable_table_device_view, decltype(deleter)>{
207-
new mutable_table_device_view(source_view, stream), deleter};
208-
}
192+
static std::unique_ptr<mutable_table_device_view, std::function<void(mutable_table_device_view*)>>
193+
create(mutable_table_view source_view, rmm::cuda_stream_view stream = cudf::get_default_stream());
209194

210195
private:
211-
mutable_table_device_view(mutable_table_view source_view, rmm::cuda_stream_view stream)
212-
: detail::table_device_view_base<mutable_column_device_view, mutable_table_view>(source_view,
213-
stream)
214-
{
215-
}
196+
mutable_table_device_view(mutable_table_view source_view, mutable_column_device_view* columns);
216197
};
217198

218199
/**
@@ -225,7 +206,7 @@ class mutable_table_device_view
225206
* @return tuple of device_buffer and @p ColumnDeviceView device pointer
226207
*/
227208
template <typename ColumnDeviceView, typename HostTableView>
228-
std::pair<std::unique_ptr<rmm::device_buffer>, ColumnDeviceView*>
229-
contiguous_copy_column_device_views(HostTableView source_view, rmm::cuda_stream_view stream);
209+
std::pair<std::unique_ptr<rmm::device_buffer>, ColumnDeviceView*> create_column_device_views(
210+
HostTableView source_view, rmm::cuda_stream_view stream);
230211

231212
} // namespace CUDF_EXPORT cudf

cpp/src/lists/dremel.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ dremel_data get_encoding(column_view h_col,
210210
}
211211

212212
[[maybe_unused]] auto [device_view_owners, d_nesting_levels] =
213-
contiguous_copy_column_device_views<column_device_view, host_span<column_view const>>(
214-
host_span<column_view const>{nesting_levels}, stream);
213+
create_column_device_views<column_device_view>(host_span<column_view const>{nesting_levels},
214+
stream);
215215

216216
auto max_def_level = def_at_level.back();
217217
thrust::exclusive_scan(

cpp/src/strings/copying/concatenate.cu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ auto create_strings_device_views(host_span<column_view const> views, rmm::cuda_s
6767
CUDF_FUNC_RANGE();
6868
// Assemble contiguous array of device views
6969
auto [device_view_owners, device_views_ptr] =
70-
contiguous_copy_column_device_views<column_device_view>(views, stream);
70+
create_column_device_views<column_device_view>(views, stream);
7171

7272
// Compute the partition offsets and size of offset column
7373
// Note: Using 64-bit size_t so we can detect overflow of 32-bit size_type

cpp/src/structs/scan/scan_inclusive.cu

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,10 @@ std::unique_ptr<column> scan_inclusive(column_view const& input,
4444

4545
// Gather the children columns of the input column. Must use `get_sliced_child` to properly
4646
// handle input in case it is a sliced view.
47+
auto const structs_view = structs_column_view{input};
4748
auto const input_children = [&] {
4849
auto const it = cudf::detail::make_counting_transform_iterator(
49-
0, [structs_view = structs_column_view{input}, &stream](auto const child_idx) {
50+
0, [&structs_view, &stream](auto const child_idx) {
5051
return structs_view.get_sliced_child(child_idx, stream);
5152
});
5253
return std::vector<column_view>(it, it + input.num_children());

cpp/src/table/table_device_view.cu

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,24 +22,14 @@ namespace detail {
2222
template <typename ColumnDeviceView, typename HostTableView>
2323
void table_device_view_base<ColumnDeviceView, HostTableView>::destroy()
2424
{
25-
delete _descendant_storage;
2625
delete this;
2726
}
2827

2928
template <typename ColumnDeviceView, typename HostTableView>
3029
table_device_view_base<ColumnDeviceView, HostTableView>::table_device_view_base(
31-
HostTableView source_view, rmm::cuda_stream_view stream)
32-
: _num_rows{source_view.num_rows()}, _num_columns{source_view.num_columns()}
30+
HostTableView source_view, ColumnDeviceView* columns)
31+
: _columns{columns}, _num_rows{source_view.num_rows()}, _num_columns{source_view.num_columns()}
3332
{
34-
// The table's columns must be converted to ColumnDeviceView
35-
// objects and copied into device memory for the table_device_view's
36-
// _columns member.
37-
if (source_view.num_columns() > 0) {
38-
std::unique_ptr<rmm::device_buffer> descendant_storage_owner;
39-
std::tie(descendant_storage_owner, _columns) =
40-
contiguous_copy_column_device_views<ColumnDeviceView, HostTableView>(source_view, stream);
41-
_descendant_storage = descendant_storage_owner.release();
42-
}
4333
}
4434

4535
// Explicit instantiation for a device table of immutable views
@@ -51,8 +41,8 @@ template class table_device_view_base<mutable_column_device_view, mutable_table_
5141
} // namespace detail
5242

5343
template <typename ColumnDeviceView, typename HostTableView>
54-
std::pair<std::unique_ptr<rmm::device_buffer>, ColumnDeviceView*>
55-
contiguous_copy_column_device_views(HostTableView source_view, rmm::cuda_stream_view stream)
44+
std::pair<std::unique_ptr<rmm::device_buffer>, ColumnDeviceView*> create_column_device_views(
45+
HostTableView source_view, rmm::cuda_stream_view stream)
5646
{
5747
// First calculate the size of memory needed to hold the
5848
// table's ColumnDeviceViews. This is done by calling extent()
@@ -89,7 +79,47 @@ contiguous_copy_column_device_views(HostTableView source_view, rmm::cuda_stream_
8979
}
9080

9181
template std::pair<std::unique_ptr<rmm::device_buffer>, column_device_view*>
92-
contiguous_copy_column_device_views<column_device_view, host_span<column_view const>>(
82+
create_column_device_views<column_device_view, host_span<column_view const>>(
9383
host_span<column_view const> source_view, rmm::cuda_stream_view stream);
9484

85+
table_device_view::table_device_view(table_view source_view, column_device_view* columns)
86+
: detail::table_device_view_base<column_device_view, table_view>(source_view, columns)
87+
{
88+
}
89+
90+
std::unique_ptr<table_device_view, std::function<void(table_device_view*)>>
91+
table_device_view::create(table_view source_view, rmm::cuda_stream_view stream)
92+
{
93+
auto [descendant_storage, columns] =
94+
create_column_device_views<column_device_view, table_view>(source_view, stream);
95+
auto deleter = [ds = descendant_storage.release()](table_device_view* tv) {
96+
tv->destroy();
97+
delete ds;
98+
};
99+
std::unique_ptr<table_device_view, decltype(deleter)> result{
100+
new table_device_view(source_view, columns), deleter};
101+
return result;
102+
}
103+
104+
mutable_table_device_view::mutable_table_device_view(mutable_table_view source_view,
105+
mutable_column_device_view* columns)
106+
: detail::table_device_view_base<mutable_column_device_view, mutable_table_view>(source_view,
107+
columns)
108+
{
109+
}
110+
111+
std::unique_ptr<mutable_table_device_view, std::function<void(mutable_table_device_view*)>>
112+
mutable_table_device_view::create(mutable_table_view source_view, rmm::cuda_stream_view stream)
113+
{
114+
auto [descendant_storage, columns] =
115+
create_column_device_views<mutable_column_device_view, mutable_table_view>(source_view, stream);
116+
auto deleter = [ds = descendant_storage.release()](mutable_table_device_view* tv) {
117+
tv->destroy();
118+
delete ds;
119+
};
120+
std::unique_ptr<mutable_table_device_view, decltype(deleter)> result{
121+
new mutable_table_device_view(source_view, columns), deleter};
122+
return result;
123+
}
124+
95125
} // namespace cudf

cpp/src/transform/row_bit_count.cu

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -520,8 +520,8 @@ std::unique_ptr<column> segmented_row_bit_count(table_view const& t,
520520
}
521521

522522
// create a contiguous block of column_device_views
523-
auto d_cols = contiguous_copy_column_device_views<column_device_view>(
524-
host_span<column_view const>{cols}, stream);
523+
auto d_cols =
524+
create_column_device_views<column_device_view>(host_span<column_view const>{cols}, stream);
525525

526526
// move stack info to the gpu
527527
rmm::device_uvector<column_info> d_info =

0 commit comments

Comments
 (0)