Skip to content

Commit ee285f4

Browse files
committed
HMMM
1 parent 4025de7 commit ee285f4

4 files changed

Lines changed: 70 additions & 10 deletions

File tree

.github/workflows/linux_rocm.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,12 @@ jobs:
115115
# Prevent the checked-out src/ tree from shadowing the installed wheel.
116116
bash packaging/remove_src.sh
117117
118+
echo '::group::Install rocJPEG runtime'
119+
# The wheel deliberately does not bundle librocjpeg (see repair_wheel.py),
120+
# so decode_jpeg(device="cuda") needs it present at runtime.
121+
bash packaging/install_rocjpeg.sh
122+
echo '::endgroup::'
123+
118124
echo '::group::Install torchcodec from the wheel'
119125
python -m pip install "${RUNNER_ARTIFACT_DIR}"/*.whl -vvv
120126
echo '::endgroup::'

packaging/install_rocjpeg.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/usr/bin/env bash
2+
# Copyright (c) Meta Platforms, Inc. and affiliates.
3+
# All rights reserved.
4+
#
5+
# This source code is licensed under the BSD-style license found in the
6+
# LICENSE file in the root directory of this source tree.
7+
8+
# Installs the rocJPEG SDK (GPU JPEG decoder), the ROCm counterpart of nvJPEG.
9+
#
10+
# rocJPEG is NOT preinstalled in the pytorch/manylinux2_28-builder:rocmX.Y
11+
# images (torchvision's build logs show it silently building "without ROCJPEG
12+
# support" there), even though ROCm itself is. Both the build (to compile
13+
# DecodeJpegRocm.cpp) and the runtime (we don't bundle librocjpeg into the wheel)
14+
# need it, so we install it from the ROCm dnf repo that ships in those images.
15+
# libva-amdgpu-devel is a rocJPEG dependency. Mirrors pytorch/vision's
16+
# "Install rocJPEG SDK" step.
17+
18+
set -euo pipefail
19+
20+
dnf install -y libva-amdgpu-devel rocjpeg-devel

packaging/pre_build_script.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,10 @@
88
set -ex
99

1010
bash packaging/install_build_dependencies.sh
11+
12+
# On ROCm wheel builds (CU_VERSION is e.g. "rocm7.1"), install the rocJPEG SDK so
13+
# the GPU JPEG decoder compiles. It's not preinstalled in the manylinux ROCm
14+
# images. Runs in the same container that then compiles the wheel.
15+
if [[ "${CU_VERSION:-}" == rocm* ]]; then
16+
bash packaging/install_rocjpeg.sh
17+
fi

src/torchcodec/_core/CMakeLists.txt

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -568,32 +568,59 @@ function(make_torchcodec_image_library)
568568
# device="cuda") routes to the same decode_jpegs_cuda op, backed by rocJPEG.
569569
resolve_image_codec("${TORCHCODEC_BUILD_ROCJPEG}" want_rocjpeg)
570570
if(ENABLE_ROCM AND want_rocjpeg)
571-
if(DEFINED ENV{ROCM_PATH})
572-
set(ROCM_PATH "$ENV{ROCM_PATH}")
573-
elseif(NOT DEFINED ROCM_PATH)
574-
set(ROCM_PATH "/opt/rocm")
571+
# Resolve the ROCm install root. torch's ROCM_HOME is the source of truth
572+
# torchvision uses and it handles versioned installs (e.g. /opt/rocm-7.2.0)
573+
# that a bare /opt/rocm may not point at. We fall back to the usual env
574+
# vars and /opt/rocm* globs if torch can't tell us.
575+
set(_rocm_candidates "")
576+
execute_process(
577+
COMMAND "${Python3_EXECUTABLE}" -c
578+
"from torch.utils.cpp_extension import ROCM_HOME; print(ROCM_HOME or '')"
579+
OUTPUT_VARIABLE _torch_rocm_home
580+
OUTPUT_STRIP_TRAILING_WHITESPACE
581+
ERROR_QUIET)
582+
if(_torch_rocm_home)
583+
list(APPEND _rocm_candidates "${_torch_rocm_home}")
575584
endif()
585+
foreach(_var ROCM_HOME ROCM_PATH HIP_PATH)
586+
if(DEFINED ENV{${_var}})
587+
list(APPEND _rocm_candidates "$ENV{${_var}}")
588+
endif()
589+
endforeach()
590+
file(GLOB _rocm_globs "/opt/rocm" "/opt/rocm-*")
591+
list(APPEND _rocm_candidates ${_rocm_globs})
592+
list(REMOVE_DUPLICATES _rocm_candidates)
593+
set(ROCM_PATH "")
594+
foreach(_cand ${_rocm_candidates})
595+
if(IS_DIRECTORY "${_cand}")
596+
set(ROCM_PATH "${_cand}")
597+
break()
598+
endif()
599+
endforeach()
600+
message(STATUS "ROCm candidates: ${_rocm_candidates} -> using ROCM_PATH=${ROCM_PATH}")
601+
576602
# So find_package(hip) locates ${ROCM_PATH}/lib/cmake/hip/hip-config.cmake.
577603
list(APPEND CMAKE_PREFIX_PATH "${ROCM_PATH}")
578604
find_package(hip REQUIRED)
579605
find_path(ROCJPEG_INCLUDE_DIR
580606
NAMES rocjpeg/rocjpeg.h
581-
PATHS "${ROCM_PATH}/include")
607+
HINTS "${ROCM_PATH}/include" "${ROCM_PATH}")
582608
find_library(ROCJPEG_LIBRARY
583609
NAMES rocjpeg
584-
PATHS "${ROCM_PATH}/lib")
610+
HINTS "${ROCM_PATH}/lib" "${ROCM_PATH}/lib64" "${ROCM_PATH}")
585611
if(NOT ROCJPEG_INCLUDE_DIR OR NOT ROCJPEG_LIBRARY)
586612
message(FATAL_ERROR
587-
"rocJPEG not found (looked under ${ROCM_PATH}), but ROCm GPU JPEG "
588-
"decoding is enabled. Install the rocJPEG runtime and dev headers, "
589-
"or set TORCHCODEC_BUILD_ROCJPEG=0 to build without it "
613+
"rocJPEG not found (searched ROCm roots: ${_rocm_candidates}). "
614+
"include=${ROCJPEG_INCLUDE_DIR} lib=${ROCJPEG_LIBRARY}. Install the "
615+
"rocJPEG runtime and dev headers (e.g. the 'rocjpeg' / 'rocjpeg-devel' "
616+
"package), or set TORCHCODEC_BUILD_ROCJPEG=0 to build without it "
590617
"(decode_jpeg(device='cuda') will raise at runtime).")
591618
endif()
592619
target_include_directories(${image_library_name} PRIVATE ${ROCJPEG_INCLUDE_DIR})
593620
target_link_libraries(${image_library_name} PRIVATE ${ROCJPEG_LIBRARY} hip::host)
594621
target_compile_definitions(${image_library_name} PRIVATE
595622
TORCHCODEC_ENABLE_ROCJPEG=1 USE_ROCM __HIP_PLATFORM_AMD__)
596-
message(STATUS "Building torchcodec with rocJPEG GPU JPEG decoding support.")
623+
message(STATUS "Building torchcodec with rocJPEG GPU JPEG decoding support (${ROCJPEG_LIBRARY}).")
597624
elseif(ENABLE_ROCM)
598625
message(STATUS "Not building torchcodec with rocJPEG support (disabled via TORCHCODEC_BUILD_ROCJPEG/TORCHCODEC_BUILD_IMAGE): decode_jpeg(device='cuda') will raise at runtime.")
599626
endif()

0 commit comments

Comments
 (0)