-
Notifications
You must be signed in to change notification settings - Fork 915
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
Refactor pinned memory vector and ORC+Parquet writers #13206
Changes from 9 commits
01d35ea
e2393ed
7aa1d75
ca18ce9
d7070e7
7358c78
a266de6
4d43687
f6c6422
d33ad7d
155f99f
4d110d1
21c3139
2b01e44
2230619
9170fef
9cc92dd
4282b94
156463c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,7 @@ | |
#include <cudf/detail/iterator.cuh> | ||
#include <cudf/detail/null_mask.hpp> | ||
#include <cudf/detail/utilities/cuda.cuh> | ||
#include <cudf/detail/utilities/pinned_host_vector.hpp> | ||
#include <cudf/detail/utilities/vector_factories.hpp> | ||
#include <cudf/strings/strings_column_view.hpp> | ||
#include <cudf/utilities/bit.hpp> | ||
|
@@ -79,11 +80,6 @@ struct row_group_index_info { | |
}; | ||
|
||
namespace { | ||
/** | ||
* @brief Helper for pinned host memory | ||
*/ | ||
template <typename T> | ||
using pinned_buffer = std::unique_ptr<T, decltype(&cudaFreeHost)>; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks good, with one minor concern. For places that already used There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I didn't see where is the initialization that you mentioned? The new
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please see benchmarks here: #13206 (comment) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought that host_vector has its own initialization outside of the allocator (same as |
||
|
||
/** | ||
* @brief Translates ORC compression to nvCOMP compression | ||
|
@@ -379,11 +375,11 @@ __global__ void copy_string_data(char* string_pool, | |
} // namespace | ||
|
||
void persisted_statistics::persist(int num_table_rows, | ||
bool single_write_mode, | ||
SingleWriteMode single_write_mode, | ||
ttnghia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
intermediate_statistics& intermediate_stats, | ||
rmm::cuda_stream_view stream) | ||
{ | ||
if (not single_write_mode) { | ||
if (single_write_mode == SingleWriteMode::YES) { | ||
ttnghia marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// persist the strings in the chunks into a string pool and update pointers | ||
auto const num_chunks = static_cast<int>(intermediate_stats.stripe_stat_chunks.size()); | ||
// min offset and max offset + 1 for total size | ||
|
@@ -670,7 +666,7 @@ orc_streams create_streams(host_span<orc_column_view> columns, | |
std::map<uint32_t, size_t> const& decimal_column_sizes, | ||
bool enable_dictionary, | ||
CompressionKind compression_kind, | ||
bool single_write_mode) | ||
SingleWriteMode single_write_mode) | ||
{ | ||
// 'column 0' row index stream | ||
std::vector<Stream> streams{{ROW_INDEX, 0}}; // TODO: Separate index and data streams? | ||
|
@@ -685,7 +681,7 @@ orc_streams create_streams(host_span<orc_column_view> columns, | |
|
||
for (auto& column : columns) { | ||
auto const is_nullable = [&]() -> bool { | ||
if (single_write_mode) { | ||
if (single_write_mode == SingleWriteMode::YES) { | ||
return column.nullable(); | ||
} else { | ||
// For chunked write, when not provided nullability, we assume the worst case scenario | ||
|
@@ -2196,28 +2192,17 @@ std::unique_ptr<table_input_metadata> make_table_meta(table_view const& input) | |
* @param stream CUDA stream used for device memory operations and kernel launches | ||
* @return A tuple of the intermediate results containing the processed data | ||
*/ | ||
std::tuple<orc_streams, | ||
hostdevice_vector<compression_result>, | ||
hostdevice_2dvector<gpu::StripeStream>, | ||
encoded_data, | ||
file_segmentation, | ||
hostdevice_2dvector<gpu::StripeDictionary>, | ||
std::vector<StripeInformation>, | ||
orc_table_view, | ||
rmm::device_buffer, | ||
intermediate_statistics, | ||
pinned_buffer<uint8_t>> | ||
convert_table_to_orc_data(table_view const& input, | ||
table_input_metadata const& table_meta, | ||
stripe_size_limits max_stripe_size, | ||
size_type row_index_stride, | ||
bool enable_dictionary, | ||
CompressionKind compression_kind, | ||
size_t compression_blocksize, | ||
statistics_freq stats_freq, | ||
bool single_write_mode, | ||
data_sink const& out_sink, | ||
rmm::cuda_stream_view stream) | ||
auto convert_table_to_orc_data(table_view const& input, | ||
table_input_metadata const& table_meta, | ||
stripe_size_limits max_stripe_size, | ||
size_type row_index_stride, | ||
bool enable_dictionary, | ||
CompressionKind compression_kind, | ||
size_t compression_blocksize, | ||
statistics_freq stats_freq, | ||
SingleWriteMode single_write_mode, | ||
data_sink const& out_sink, | ||
rmm::cuda_stream_view stream) | ||
{ | ||
auto const input_tview = table_device_view::create(input, stream); | ||
|
||
|
@@ -2288,17 +2273,17 @@ convert_table_to_orc_data(table_view const& input, | |
auto stripes = gather_stripes(num_index_streams, segmentation, &enc_data, &strm_descs, stream); | ||
|
||
if (num_rows == 0) { | ||
return {std::move(streams), | ||
hostdevice_vector<compression_result>{}, // comp_results | ||
std::move(strm_descs), | ||
std::move(enc_data), | ||
std::move(segmentation), | ||
std::move(stripe_dict), | ||
std::move(stripes), | ||
std::move(orc_table), | ||
rmm::device_buffer{}, // compressed_data | ||
intermediate_statistics{stream}, | ||
pinned_buffer<uint8_t>{nullptr, cudaFreeHost}}; | ||
return std::tuple{std::move(streams), | ||
hostdevice_vector<compression_result>{}, // comp_results | ||
std::move(strm_descs), | ||
std::move(enc_data), | ||
std::move(segmentation), | ||
std::move(stripe_dict), | ||
std::move(stripes), | ||
std::move(orc_table), | ||
rmm::device_buffer{}, // compressed_data | ||
intermediate_statistics{stream}, | ||
cudf::detail::pinned_host_vector<uint8_t>()}; | ||
} | ||
|
||
// Allocate intermediate output stream buffer | ||
|
@@ -2312,7 +2297,7 @@ convert_table_to_orc_data(table_view const& input, | |
auto const padded_block_header_size = | ||
util::round_up_unsafe<size_t>(block_header_size, compressed_block_align); | ||
|
||
auto stream_output = [&]() { | ||
auto bounce_buffer = [&]() { | ||
size_t max_stream_size = 0; | ||
bool all_device_write = true; | ||
|
||
|
@@ -2333,16 +2318,7 @@ convert_table_to_orc_data(table_view const& input, | |
max_stream_size = std::max(max_stream_size, stream_size); | ||
} | ||
|
||
if (all_device_write) { | ||
return pinned_buffer<uint8_t>{nullptr, cudaFreeHost}; | ||
} else { | ||
return pinned_buffer<uint8_t>{[](size_t size) { | ||
uint8_t* ptr = nullptr; | ||
CUDF_CUDA_TRY(cudaMallocHost(&ptr, size)); | ||
return ptr; | ||
}(max_stream_size), | ||
cudaFreeHost}; | ||
} | ||
return cudf::detail::pinned_host_vector<uint8_t>(all_device_write ? 0 : max_stream_size); | ||
}(); | ||
|
||
// Compress the data streams | ||
|
@@ -2374,17 +2350,17 @@ convert_table_to_orc_data(table_view const& input, | |
|
||
auto intermediate_stats = gather_statistic_blobs(stats_freq, orc_table, segmentation, stream); | ||
|
||
return {std::move(streams), | ||
std::move(comp_results), | ||
std::move(strm_descs), | ||
std::move(enc_data), | ||
std::move(segmentation), | ||
std::move(stripe_dict), | ||
std::move(stripes), | ||
std::move(orc_table), | ||
std::move(compressed_data), | ||
std::move(intermediate_stats), | ||
std::move(stream_output)}; | ||
return std::tuple{std::move(streams), | ||
std::move(comp_results), | ||
std::move(strm_descs), | ||
std::move(enc_data), | ||
std::move(segmentation), | ||
std::move(stripe_dict), | ||
std::move(stripes), | ||
std::move(orc_table), | ||
std::move(compressed_data), | ||
std::move(intermediate_stats), | ||
std::move(bounce_buffer)}; | ||
} | ||
|
||
} // namespace | ||
|
@@ -2399,7 +2375,7 @@ writer::impl::impl(std::unique_ptr<data_sink> sink, | |
_compression_kind(to_orc_compression(options.get_compression())), | ||
_compression_blocksize(compression_block_size(_compression_kind)), | ||
_stats_freq(options.get_statistics_freq()), | ||
_single_write_mode(mode == SingleWriteMode::YES), | ||
_single_write_mode(mode), | ||
_kv_meta(options.get_key_value_metadata()), | ||
_out_sink(std::move(sink)) | ||
{ | ||
|
@@ -2419,7 +2395,7 @@ writer::impl::impl(std::unique_ptr<data_sink> sink, | |
_compression_kind(to_orc_compression(options.get_compression())), | ||
_compression_blocksize(compression_block_size(_compression_kind)), | ||
_stats_freq(options.get_statistics_freq()), | ||
_single_write_mode(mode == SingleWriteMode::YES), | ||
_single_write_mode(mode), | ||
_kv_meta(options.get_key_value_metadata()), | ||
_out_sink(std::move(sink)) | ||
{ | ||
|
@@ -2458,7 +2434,7 @@ void writer::impl::write(table_view const& input) | |
orc_table, | ||
compressed_data, | ||
intermediate_stats, | ||
stream_output] = [&] { | ||
bounce_buffer] = [&] { | ||
try { | ||
return convert_table_to_orc_data(input, | ||
*_table_meta, | ||
|
@@ -2489,7 +2465,7 @@ void writer::impl::write(table_view const& input) | |
orc_table, | ||
compressed_data, | ||
intermediate_stats, | ||
stream_output.get()); | ||
bounce_buffer); | ||
|
||
// Update data into the footer. This needs to be called even when num_rows==0. | ||
add_table_to_footer_data(orc_table, stripes); | ||
|
@@ -2504,7 +2480,7 @@ void writer::impl::write_orc_data_to_sink(orc_streams& streams, | |
orc_table_view const& orc_table, | ||
rmm::device_buffer const& compressed_data, | ||
intermediate_statistics& intermediate_stats, | ||
uint8_t* stream_output) | ||
host_span<uint8_t> bounce_buffer) | ||
{ | ||
if (orc_table.num_rows() == 0) { return; } | ||
|
||
|
@@ -2544,7 +2520,7 @@ void writer::impl::write_orc_data_to_sink(orc_streams& streams, | |
strm_desc, | ||
enc_data.streams[strm_desc.column_id][segmentation.stripes[stripe_id].first], | ||
static_cast<uint8_t const*>(compressed_data.data()), | ||
stream_output, | ||
bounce_buffer.data(), | ||
&stripe, | ||
&streams, | ||
_compression_kind, | ||
|
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.
IIUC, pinned memory is always on the host side thus not sure this renaming is really needed.
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.
IMO the name
*_host_vector
is better expressing its purpose, similar to havingthurst::host_vector
instead of justthrust::vector
.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 read the name as host_vector in pinned memory, so the name looks good.