Skip to content

Commit

Permalink
Remove metadata type in favor of just std::vector<uint8_t>
Browse files Browse the repository at this point in the history
  • Loading branch information
abellina committed Apr 24, 2023
1 parent 71d4645 commit d8dd746
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 32 deletions.
21 changes: 8 additions & 13 deletions cpp/include/cudf/contiguous_split.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,9 @@ namespace cudf {
* table metadata and one on device which contains the table data.
*/
struct packed_columns {
/**
* @brief Host-side metadata buffer used for reconstructing columns via unpack.
*
* @ingroup copy_split
*/
using metadata = std::vector<uint8_t>;

packed_columns()
: metadata_(std::make_unique<metadata>()), gpu_data(std::make_unique<rmm::device_buffer>())
: metadata_(std::make_unique<std::vector<uint8_t>>()),
gpu_data(std::make_unique<rmm::device_buffer>())
{
}

Expand All @@ -58,12 +52,13 @@ struct packed_columns {
* @param md Host-side metadata buffer
* @param gd Device-side data buffer
*/
packed_columns(std::unique_ptr<metadata>&& md, std::unique_ptr<rmm::device_buffer>&& gd)
packed_columns(std::unique_ptr<std::vector<uint8_t>>&& md,
std::unique_ptr<rmm::device_buffer>&& gd)
: metadata_(std::move(md)), gpu_data(std::move(gd))
{
}

std::unique_ptr<metadata> metadata_; ///< Host-side metadata buffer
std::unique_ptr<std::vector<uint8_t>> metadata_; ///< Host-side metadata buffer
std::unique_ptr<rmm::device_buffer> gpu_data; ///< Device-side data buffer
};

Expand Down Expand Up @@ -160,9 +155,9 @@ packed_columns pack(cudf::table_view const& input,
* @param buffer_size The size of `contiguous_buffer`
* @return Vector of bytes representing the metadata used to `unpack` a packed_columns struct
*/
packed_columns::metadata pack_metadata(table_view const& table,
uint8_t const* contiguous_buffer,
size_t buffer_size);
std::vector<uint8_t> pack_metadata(table_view const& table,
uint8_t const* contiguous_buffer,
size_t buffer_size);

/**
* @brief Deserialize the result of `cudf::pack`.
Expand Down
4 changes: 2 additions & 2 deletions cpp/src/copying/contiguous_split.cu
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ std::vector<packed_table> contiguous_split(cudf::table_view const& input,
[&empty_inputs](int partition_index) {
return packed_table{
empty_inputs,
packed_columns{std::make_unique<packed_columns::metadata>(pack_metadata(
packed_columns{std::make_unique<std::vector<uint8_t>>(pack_metadata(
empty_inputs, static_cast<uint8_t const*>(nullptr), 0)),
std::make_unique<rmm::device_buffer>()}};
});
Expand Down Expand Up @@ -1251,7 +1251,7 @@ std::vector<packed_table> contiguous_split(cudf::table_view const& input,
result.push_back(packed_table{
t,
packed_columns{
std::make_unique<packed_columns::metadata>(cudf::pack_metadata(
std::make_unique<std::vector<uint8_t>>(cudf::pack_metadata(
t, reinterpret_cast<uint8_t const*>(out_buffers[idx].data()), out_buffers[idx].size())),
std::make_unique<rmm::device_buffer>(std::move(out_buffers[idx]))}});

Expand Down
14 changes: 7 additions & 7 deletions cpp/src/copying/pack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ packed_columns pack(cudf::table_view const& input,
}

template <typename ColumnIter>
packed_columns::metadata pack_metadata(ColumnIter begin,
ColumnIter end,
uint8_t const* contiguous_buffer,
size_t buffer_size)
std::vector<uint8_t> pack_metadata(ColumnIter begin,
ColumnIter end,
uint8_t const* contiguous_buffer,
size_t buffer_size)
{
std::vector<serialized_column> metadata;

Expand All @@ -174,7 +174,7 @@ packed_columns::metadata pack_metadata(ColumnIter begin,
metadata_begin + (metadata.size() * sizeof(serialized_column)),
std::back_inserter(metadata_bytes));

return packed_columns::metadata{std::move(metadata_bytes)};
return metadata_bytes;
}

/**
Expand Down Expand Up @@ -222,13 +222,13 @@ packed_columns pack(cudf::table_view const& input, rmm::mr::device_memory_resour
/**
* @copydoc cudf::pack_metadata
*/
packed_columns::metadata pack_metadata(table_view const& table,
std::vector<uint8_t> pack_metadata(table_view const& table,
uint8_t const* contiguous_buffer,
size_t buffer_size)
{
CUDF_FUNC_RANGE();
return table.is_empty()
? packed_columns::metadata{}
? std::vector<uint8_t>()
: detail::pack_metadata(table.begin(), table.end(), contiguous_buffer, buffer_size);
}

Expand Down
6 changes: 3 additions & 3 deletions java/src/main/native/src/ContiguousTableJni.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ContiguousTable_createPackedMetadata
auto data_addr = reinterpret_cast<uint8_t const *>(j_buffer_addr);
auto data_size = static_cast<size_t>(j_buffer_length);
auto metadata_ptr =
new cudf::packed_columns::metadata(cudf::pack_metadata(*table, data_addr, data_size));
new std::vector<uint8_t>(cudf::pack_metadata(*table, data_addr, data_size));
return reinterpret_cast<jlong>(metadata_ptr);
}
CATCH_STD(env, 0);
Expand All @@ -154,7 +154,7 @@ JNIEXPORT jobject JNICALL Java_ai_rapids_cudf_ContiguousTable_createMetadataDire
JNIEnv *env, jclass, jlong j_metadata_ptr) {
JNI_NULL_CHECK(env, j_metadata_ptr, "metadata is null", nullptr);
try {
auto metadata = reinterpret_cast<cudf::packed_columns::metadata *>(j_metadata_ptr);
auto metadata = reinterpret_cast<std::vector<uint8_t>*>(j_metadata_ptr);
return env->NewDirectByteBuffer(const_cast<uint8_t *>(metadata->data()), metadata->size());
}
CATCH_STD(env, nullptr);
Expand All @@ -164,7 +164,7 @@ JNIEXPORT void JNICALL Java_ai_rapids_cudf_ContiguousTable_closeMetadata(JNIEnv
jlong j_metadata_ptr) {
JNI_NULL_CHECK(env, j_metadata_ptr, "metadata is null", );
try {
auto metadata = reinterpret_cast<cudf::packed_columns::metadata *>(j_metadata_ptr);
auto metadata = reinterpret_cast<std::vector<uint8_t>*>(j_metadata_ptr);
delete metadata;
}
CATCH_STD(env, );
Expand Down
2 changes: 1 addition & 1 deletion python/cudf/cudf/_lib/copying.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -772,7 +772,7 @@ cdef class _CPackedColumns:

cdef cpp_contiguous_split.packed_columns data
data.metadata_ = move(
make_unique[cpp_contiguous_split.metadata](
make_unique[vector[uint8_t]](
move(<vector[uint8_t]>header.get("metadata", []))
)
)
Expand Down
7 changes: 1 addition & 6 deletions python/cudf/cudf/_lib/cpp/contiguous_split.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,9 @@ from rmm._lib.device_buffer cimport device_buffer
from cudf._lib.cpp.table.table_view cimport table_view
from cudf._lib.cpp.types cimport size_type


cdef extern from "cudf/contiguous_split.hpp" namespace \
"cudf::packed_columns" nogil:
ctypedef vector[uint8_t] metadata

cdef extern from "cudf/contiguous_split.hpp" namespace "cudf" nogil:
cdef cppclass packed_columns:
unique_ptr[metadata] metadata_
unique_ptr[vector[uint8_t]] metadata_
unique_ptr[device_buffer] gpu_data

cdef struct contiguous_split_result:
Expand Down

0 comments on commit d8dd746

Please sign in to comment.