Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion dali/operators/decoder/inflate/inflate.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ namespace inflate {
template <typename Backend>
class InflateOpImplBase : public OpImplBase<Backend> {
public:
explicit InflateOpImplBase(const OpSpec &spec) : params_{spec} {
explicit InflateOpImplBase(const OpSpec &spec)
: check_output_size_{spec.GetArgument<bool>(inflate::checkOutputSizeArgName)},
params_{spec} {
dtype_ = spec.GetArgument<DALIDataType>(inflate::dTypeArgName);
DALI_ENFORCE(
IsFloatingPoint(dtype_) || IsIntegral(dtype_),
Expand Down Expand Up @@ -64,6 +66,7 @@ class InflateOpImplBase : public OpImplBase<Backend> {
protected:
DALIDataType dtype_;
TypeInfo element_type_;
bool check_output_size_;
inflate::ShapeParams<Backend> params_;
};

Expand Down
20 changes: 20 additions & 0 deletions dali/operators/decoder/inflate/inflate_gpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ 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));
for (size_t chunk_idx = 0; chunk_idx < total_chunks_num; chunk_idx++) {
DALI_ENFORCE(
decoded_sizes[chunk_idx] <= inflated_sizes_[chunk_idx],
make_string("Output buffer for inflated chunk ", chunk_idx, " is too small: it has ",
inflated_sizes_[chunk_idx], " bytes, but the compressed input expands to ",
decoded_sizes[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
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
16 changes: 16 additions & 0 deletions dali/test/python/operator_1/test_inflate.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,22 @@ 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 is too small"):
pipeline().run()
Comment thread
JanuszL marked this conversation as resolved.


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