Skip to content

Commit

Permalink
Merge pull request #121 from rapidsai/branch-21.10
Browse files Browse the repository at this point in the history
  • Loading branch information
raydouglass committed Oct 7, 2021
2 parents a89f250 + 4d861fe commit 572520c
Show file tree
Hide file tree
Showing 62 changed files with 2,438 additions and 52 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# cuCIM 21.10.00 (Date TBD)

Please see https://github.com/rapidsai/cucim/releases/tag/v21.10.00a for the latest changes to this development branch.

# cuCIM 21.08.00 (4 Aug 2021)

## 🐛 Bug Fixes
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ include(ExternalProject)
################################################################################
# Options
################################################################################
option(CUCIM_SUPPORT_GDS "Support cufile library" OFF)
option(CUCIM_SUPPORT_GDS "Support cufile library" ON)
option(CUCIM_STATIC_GDS "Use static cufile library" OFF)
option(CUCIM_SUPPORT_CUDA "Support CUDA" ON)

Expand Down
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@
`<CUDA version>` should be 11.0+ (e.g., `11.0`, `11.2`, etc.)

**NOTE:** The first cuCIM conda package (v0.19.0) would be available on 4/19/2021.

#### Conda (nightlies)

> conda create -n cucim -c rapidsai-nightly -c conda-forge cucim cudatoolkit=`<CUDA version>`
Expand Down Expand Up @@ -53,6 +51,7 @@ docker rm -v ${tmp_id}
```

## Build/Install from Source

See build [instructions](CONTRIBUTING.md#setting-up-your-build-environment).

## Contributing Guide
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21.08.01
21.10.00
6 changes: 3 additions & 3 deletions ci/gpu/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ gpuci_logger "Activate conda env"
conda activate rapids

gpuci_logger "Install dependencies"
gpuci_conda_retry install -y -c rapidsai-nightly \
gpuci_mamba_retry install -y -c rapidsai-nightly \
"cudatoolkit=${CUDA_VER}.*" \
"rapids-build-env=$MINOR_VERSION.*"

Expand All @@ -69,7 +69,7 @@ CUCIM_BLD_PATH=/opt/conda/envs/rapids/conda-bld
mkdir -p ${CUCIM_BLD_PATH}


gpuci_conda_retry build -c ${LIBCUCIM_BLD_PATH} -c conda-forge -c rapidsai-nightly \
gpuci_mamba_retry build -c ${LIBCUCIM_BLD_PATH} -c conda-forge -c rapidsai-nightly \
--dirty \
--no-remove-work-dir \
--croot ${CUCIM_BLD_PATH} \
Expand All @@ -82,7 +82,7 @@ gpuci_conda_retry build -c ${LIBCUCIM_BLD_PATH} -c conda-forge -c rapidsai-night

# Install cuCIM and its dependencies
gpuci_logger "Installing cuCIM and its dependencies"
gpuci_conda_retry install -y -c ${LIBCUCIM_BLD_PATH} -c ${CUCIM_BLD_PATH} -c rapidsai-nightly \
gpuci_mamba_retry install -y -c ${LIBCUCIM_BLD_PATH} -c ${CUCIM_BLD_PATH} -c rapidsai-nightly \
"rapids-build-env=$MINOR_VERSION.*" \
libcucim \
cucim
Expand Down
4 changes: 3 additions & 1 deletion cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ add_library(${CUCIM_PACKAGE_NAME}
include/cucim/memory/memory_manager.h
include/cucim/util/cuda.h
include/cucim/util/file.h
include/cucim/util/platform.h
include/cucim/3rdparty/dlpack/dlpack.h
include/cucim/3rdparty/dlpack/dlpackcpp.h
src/cuimage.cpp
Expand Down Expand Up @@ -95,7 +96,8 @@ add_library(${CUCIM_PACKAGE_NAME}
src/logger/logger.cpp
src/logger/timer.cpp
src/memory/memory_manager.cu
src/util/file.cpp)
src/util/file.cpp
src/util/platform.cpp)

# Compile options
set_target_properties(${CUCIM_PACKAGE_NAME}
Expand Down
2 changes: 2 additions & 0 deletions cpp/include/cucim/cuimage.h
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ class EXPORT_VISIBLE CuImage : public std::enable_shared_from_this<CuImage>

void save(std::string file_path) const;

void close();

private:
using Mutex = std::mutex;
using ScopedLock = std::scoped_lock<Mutex>;
Expand Down
32 changes: 32 additions & 0 deletions cpp/include/cucim/util/platform.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright (c) 2021, 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.
*/
//
#ifndef CUCIM_UTIL_PLATFORM_H
#define CUCIM_UTIL_PLATFORM_H

#include "cucim/macros/api_header.h"

/**
* @brief Platform-specific macros and functions.
*/
namespace cucim::util
{

EXPORT_VISIBLE bool is_in_wsl();

} // namespace cucim::util

#endif // CUCIM_UTIL_PLATFORM_H
2 changes: 2 additions & 0 deletions cpp/plugins/cucim.kit.cuslide/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ add_library(${CUCIM_PLUGIN_NAME}
src/cuslide/deflate/deflate.h
src/cuslide/jpeg/libjpeg_turbo.cpp
src/cuslide/jpeg/libjpeg_turbo.h
src/cuslide/raw/raw.cpp
src/cuslide/raw/raw.h
src/cuslide/tiff/ifd.cpp
src/cuslide/tiff/ifd.h
src/cuslide/tiff/tiff.cpp
Expand Down
2 changes: 1 addition & 1 deletion cpp/plugins/cucim.kit.cuslide/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
21.08.01
21.10.00
14 changes: 14 additions & 0 deletions cpp/plugins/cucim.kit.cuslide/src/cuslide/deflate/deflate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,20 @@ bool decode_deflate(int fd,
(void)out_device;
struct libdeflate_decompressor* d;

if (dest == nullptr)
{
throw std::runtime_error("'dest' shouldn't be nullptr in decode_deflate()");
}

// Allocate memory only when dest is not null
if (*dest == nullptr)
{
if ((*dest = (unsigned char*)malloc(dest_nbytes)) == nullptr)
{
throw std::runtime_error("Unable to allocate uncompressed image buffer");
}
}

d = libdeflate_alloc_decompressor();

if (d == nullptr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ bool decode_libjpeg(int fd,
if (size == 0)
THROW("determining input file size", "Input file contains no data");

if (dest == nullptr)
{
THROW("checking dest ptr", "'dest' shouldn't be nullptr in decode_libjpeg()");
}

if (jpeg_buf == nullptr)
{
if ((jpeg_buf = (unsigned char*)tjAlloc(size)) == nullptr)
Expand Down Expand Up @@ -145,7 +150,7 @@ bool decode_libjpeg(int fd,
if (*dest == nullptr)
{
if ((*dest = (unsigned char*)tjAlloc(width * height * tjPixelSize[pixelFormat])) == nullptr)
THROW_UNIX("allocating uncompressed image buffer");
THROW_UNIX("Unable to allocate uncompressed image buffer");
}

if (tjDecompress2(tjInstance, jpeg_buf, size, (unsigned char*)*dest, width, 0, height, pixelFormat, flags) < 0)
Expand Down
85 changes: 85 additions & 0 deletions cpp/plugins/cucim.kit.cuslide/src/cuslide/raw/raw.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
/*
* Apache License, Version 2.0
* Copyright 2021 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.
*/

/**
* Code below is using libdeflate library which is under MIT license
* Please see LICENSE-3rdparty.md for the detail.
*/

#include "raw.h"

#include <cstring>
#include <stdexcept>
#include <unistd.h>


namespace cuslide::raw
{

bool decode_raw(int fd,
unsigned char* raw_buf,
uint64_t offset,
uint64_t size,
uint8_t** dest,
uint64_t dest_nbytes,
const cucim::io::Device& out_device)
{
(void)out_device;

if (dest == nullptr)
{
throw std::runtime_error("'dest' shouldn't be nullptr in decode_raw()");
}

// Allocate memory only when dest is not null
if (*dest == nullptr)
{
if ((*dest = (unsigned char*)malloc(dest_nbytes)) == nullptr)
{
throw std::runtime_error("Unable to allocate uncompressed image buffer");
}
}

if (raw_buf == nullptr)
{
if ((raw_buf = (unsigned char*)malloc(size)) == nullptr)
{
throw std::runtime_error("Unable to allocate buffer for raw data!");
}

if (pread(fd, raw_buf, size, offset) < 1)
{
throw std::runtime_error("Unable to read file for raw data!");
}
}
else
{
fd = -1;
raw_buf += offset;
}

memcpy(*dest, raw_buf, dest_nbytes);

if (fd != -1)
{
free(raw_buf);
}

return true;
}

} // namespace cuslide::raw
33 changes: 33 additions & 0 deletions cpp/plugins/cucim.kit.cuslide/src/cuslide/raw/raw.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Apache License, Version 2.0
* Copyright 2021 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.
*/
#ifndef CUSLIDE_RAW_H
#define CUSLIDE_RAW_H

#include <cucim/io/device.h>

namespace cuslide::raw
{

bool decode_raw(int fd,
unsigned char* raw_buf,
uint64_t offset,
uint64_t size,
uint8_t** dest,
uint64_t dest_nbytes,
const cucim::io::Device& out_device);
}
#endif // CUSLIDE_RAW_H
33 changes: 27 additions & 6 deletions cpp/plugins/cucim.kit.cuslide/src/cuslide/tiff/ifd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

#include "cuslide/jpeg/libjpeg_turbo.h"
#include "cuslide/deflate/deflate.h"
#include "cuslide/raw/raw.h"
#include "tiff.h"


Expand Down Expand Up @@ -151,7 +152,7 @@ bool IFD::read(const TIFF* tiff,
int64_t sy = request->location[1];
int64_t w = request->size[0];
int64_t h = request->size[1];
int32_t n_ch = 3; // number of channels
int32_t n_ch = samples_per_pixel_; // number of channels

size_t raster_size = w * h * samples_per_pixel_;
void* raster = nullptr;
Expand Down Expand Up @@ -365,13 +366,22 @@ const std::vector<uint64_t>& IFD::image_piece_bytecounts() const

bool IFD::is_compression_supported() const
{
return (compression_ == COMPRESSION_ADOBE_DEFLATE || compression_ == COMPRESSION_JPEG ||
compression_ == COMPRESSION_DEFLATE);
switch (compression_)
{
case COMPRESSION_NONE:
case COMPRESSION_JPEG:
case COMPRESSION_ADOBE_DEFLATE:
case COMPRESSION_DEFLATE:
return true;
default:
return false;
}
}

bool IFD::is_read_optimizable() const
{
return is_compression_supported() && bits_per_sample_ == 8 && samples_per_pixel_ == 3 &&
planar_config_ == PLANARCONFIG_CONTIG &&
(tile_width_ != 0 && tile_height_ != 0) && planar_config_ == PLANARCONFIG_CONTIG &&
(photometric_ == PHOTOMETRIC_RGB || photometric_ == PHOTOMETRIC_YCBCR) &&
!tiff_->is_in_read_config(TIFF::kUseLibTiff);
}
Expand Down Expand Up @@ -501,7 +511,12 @@ bool IFD::read_region_tiles(const TIFF* tiff,
tile_data = static_cast<uint8_t*>(image_cache.allocate(tile_raster_nbytes));
}

if (compression_method == COMPRESSION_JPEG)
if (compression_method == COMPRESSION_NONE)
{
cuslide::raw::decode_raw(tiff_file, nullptr, tiledata_offset, tiledata_size, &tile_data,
tile_raster_nbytes, out_device);
}
else if (compression_method == COMPRESSION_JPEG)
{
cuslide::jpeg::decode_libjpeg(tiff_file, nullptr, tiledata_offset, tiledata_size,
jpegtable_data, jpegtable_count, &tile_data, out_device);
Expand Down Expand Up @@ -745,7 +760,13 @@ bool IFD::read_region_tiles_boundary(const TIFF* tiff,
{
tile_data = static_cast<uint8_t*>(image_cache.allocate(tile_raster_nbytes));
}
if (compression_method == COMPRESSION_JPEG)

if (compression_method == COMPRESSION_NONE)
{
cuslide::raw::decode_raw(tiff_file, nullptr, tiledata_offset, tiledata_size, &tile_data,
tile_raster_nbytes, out_device);
}
else if (compression_method == COMPRESSION_JPEG)
{
cuslide::jpeg::decode_libjpeg(tiff_file, nullptr, tiledata_offset, tiledata_size,
jpegtable_data, jpegtable_count, &tile_data, out_device);
Expand Down
Loading

0 comments on commit 572520c

Please sign in to comment.