-
Notifications
You must be signed in to change notification settings - Fork 912
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/branch-24.12' into numpy_random
- Loading branch information
Showing
29 changed files
with
1,430 additions
and
372 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) 2024, 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 <cudf/io/types.hpp> | ||
#include <cudf/table/table_view.hpp> | ||
|
||
#include <rmm/cuda_stream_view.hpp> | ||
#include <rmm/mr/device/device_memory_resource.hpp> | ||
|
||
#include <memory> | ||
#include <string> | ||
|
||
/** | ||
* @file common_utils.hpp | ||
* @brief Common utilities for `parquet_io` examples | ||
* | ||
*/ | ||
|
||
/** | ||
* @brief Create memory resource for libcudf functions | ||
* | ||
* @param pool Whether to use a pool memory resource. | ||
* @return Memory resource instance | ||
*/ | ||
std::shared_ptr<rmm::mr::device_memory_resource> create_memory_resource(bool is_pool_used); | ||
|
||
/** | ||
* @brief Get encoding type from the keyword | ||
* | ||
* @param name encoding keyword name | ||
* @return corresponding column encoding type | ||
*/ | ||
[[nodiscard]] cudf::io::column_encoding get_encoding_type(std::string name); | ||
|
||
/** | ||
* @brief Get compression type from the keyword | ||
* | ||
* @param name compression keyword name | ||
* @return corresponding compression type | ||
*/ | ||
[[nodiscard]] cudf::io::compression_type get_compression_type(std::string name); | ||
|
||
/** | ||
* @brief Get boolean from they keyword | ||
* | ||
* @param input keyword affirmation string such as: Y, T, YES, TRUE, ON | ||
* @return true or false | ||
*/ | ||
[[nodiscard]] bool get_boolean(std::string input); | ||
|
||
/** | ||
* @brief Check if two tables are identical, throw an error otherwise | ||
* | ||
* @param lhs_table View to lhs table | ||
* @param rhs_table View to rhs table | ||
*/ | ||
void check_tables_equal(cudf::table_view const& lhs_table, cudf::table_view const& rhs_table); | ||
|
||
/** | ||
* @brief Concatenate a vector of tables and return the resultant table | ||
* | ||
* @param tables Vector of tables to concatenate | ||
* @param stream CUDA stream to use | ||
* | ||
* @return Unique pointer to the resultant concatenated table. | ||
*/ | ||
std::unique_ptr<cudf::table> concatenate_tables(std::vector<std::unique_ptr<cudf::table>> tables, | ||
rmm::cuda_stream_view stream); | ||
|
||
/** | ||
* @brief Returns a string containing current date and time | ||
* | ||
*/ | ||
std::string current_date_and_time(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/* | ||
* Copyright (c) 2024, 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. | ||
*/ | ||
|
||
#include "io_source.hpp" | ||
|
||
#include <cudf/io/types.hpp> | ||
#include <cudf/utilities/memory_resource.hpp> | ||
|
||
#include <rmm/cuda_stream_view.hpp> | ||
#include <rmm/mr/pinned_host_memory_resource.hpp> | ||
|
||
#include <thrust/host_vector.h> | ||
|
||
#include <filesystem> | ||
#include <fstream> | ||
#include <string> | ||
|
||
rmm::host_async_resource_ref pinned_memory_resource() | ||
{ | ||
static auto mr = rmm::mr::pinned_host_memory_resource{}; | ||
return mr; | ||
} | ||
|
||
io_source_type get_io_source_type(std::string name) | ||
{ | ||
static std::unordered_map<std::string_view, io_source_type> const map = { | ||
{"FILEPATH", io_source_type::FILEPATH}, | ||
{"HOST_BUFFER", io_source_type::HOST_BUFFER}, | ||
{"PINNED_BUFFER", io_source_type::PINNED_BUFFER}, | ||
{"DEVICE_BUFFER", io_source_type::DEVICE_BUFFER}}; | ||
|
||
std::transform(name.begin(), name.end(), name.begin(), ::toupper); | ||
if (map.find(name) != map.end()) { | ||
return map.at(name); | ||
} else { | ||
throw std::invalid_argument(name + | ||
" is not a valid io source type. Available: FILEPATH,\n" | ||
"HOST_BUFFER, PINNED_BUFFER, DEVICE_BUFFER.\n\n"); | ||
} | ||
} | ||
|
||
io_source::io_source(std::string_view file_path, io_source_type type, rmm::cuda_stream_view stream) | ||
: pinned_buffer({pinned_memory_resource(), stream}), d_buffer{0, stream} | ||
{ | ||
std::string const file_name{file_path}; | ||
auto const file_size = std::filesystem::file_size(file_name); | ||
|
||
// For filepath make a quick source_info and return early | ||
if (type == io_source_type::FILEPATH) { | ||
source_info = cudf::io::source_info(file_name); | ||
return; | ||
} | ||
|
||
std::ifstream file{file_name, std::ifstream::binary}; | ||
|
||
// Copy file contents to the specified io source buffer | ||
switch (type) { | ||
case io_source_type::HOST_BUFFER: { | ||
h_buffer.resize(file_size); | ||
file.read(h_buffer.data(), file_size); | ||
source_info = cudf::io::source_info(h_buffer.data(), file_size); | ||
break; | ||
} | ||
case io_source_type::PINNED_BUFFER: { | ||
pinned_buffer.resize(file_size); | ||
file.read(pinned_buffer.data(), file_size); | ||
source_info = cudf::io::source_info(pinned_buffer.data(), file_size); | ||
break; | ||
} | ||
case io_source_type::DEVICE_BUFFER: { | ||
h_buffer.resize(file_size); | ||
file.read(h_buffer.data(), file_size); | ||
d_buffer.resize(file_size, stream); | ||
CUDF_CUDA_TRY(cudaMemcpyAsync( | ||
d_buffer.data(), h_buffer.data(), file_size, cudaMemcpyDefault, stream.value())); | ||
|
||
source_info = cudf::io::source_info(d_buffer); | ||
break; | ||
} | ||
default: { | ||
throw std::runtime_error("Encountered unexpected source type\n\n"); | ||
} | ||
} | ||
} |
Oops, something went wrong.