From ac3cf4c5684cb450ba6026c25093f349f1adbdcb Mon Sep 17 00:00:00 2001 From: Vukasin Milovanovic Date: Mon, 9 Dec 2024 10:06:28 -0800 Subject: [PATCH] hash --- cpp/src/text/subword/load_hash_file.cu | 37 +++++++++++++------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/cpp/src/text/subword/load_hash_file.cu b/cpp/src/text/subword/load_hash_file.cu index b13ad0a7de8..d51adcdd34a 100644 --- a/cpp/src/text/subword/load_hash_file.cu +++ b/cpp/src/text/subword/load_hash_file.cu @@ -14,11 +14,13 @@ * limitations under the License. */ +#include "cudf/detail/utilities/cuda_memcpy.hpp" #include "text/subword/detail/codepoint_metadata.ah" #include "text/subword/detail/tokenizer_utils.cuh" #include #include +#include #include #include #include @@ -198,8 +200,8 @@ std::unique_ptr load_vocabulary_file( std::getline(hash_file, line); result.num_bins = str_to_uint32(line, line_no++); - std::vector bin_coefficients(result.num_bins); - std::vector bin_offsets(result.num_bins); + auto bin_coefficients = cudf::detail::make_host_vector(result.num_bins, stream); + auto bin_offsets = cudf::detail::make_host_vector(result.num_bins, stream); for (int i = 0; i < result.num_bins; ++i) { std::getline(hash_file, line); @@ -216,7 +218,7 @@ std::unique_ptr load_vocabulary_file( std::getline(hash_file, line); uint64_t hash_table_length = str_to_uint64(line, line_no++); - std::vector table(hash_table_length); + auto table = cudf::detail::make_host_vector(hash_table_length, stream); std::generate(table.begin(), table.end(), [&hash_file, &line_no]() { std::string line; @@ -239,33 +241,32 @@ std::unique_ptr load_vocabulary_file( cudf::mask_state::UNALLOCATED, stream, mr); - CUDF_CUDA_TRY(cudaMemcpyAsync(result.table->mutable_view().data(), - table.data(), - table.size() * sizeof(uint64_t), - cudaMemcpyDefault, - stream.value())); + cudf::detail::cuda_memcpy_async( + cudf::device_span(result.table->mutable_view().data(), table.size()), + table, + stream); result.bin_coefficients = cudf::make_numeric_column(cudf::data_type{cudf::type_id::UINT64}, bin_coefficients.size(), cudf::mask_state::UNALLOCATED, stream, mr); - CUDF_CUDA_TRY(cudaMemcpyAsync(result.bin_coefficients->mutable_view().data(), - bin_coefficients.data(), - bin_coefficients.size() * sizeof(uint64_t), - cudaMemcpyDefault, - stream.value())); + cudf::detail::cuda_memcpy_async( + cudf::device_span(result.bin_coefficients->mutable_view().data(), + bin_coefficients.size()), + bin_coefficients, + stream); result.bin_offsets = cudf::make_numeric_column(cudf::data_type{cudf::type_id::UINT16}, bin_offsets.size(), cudf::mask_state::UNALLOCATED, stream, mr); - CUDF_CUDA_TRY(cudaMemcpyAsync(result.bin_offsets->mutable_view().data(), - bin_offsets.data(), - bin_offsets.size() * sizeof(uint16_t), - cudaMemcpyDefault, - stream.value())); + cudf::detail::cuda_memcpy_async( + cudf::device_span(result.bin_offsets->mutable_view().data(), + bin_offsets.size()), + bin_offsets, + stream); auto cp_metadata = detail::get_codepoint_metadata(stream); auto const cp_metadata_size = static_cast(cp_metadata.size());