Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make is_decompression_disabled and is_compression_disabled thread-safe #13240

Merged
merged 1 commit into from
Apr 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions cpp/src/io/comp/nvcomp_adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@

#include <nvcomp/snappy.h>

#include <mutex>

#define NVCOMP_DEFLATE_HEADER <nvcomp/deflate.h>
#if __has_include(NVCOMP_DEFLATE_HEADER)
#include NVCOMP_DEFLATE_HEADER
Expand Down Expand Up @@ -506,6 +508,9 @@ std::optional<std::string> is_compression_disabled(compression_type compression,
feature_status_parameters params)
{
static feature_status_memo_map comp_status_reason;
static std::mutex memo_map_mutex;

std::unique_lock memo_map_lock{memo_map_mutex};
if (auto mem_res_it = comp_status_reason.find(feature_status_inputs{compression, params});
mem_res_it != comp_status_reason.end()) {
return mem_res_it->second;
Expand All @@ -515,6 +520,8 @@ std::optional<std::string> is_compression_disabled(compression_type compression,
// in all subsequent calls with the same compression type
auto const reason = is_compression_disabled_impl(compression, params);
comp_status_reason[{compression, params}] = reason;
memo_map_lock.unlock();

if (reason.has_value()) {
CUDF_LOG_INFO("nvCOMP is disabled for {} compression; reason: {}",
compression_type_name(compression),
Expand Down Expand Up @@ -584,6 +591,9 @@ std::optional<std::string> is_decompression_disabled(compression_type compressio
feature_status_parameters params)
{
static feature_status_memo_map decomp_status_reason;
static std::mutex memo_map_mutex;

std::unique_lock memo_map_lock{memo_map_mutex};
if (auto mem_res_it = decomp_status_reason.find(feature_status_inputs{compression, params});
mem_res_it != decomp_status_reason.end()) {
return mem_res_it->second;
Expand All @@ -593,6 +603,8 @@ std::optional<std::string> is_decompression_disabled(compression_type compressio
// in all subsequent calls with the same compression type
auto const reason = is_decompression_disabled_impl(compression, params);
decomp_status_reason[{compression, params}] = reason;
memo_map_lock.unlock();

if (reason.has_value()) {
CUDF_LOG_INFO("nvCOMP is disabled for {} decompression; reason: {}",
compression_type_name(compression),
Expand Down