diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index bb7ef34..7cb81d7 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -22,12 +22,12 @@ jobs: fail-fast: false matrix: config: - - {runner: macOS-latest, r_version: release, os: macOS} + - {runner: macOS-13, r_version: release, os: macOS} - {runner: [self-hosted, m1], r_version: '', os: macOS} - {runner: windows-2019, r_version: release, os: windows} - {runner: ubuntu-latest, r_version: release, os: ubuntu} - - {runner: [self-hosted, linux], r_version: release, os: ubuntu, cuda: 11.7, cuda_patch: 0} - - {runner: windows-2019, r_version: release, os: windows, cuda: 11.7, cuda_patch: 0} + - {runner: [self-hosted, linux], r_version: release, os: ubuntu, cuda: 11.8, cuda_patch: 0} + - {runner: windows-2019, r_version: release, os: windows, cuda: 11.8, cuda_patch: 0} include: - config: {os: ubuntu} @@ -58,12 +58,12 @@ jobs: DRY_RUN=1 sh ./get-docker.sh - name: Setup cmake - uses: jwlawson/actions-setup-cmake@v1 + uses: jwlawson/actions-setup-cmake@v2 with: - cmake-version: '3.25.2' + cmake-version: 'latest' - if: ${{matrix.config.cuda != ''}} - uses: Jimver/cuda-toolkit@v0.2.8 + uses: Jimver/cuda-toolkit@v0.2.21 id: cuda-toolkit with: cuda: '${{matrix.config.cuda}}.${{matrix.config.cuda_patch}}' @@ -76,8 +76,8 @@ jobs: - name: Install dependencies run: | - Rscript -e "install.packages(c('remotes', 'desc', 'rcmdcheck'))" - Rscript -e "remotes::install_github('mlverse/torchexport')" + Rscript -e "install.packages(c('remotes', 'desc', 'rcmdcheck', 'hms'))" + Rscript -e "remotes::install_github('mlverse/torchexport', force = TRUE)" - run: | cd csrc @@ -102,7 +102,7 @@ jobs: file_glob: true tag: v${{ steps.version.outputs.version }} - - uses: actions/upload-artifact@v3 + - uses: actions/upload-artifact@v4 with: name: ${{ steps.version.outputs.fname }} path: csrc/build/*.zip @@ -117,10 +117,9 @@ jobs: fail-fast: false matrix: config: - - {os: mac, runner: macOS-latest, r: 'release', artifact: '+cpu+x86_64-Darwin.zip'} + - {os: mac, runner: macOS-13, r: 'release', artifact: '+cpu+x86_64-Darwin.zip'} - {os: m1mac, runner: ['self-hosted', 'm1'], artifact: '+cpu+arm64-Darwin.zip'} - {os: windows, runner: windows-latest, r: 'release', rtools: '42', artifact: '+cpu-win64.zip'} - - {os: windows, runner: windows-latest, r: '3.6', artifact: '+cpu-win64.zip'} - {os: ubuntu, runner: ubuntu-20.04, r: 'release', artifact: '+cpu-Linux.zip'} env: @@ -157,7 +156,7 @@ jobs: version=$(Rscript -e "cat(as.character(desc::desc_get_version()))") echo "::set-output name=version::$version" - - uses: actions/download-artifact@v3 + - uses: actions/download-artifact@v4 with: name: 'torchvisionlib-${{ steps.version.outputs.version }}${{ matrix.config.artifact }}' path: build/ diff --git a/DESCRIPTION b/DESCRIPTION index 072ffae..9ace0cd 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: torchvisionlib Title: Additional Operators for Image Models -Version: 0.5.0.9000 +Version: 0.6.0 Authors@R: c( person("Daniel", "Falbel", , "daniel@rstudio.com", role = c("aut", "cre")), person(family = "RStudio", role = c("cph")) @@ -19,7 +19,7 @@ LinkingTo: torch Imports: Rcpp, - torch (>= 0.9.0), + torch (>= 0.14.0), rlang, glue, withr diff --git a/csrc/CMakeLists.txt b/csrc/CMakeLists.txt index 2988cc0..c705c75 100644 --- a/csrc/CMakeLists.txt +++ b/csrc/CMakeLists.txt @@ -41,7 +41,9 @@ message(STATUS "TORCH_HOME=${TORCH_HOME}") if (DEFINED ENV{CUDA} AND NOT '$ENV{CUDA}' STREQUAL '') if (WIN32) - find_package(CUDAToolkit) + find_package(CUDAToolkit REQUIRED) + else() + set(PATCH_CMD git apply ${CMAKE_SOURCE_DIR}/patch/kuint16.patch || true) endif() enable_language(CUDA) endif() @@ -64,13 +66,13 @@ if(WIN32) GIT_TAG v1.6.37 DEPENDS zlib PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libpng" - CMAKE_ARGS ${COMMON_CMAKE_ARGS} -DCMAKE_IGNORE_PATH=C:/rtools40/ucrt64/include -DCMAKE_IGNORE_PATH=C:/rtools43/x86_64-w64-mingw32.static.posix/include -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH};${CURRENT_BINARY_DIR}/lib + CMAKE_ARGS ${COMMON_CMAKE_ARGS} -DCMAKE_IGNORE_PATH=C:/rtools44/x86_64-w64-mingw32.static.posix/include -DCMAKE_PREFIX_PATH=${CMAKE_PREFIX_PATH};${CURRENT_BINARY_DIR}/lib ) ExternalProject_Add(libjpeg GIT_REPOSITORY https://github.com/libjpeg-turbo/libjpeg-turbo GIT_TAG 2.1.2 PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libjpeg" - CMAKE_ARGS ${COMMON_CMAKE_ARGS} -DWITH_JPEG8=0 -DWITH_JPEG7=0 -DENABLE_SHARED=0 -DWITH_TURBOJPEG=0-DCMAKE_IGNORE_PATH=C:/rtools43/x86_64-w64-mingw32.static.posix/include + CMAKE_ARGS ${COMMON_CMAKE_ARGS} -DWITH_JPEG8=0 -DWITH_JPEG7=0 -DENABLE_SHARED=0 -DWITH_TURBOJPEG=0 -DCMAKE_IGNORE_PATH=C:/rtools44/x86_64-w64-mingw32.static.posix/include ) endif() @@ -85,14 +87,17 @@ set(TORCHVISION_CMAKE_ARGS -DCMAKE_PREFIX_PATH:PATH=${CMAKE_PREFIX_PATH}) list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_INSTALL_PREFIX:PATH=${TorchVision_DESTDIR}) if(WIN32) - list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_IGNORE_PREFIX_PATH:PATH=C:/rtools43/x86_64-w64-mingw32.static.posix/) + list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_IGNORE_PREFIX_PATH:PATH=C:/rtools44/x86_64-w64-mingw32.static.posix/) + if (DEFINED ENV{CUDA} AND NOT '$ENV{CUDA}' STREQUAL '') + list(APPEND TORCHVISION_CMAKE_ARGS -DWITH_CUDA=ON) + endif() + elseif(APPLE) list(APPEND TORCHVISION_CMAKE_ARGS -DCMAKE_FIND_FRAMEWORK:STRING=LAST) endif() if (WIN32) set(TORCHVISION_DEPENDS libpng libjpeg) - set(PATCH_CMD git apply ${CMAKE_SOURCE_DIR}/patch/jpeg_types.diff || true) else() set(TORCHVISION_DEPENDS) endif() @@ -100,7 +105,7 @@ endif() message(STATUS "CMAKE_ARGS: ${TORCHVISION_CMAKE_ARGS}") ExternalProject_Add(TorchVision-project GIT_REPOSITORY https://github.com/pytorch/vision - GIT_TAG v0.15.2 + GIT_TAG v0.20.1 DEPENDS ${TORCHVISION_DEPENDS} CMAKE_CACHE_ARGS ${TORCHVISION_CMAKE_ARGS} PREFIX "${CMAKE_CURRENT_BINARY_DIR}/libtorchvision" diff --git a/csrc/patch/kuint16.patch b/csrc/patch/kuint16.patch new file mode 100644 index 0000000..0e67e73 --- /dev/null +++ b/csrc/patch/kuint16.patch @@ -0,0 +1,36 @@ +diff --git a/torchvision/csrc/io/image/cpu/decode_png.cpp b/torchvision/csrc/io/image/cpu/decode_png.cpp +index ede14c1e94..a42bd06c35 100644 +--- a/torchvision/csrc/io/image/cpu/decode_png.cpp ++++ b/torchvision/csrc/io/image/cpu/decode_png.cpp +@@ -195,9 +195,13 @@ torch::Tensor decode_png( + + auto num_pixels_per_row = width * channels; + auto is_16_bits = bit_depth == 16; ++ ++ if (is_16_bits) { ++ throw std::runtime_error("16-bit PNG images are not supported."); ++ } ++ + auto tensor = torch::empty( +- {int64_t(height), int64_t(width), channels}, +- is_16_bits ? at::kUInt16 : torch::kU8); ++ {int64_t(height), int64_t(width), channels}, torch::kU8); + if (is_little_endian()) { + png_set_swap(png_ptr); + } +diff --git a/torchvision/csrc/ops/nms.cpp b/torchvision/csrc/ops/nms.cpp +index 5ecf8812f1..2cbbe93873 100644 +--- a/torchvision/csrc/ops/nms.cpp ++++ b/torchvision/csrc/ops/nms.cpp +@@ -18,11 +18,5 @@ at::Tensor nms( + return op.call(dets, scores, iou_threshold); + } + +-TORCH_LIBRARY_FRAGMENT(torchvision, m) { +- m.set_python_module("torchvision._meta_registrations"); +- m.def(TORCH_SELECTIVE_SCHEMA( +- "torchvision::nms(Tensor dets, Tensor scores, float iou_threshold) -> Tensor")); +-} +- + } // namespace ops + } // namespace vision diff --git a/csrc/patch/nvtx_workaround.diff b/csrc/patch/nvtx_workaround.diff new file mode 100644 index 0000000..f4a573a --- /dev/null +++ b/csrc/patch/nvtx_workaround.diff @@ -0,0 +1,26 @@ +diff --git a/CMakeLists.txt b/CMakeLists.txt +index f243055990..04b06e8335 100644 +--- a/CMakeLists.txt ++++ b/CMakeLists.txt +@@ -15,6 +15,21 @@ option(WITH_WEBP "Enable features requiring LibWEBP." OFF) + option(WITH_AVIF "Enable features requiring LibAVIF." OFF) + + if(WITH_CUDA) ++ if (WIN32) ++ find_package(CUDAToolkit REQUIRED) ++ message(STATUS "PyTorch NVTX headers workaround: Yes") ++ # only do this if nvToolsExt is not defined and CUDA::nvtx3 exists ++ if(NOT TARGET CUDA::nvToolsExt AND TARGET CUDA::nvtx3) ++ add_library(CUDA::nvToolsExt INTERFACE IMPORTED) ++ # ensure that PyTorch is told to use NVTX3 headers ++ target_compile_definitions( ++ CUDA::nvToolsExt INTERFACE ++ TORCH_CUDA_USE_NVTX3 ++ ) ++ target_link_libraries(CUDA::nvToolsExt INTERFACE CUDA::nvtx3) ++ endif() ++ endif() ++ + enable_language(CUDA) + add_definitions(-D__CUDA_NO_HALF_OPERATORS__) + add_definitions(-DWITH_CUDA) diff --git a/csrc/src/ops.cpp b/csrc/src/ops.cpp index 75ad093..46439fa 100644 --- a/csrc/src/ops.cpp +++ b/csrc/src/ops.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -137,4 +138,4 @@ torch::Tensor vision_read_jpeg(std::string fpath) { torch::Tensor vision_read_jpeg_float(std::string fpath) { auto ten = vision_read_jpeg(fpath); return ten.to(torch::kFloat32).div_(255); -} \ No newline at end of file +}