Skip to content

draft: Add support for Hexagon HVX#309

Draft
androm3da wants to merge 10 commits intoermig1979:masterfrom
androm3da:bcain/hvx
Draft

draft: Add support for Hexagon HVX#309
androm3da wants to merge 10 commits intoermig1979:masterfrom
androm3da:bcain/hvx

Conversation

@androm3da
Copy link

No description provided.

Add the foundational infrastructure for the Hexagon HVX SIMD backend,
including build system integration, architecture detection, memory
alignment, and load/store primitives. No algorithm implementations yet.
Add HVX-optimized implementations for: AbsDifference, AbsDifferenceSum,
AbsGradientSaturatedSum, AddFeatureDifference, BgrToGray, BgrToRgb,
FillBgra, FillPixel, OperationBinary8u, and GetStatistic. Wire up
dispatch blocks in SimdLib.cpp.
Replace __sighandler_t with sighandler_t for compatibility with musl
libc, which does not define the double-underscore variant.
Implement HVX-optimized versions of: GetRowSums, GetColSums,
GetAbsDyRowSums, GetAbsDxColSums, ValueSum, SquareSum,
ValueSquareSum, ValueSquareSums, and CorrelationSum.

Uses unaligned vector access (Load<false>/Store<false>) for
Allocate'd buffers to avoid misalignment from SIMD_NO_MANS_LAND.
Implement HVX-optimized versions of: AbsSecondDerivativeHistogram,
HistogramMasked, and HistogramConditional.

Uses Q6_Vub_vavg_VubVub_rnd for rounding average (matching Base and
NEON behavior), Q6_Vh_vmpyi_VhVh for integer halfword multiply, and
HVX Compare8u templates for conditional histogram operations.
Document HVX as a supported SIMD extension, add Hexagon to the
platform list, and include cross-compilation build instructions.
@androm3da
Copy link
Author

I'll share this as a draft - I'm not sure how well I have followed this project's idioms.

And apologies in advance: I will be away for a few days so I'll be slow to respond over the next ~week.

@ermig1979
Copy link
Owner

Hi! It is a good job!
Unfortunately I still have not faced with HVX so I can't verify correctness of your code.
There are following features are missed:

  1. Test to verify function output of Base implementation and SIMD optimization (for example https://github.com/ermig1979/Simd/blob/master/src/Test/TestAbsDifference.cpp for function Hvx::AbsDifference). Tests like this have to be for every implementation of every function.
  2. There is github action: https://github.com/ermig1979/Simd/blob/master/.github/workflows/cmake.yml . It should be possible to at least test the buildability of the project with HVX.

Register HVX backend in the test framework so that `./Test -m=a`
exercises all 22 HVX functions against the API dispatch:

- TestConfig.h: include SimdHvx.h
- TestOptions.h: add TestHvx() gate function
- Test.cpp: update -de= help text to mention HVX
- 9 test files: add #ifdef SIMD_HVX_ENABLE blocks mirroring the
  NEON pattern for AbsDifference, AbsDifferenceSum,
  AbsGradientSaturatedSum, AddFeatureDifference, BgrToGray,
  BgrToRgb, FillBgra, FillPixel, OperationBinary8u, GetStatistic,
  GetRowSums, GetColSums, GetAbsDyRowSums, GetAbsDxColSums,
  ValueSum, SquareSum, ValueSquareSum, ValueSquareSums,
  CorrelationSum, AbsSecondDerivativeHistogram, HistogramMasked,
  HistogramConditional
Add build_and_test_hexagon_cross job that downloads the CodeLinaro
Hexagon toolchain (clang 22.1.0), cross-compiles the library and
tests, then runs the test suite under qemu-hexagon.
@androm3da
Copy link
Author

After adding the test changes requested, I seem to have stumbled over a compiler defect at -O2/-O3. I will take some time to investigate that issue.

Locally I seem to be able to workaround this bug with test case changes like so:

-               bool result = true;
+               volatile bool result = true;

Since these are undesirable architecture-independent changes, I will look closer at the compiler defect to find other possible workarounds or maybe just a fix for the codegen problem in LLVM itself.

@ermig1979
Copy link
Owner

Hi. There are some errors in build_and_test_hexagon_cross action. It seems to incorrect toolchain installation.

…d testing

fixup! Add GitHub Actions CI job for Hexagon HVX cross-compilation and testing

Install host libc++/libc++abi for hexagon-linux-musl-clang binary.
@ermig1979
Copy link
Owner

@androm3da
Copy link
Author

There is an error: https://github.com/ermig1979/Simd/actions/runs/23249023929/job/67590194524

Sorry, I'll fix it. I hadn't tried to run the CI workflow locally but I will try that before the next push.

…d testing

Add missing QEMU runtime dependencies (liburing2, libglib2.0-0t64).
@ermig1979
Copy link
Owner

Sorry, I'll fix it. I hadn't tried to run the CI workflow locally but I will try that before the next push.

Its OK. I'v never to create CI workflow with the first attempt.

@ermig1979
Copy link
Owner

ermig1979 commented Mar 19, 2026

There is a progress. The build step is passed. There is an error during execution of AbsDifferenceAutoTest.
P.S. As I can see the first case with aligned input and output images is passed and an error is occured when test images have unaligned size. So I thing that error is concerned with handling of this case in your HVX code.

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