diff --git a/conda/recipes/libcudf/meta.yaml b/conda/recipes/libcudf/meta.yaml index 94b244b94d5..c796bbf6240 100644 --- a/conda/recipes/libcudf/meta.yaml +++ b/conda/recipes/libcudf/meta.yaml @@ -91,6 +91,7 @@ outputs: - test -f $PREFIX/include/cudf/column/column_factories.hpp - test -f $PREFIX/include/cudf/column/column_view.hpp - test -f $PREFIX/include/cudf/concatenate.hpp + - test -f $PREFIX/include/cudf/contiguous_split.hpp - test -f $PREFIX/include/cudf/copying.hpp - test -f $PREFIX/include/cudf/datetime.hpp - test -f $PREFIX/include/cudf/timezone.hpp @@ -99,6 +100,7 @@ outputs: - test -f $PREFIX/include/cudf/detail/binaryop.hpp - test -f $PREFIX/include/cudf/detail/calendrical_month_sequence.cuh - test -f $PREFIX/include/cudf/detail/concatenate.hpp + - test -f $PREFIX/include/cudf/detail/contiguous_split.hpp - test -f $PREFIX/include/cudf/detail/copy.hpp - test -f $PREFIX/include/cudf/detail/datetime.hpp - test -f $PREFIX/include/cudf/detail/fill.hpp diff --git a/cpp/benchmarks/copying/contiguous_split.cu b/cpp/benchmarks/copying/contiguous_split.cu index 62a9ce99c50..aff90039cb9 100644 --- a/cpp/benchmarks/copying/contiguous_split.cu +++ b/cpp/benchmarks/copying/contiguous_split.cu @@ -21,7 +21,7 @@ #include #include -#include +#include #include diff --git a/cpp/include/cudf/contiguous_split.hpp b/cpp/include/cudf/contiguous_split.hpp new file mode 100644 index 00000000000..62d668a98cb --- /dev/null +++ b/cpp/include/cudf/contiguous_split.hpp @@ -0,0 +1,198 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include + +#include +#include + +namespace cudf { + +/** + * @addtogroup column_copy + * @{ + * @file + * @brief Table APIs for contiguous_split, pack, unpack, and metadadata + */ + +/** + * @brief Column data in a serialized format + * + * @ingroup copy_split + * + * Contains data from an array of columns in two contiguous buffers: one on host, which contains + * table metadata and one on device which contains the table data. + */ +struct packed_columns { + packed_columns() + : metadata(std::make_unique>()), + gpu_data(std::make_unique()) + { + } + + /** + * @brief Construct a new packed columns object + * + * @param md Host-side metadata buffer + * @param gd Device-side data buffer + */ + packed_columns(std::unique_ptr>&& md, + std::unique_ptr&& gd) + : metadata(std::move(md)), gpu_data(std::move(gd)) + { + } + + std::unique_ptr> metadata; ///< Host-side metadata buffer + std::unique_ptr gpu_data; ///< Device-side data buffer +}; + +/** + * @brief The result(s) of a cudf::contiguous_split + * + * @ingroup copy_split + * + * Each table_view resulting from a split operation performed by contiguous_split, + * will be returned wrapped in a `packed_table`. The table_view and internal + * column_views in this struct are not owned by a top level cudf::table or cudf::column. + * The backing memory and metadata is instead owned by the `data` field and is in one + * contiguous block. + * + * The user is responsible for assuring that the `table` or any derived table_views do + * not outlive the memory owned by `data`. + */ +struct packed_table { + cudf::table_view table; ///< Result table_view of a cudf::contiguous_split + packed_columns data; ///< Column data owned +}; + +/** + * @brief Performs a deep-copy split of a `table_view` into a vector of `packed_table` where each + * `packed_table` is using a single contiguous block of memory for all of the split's column data. + * + * @ingroup copy_split + * + * The memory for the output views is allocated in a single contiguous `rmm::device_buffer` returned + * in the `packed_table`. There is no top-level owning table. + * + * The returned views of `input` are constructed from a vector of indices, that indicate + * where each split should occur. The `i`th returned `table_view` is sliced as + * `[0, splits[i])` if `i`=0, else `[splits[i], input.size())` if `i` is the last view and + * `[splits[i-1], splits[i]]` otherwise. + * + * For all `i` it is expected `splits[i] <= splits[i+1] <= input.size()`. + * For a `splits` size N, there will always be N+1 splits in the output. + * + * @note It is the caller's responsibility to ensure that the returned views + * do not outlive the viewed device memory contained in the `all_data` field of the + * returned packed_table. + * + * @code{.pseudo} + * Example: + * input: [{10, 12, 14, 16, 18, 20, 22, 24, 26, 28}, + * {50, 52, 54, 56, 58, 60, 62, 64, 66, 68}] + * splits: {2, 5, 9} + * output: [{{10, 12}, {14, 16, 18}, {20, 22, 24, 26}, {28}}, + * {{50, 52}, {54, 56, 58}, {60, 62, 64, 66}, {68}}] + * @endcode + * + * + * @throws cudf::logic_error if `splits` has end index > size of `input`. + * @throws cudf::logic_error When the value in `splits` is not in the range [0, input.size()). + * @throws cudf::logic_error When the values in the `splits` are 'strictly decreasing'. + * + * @param input View of a table to split + * @param splits A vector of indices where the view will be split + * @param mr An optional memory resource to use for all returned device allocations + * @return The set of requested views of `input` indicated by the `splits` and the viewed memory + * buffer + */ +std::vector contiguous_split( + cudf::table_view const& input, + std::vector const& splits, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @brief Deep-copy a `table_view` into a serialized contiguous memory format. + * + * The metadata from the `table_view` is copied into a host vector of bytes and the data from the + * `table_view` is copied into a `device_buffer`. Pass the output of this function into + * `cudf::unpack` to deserialize. + * + * @param input View of the table to pack + * @param mr An optional memory resource to use for all returned device allocations + * @return packed_columns A struct containing the serialized metadata and data in contiguous host + * and device memory respectively + */ +packed_columns pack(cudf::table_view const& input, + rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); + +/** + * @brief Produce the metadata used for packing a table stored in a contiguous buffer. + * + * The metadata from the `table_view` is copied into a host vector of bytes which can be used to + * construct a `packed_columns` or `packed_table` structure. The caller is responsible for + * guaranteeing that that all of the columns in the table point into `contiguous_buffer`. + * + * @param table View of the table to pack + * @param contiguous_buffer A contiguous buffer of device memory which contains the data referenced + * by the columns in `table` + * @param buffer_size The size of `contiguous_buffer` + * @return Vector of bytes representing the metadata used to `unpack` a packed_columns struct + */ +std::vector pack_metadata(table_view const& table, + uint8_t const* contiguous_buffer, + size_t buffer_size); + +/** + * @brief Deserialize the result of `cudf::pack`. + * + * Converts the result of a serialized table into a `table_view` that points to the data stored in + * the contiguous device buffer contained in `input`. + * + * It is the caller's responsibility to ensure that the `table_view` in the output does not outlive + * the data in the input. + * + * No new device memory is allocated in this function. + * + * @param input The packed columns to unpack + * @return The unpacked `table_view` + */ +table_view unpack(packed_columns const& input); + +/** + * @brief Deserialize the result of `cudf::pack`. + * + * Converts the result of a serialized table into a `table_view` that points to the data stored in + * the contiguous device buffer contained in `gpu_data` using the metadata contained in the host + * buffer `metadata`. + * + * It is the caller's responsibility to ensure that the `table_view` in the output does not outlive + * the data in the input. + * + * No new device memory is allocated in this function. + * + * @param metadata The host-side metadata buffer resulting from the initial pack() call + * @param gpu_data The device-side contiguous buffer storing the data that will be referenced by + * the resulting `table_view` + * @return The unpacked `table_view` + */ +table_view unpack(uint8_t const* metadata, uint8_t const* gpu_data); + +/** @} */ +} // namespace cudf diff --git a/cpp/include/cudf/copying.hpp b/cpp/include/cudf/copying.hpp index d5a3c930853..921ef5f65f1 100644 --- a/cpp/include/cudf/copying.hpp +++ b/cpp/include/cudf/copying.hpp @@ -541,200 +541,6 @@ std::vector split(table_view const& input, host_span split(table_view const& input, std::initializer_list splits); -/** - * @brief Column data in a serialized format - * - * @ingroup copy_split - * - * Contains data from an array of columns in two contiguous buffers: one on host, which contains - * 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 - */ - struct metadata { - metadata() = default; - - /** - * @brief Construct a new metadata object - * - * @param v Host-side buffer containing metadata - */ - metadata(std::vector&& v) : data_(std::move(v)) {} - - /** - * @brief Returns pointer to the host-side metadata buffer data - * - * @return Pointer to the host-side metadata buffer - */ - [[nodiscard]] uint8_t const* data() const { return data_.data(); } - - /** - * @brief Returns size of the metadata buffer - * - * @return Size of the metadata buffer - */ - [[nodiscard]] size_t size() const { return data_.size(); } - - private: - std::vector data_; - }; - - packed_columns() - : metadata_(std::make_unique()), gpu_data(std::make_unique()) - { - } - - /** - * @brief Construct a new packed columns object - * - * @param md Host-side metadata buffer - * @param gd Device-side data buffer - */ - packed_columns(std::unique_ptr&& md, std::unique_ptr&& gd) - : metadata_(std::move(md)), gpu_data(std::move(gd)) - { - } - - std::unique_ptr metadata_; ///< Host-side metadata buffer - std::unique_ptr gpu_data; ///< Device-side data buffer -}; - -/** - * @brief The result(s) of a cudf::contiguous_split - * - * @ingroup copy_split - * - * Each table_view resulting from a split operation performed by contiguous_split, - * will be returned wrapped in a `packed_table`. The table_view and internal - * column_views in this struct are not owned by a top level cudf::table or cudf::column. - * The backing memory and metadata is instead owned by the `data` field and is in one - * contiguous block. - * - * The user is responsible for assuring that the `table` or any derived table_views do - * not outlive the memory owned by `data` - */ -struct packed_table { - cudf::table_view table; ///< Result table_view of a cudf::contiguous_split - packed_columns data; ///< Column data owned -}; - -/** - * @brief Performs a deep-copy split of a `table_view` into a set of `table_view`s into a single - * contiguous block of memory. - * - * @ingroup copy_split - * - * The memory for the output views is allocated in a single contiguous `rmm::device_buffer` returned - * in the `packed_table`. There is no top-level owning table. - * - * The returned views of `input` are constructed from a vector of indices, that indicate - * where each split should occur. The `i`th returned `table_view` is sliced as - * `[0, splits[i])` if `i`=0, else `[splits[i], input.size())` if `i` is the last view and - * `[splits[i-1], splits[i]]` otherwise. - * - * For all `i` it is expected `splits[i] <= splits[i+1] <= input.size()` - * For a `splits` size N, there will always be N+1 splits in the output - * - * @note It is the caller's responsibility to ensure that the returned views - * do not outlive the viewed device memory contained in the `all_data` field of the - * returned packed_table. - * - * @code{.pseudo} - * Example: - * input: [{10, 12, 14, 16, 18, 20, 22, 24, 26, 28}, - * {50, 52, 54, 56, 58, 60, 62, 64, 66, 68}] - * splits: {2, 5, 9} - * output: [{{10, 12}, {14, 16, 18}, {20, 22, 24, 26}, {28}}, - * {{50, 52}, {54, 56, 58}, {60, 62, 64, 66}, {68}}] - * @endcode - * - * - * @throws cudf::logic_error if `splits` has end index > size of `input`. - * @throws cudf::logic_error When the value in `splits` is not in the range [0, input.size()). - * @throws cudf::logic_error When the values in the `splits` are 'strictly decreasing'. - * - * @param input View of a table to split - * @param splits A vector of indices where the view will be split - * @param[in] mr Device memory resource used to allocate the returned result's device memory - * @return The set of requested views of `input` indicated by the `splits` and the viewed memory - * buffer. - */ -std::vector contiguous_split( - cudf::table_view const& input, - std::vector const& splits, - rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); - -/** - * @brief Deep-copy a `table_view` into a serialized contiguous memory format - * - * The metadata from the `table_view` is copied into a host vector of bytes and the data from the - * `table_view` is copied into a `device_buffer`. Pass the output of this function into - * `cudf::unpack` to deserialize. - * - * @param input View of the table to pack - * @param[in] mr Optional, The resource to use for all returned device allocations - * @return packed_columns A struct containing the serialized metadata and data in contiguous host - * and device memory respectively - */ -packed_columns pack(cudf::table_view const& input, - rmm::mr::device_memory_resource* mr = rmm::mr::get_current_device_resource()); - -/** - * @brief Produce the metadata used for packing a table stored in a contiguous buffer. - * - * The metadata from the `table_view` is copied into a host vector of bytes which can be used to - * construct a `packed_columns` or `packed_table` structure. The caller is responsible for - * guaranteeing that that all of the columns in the table point into `contiguous_buffer`. - * - * @param table View of the table to pack - * @param contiguous_buffer A contiguous buffer of device memory which contains the data referenced - * by the columns in `table` - * @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); - -/** - * @brief Deserialize the result of `cudf::pack` - * - * Converts the result of a serialized table into a `table_view` that points to the data stored in - * the contiguous device buffer contained in `input`. - * - * It is the caller's responsibility to ensure that the `table_view` in the output does not outlive - * the data in the input. - * - * No new device memory is allocated in this function. - * - * @param input The packed columns to unpack - * @return The unpacked `table_view` - */ -table_view unpack(packed_columns const& input); - -/** - * @brief Deserialize the result of `cudf::pack` - * - * Converts the result of a serialized table into a `table_view` that points to the data stored in - * the contiguous device buffer contained in `gpu_data` using the metadata contained in the host - * buffer `metadata`. - * - * It is the caller's responsibility to ensure that the `table_view` in the output does not outlive - * the data in the input. - * - * No new device memory is allocated in this function. - * - * @param metadata The host-side metadata buffer resulting from the initial pack() call - * @param gpu_data The device-side contiguous buffer storing the data that will be referenced by - * the resulting `table_view` - * @return The unpacked `table_view` - */ -table_view unpack(uint8_t const* metadata, uint8_t const* gpu_data); - /** * @brief Returns a new column, where each element is selected from either @p lhs or * @p rhs based on the value of the corresponding element in @p boolean_mask diff --git a/cpp/include/cudf/detail/contiguous_split.hpp b/cpp/include/cudf/detail/contiguous_split.hpp new file mode 100644 index 00000000000..6abaaabdd3c --- /dev/null +++ b/cpp/include/cudf/detail/contiguous_split.hpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2023, NVIDIA CORPORATION. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#pragma once + +#include +#include +#include + +#include + +namespace cudf { +namespace detail { + +/** + * @copydoc cudf::contiguous_split + * + * @param stream CUDA stream used for device memory operations and kernel launches. + **/ +std::vector contiguous_split(cudf::table_view const& input, + std::vector const& splits, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr); + +/** + * @copydoc cudf::pack + * + * @param stream Optional CUDA stream on which to execute kernels + **/ +packed_columns pack(cudf::table_view const& input, + rmm::cuda_stream_view stream, + rmm::mr::device_memory_resource* mr); + +} // namespace detail +} // namespace cudf diff --git a/cpp/include/cudf/detail/copy.hpp b/cpp/include/cudf/detail/copy.hpp index 990f4425571..115822163c3 100644 --- a/cpp/include/cudf/detail/copy.hpp +++ b/cpp/include/cudf/detail/copy.hpp @@ -173,25 +173,6 @@ std::unique_ptr segmented_shift(column_view const& segmented_values, rmm::cuda_stream_view stream, rmm::mr::device_memory_resource* mr); -/** - * @copydoc cudf::contiguous_split - * - * @param stream CUDA stream used for device memory operations and kernel launches. - **/ -std::vector contiguous_split(cudf::table_view const& input, - std::vector const& splits, - rmm::cuda_stream_view stream, - rmm::mr::device_memory_resource* mr); - -/** - * @copydoc cudf::pack - * - * @param stream Optional CUDA stream on which to execute kernels - **/ -packed_columns pack(cudf::table_view const& input, - rmm::cuda_stream_view stream, - rmm::mr::device_memory_resource* mr); - /** * @copydoc cudf::allocate_like(column_view const&, size_type, mask_allocation_policy, * rmm::mr::device_memory_resource*) diff --git a/cpp/include/doxygen_groups.h b/cpp/include/doxygen_groups.h index a31e7fc7165..094f2127e3a 100644 --- a/cpp/include/doxygen_groups.h +++ b/cpp/include/doxygen_groups.h @@ -66,6 +66,7 @@ * @} * @defgroup copy_split Splitting * @{ + * @file cudf/contiguous_split.hpp * @file cudf/copying.hpp * @} * @defgroup copy_shift Shifting diff --git a/cpp/src/copying/contiguous_split.cu b/cpp/src/copying/contiguous_split.cu index 0e99f10ae19..289464d7907 100644 --- a/cpp/src/copying/contiguous_split.cu +++ b/cpp/src/copying/contiguous_split.cu @@ -16,7 +16,8 @@ #include #include -#include +#include +#include #include #include #include @@ -1000,7 +1001,7 @@ std::vector contiguous_split(cudf::table_view const& input, [&empty_inputs](int partition_index) { return packed_table{ empty_inputs, - packed_columns{std::make_unique(pack_metadata( + packed_columns{std::make_unique>(pack_metadata( empty_inputs, static_cast(nullptr), 0)), std::make_unique()}}; }); @@ -1250,7 +1251,7 @@ std::vector contiguous_split(cudf::table_view const& input, result.push_back(packed_table{ t, packed_columns{ - std::make_unique(cudf::pack_metadata( + std::make_unique>(cudf::pack_metadata( t, reinterpret_cast(out_buffers[idx].data()), out_buffers[idx].size())), std::make_unique(std::move(out_buffers[idx]))}}); diff --git a/cpp/src/copying/pack.cpp b/cpp/src/copying/pack.cpp index 53006bc62ff..5884fcc100a 100644 --- a/cpp/src/copying/pack.cpp +++ b/cpp/src/copying/pack.cpp @@ -14,7 +14,8 @@ * limitations under the License. */ -#include +#include +#include #include #include @@ -150,10 +151,10 @@ packed_columns pack(cudf::table_view const& input, } template -packed_columns::metadata pack_metadata(ColumnIter begin, - ColumnIter end, - uint8_t const* contiguous_buffer, - size_t buffer_size) +std::vector pack_metadata(ColumnIter begin, + ColumnIter end, + uint8_t const* contiguous_buffer, + size_t buffer_size) { std::vector metadata; @@ -173,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; } /** @@ -221,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, - uint8_t const* contiguous_buffer, - size_t buffer_size) +std::vector 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{} : detail::pack_metadata(table.begin(), table.end(), contiguous_buffer, buffer_size); } @@ -237,9 +238,9 @@ packed_columns::metadata pack_metadata(table_view const& table, table_view unpack(packed_columns const& input) { CUDF_FUNC_RANGE(); - return input.metadata_->size() == 0 + return input.metadata->size() == 0 ? table_view{} - : detail::unpack(input.metadata_->data(), + : detail::unpack(input.metadata->data(), reinterpret_cast(input.gpu_data->data())); } diff --git a/cpp/tests/copying/pack_tests.cpp b/cpp/tests/copying/pack_tests.cpp index a2ef8f3a3db..5f88070107c 100644 --- a/cpp/tests/copying/pack_tests.cpp +++ b/cpp/tests/copying/pack_tests.cpp @@ -18,7 +18,7 @@ #include #include -#include +#include struct PackUnpackTest : public cudf::test::BaseFixture { void run_test(cudf::table_view const& t) @@ -31,9 +31,9 @@ struct PackUnpackTest : public cudf::test::BaseFixture { // verify pack_metadata itself works auto metadata = cudf::pack_metadata( unpacked, reinterpret_cast(packed.gpu_data->data()), packed.gpu_data->size()); - EXPECT_EQ(metadata.size(), packed.metadata_->size()); + EXPECT_EQ(metadata.size(), packed.metadata->size()); EXPECT_EQ( - std::equal(metadata.data(), metadata.data() + metadata.size(), packed.metadata_->data()), + std::equal(metadata.data(), metadata.data() + metadata.size(), packed.metadata->data()), true); } void run_test(std::vector const& t) { run_test(cudf::table_view{t}); } diff --git a/cpp/tests/copying/split_tests.cpp b/cpp/tests/copying/split_tests.cpp index d0dace24dc3..5d47a123c58 100644 --- a/cpp/tests/copying/split_tests.cpp +++ b/cpp/tests/copying/split_tests.cpp @@ -24,6 +24,7 @@ #include #include +#include #include #include #include diff --git a/java/src/main/native/src/ColumnVectorJni.cpp b/java/src/main/native/src/ColumnVectorJni.cpp index 1d22d8a5d79..8fb7df78c09 100644 --- a/java/src/main/native/src/ColumnVectorJni.cpp +++ b/java/src/main/native/src/ColumnVectorJni.cpp @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/java/src/main/native/src/ContiguousTableJni.cpp b/java/src/main/native/src/ContiguousTableJni.cpp index f6dfb985ce7..85a5a24262e 100644 --- a/java/src/main/native/src/ContiguousTableJni.cpp +++ b/java/src/main/native/src/ContiguousTableJni.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022, NVIDIA CORPORATION. + * Copyright (c) 2021-2023, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -108,7 +108,7 @@ jobject contig_split_group_by_result_from(JNIEnv *env, jobjectArray &groups, } jobject contiguous_table_from(JNIEnv *env, cudf::packed_columns &split, long row_count) { - jlong metadata_address = reinterpret_cast(split.metadata_.get()); + jlong metadata_address = reinterpret_cast(split.metadata.get()); jlong data_address = reinterpret_cast(split.gpu_data->data()); jlong data_size = static_cast(split.gpu_data->size()); jlong rmm_buffer_address = reinterpret_cast(split.gpu_data.get()); @@ -118,7 +118,7 @@ jobject contiguous_table_from(JNIEnv *env, cudf::packed_columns &split, long row rmm_buffer_address, row_count); if (contig_table_obj != nullptr) { - split.metadata_.release(); + split.metadata.release(); split.gpu_data.release(); } @@ -143,8 +143,7 @@ JNIEXPORT jlong JNICALL Java_ai_rapids_cudf_ContiguousTable_createPackedMetadata auto table = reinterpret_cast(j_table); auto data_addr = reinterpret_cast(j_buffer_addr); auto data_size = static_cast(j_buffer_length); - auto metadata_ptr = - new cudf::packed_columns::metadata(cudf::pack_metadata(*table, data_addr, data_size)); + auto metadata_ptr = new std::vector(cudf::pack_metadata(*table, data_addr, data_size)); return reinterpret_cast(metadata_ptr); } CATCH_STD(env, 0); @@ -154,7 +153,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(j_metadata_ptr); + auto metadata = reinterpret_cast *>(j_metadata_ptr); return env->NewDirectByteBuffer(const_cast(metadata->data()), metadata->size()); } CATCH_STD(env, nullptr); @@ -164,7 +163,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(j_metadata_ptr); + auto metadata = reinterpret_cast *>(j_metadata_ptr); delete metadata; } CATCH_STD(env, ); diff --git a/java/src/main/native/src/TableJni.cpp b/java/src/main/native/src/TableJni.cpp index 22a0e4f5c33..51c2e92492f 100644 --- a/java/src/main/native/src/TableJni.cpp +++ b/java/src/main/native/src/TableJni.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include diff --git a/java/src/main/native/src/cudf_jni_apis.hpp b/java/src/main/native/src/cudf_jni_apis.hpp index 8a448810390..18993aea294 100644 --- a/java/src/main/native/src/cudf_jni_apis.hpp +++ b/java/src/main/native/src/cudf_jni_apis.hpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2019-2022, NVIDIA CORPORATION. + * Copyright (c) 2019-2023, NVIDIA CORPORATION. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,7 +15,7 @@ */ #pragma once -#include +#include #include #include "jni_utils.hpp" diff --git a/python/cudf/cudf/_lib/copying.pxd b/python/cudf/cudf/_lib/copying.pxd index 9457a3c2277..599b9c5a067 100644 --- a/python/cudf/cudf/_lib/copying.pxd +++ b/python/cudf/cudf/_lib/copying.pxd @@ -1,6 +1,6 @@ -# Copyright (c) 2021, NVIDIA CORPORATION. +# Copyright (c) 2021-2023, NVIDIA CORPORATION. -from cudf._lib.cpp.copying cimport packed_columns +from cudf._lib.cpp.contiguous_split cimport packed_columns cdef class _CPackedColumns: diff --git a/python/cudf/cudf/_lib/copying.pyx b/python/cudf/cudf/_lib/copying.pyx index 6a53586396f..56291ac0a12 100644 --- a/python/cudf/cudf/_lib/copying.pyx +++ b/python/cudf/cudf/_lib/copying.pyx @@ -23,6 +23,7 @@ from cudf._lib.utils cimport table_view_from_columns, table_view_from_table from cudf._lib.reduce import minmax from cudf.core.abc import Serializable +cimport cudf._lib.cpp.contiguous_split as cpp_contiguous_split cimport cudf._lib.cpp.copying as cpp_copying from cudf._lib.cpp.column.column cimport column from cudf._lib.cpp.column.column_view cimport column_view, mutable_column_view @@ -712,7 +713,7 @@ cdef class _CPackedColumns: if isinstance(col.dtype, cudf.core.dtypes._BaseDtype): p.column_dtypes[name] = col.dtype - p.c_obj = move(cpp_copying.pack(input_table_view)) + p.c_obj = move(cpp_contiguous_split.pack(input_table_view)) return p @@ -740,10 +741,10 @@ cdef class _CPackedColumns: header["column-names"] = self.column_names header["index-names"] = self.index_names - if self.c_obj.metadata_.get()[0].data() != NULL: + if self.c_obj.metadata.get()[0].data() != NULL: header["metadata"] = list( - - self.c_obj.metadata_.get()[0].data() + + self.c_obj.metadata.get()[0].data() ) column_dtypes = {} @@ -769,9 +770,9 @@ cdef class _CPackedColumns: size=gpu_data.nbytes ) - cdef cpp_copying.packed_columns data - data.metadata_ = move( - make_unique[cpp_copying.metadata]( + cdef cpp_contiguous_split.packed_columns data + data.metadata = move( + make_unique[vector[uint8_t]]( move(header.get("metadata", [])) ) ) @@ -793,7 +794,7 @@ cdef class _CPackedColumns: def unpack(self): output_table = cudf.DataFrame._from_data(*data_from_table_view( - cpp_copying.unpack(self.c_obj), + cpp_contiguous_split.unpack(self.c_obj), self, self.column_names, self.index_names diff --git a/python/cudf/cudf/_lib/cpp/contiguous_split.pxd b/python/cudf/cudf/_lib/cpp/contiguous_split.pxd new file mode 100644 index 00000000000..134e4ed0723 --- /dev/null +++ b/python/cudf/cudf/_lib/cpp/contiguous_split.pxd @@ -0,0 +1,29 @@ +# Copyright (c) 2023, NVIDIA CORPORATION. + +from libc.stdint cimport uint8_t +from libcpp.memory cimport unique_ptr +from libcpp.vector cimport vector + +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" nogil: + cdef cppclass packed_columns: + unique_ptr[vector[uint8_t]] metadata + unique_ptr[device_buffer] gpu_data + + cdef struct contiguous_split_result: + table_view table + vector[device_buffer] all_data + + cdef vector[contiguous_split_result] contiguous_split ( + table_view input_table, + vector[size_type] splits + ) except + + + cdef packed_columns pack (const table_view& input) except + + + cdef table_view unpack (const packed_columns& input) except + diff --git a/python/cudf/cudf/_lib/cpp/copying.pxd b/python/cudf/cudf/_lib/cpp/copying.pxd index 09e8538ebb7..8961675711f 100644 --- a/python/cudf/cudf/_lib/cpp/copying.pxd +++ b/python/cudf/cudf/_lib/cpp/copying.pxd @@ -18,12 +18,6 @@ from cudf._lib.exception_handler cimport cudf_exception_handler ctypedef const scalar constscalar -cdef extern from "cudf/copying.hpp" namespace "cudf::packed_columns" nogil: - cdef struct metadata: - metadata(vector[uint8_t]&& v) - const uint8_t* data () except + - size_type size () except + - cdef extern from "cudf/copying.hpp" namespace "cudf" nogil: ctypedef enum out_of_bounds_policy: NULLIFY 'cudf::out_of_bounds_policy::NULLIFY' @@ -113,23 +107,6 @@ cdef extern from "cudf/copying.hpp" namespace "cudf" nogil: vector[size_type] splits ) except + - cdef cppclass packed_columns: - unique_ptr[metadata] metadata_ - unique_ptr[device_buffer] gpu_data - - cdef struct contiguous_split_result: - table_view table - vector[device_buffer] all_data - - cdef vector[contiguous_split_result] contiguous_split ( - table_view input_table, - vector[size_type] splits - ) except + - - cdef packed_columns pack (const table_view& input) except + - - cdef table_view unpack (const packed_columns& input) except + - cdef unique_ptr[column] copy_if_else ( column_view lhs, column_view rhs,