Skip to content

Fix vector add example runtime validation - #17

Open
cherubrock-seb wants to merge 1 commit into
KernelTuner:mainfrom
cherubrock-seb:fix/example-runtime-correctness-20261110
Open

cherubrock-seb wants to merge 1 commit into
KernelTuner:mainfrom
cherubrock-seb:fix/example-runtime-correctness-20261110

Conversation

@cherubrock-seb

Copy link
Copy Markdown

Problem

The CUDA examples under examples/vector_add and examples/vector_add_tiling currently crash before they can validate their kernels.

On an RTX 3080 with CUDA 12.0, both exact upstream binaries at 67c6589aed8653629209f87d35627ac51dec3ca8 terminate with SIGSEGV (exit 139). PR #16 independently notes the same empty-vector failure and intentionally leaves these examples unchanged.

Reproduction

Build the examples in Release mode and run:

  • kernel_float_vecadd
  • kernel_float_vecadd_tiling

Both index zero-sized output_expected / output_result host vectors. The copy-back cudaMemcpy is also reversed, so the host result buffer is never populated correctly.

After fixing those two memory issues, the examples expose a second stale check: their expected values still use i + constant, while the kernels actually compute:

  • vector_add: half-precision fma(input, input, constant)
  • vector_add_tiling: the half-rounded square multiplied by constant

Root cause

The example host-side validation code drifted from the kernel behavior:

  1. output vectors are declared without size;
  2. the post-kernel copy uses device as destination and host as source;
  3. expected values no longer match the implemented square/FMA operations.

Minimal fix

Only the two example files are changed:

  • size both host output vectors to n;
  • copy output_dev back into output_result.data();
  • compute expected values using the same half-precision semantics as each kernel.

No library implementation or public API is changed.

Validation

Validated exact candidate head: 1b1feaa8cbb1b678193f98a70580496e7558691c

Against upstream base: 67c6589aed8653629209f87d35627ac51dec3ca8

Environment:

  • NVIDIA GeForce RTX 3080
  • CUDA Toolkit 12.0.140
  • Release build
  • CMAKE_CUDA_ARCHITECTURES=80

Results:

  • baseline kernel_float_vecadd: SIGSEGV, exit 139
  • baseline kernel_float_vecadd_tiling: SIGSEGV, exit 139
  • candidate build: PASS
  • candidate kernel_float_vecadd: PASS, prints result correct
  • candidate kernel_float_vecadd_tiling: PASS, prints result correct
  • git diff --check: PASS

Scope and limitations

This fixes only the two standalone CUDA examples and their validation logic. It does not alter kernel_float arithmetic, tests, or runtime behavior outside these examples.

This branch has not been deployed

No deployments
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.

1 participant