Verify the loaded nvImageCodec version at runtime, and consolidate nvimgcodec.cmake #1148
Thank you @cdinea for the change!
AI-assisted review. No actionable correctness defect was identified in this review. There is no finding to anchor inline, so this is a summary-only review; no formal approval is implied.
Reviewed commit: 84cda22c703f1d1463dca9ffd868222e803ec5dc. The PR description was read before the diff; the current head and inline locations were rechecked before publication.
Validation and limitations: The actual version helper bodies passed a host C++17 harness using the vendored version macros, a properties-API stub, and a formatting stand-in. Supported/unsupported versions, packed values 0 through 2500, and query failure were covered. This does not validate a real nvImageCodec binary ABI, dynamic-library load, full cuslide2/Catch2 build, or GPU decoding.
This is a non-blocking COMMENT review, not an approval or formal request for changes. No implementation changes or fixes were applied.
<details>
<summary>Review scope and additional context</summary>
Scope and method
Ran gh pr checkout 1148, read gh pr view 1148, then reviewed gh pr diff 1148 --color never. Reviewed all six changed files, including the deleted dependency module, and traced the runtime query, dynamic symbol wrapper, constructor failure path, version macros, dependency pins, and plugin build flow.
No corrective implementation diff is proposed because this review did not establish a concrete defect. The excerpts below document the reviewed behavior; they are not independently applicable patches.
Runtime version check
Relevant additions
cpp/plugins/cucim.kit.cuslide2/src/cuslide/nvimgcodec/nvimgcodec_tiff_parser.cpp:79-80,98-101:
--- a/cpp/plugins/cucim.kit.cuslide2/src/cuslide/nvimgcodec/nvimgcodec_tiff_parser.cpp
+++ b/cpp/plugins/cucim.kit.cuslide2/src/cuslide/nvimgcodec/nvimgcodec_tiff_parser.cpp
@@ -71,0 +79,2 @@
+static constexpr uint32_t kMinNvimgcodecVersion = MAKE_SEMANTIC_VERSION(0, 9, 0);
+static constexpr uint32_t kFirstUnsupportedNvimgcodecVersion = MAKE_SEMANTIC_VERSION(0, 10, 0);
@@ -71,0 +98,4 @@
+bool is_supported_nvimgcodec_version(uint32_t packed_version)
+{
+ return packed_version >= kMinNvimgcodecVersion && packed_version < kFirstUnsupportedNvimgcodecVersion;
+}
The runtime query initializes the API structure before calling the dynamically resolved function:
--- a/cpp/plugins/cucim.kit.cuslide2/src/cuslide/nvimgcodec/nvimgcodec_tiff_parser.cpp
+++ b/cpp/plugins/cucim.kit.cuslide2/src/cuslide/nvimgcodec/nvimgcodec_tiff_parser.cpp
@@ -71,0 +122,6 @@
+ nvimgcodecProperties_t properties{};
+ properties.struct_type = NVIMGCODEC_STRUCTURE_TYPE_PROPERTIES;
+ properties.struct_size = sizeof(nvimgcodecProperties_t);
+ properties.struct_next = nullptr;
+
+ const nvimgcodecStatus_t status = nvimgcodecGetProperties(&properties);
Assessment
major 1000 + minor 100 + patch; the intended supported packed interval is [900, 1000).>=0.9.0,<0.10.0 dependency declarations in dependencies.yaml and the vendored 0.9.0 header.nvimgcodec_tiff_parser.cpp:407-426). A version failure leaves initialized_ false and records the detailed message.NVIMGCODEC_STATUS_IMPLEMENTATION_UNSUPPORTED, so the new call does not unconditionally invoke a null function pointer (nvimgcodec_stubs_generated.cc:10-19).DEBUG: TiffFileParser throws the manager status (nvimgcodec_tiff_parser.cpp:578-584), and the TIFF constructor rethrows it with the file context (tiff.cpp:331-351).CMake consolidation
The new conda-build branch uses the host/install prefix rather than the active build environment:
--- a/cpp/plugins/cucim.kit.cuslide2/cmake/deps/nvimgcodec.cmake
+++ b/cpp/plugins/cucim.kit.cuslide2/cmake/deps/nvimgcodec.cmake
@@ -85,1 +98,6 @@
- if (DEFINED ENV{CONDA_PREFIX})
+ if (DEFINED ENV{CONDA_BUILD})
+ # Inside conda-build, CONDA_PREFIX points at the build environment
+ # rather than the install prefix, so use PREFIX instead.
+ _cucim_find_nvimgcodec_library(NVIMGCODEC_LIB_PATH "$ENV{PREFIX}/lib")
+ set(NVIMGCODEC_INCLUDE_PATH "$ENV{PREFIX}/include/")
+ elseif (DEFINED ENV{CONDA_PREFIX})
Checked the deletion against the repository's current build flow:
superbuild_depend(nvimgcodec) call is in the cuslide2 project.run script configures cuslide2 as a separate CMake project.No regression was identified in these changes.
Validation performed
Compiled the actual version-check helper bodies extracted from the reviewed Git object into a C++17 host harness with:
nvimgcodec_version.h macros.The harness passed:
1. Supported/unsupported version-query cases for packed values 700, 800, 899, 900, 901, 999, 1000, and 2304.
2. A complete packed-value sweep from 0 through 2500, accepting exactly [900, 1000).
3. Acceptance of the vendored NVIMGCODEC_VER.
4. The documented 0.10.0/1.0.0 packed collision.
5. A non-success properties response, checking that the status and supported range appear in the error.
6. Required range and loader-path guidance in unsupported-version diagnostics.
The harness compiled with clang++ -std=c++17 -Wall -Wextra -Werror and ran successfully. It does not replace a full cuslide2 build or live-library test.
Remaining integration coverage
cuslide2_tests executable with the Catch2 filter [test_nvimgcodec_version.cpp].CuImage error includes the observed version/status and supported range.PREFIX and CONDA_PREFIX values.dependencies.yaml.No source files were modified, and no real GPU decoding, installed-library loading, or full Catch2 suite was executed on this macOS machine.
</details>
Non-blocking, for future consideration: this test pins the same boundaries as the C++ implementation, but it does not inspect dependencies.yaml, so it cannot detect packaging-pin drift by itself. For example, packaging could move to >=0.10.0,<0.11.0 while this helper and test remain unchanged and continue passing. For this PR, I suggest renaming the test to describe the runtime policy (for example, “supported nvImageCodec runtime range is 0.9.x”) and avoiding the claim that it catches YAML drift. A separate CI consistency check or generated source of truth could enforce that later.
This ambiguity is an nvImageCodec bug rather than something cuCIM can resolve from the packed value. It should be fixed in nvImageCodec 0.10.0 by replacing MAKE_SEMANTIC_VERSION with NVIMGCODEC_MAKE_SEMANTIC_VERSION and changing the encoding to major 10000 + minor 100 + patch. This preserves 0.9.0 == 900 and 0.10.0 == 1000, while making 1.0.0 == 10000.
Until cuCIM adopts the 0.10 header, packed value 1000 remains ambiguous to its current formatter. Could this diagnostic therefore avoid claiming the loaded version is exactly 1.0.0, and report the raw/ambiguous value instead? The range rejection itself is correct.
thank you for the feedback @smatysik-nv - I think I addressed this in this commit 7c219ba: the diagnostic now reports the raw packed value and notes the ambiguity instead of identifying it as exactly 1.0.0. The range check remains unchanged, and I added regression coverage for ambiguous values, including 1000.
thank you for the review @smatysik-nv - yes, the test verifies the runtime policy but cannot detect packaging-pin drift. Addressed in the previous 7c219ba commit : renamed it to “supported nvImageCodec runtime range is 0.9.x” and updated the comments to ctlarify that checking consistency with the packaging pin requires a separate check
thank you for the review @gigony amd @smatysik-nv - I believe I addressed all the feedback.Please take a look and let me know if there are any other concerns
Thank you @cdinea for this change! It looks good to me.
/ok to test 63fde53
/ok to test 4fa6169
/ok to test 0c21dac
/merge
gigony
cdinea
Summary
Follow-up to @mkepa-nv's review feedback on the nvImageCodec SONAME candidates:
Both parts are here: the runtime
getPropertiescheck, and the consolidation of the twonvimgcodec.cmakecopies.Why the runtime check is the one that matters
Investigating this turned out to justify the suggestion more strongly than I expected. The configure-time header check I added in the previous PR is bypassed entirely in the default build:
WITH_DYNAMIC_NVIMGCODECdefaults to ON (cuslide2/CMakeLists.txt:216), so nvImageCodec isdlopen'd at runtime anddeps::nvimgcodecis not linked at all.libnvimgcodec.so.0andlibnvimgcodec.so, which resolve to whichever major-0 build is installed.So the version found at configure time need not be the version loaded, and an unsupported library surfaces as a missing symbol or as wrong behaviour partway through a decode. Asking the library its own version is the only dependable check — exactly as suggested.
What the check does
NvImageCodecTiffParserManager's constructor now callsnvimgcodecGetProperties()before creating an instance, and rejects anything outside>=0.9.0,<0.10.0.That constructor is a good fit for this: it is the single point every read path passes through exactly once (
CuImage→parser_open→TIFF→TiffFileParser→manager.instance()), and it already reports failure by settingstatus_message_and returning, whichTiffFileParserturns into an exception. So an unsupported install now fails at open with one clear message naming the version found and pointing atLD_LIBRARY_PATHand thelibnvimgcodec.sosymlinks, instead of failing later and less legibly.Worth noting
nvimgcodecGetPropertieswas already being resolved as a symbol (nvimgcodec_tiff_parser.cpp:86) purely fordladdr()path probing, and never actually called — so no new dynlink surface is involved.On the packed version encoding
nvimgcodecProperties_t::versionis packed asmajor 1000 + minor 100 + patch, which gives the minor component only one digit. Two consequences, both handled:MAKE_SEMANTIC_VERSION(0, 10, 0)andMAKE_SEMANTIC_VERSION(1, 0, 0)both equal 1000. The range is therefore compared as packed integers rather than by unpacking major/minor — ordering is preserved, so the comparison stays correct, and both values are out of range either way.0.10.0as"1.0.0". Commented at the formatting helper. The human-readable range in messages is a separate literal rather than derived from the constants, so it cannot be rendered misleadingly.Consolidating the two cmake files
cpp/cmake/deps/nvimgcodec.cmaketurned out to be dead code, which makes the consolidation simpler than "merge two live files":cuslide2/CMakeLists.txt:112callssuperbuild_depend(nvimgcodec).SUPERBUILD_ADDITIONAL_DEPS_DIRSto its owncmake/deps(CMakeLists.txt:31), which is searched first.CMAKE_SUPERBUILD_DEPS_ROOT_DIRpoints at cuslide's cmake directory, notcpp/cmake, so the top-level copy was unreachable even as a fallback.So the cuslide2 copy is now the single source of truth. Before deleting the orphan I merged over the one capability the live copy lacked: resolving
$PREFIXwhenCONDA_BUILDis set, sinceCONDA_PREFIXpoints at the build environment rather than the install prefix under conda-build.I also gave the
find_packagepath the upper-bound warning it was missing — it previously only had the<0.9.0fatal error and never called_cucim_check_nvimgcodec_version()— so one policy now applies however nvImageCodec is discovered. That was the duplication I flagged in the review thread; with one copy it is no longer duplicated.This does leave the more general duplication across plugin
cmake/deps/directories (catch2,cli11,fmt,googletest,googlebenchmarkare copied between cuslide, cumed and the top level) untouched. nvimgcodec was the case under discussion; the rest is a larger cleanup.Testing
tests/test_nvimgcodec_version.cpp(new) pins the supported range. The range has to agree with the pin independencies.yamland the one enforced on headers incmake/deps/nvimgcodec.cmake, and nothing derives one from another, sois_supported_nvimgcodec_version()is exposed to make that testable. Cases:limit_imageswas removed in 0.9.NVIMGCODEC_VERfrom the vendored headers is itself in range, which catches a header bump that would otherwise reject every install including the intended one.Verification and its limits: the modified translation unit and the new test both compile clean with the build's own
-Werror -Wall -Wextra. The boundary logic was additionally executed standalone against the real vendored macros and all ten cases pass. A full cuslide2 build and the Catch2 suite were not run here (no GPU access in this environment), so CI is the real check. ThegetPropertiescall itself has not been exercised against a live library — worth a look from someone with a GPU box, particularly the case where the loaded library is genuinely older.