Skip to content
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 std::array usage in row group index writing in ORC #6807

Merged
merged 7 commits into from
Dec 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@
- PR #6835 Move template param to member var to improve compile of hash/groupby.cu
- PR #6837 Avoid gather when copying strings view from start of strings column
- PR #6859 Move align_ptr_for_type() from cuda.cuh to alignment.hpp
- PR #6807 Refactor `std::array` usage in row group index writing in ORC

## Bug Fixes

Expand Down
45 changes: 27 additions & 18 deletions cpp/src/io/orc/writer_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ namespace orc {
using namespace cudf::io::orc;
using namespace cudf::io;

struct row_group_index_info {
int32_t pos = -1; // Position
int32_t blk_pos = -1; // Block Position
int32_t comp_pos = -1; // Compressed Position
int32_t comp_size = -1; // Compressed size
};

namespace {
/**
* @brief Helper for pinned host memory
Expand Down Expand Up @@ -858,36 +865,37 @@ void writer::impl::write_index_stream(int32_t stripe_id,
std::vector<Stream> &streams,
ProtobufWriter *pbw)
{
// 0: position, 1: block position, 2: compressed position, 3: compressed size
std::array<int32_t, 4> present;
std::array<int32_t, 4> data;
std::array<int32_t, 4> data2;
row_group_index_info present;
row_group_index_info data;
row_group_index_info data2;
auto kind = TypeKind::STRUCT;

auto find_record = [=, &strm_desc](gpu::EncChunk const &chunk, gpu::StreamIndexType type) {
std::array<int32_t, 4> record{-1, -1, -1, -1};
row_group_index_info record;
if (chunk.strm_id[type] > 0) {
record[0] = 0;
record.pos = 0;
if (compression_kind_ != NONE) {
const auto *ss =
&strm_desc[stripe_id * num_data_streams + chunk.strm_id[type] - (num_columns + 1)];
record[1] = ss->first_block;
record[2] = 0;
record[3] = ss->stream_size;
record.blk_pos = ss->first_block;
record.comp_pos = 0;
record.comp_size = ss->stream_size;
}
}
return record;
};
auto scan_record = [=, &comp_out](gpu::EncChunk const &chunk,
gpu::StreamIndexType type,
std::array<int32_t, 4> &record) {
if (record[0] >= 0) {
record[0] += chunk.strm_len[type];
while ((record[1] >= 0) && (static_cast<size_t>(record[0]) >= compression_blocksize_) &&
(record[2] + 3 + comp_out[record[1]].bytes_written < static_cast<size_t>(record[3]))) {
record[0] -= compression_blocksize_;
record[2] += 3 + comp_out[record[1]].bytes_written;
record[1] += 1;
row_group_index_info &record) {
if (record.pos >= 0) {
record.pos += chunk.strm_len[type];
while ((record.pos >= 0) && (record.blk_pos >= 0) &&
(static_cast<size_t>(record.pos) >= compression_blocksize_) &&
(record.comp_pos + 3 + comp_out[record.blk_pos].bytes_written <
static_cast<size_t>(record.comp_size))) {
record.pos -= compression_blocksize_;
record.comp_pos += 3 + comp_out[record.blk_pos].bytes_written;
record.blk_pos += 1;
}
}
};
Expand All @@ -910,7 +918,8 @@ void writer::impl::write_index_stream(int32_t stripe_id,

// Add row index entries
for (size_t g = group; g < group + groups_in_stripe; g++) {
pbw->put_row_index_entry(present[2], present[0], data[2], data[0], data2[2], data2[0], kind);
pbw->put_row_index_entry(
present.comp_pos, present.pos, data.comp_pos, data.pos, data2.comp_pos, data2.pos, kind);

if (stream_id != 0) {
const auto &ck = chunks[g * num_columns + stream_id - 1];
Expand Down