Skip to content

Commit

Permalink
Promote IO support queries to cudf API
Browse files Browse the repository at this point in the history
  • Loading branch information
robertmaynard committed Jun 28, 2024
1 parent fb12d98 commit acc0b00
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 124 deletions.
53 changes: 53 additions & 0 deletions cpp/include/cudf/io/config_utils.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* 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/utilities/export.hpp>

namespace CUDF_EXPORT cudf {
namespace io::cufile_integration {

/**
* @brief Returns true if cuFile and its compatibility mode are enabled.
*/
bool is_always_enabled();

/**
* @brief Returns true if only direct IO through cuFile is enabled (compatibility mode is disabled).
*/
bool is_gds_enabled();

/**
* @brief Returns true if KvikIO is enabled.
*/
bool is_kvikio_enabled();

} // namespace io::cufile_integration

namespace io::nvcomp_integration {

/**
* @brief Returns true if all nvCOMP uses are enabled.
*/
bool is_all_enabled();

/**
* @brief Returns true if stable nvCOMP use is enabled.
*/
bool is_stable_enabled();

} // namespace io::nvcomp_integration
} // namespace cudf
92 changes: 92 additions & 0 deletions cpp/include/cudf/io/nvcomp_adapter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
* 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/utilities/export.hpp>

#include <optional>
#include <string>


namespace CUDF_EXPORT cudf {
namespace io::nvcomp {

enum class compression_type { SNAPPY, ZSTD, DEFLATE, LZ4 };

/**
* @brief Set of parameters that impact whether the use nvCOMP features is enabled.
*/
struct feature_status_parameters {
int lib_major_version;
int lib_minor_version;
int lib_patch_version;
bool are_all_integrations_enabled;
bool are_stable_integrations_enabled;
int compute_capability_major;

feature_status_parameters();
feature_status_parameters(
int major, int minor, int patch, bool all_enabled, bool stable_enabled, int cc_major)
: lib_major_version{major},
lib_minor_version{minor},
lib_patch_version{patch},
are_all_integrations_enabled{all_enabled},
are_stable_integrations_enabled{stable_enabled},
compute_capability_major{cc_major}
{
}
};

/**
* @brief Equality operator overload. Required to use `feature_status_parameters` as a map key.
*/
inline bool operator==(feature_status_parameters const& lhs, feature_status_parameters const& rhs)
{
return lhs.lib_major_version == rhs.lib_major_version and
lhs.lib_minor_version == rhs.lib_minor_version and
lhs.lib_patch_version == rhs.lib_patch_version and
lhs.are_all_integrations_enabled == rhs.are_all_integrations_enabled and
lhs.are_stable_integrations_enabled == rhs.are_stable_integrations_enabled and
lhs.compute_capability_major == rhs.compute_capability_major;
}

/**
* @brief If a compression type is disabled through nvCOMP, returns the reason as a string.
*
* Result cab depend on nvCOMP version and environment variables.
*
* @param compression Compression type
* @param params Optional parameters to query status with different configurations
* @returns Reason for the feature disablement, `std::nullopt` if the feature is enabled
*/
[[nodiscard]] std::optional<std::string> is_compression_disabled(
compression_type compression, feature_status_parameters params = feature_status_parameters());

/**
* @brief If a decompression type is disabled through nvCOMP, returns the reason as a string.
*
* Result can depend on nvCOMP version and environment variables.
*
* @param compression Compression type
* @param params Optional parameters to query status with different configurations
* @returns Reason for the feature disablement, `std::nullopt` if the feature is enabled
*/
[[nodiscard]] std::optional<std::string> is_decompression_disabled(
compression_type compression, feature_status_parameters params = feature_status_parameters());

} // namespace io::nvcomp
} // namespace cudf
4 changes: 3 additions & 1 deletion cpp/include/cudf/utilities/logger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@

#pragma once

#include <cudf/utilities/export.hpp>

#include <spdlog/spdlog.h>

namespace cudf {
namespace CUDF_EXPORT cudf {

/**
* @brief Returns the global logger.
Expand Down
8 changes: 5 additions & 3 deletions cpp/src/io/comp/nvcomp_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "nvcomp_adapter.hpp"

#include "io/utilities/config_utils.hpp"
#include "nvcomp_adapter.cuh"

#include <cudf/detail/utilities/logger.hpp>
#include <cudf/io/config_utils.hpp>
#include <cudf/utilities/error.hpp>

#include <nvcomp/lz4.h>
Expand Down Expand Up @@ -472,8 +474,8 @@ feature_status_parameters::feature_status_parameters()
: lib_major_version{NVCOMP_MAJOR_VERSION},
lib_minor_version{NVCOMP_MINOR_VERSION},
lib_patch_version{NVCOMP_PATCH_VERSION},
are_all_integrations_enabled{detail::nvcomp_integration::is_all_enabled()},
are_stable_integrations_enabled{detail::nvcomp_integration::is_stable_enabled()}
are_all_integrations_enabled{nvcomp_integration::is_all_enabled()},
are_stable_integrations_enabled{nvcomp_integration::is_stable_enabled()}
{
int device;
CUDF_CUDA_TRY(cudaGetDevice(&device));
Expand Down
67 changes: 2 additions & 65 deletions cpp/src/io/comp/nvcomp_adapter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/

#pragma once
#include <cudf/io/nvcomp_adapter.hpp>

#include "gpuinflate.hpp"
#include "io/utilities/config_utils.hpp"

#include <cudf/io/config_utils.hpp>
#include <cudf/utilities/error.hpp>
#include <cudf/utilities/span.hpp>

Expand All @@ -27,70 +28,6 @@
#include <optional>

namespace cudf::io::nvcomp {

enum class compression_type { SNAPPY, ZSTD, DEFLATE, LZ4 };

/**
* @brief Set of parameters that impact whether the use nvCOMP features is enabled.
*/
struct feature_status_parameters {
int lib_major_version;
int lib_minor_version;
int lib_patch_version;
bool are_all_integrations_enabled;
bool are_stable_integrations_enabled;
int compute_capability_major;

feature_status_parameters();
feature_status_parameters(
int major, int minor, int patch, bool all_enabled, bool stable_enabled, int cc_major)
: lib_major_version{major},
lib_minor_version{minor},
lib_patch_version{patch},
are_all_integrations_enabled{all_enabled},
are_stable_integrations_enabled{stable_enabled},
compute_capability_major{cc_major}
{
}
};

/**
* @brief Equality operator overload. Required to use `feature_status_parameters` as a map key.
*/
inline bool operator==(feature_status_parameters const& lhs, feature_status_parameters const& rhs)
{
return lhs.lib_major_version == rhs.lib_major_version and
lhs.lib_minor_version == rhs.lib_minor_version and
lhs.lib_patch_version == rhs.lib_patch_version and
lhs.are_all_integrations_enabled == rhs.are_all_integrations_enabled and
lhs.are_stable_integrations_enabled == rhs.are_stable_integrations_enabled and
lhs.compute_capability_major == rhs.compute_capability_major;
}

/**
* @brief If a compression type is disabled through nvCOMP, returns the reason as a string.
*
* Result cab depend on nvCOMP version and environment variables.
*
* @param compression Compression type
* @param params Optional parameters to query status with different configurations
* @returns Reason for the feature disablement, `std::nullopt` if the feature is enabled
*/
[[nodiscard]] std::optional<std::string> is_compression_disabled(
compression_type compression, feature_status_parameters params = feature_status_parameters());

/**
* @brief If a decompression type is disabled through nvCOMP, returns the reason as a string.
*
* Result can depend on nvCOMP version and environment variables.
*
* @param compression Compression type
* @param params Optional parameters to query status with different configurations
* @returns Reason for the feature disablement, `std::nullopt` if the feature is enabled
*/
[[nodiscard]] std::optional<std::string> is_decompression_disabled(
compression_type compression, feature_status_parameters params = feature_status_parameters());

/**
* @brief Device batch decompression of given type.
*
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/io/orc/reader_impl_decode.cu
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@
#include "io/orc/reader_impl.hpp"
#include "io/orc/reader_impl_chunking.hpp"
#include "io/orc/reader_impl_helpers.hpp"
#include "io/utilities/config_utils.hpp"
#include "io/utilities/hostdevice_span.hpp"

#include <cudf/detail/copy.hpp>
#include <cudf/detail/transform.hpp>
#include <cudf/detail/utilities/integer_utils.hpp>
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/io/config_utils.hpp>
#include <cudf/table/table.hpp>
#include <cudf/utilities/error.hpp>

Expand Down
2 changes: 1 addition & 1 deletion cpp/src/io/orc/stripe_enc.cu
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@

#include "io/comp/nvcomp_adapter.hpp"
#include "io/utilities/block_utils.cuh"
#include "io/utilities/config_utils.hpp"
#include "io/utilities/time_utils.cuh"
#include "orc_gpu.hpp"

#include <cudf/column/column_device_view.cuh>
#include <cudf/detail/utilities/integer_utils.hpp>
#include <cudf/detail/utilities/logger.hpp>
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/io/orc_types.hpp>
#include <cudf/lists/lists_column_view.hpp>
Expand Down
1 change: 1 addition & 0 deletions cpp/src/io/orc/writer_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include <cudf/detail/iterator.cuh>
#include <cudf/detail/null_mask.hpp>
#include <cudf/detail/utilities/cuda.cuh>
#include <cudf/detail/utilities/logger.hpp>
#include <cudf/detail/utilities/stream_pool.hpp>
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/strings/strings_column_view.hpp>
Expand Down
6 changes: 3 additions & 3 deletions cpp/src/io/parquet/reader_impl_chunking.cu
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

#include "compact_protocol_reader.hpp"
#include "io/comp/nvcomp_adapter.hpp"
#include "io/utilities/config_utils.hpp"
#include "io/utilities/time_utils.cuh"
#include "reader_impl.hpp"
#include "reader_impl_chunking.hpp"
Expand All @@ -25,6 +24,7 @@
#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/detail/utilities/integer_utils.hpp>
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/io/config_utils.hpp>

#include <rmm/exec_policy.hpp>

Expand Down Expand Up @@ -862,7 +862,7 @@ std::vector<row_range> compute_page_splits_by_row(device_span<cumulative_page_in
gpuinflate(d_comp_in, d_comp_out, d_comp_res_view, gzip_header_included::YES, stream);
break;
case SNAPPY:
if (cudf::io::detail::nvcomp_integration::is_stable_enabled()) {
if (cudf::io::nvcomp_integration::is_stable_enabled()) {
nvcomp::batched_decompress(nvcomp::compression_type::SNAPPY,
d_comp_in,
d_comp_out,
Expand Down Expand Up @@ -1071,7 +1071,7 @@ struct get_decomp_scratch {
case BROTLI: return get_gpu_debrotli_scratch_size(di.num_pages);

case SNAPPY:
if (cudf::io::detail::nvcomp_integration::is_stable_enabled()) {
if (cudf::io::nvcomp_integration::is_stable_enabled()) {
return cudf::io::nvcomp::batched_decompress_temp_size(
cudf::io::nvcomp::compression_type::SNAPPY,
di.num_pages,
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/io/parquet/writer_impl.cu
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
#include "io/parquet/parquet_gpu.hpp"
#include "io/statistics/column_statistics.cuh"
#include "io/utilities/column_utils.cuh"
#include "io/utilities/config_utils.hpp"
#include "parquet_common.hpp"
#include "parquet_gpu.cuh"
#include "writer_impl.hpp"
Expand All @@ -36,6 +35,7 @@
#include <cudf/detail/get_value.cuh>
#include <cudf/detail/utilities/integer_utils.hpp>
#include <cudf/detail/utilities/linked_column.hpp>
#include <cudf/detail/utilities/logger.hpp>
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/lists/detail/dremel.hpp>
#include <cudf/lists/lists_column_view.hpp>
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/io/text/bgzip_data_chunk_source.cu
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

#include "io/comp/nvcomp_adapter.hpp"
#include "io/text/device_data_chunks.hpp"
#include "io/utilities/config_utils.hpp"

#include <cudf/detail/nvtx/ranges.hpp>
#include <cudf/detail/utilities/host_vector.hpp>
#include <cudf/detail/utilities/integer_utils.hpp>
#include <cudf/detail/utilities/vector_factories.hpp>
#include <cudf/io/text/data_chunk_source_factories.hpp>
#include <cudf/io/text/detail/bgzip_utils.hpp>
#include <cudf/io/config_utils.hpp>
#include <cudf/utilities/default_stream.hpp>
#include <cudf/utilities/error.hpp>

Expand Down
8 changes: 5 additions & 3 deletions cpp/src/io/utilities/config_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,16 @@
* limitations under the License.
*/

#include "config_utils.hpp"
#include "getenv_or.hpp"

#include <cudf/detail/utilities/logger.hpp>
#include <cudf/utilities/error.hpp>

#include <cstdlib>
#include <sstream>
#include <string>

namespace cudf::io::detail {
namespace cudf::io {

namespace cufile_integration {

Expand Down Expand Up @@ -80,4 +82,4 @@ bool is_stable_enabled() { return is_all_enabled() or get_env_policy() == usage_

} // namespace nvcomp_integration

} // namespace cudf::io::detail
} // namespace cudf::io
Loading

0 comments on commit acc0b00

Please sign in to comment.