Skip to content

Fix vxMinMaxLoc minCount/maxCount scalar type to VX_TYPE_SIZE#68

Merged
kiritigowda merged 4 commits into
openvx_1.3.2from
kg/min-max-fix
Jul 14, 2026
Merged

Fix vxMinMaxLoc minCount/maxCount scalar type to VX_TYPE_SIZE#68
kiritigowda merged 4 commits into
openvx_1.3.2from
kg/min-max-fix

Conversation

@kiritigowda

Copy link
Copy Markdown
Member

Summary

The OpenVX 1.3 specification requires the minCount and maxCount parameters of vxMinMaxLocNode to be VX_TYPE_SIZE scalars:

{min, max}Count: [Opt.] The number of detected {mins, maxes} in image. Type VX_TYPE_SIZE.

The sample implementation instead:

  • computed the counts into vx_uint32 locals in the c_model and venum statistics kernels, and
  • declared the count output parameters as VX_TYPE_UINT32 in the MinMaxLoc output validators.

On LP64 platforms (Linux/macOS/ARM64) vx_size is 8 bytes while vx_uint32 is 4. When a spec-conformant client supplies a VX_TYPE_SIZE count scalar, vxCopyScalar dispatches on the scalar's declared type and performs an 8-byte read from a 4-byte source, so the returned count is corrupted with adjacent stack bytes. This makes the MinMaxLoc.OnRandom conformance tests fail against the implementation once the CTS is updated to use the spec-correct VX_TYPE_SIZE scalar.

Changes

  • kernels/c_model/c_statistics.c: analyzeMinMaxValue count params and iMinCount/iMaxCount locals vx_uint32 -> vx_size.
  • kernels/venum/venum_statistics.c: same for analyzeMinMaxValue, calcMinMaxLocu8, calcMinMaxLocs16 and the outer vxMinMaxLoc (internal NEON accumulators stay uint32; only the value carried to vxCopyScalar widens).
  • sample/targets/c_model/vx_minmaxloc.c and sample/targets/venum/vx_minmaxloc.c: MinMaxLoc output validator for params 5/6 VX_TYPE_UINT32 -> VX_TYPE_SIZE.

The framework node/vxu wrappers only pass the user-provided scalars through, so no other changes are required.

Test plan

Made with Cursor

The OpenVX 1.3 specification requires the minCount/maxCount parameters of vxMinMaxLocNode to be VX_TYPE_SIZE scalars, but the sample implementation produced them as vx_uint32 and its output validator declared them as VX_TYPE_UINT32.

On LP64 platforms vx_size is 8 bytes while vx_uint32 is 4, so when a spec-conformant client supplies a VX_TYPE_SIZE count scalar, vxCopyScalar performs an 8-byte read from a 4-byte source, corrupting the returned count with adjacent stack bytes. This makes MinMaxLoc.OnRandom conformance tests fail against the impl.

Change the count locals/helpers in c_model and venum statistics kernels from vx_uint32 to vx_size, and set the MinMaxLoc output validator (params 5/6) to VX_TYPE_SIZE in both the c_model and venum targets.

Co-authored-by: Cursor <cursoragent@cursor.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR aligns the sample implementation of vxMinMaxLocNode with the OpenVX 1.3 spec by making the {min,max}Count scalar outputs use VX_TYPE_SIZE end-to-end, preventing corrupted results on LP64 platforms when clients supply spec-correct VX_TYPE_SIZE scalars.

Changes:

  • Updated MinMaxLoc output validators (c_model + venum targets) to declare params 5/6 as VX_TYPE_SIZE instead of VX_TYPE_UINT32.
  • Updated c_model and venum MinMaxLoc implementations to compute and store minCount/maxCount in vx_size (and to pass vx_size* through helper functions), matching what vxCopyScalar expects for VX_TYPE_SIZE.
  • Kept NEON/count-accumulation internals in uint32 where appropriate, only widening at the boundary where results are written out.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
sample/targets/venum/vx_minmaxloc.c Output validator now enforces VX_TYPE_SIZE for min/max count scalar outputs.
sample/targets/c_model/vx_minmaxloc.c Output validator now enforces VX_TYPE_SIZE for min/max count scalar outputs.
kernels/venum/venum_statistics.c Min/max count computation and plumbing widened to vx_size to match VX_TYPE_SIZE scalars.
kernels/c_model/c_statistics.c Min/max count computation and plumbing widened to vx_size to match VX_TYPE_SIZE scalars.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Point the bundled conformance suite at the OpenVX-cts branch that creates the MinMaxLoc minCount/maxCount scalars (and the MatchTemplate test's internal MinMaxLoc usage) as VX_TYPE_SIZE, matching this implementation's spec-conformant kernel change. Without this bump the pinned CTS still supplies VX_TYPE_UINT32 count scalars, which now fail graph verification against the corrected validator.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kiritigowda kiritigowda requested a review from jessegv July 14, 2026 04:48
ownDestructGraph removed the graph's nodes but never dereferenced virtual objects (images, tensors, etc.) whose scope is the dying graph, leaking memory in loops that repeatedly create graphs and virtual data. After removing the nodes, iterate the context reference table and release any virtual reference scoped to this graph. Ports the fix from PR #60 to openvx_1.3.2's ownDestructGraph, which was the only PR #60 code change missing from tip.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kiritigowda kiritigowda merged commit 210e8f4 into openvx_1.3.2 Jul 14, 2026
55 checks passed
@kiritigowda kiritigowda deleted the kg/min-max-fix branch July 15, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants