← Back to Pull requests

Add per-codec tile cache benchmark for cuslide2, fix raw TIFF recipe #1143

Closed
unknown closed this pull request without merging on Sep 22, 2026 03:18 UTC
View on GitHub
unknown unknown commented on Sep 07, 2026 01:41 UTC
Author

Addresses the review feedback on #1034 / #1069 from @mkepa-nv, which asked for two things: numbers on whether a warm cache read actually beats decoding again when the codec is light, and whether the tiles would be better cached in GPU memory.

This PR delivers the benchmark. It does not implement a GPU-resident cache — that is an architecture decision (make the global cache device-aware, vs. keep separate CPU and GPU caches as suggested in the thread), and the point of the benchmark is to make that call with evidence rather than intuition.

What the benchmark measures

scripts/benchmark_tile_cache.py sweeps compression × cache setting × output device, timing two access patterns per cell:

  • warm — the same region read repeatedly, which is the case tile caching is meant to win

  • cold — distinct non-overlapping regions, which pays decode plus insert overhead
  • Cache hit/miss counters are reported for every cell. This is load-bearing rather than decorative: the cache path requires tile_width_ > 0 && tile_height_ > 0, so whenever nvImageCodec does not report TileWidth/TileLength the tile dims stay (0,0) and the cache is bypassed entirely. Without the counters, a run where the cache silently never engaged looks exactly like a run where caching genuinely did not help. The script labels that case instead of printing a meaningless ratio.

    The CUDA rows need reading carefully

    For device="cuda" this is not a plain cache-vs-no-cache comparison, and the script says so in its output. With the cache off, nvImageCodec decodes straight into device memory:

    https://github.com/rapidsai/cucim/blob/main/cpp/plugins/cucim.kit.cuslide2/src/cuslide/nvimgcodec/nvimgcodec_decoder.cpp#L317-L374

    With the cache on, tiles are decoded to host regardless of the requested output device, assembled there with a single-threaded per-row memcpy, and the finished region is copied up with one cudaMemcpyHostToDevice.

    So enabling the cache gives up direct-to-device decode for GPU output. A warm ratio below 1.0x on the CUDA rows is the cost of that host round-trip, and is an argument for the GPU-resident cache in #1069 rather than against caching in general. Worth noting the infrastructure is already most of the way there: PerProcessImageCache::allocate() calls cudaMalloc when constructed with DeviceType::kCUDA, the global cache simply never is, and legacy cuslide's NvJpegProcessor already keeps a private device-resident tile cache as a working in-tree reference.

    Generator fix (prerequisite)

    The uncompressed case central to the review feedback could not be generated at all. In gen_tiff.py, raw mapped to None and was then overwritten:

    compression = COMPRESSION_MAP.get(compression)
    compressionargs = None
    if not compression:
        compression = "jpeg"
    

    So every testimg_tiff_stripe_*_raw fixture has in fact been producing JPEG images, and unknown compression names took the same silent fallback. Both are fixed; unknown names now raise.

    Verified directly:

        jpeg: compression=COMPRESSION.JPEG      size=  46666 bytes
     deflate: compression=COMPRESSION.DEFLATE   size=   3380 bytes
         raw: compression=COMPRESSION.NONE      size= 246832 bytes
    
    unknown compression rejected: Unknown compression 'lzw'. Expected one of ['deflate', 'jpeg', 'raw']
    

    Reviewer notes

  • Please let CI confirm the fixture change. gen_tiff.py feeds the compression-parametrized fixtures used across test_tiff_read_region.py, test_batch_decoding.py and test_load_image_metadata.py. I checked their assertions are structural (e.g. assert np.all(channel_value_count > 0)) rather than exact-pixel comparisons, so lossy→lossless should be safe, but I had no cuCIM install or GPU available to run the suite locally.

  • The 4096x4096 raw fixture gets materially larger now that it is genuinely uncompressed instead of silently JPEG.

  • Unrelated rough edge noticed while working here, left alone: --discard_cache in the C++ benchmarks only drops the OS page cache via posix_fadvise, not cuCIM's ImageCache, so no existing C++ benchmark exercises the tile cache.
  • Diff: 519 lines (+389 / -130) across 6 files Reviewer: gigony Review duration: 21697m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.53) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.53 · 519 lines diff across 6 files
    0.53
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.374
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #1143"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52.7% (MEDIUM) · Higher = larger blast radius
    52.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.8% · Safe to merge
    22.8%
    Repository