Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

fix(service-maker): validate buffer extraction before creating tensors - #114

Draft
chunlinl1980 wants to merge 2 commits into
developfrom
fix/101-buffer-extract-validation
Draft

chunlinl1980 wants to merge 2 commits into
developfrom
fix/101-buffer-extract-validation

Conversation

@chunlinl1980

@chunlinl1980 chunlinl1980 commented Nov 3, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Fixes #101.

Validate the mapped buffer size, surface list, batch capacity, and filled-frame count before accessing a surface. Return Python None when extraction fails instead of creating a wrapper around a null tensor. RGB extraction remains supported; unsupported formats such as RGBA and NV12 return None.

On the EGL path, use CUDA image index zero: the batch ID already selected the registered image. Check mapping/registration results and require a pitched, single-plane frame before accessing its pointer. Use the mapped frame dimensions and pitch. Retain the backing GstBuffer for tensor lifetime, and restore the extraction CUDA context for synchronization and unregistration before EGL image destruction. Restrict EGL mapping to its documented SURFACE_ARRAY memory type.

Update the C++ and Python API documentation and add six subprocess GPU regression cases covering RGB/RGBA/NV12 with single-frame and partially filled batches, empty/non-surface buffers, invalid batch IDs, and copying a retained RGB tensor after pipeline teardown.

Reason

The core indexed the surface array before validating its layout or batch ID. Failed extraction was then exposed to Python as a tensor whose methods could dereference null. Checking the filled-frame count also prevents returning tensors for unused batch slots.

Validation

Item Value
Platform (x86 GPU / Jetson, GPU or board, OS) x86_64, NVIDIA GeForce RTX 4090, Ubuntu 24.04.3, driver 595.71.05
DeepStream version 9.2.0; CUDA runtime 13.2; TensorRT 10.16
Tested commit 617ca64; implementation and tests validated before commit, with subsequent documentation-only wording updates
Build result (bash ./build/build.sh --package) Not run; full build/package validation outstanding
Component builds Service Maker core and Python extension compiled successfully using isolated build headers and runtime paths
Regression tests Six updated extraction/lifetime cases passed with rebuilt core/bindings in 2.70 seconds; the original six regression cases failed against the installed stock SDK
Sanity config (source4) source4_1080p_dec_infer-resnet_tracker_sgie_tiled_display.txt
Test duration Source4 run with newly built binaries outstanding
Test result Targeted regressions pass; full acceptance validation pending

The earlier source4 smoke test passed against the installed SDK, not this source build, and does not satisfy the required source4 validation. The ARM EGL branch passed a syntax-only check with local CUDA headers and aarch64 enabled; this is not a Jetson build or runtime test. Jetson EGL runtime validation, including nonzero batch IDs and mapping/registration failure paths, remains outstanding. The installed SDK was not replaced. This PR remains a draft pending full validation.

Checklist

  • My working branch is based on NVIDIA/DeepStream:develop.
  • The PR targets NVIDIA/DeepStream:develop.
  • bash ./build/build.sh --package completed successfully.
  • The source4 sanity test passed with the newly built deepstream-app on x86 or Jetson.
  • The PR records the tested platform, software version, commit, source4 configuration, test duration, and results.
  • Additional tests relevant to the change passed, where applicable.
  • My submitted commits include contributor sign-off (git commit -s).
  • Affected documentation is updated.

Check mapped surface size and filled batch bounds before indexing. Return None from Python when extraction fails, and document the contract with GPU regression coverage.

Fixes #101

Signed-off-by: chunlinl <chunlinl@nvidia.com>
cuStatus = cuGraphicsEGLRegisterImage(&cuGrphRes, surface.mappedAddr.eglImage, CU_GRAPHICS_MAP_RESOURCE_FLAGS_NONE);
if (cuStatus != CUDA_SUCCESS)
g_printerr("EGL Reguster Image Failed\n");
cuGraphicsResourceGetMappedEglFrame(&eglFrame, cuGrphRes, batchId, 0);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @chunlinl1980 , the 3rd arg of this API is the array/cubemap index within the registered resource, not a batch index. Could you confirm the index should be 0 like nvinfer? Thanks

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're absolutely right, I've posted a new commit.

Use EGL image index zero rather than the DeepStream batch index. Check mapping, registration and frame layout before creating a tensor, retain the backing buffer, and synchronize and unregister CUDA resources before destroying the EGL image.

Signed-off-by: chunlinl <chunlinl@nvidia.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants