Skip to content

Commit

Permalink
Make is_decompression_disabled and is_compression_disabled thread…
Browse files Browse the repository at this point in the history
…-safe (#13240)

Adds a mutex to guard the use of the memoization map for the status of nvCOMP features.

Authors:
  - Vukasin Milovanovic (https://github.com/vuule)

Approvers:
  - Alessandro Bellina (https://github.com/abellina)
  - Nghia Truong (https://github.com/ttnghia)

URL: #13240
  • Loading branch information
vuule authored Apr 28, 2023
1 parent ca2ca37 commit c93d800
Showing 1 changed file with 12 additions and 0 deletions.
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

0 comments on commit c93d800

Please sign in to comment.