Skip to content
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion cmake/Dependencies.common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ if(BUILD_NVCOMP)
list(APPEND DALI_LIBS ${nvcomp_LIBS})
else()
message(STATUS "Found nvCOMP: ${nvcomp_INCLUDE_DIR}.")
set(DALI_INSTALL_REQUIRES_NVCOMP "\'nvidia-libnvcomp-cu${CUDA_VERSION_MAJOR} == 5.2.0.13\',")
set(DALI_INSTALL_REQUIRES_NVCOMP "\'nvidia-libnvcomp-cu${CUDA_VERSION_MAJOR} == 5.3.0.16\',")
message(STATUS "Adding nvComp requirement as: ${DALI_INSTALL_REQUIRES_NVCOMP}")
endif()
endif()
Expand Down
6 changes: 6 additions & 0 deletions dali/operators/decoder/inflate/inflate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ concatenating compressed frames from the corresponding sequences.::
.NumOutput(1)
.AddArg(inflate::shapeArgName, "The shape of the output (inflated) chunk.", DALI_INT_VEC, true)
.AddOptionalTypeArg(inflate::dTypeArgName, "The output (inflated) data type.", DALI_UINT8)
.AddOptionalArg<bool>(inflate::checkOutputSizeArgName,
R"code(If True, validates before decompression that the requested output
buffers are large enough for the compressed data.

This validation synchronizes the GPU stream and is disabled by default.)code",
false)
Comment on lines +57 to +62

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@stiepan did we have a discussion about this unsafe behavior and potential switch for that or I mixing things?

.AddOptionalArg<std::vector<int>>(inflate::offsetArgName,
R"code(A list of offsets within the input sample
describing where the consecutive chunks begin.
Expand Down
31 changes: 30 additions & 1 deletion dali/operators/decoder/inflate/inflate_gpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,9 @@ namespace inflate {

class InflateOpGpuLZ4Impl : public InflateOpImplBase<GPUBackend> {
public:
explicit InflateOpGpuLZ4Impl(const OpSpec &spec) : InflateOpImplBase<GPUBackend>{spec} {}
explicit InflateOpGpuLZ4Impl(const OpSpec &spec)
: InflateOpImplBase<GPUBackend>{spec},
check_output_size_{spec.GetArgument<bool>(inflate::checkOutputSizeArgName)} {}

void RunImpl(Workspace &ws) override {
const auto &input = ws.template Input<GPUBackend>(0);
Expand All @@ -57,6 +59,32 @@ class InflateOpGpuLZ4Impl : public InflateOpImplBase<GPUBackend> {
auto [in_sizes, in, out_sizes, out] = scratchpad.ToContiguousGPU(
stream, params_.GetInChunkSizes(), input_ptrs_, inflated_sizes_, inflated_ptrs_);

if (check_output_size_) {
// Query the decoded sizes before decompression. nvCOMP's decompression API documents an
// insufficient output buffer as undefined behaviour for some backends, so relying on its
// per-chunk status is not safe here.
CUDA_CALL(nvcompBatchedLZ4GetDecompressSizeAsync(in, in_sizes, actual_out_sizes,
total_chunks_num, stream));
std::vector<size_t> decoded_sizes(total_chunks_num);
CUDA_CALL(cudaMemcpyAsync(decoded_sizes.data(), actual_out_sizes,
total_chunks_num * sizeof(size_t), cudaMemcpyDeviceToHost, stream));
CUDA_CALL(cudaStreamSynchronize(stream));
size_t flat_chunk_idx = 0;
const auto &chunks_per_sample = params_.GetChunksNumPerSample();
for (int sample_idx = 0; sample_idx < chunks_per_sample.num_samples(); sample_idx++) {
auto num_chunks = chunks_per_sample[sample_idx].num_elements();
for (int chunk_idx = 0; chunk_idx < num_chunks; chunk_idx++, flat_chunk_idx++) {
DALI_ENFORCE(
decoded_sizes[flat_chunk_idx] <= inflated_sizes_[flat_chunk_idx],
make_string("Output buffer for inflated chunk ", chunk_idx, " in sample ", sample_idx,
" is too small: it has ", inflated_sizes_[flat_chunk_idx],
" bytes, but the compressed input expands to ",
decoded_sizes[flat_chunk_idx],
" bytes. Check the `shape` and `dtype` arguments."));
}
}
Comment thread
JanuszL marked this conversation as resolved.
}

size_t tempSize;
CUDA_CALL(nvcompBatchedLZ4DecompressGetTempSizeAsync(
total_chunks_num,
Expand Down Expand Up @@ -131,6 +159,7 @@ class InflateOpGpuLZ4Impl : public InflateOpImplBase<GPUBackend> {
std::vector<const void *> input_ptrs_;
std::vector<void *> inflated_ptrs_;
std::vector<size_t> inflated_sizes_;
bool check_output_size_;
};

} // namespace inflate
Expand Down
1 change: 1 addition & 0 deletions dali/operators/decoder/inflate/inflate_params.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ constexpr static const char *offsetArgName = "chunk_offsets";
constexpr static const char *sizeArgName = "chunk_sizes";
constexpr static const char *layoutArgName = "layout";
constexpr static const char *sequenceLayoutArgName = "sequence_axis_name";
constexpr static const char *checkOutputSizeArgName = "check_output_size";

enum class InflateAlg {
LZ4
Expand Down
40 changes: 39 additions & 1 deletion dali/test/python/operator_1/test_inflate.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -129,6 +129,44 @@ def test_sample_inflate():
seed += 1


@has_operator("decoders.inflate")
@restrict_platform(min_compute_cap=6.0)
def test_rejects_insufficient_output_buffer():
sample = np.full((13, 7), 42, dtype=np.int64)
deflated = sample_to_lz4(sample)

@pipeline_def(batch_size=1, num_threads=4, device_id=0)
def pipeline():
compressed = fn.external_source(source=lambda: deflated, batch=False)
# dtype defaults to uint8, which is too small for the int64 LZ4 payload.
return fn.decoders.inflate(compressed.gpu(), shape=sample.shape, check_output_size=True)

with assert_raises(
RuntimeError, glob="Output buffer for inflated chunk 0 in sample 0 is too small"
):
pipeline().run()
Comment thread
JanuszL marked this conversation as resolved.


@has_operator("decoders.inflate")
@restrict_platform(min_compute_cap=6.0)
def test_checks_sufficient_output_buffer():
sample = np.full((13, 7), 42, dtype=np.int64)
deflated = sample_to_lz4(sample)

@pipeline_def(batch_size=1, num_threads=4, device_id=0)
def pipeline():
compressed = fn.external_source(source=lambda: deflated, batch=False)
return fn.decoders.inflate(
compressed.gpu(),
shape=sample.shape,
dtype=types.INT64,
check_output_size=True,
)

(inflated,) = pipeline().run()
check_batch(inflated, [sample], batch_size=1)


def _test_scalar_shape(dtype, shape, layout):
def sample_source(sample_info):
sample_size = np.prod(shape)
Expand Down
2 changes: 1 addition & 1 deletion dali/test/python/test_dali_variable_batch_size.py
Original file line number Diff line number Diff line change
Expand Up @@ -1460,7 +1460,7 @@ def inflate_pipline(max_batch_size, inputs, device):
def piepline():
defalted = fn.external_source(source=input_data)
shape = fn.external_source(source=input_shape)
return fn.decoders.inflate(defalted.gpu(), shape=shape)
return fn.decoders.inflate(defalted.gpu(), shape=shape, dtype=types.INT64)

return piepline(batch_size=max_batch_size, num_threads=4, device_id=0)

Expand Down
8 changes: 4 additions & 4 deletions docker/Dockerfile.cuda129.aarch64.deps
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN curl -LO https://developer.download.nvidia.com/compute/cuda/12.9.1/local_ins
rm -f cuda_*.run;

RUN CUFILE_VERSION=1.14.1.1-1 && \
NVCOMP_VERSION=4.2.0.11-1 && \
NVCOMP_VERSION=5.3.0.16 && \
CUDA_VERSION_MAJOR=12 && \
CUDA_VERSION_MINOR=9 && \
apt-get update && \
Expand All @@ -22,9 +22,9 @@ RUN CUFILE_VERSION=1.14.1.1-1 && \
apt-get update && \
apt-get install libcufile-dev-${CUDA_VERSION_MAJOR}-${CUDA_VERSION_MINOR}=${CUFILE_VERSION} -y && \
mkdir /tmp/nvcomp && cd /tmp/nvcomp && \
wget https://developer.download.nvidia.com/compute/nvcomp/redist/nvcomp/linux-sbsa/nvcomp-linux-sbsa-5.2.0.10_cuda12-archive.tar.xz && \
wget https://developer.download.nvidia.com/compute/nvcomp/redist/nvcomp/linux-sbsa/nvcomp-linux-sbsa-${NVCOMP_VERSION}_cuda12-archive.tar.xz && \
tar -xf * && \
cp -r nvcomp-linux-sbsa-5.2.0.10_cuda12-archive/include/* /usr/local/cuda/include/ && \
cp -r nvcomp-linux-sbsa-5.2.0.10_cuda12-archive/lib/* /usr/local/cuda/lib64/ && \
cp -r nvcomp-linux-sbsa-${NVCOMP_VERSION}_cuda12-archive/include/* /usr/local/cuda/include/ && \
cp -r nvcomp-linux-sbsa-${NVCOMP_VERSION}_cuda12-archive/lib/* /usr/local/cuda/lib64/ && \
cd / && rm -rf /tmp/nvcomp && \
rm -rf /var/lib/apt/lists/*
8 changes: 4 additions & 4 deletions docker/Dockerfile.cuda129.x86_64.deps
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ RUN curl -LO https://developer.download.nvidia.com/compute/cuda/12.9.1/local_ins
rm -f cuda_*.run;

RUN CUFILE_VERSION=1.14.1.1-1 && \
NVCOMP_VERSION=4.2.0.11-1 && \
NVCOMP_VERSION=5.3.0.16 && \
CUDA_VERSION_MAJOR=12 && \
CUDA_VERSION_MINOR=9 && \
apt-get update && \
Expand All @@ -22,9 +22,9 @@ RUN CUFILE_VERSION=1.14.1.1-1 && \
apt-get update && \
apt-get install libcufile-dev-${CUDA_VERSION_MAJOR}-${CUDA_VERSION_MINOR}=${CUFILE_VERSION} -y && \
mkdir /tmp/nvcomp && cd /tmp/nvcomp && \
wget https://developer.download.nvidia.com/compute/nvcomp/redist/nvcomp/linux-x86_64/nvcomp-linux-x86_64-5.2.0.10_cuda12-archive.tar.xz && \
wget https://developer.download.nvidia.com/compute/nvcomp/redist/nvcomp/linux-x86_64/nvcomp-linux-x86_64-${NVCOMP_VERSION}_cuda12-archive.tar.xz && \
tar -xf * && \
cp -r nvcomp-linux-x86_64-5.2.0.10_cuda12-archive/include/* /usr/local/cuda/include/ && \
cp -r nvcomp-linux-x86_64-5.2.0.10_cuda12-archive/lib/* /usr/local/cuda/lib64/ && \
cp -r nvcomp-linux-x86_64-${NVCOMP_VERSION}_cuda12-archive/include/* /usr/local/cuda/include/ && \
cp -r nvcomp-linux-x86_64-${NVCOMP_VERSION}_cuda12-archive/lib/* /usr/local/cuda/lib64/ && \
cd / && rm -rf /tmp/nvcomp && \
rm -rf /var/lib/apt/lists/*
7 changes: 4 additions & 3 deletions docker/Dockerfile.cuda133.aarch64.deps
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN CUDA_SUBVERSION=13.3.1-1 && \
CUFILE_VERSION=1.18.1.6-1 && \
CUDA_VERSION_MAJOR=13 && \
CUDA_VERSION_MINOR=3 && \
NVCOMP_VERSION=5.3.0.16 && \
apt-get update && \
apt-get install wget software-properties-common -y && \
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/sbsa/3bf863cc.pub && \
Expand All @@ -29,10 +30,10 @@ RUN CUDA_SUBVERSION=13.3.1-1 && \
cuda-compat-${CUDA_VERSION_MAJOR}-${CUDA_VERSION_MINOR} \
libcufile-dev-${CUDA_VERSION_MAJOR}-${CUDA_VERSION_MINOR}=${CUFILE_VERSION} && \
mkdir /tmp/nvcomp && cd /tmp/nvcomp && \
wget https://developer.download.nvidia.com/compute/nvcomp/redist/nvcomp/linux-sbsa/nvcomp-linux-sbsa-5.2.0.10_cuda13-archive.tar.xz && \
wget https://developer.download.nvidia.com/compute/nvcomp/redist/nvcomp/linux-sbsa/nvcomp-linux-sbsa-${NVCOMP_VERSION}_cuda13-archive.tar.xz && \
tar -xf * && \
cp -r nvcomp-linux-sbsa-5.2.0.10_cuda13-archive/include/* /usr/local/cuda/include/ && \
cp -r nvcomp-linux-sbsa-5.2.0.10_cuda13-archive/lib/* /usr/local/cuda/lib64/ && \
cp -r nvcomp-linux-sbsa-${NVCOMP_VERSION}_cuda13-archive/include/* /usr/local/cuda/include/ && \
cp -r nvcomp-linux-sbsa-${NVCOMP_VERSION}_cuda13-archive/lib/* /usr/local/cuda/lib64/ && \
cd / && rm -rf /tmp/nvcomp && \
mv /usr/local/cuda/bin/fatbinary /usr/local/cuda/bin/fatbinary_org && \
# fatbinary removed one of the options while clang still uses it
Expand Down
7 changes: 4 additions & 3 deletions docker/Dockerfile.cuda133.x86_64.deps
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ RUN CUDA_SUBVERSION=13.3.1-1 && \
CUFILE_VERSION=1.18.1.6-1 && \
CUDA_VERSION_MAJOR=13 && \
CUDA_VERSION_MINOR=3 && \
NVCOMP_VERSION=5.3.0.16 && \
apt-get update && \
apt-get install wget software-properties-common -y && \
apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub && \
Expand All @@ -29,10 +30,10 @@ RUN CUDA_SUBVERSION=13.3.1-1 && \
cuda-compat-${CUDA_VERSION_MAJOR}-${CUDA_VERSION_MINOR} \
libcufile-dev-${CUDA_VERSION_MAJOR}-${CUDA_VERSION_MINOR}=${CUFILE_VERSION} && \
mkdir /tmp/nvcomp && cd /tmp/nvcomp && \
wget https://developer.download.nvidia.com/compute/nvcomp/redist/nvcomp/linux-x86_64/nvcomp-linux-x86_64-5.2.0.10_cuda13-archive.tar.xz && \
wget https://developer.download.nvidia.com/compute/nvcomp/redist/nvcomp/linux-x86_64/nvcomp-linux-x86_64-${NVCOMP_VERSION}_cuda13-archive.tar.xz && \
tar -xf * && \
cp -r nvcomp-linux-x86_64-5.2.0.10_cuda13-archive/include/* /usr/local/cuda/include/ && \
cp -r nvcomp-linux-x86_64-5.2.0.10_cuda13-archive/lib/* /usr/local/cuda/lib64/ && \
cp -r nvcomp-linux-x86_64-${NVCOMP_VERSION}_cuda13-archive/include/* /usr/local/cuda/include/ && \
cp -r nvcomp-linux-x86_64-${NVCOMP_VERSION}_cuda13-archive/lib/* /usr/local/cuda/lib64/ && \
cd / && rm -rf /tmp/nvcomp && \
mv /usr/local/cuda/bin/fatbinary /usr/local/cuda/bin/fatbinary_org && \
# fatbinary removed one of the options while clang still uses it
Expand Down
1 change: 1 addition & 0 deletions internal_tools/stub_generator/nvcomp.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"functions": {
"nvcompBatchedLZ4DecompressGetTempSizeAsync": {},
"nvcompBatchedLZ4DecompressAsync": {},
"nvcompBatchedLZ4GetDecompressSizeAsync": {},
"nvcompGetStatusString": {
"return_type":"const char*",
"not_found_error":"\"(nvcompGetStatusString not available)\""
Expand Down