Skip to content

Tests - Fix compile warnings in cpp_api unit_tests - #508

Open
levxn wants to merge 3 commits into
ROCm:developfrom
levxn:fix/tests-compile-warning
Open

Tests - Fix compile warnings in cpp_api unit_tests#508
levxn wants to merge 3 commits into
ROCm:developfrom
levxn:fix/tests-compile-warning

Conversation

@levxn

@levxn levxn commented Aug 11, 2026

Copy link
Copy Markdown
Member

Motivation

Fixes #497: Compile warnings in tests/cpp_api/unit_tests/unit_tests.cpp

Technical Details

Removed unused variable captures for rocalTensorSum, rocalTensorMin, rocalTensorMax, rocalTensorStdDev, and rocalGetLastBatchPaddedSize calls that were made purely for side effects but whose return values were never used or asserted on. Removed the unused loop index variable that was declared and incremented but never read. Explicitly discarded the hipError_t return values of the hipMalloc/hipFree calls (now [[nodiscard]] in current HIP headers) using (void) casts, since these test-only allocations were not being checked for failure.

Affected file: tests/cpp_api/unit_tests/unit_tests.cpp (lines 1190-1194, 1220, 1235, 1434-1462).

Test Plan

Built unit_tests from a clean configure with the HIP backend enabled, across all GPU targets, to confirm the warning count drops to zero:

cd tests/cpp_api/unit_tests
rm -rf CMakeCache.txt CMakeFiles
cmake -DCMAKE_CXX_COMPILER=<path-to-amdclang++> \
      -DROCM_PATH=<rocm-install-path> \
      -DHIP_DIR=<rocm-install-path>/lib/cmake/hip \
      -Dhip_DIR=<rocm-install-path>/lib/cmake/hip \
      -DBACKEND=HIP \
      .
make clean
make

Test Result

Before fix: 14 warnings generated per compile target (gfx..., host) — 4 unused-variable warnings, 8 hipMalloc/hipFree nodiscard warnings, 1 last_batch_padded_size unused-variable warning and 1 index set but unused warning.

After fix: 0 warnings generated across all three compile passes (gfx..., host); unit_tests builds and links cleanly.

@kiritigowda

Copy link
Copy Markdown
Collaborator

Resolves #497

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 targets build cleanliness for the C++ API unit tests by removing/handling constructs that trigger compiler warnings (unused variables and ignored [[nodiscard]] HIP API results), plus a small .gitignore update for an additional build directory.

Changes:

  • Stop capturing return values from several rocalTensor* reduction calls where the return was not used.
  • Replace ignored hipMalloc/hipFree results with check_hip(...) to satisfy [[nodiscard]] and fail fast on HIP errors.
  • Add build_verify/ to .gitignore.

Reviewed changes

Copilot reviewed 1 out of 2 changed files in this pull request and generated 1 comment.

File Description
tests/cpp_api/unit_tests/unit_tests.cpp Removes/handles unused values and HIP [[nodiscard]] warnings; adds a small HIP error-check helper.
.gitignore Ignores build_verify/ build output directory.
Suppressed comments (2)

tests/cpp_api/unit_tests/unit_tests.cpp:1244

  • index is still never read: it is only incremented and not used anywhere else in this file (even under ENABLE_OPENCV), so OpenCV-enabled builds will continue to emit -Wunused-but-set-variable. Remove the unused counter entirely (or actually use it).
#if ENABLE_OPENCV
    int index = 0;
#endif

tests/cpp_api/unit_tests/unit_tests.cpp:1249

  • This index++ is part of an unused counter and triggers -Wunused-but-set-variable when ENABLE_OPENCV is on. If the counter is not used (it isn't elsewhere in this file), delete the increment block.
    while (rocalGetRemainingImages(handle) >= input_batch_size) {
#if ENABLE_OPENCV
        index++;
#endif

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread tests/cpp_api/unit_tests/unit_tests.cpp

// Get output matched indices
if (enable_iou_matcher) {
rocalGetMatchedIndices(handle); // TODO - To verify the output

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For consistency with above copilot comment consider adding (void)rocalGetMatchedIndices(handle)

auto tensor_max = rocalTensorMax(handle, input, false, ROCAL_NONE, ROCAL_UINT8);
rocalTensorSum(handle, input, false, ROCAL_NONE, ROCAL_FP32);
rocalTensorMin(handle, input, false, ROCAL_NONE, ROCAL_UINT8);
rocalTensorMax(handle, input, false, ROCAL_NONE, ROCAL_UINT8);

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.

I think this test case for sum, min and max is flawed. We need to verify the output of these functions here.

int w = rocalGetOutputWidth(handle);
int output_color_format = rocalGetOutputColorFormat(handle);
auto last_batch_padded_size = rocalGetLastBatchPaddedSize(handle);
rocalGetLastBatchPaddedSize(handle);

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.

Also here. Add code to verify output

Comment thread .gitignore
@kiritigowda

Copy link
Copy Markdown
Collaborator

@levxn -- please address the review comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug fix enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Issue]: Tests - Compile warnings

6 participants