Skip to content

Add std C++ components to rocm namespace and add unit tests#4752

Open
pfultz2 wants to merge 65 commits into
developfrom
rocm-cxx
Open

Add std C++ components to rocm namespace and add unit tests#4752
pfultz2 wants to merge 65 commits into
developfrom
rocm-cxx

Conversation

@pfultz2

@pfultz2 pfultz2 commented Apr 8, 2026

Copy link
Copy Markdown
Collaborator

Motivation

This adds std C++ components to rocm namespace using many of our existing implementations. In a followup PR, I will be removing the implementation from migraphx.

This will help reduce name collisions in the migraphx namespace with std named components.

Technical Details

Changelog Category

Add a CHANGELOG.md entry for any option other than Not Applicable

    • Added: New functionality.
    • Changed: Changes to existing functionality.
    • Removed: Functionality or support that has been removed. (Compared to a previous release)
    • Optimized: Component performance that has been optimized or improved.
    • Resolved Issues: Known issues from a previous version that have been resolved.
    • Not Applicable: This PR is not to be included in the changelog.

@github-actions github-actions Bot 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.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

format.py

[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::iterator_traits<volatile int*>::reference, volatile int&>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::iterator_traits<const volatile int*>::value_type, int>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::iterator_traits<float*>::value_type, float>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::iterator_traits<double*>::difference_type, rocm::ptrdiff_t>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::iterator_traits<char*>::reference, char&>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::iterator_traits<mock_iterator>::difference_type, int>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::iterator_traits<mock_iterator>::value_type, double>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::iterator_traits<mock_iterator>::pointer, double*>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::iterator_traits<mock_iterator>::reference, double&>{});
}


[format.py] reported by reviewdog 🐶


[format.py] reported by reviewdog 🐶


[format.py] reported by reviewdog 🐶

{
return rocm::forward<T>(x);
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::integer_sequence<int, 0, 1, 2>::value_type, int>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::integer_sequence<long, 0, 1>::value_type, long>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::integer_sequence<char, 'a', 'b'>::value_type, char>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::integer_sequence<rocm::size_t, 0, 1>::value_type, rocm::size_t>{});
}


[format.py] reported by reviewdog 🐶

{
static_assert(rocm::integer_sequence<int, 10, 20, 30>::size() == 3);
}


[format.py] reported by reviewdog 🐶

{
static_assert(rocm::integer_sequence<int, 0, 1, 2, 3, 4>::size() == 5);
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::index_sequence<>, rocm::integer_sequence<rocm::size_t>>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::index_sequence<0>::value_type, rocm::size_t>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::make_integer_sequence<int, 0>, rocm::integer_sequence<int>>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::make_integer_sequence<int, 1>, rocm::integer_sequence<int, 0>>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::make_index_sequence<0>, rocm::index_sequence<>>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::make_index_sequence<1>, rocm::index_sequence<0>>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::make_index_sequence<4>, rocm::index_sequence<0, 1, 2, 3>>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::index_sequence_for<>, rocm::index_sequence<>>{});
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_same<rocm::index_sequence_for<int>, rocm::index_sequence<0>>{});
}


[format.py] reported by reviewdog 🐶

{
static_assert(rocm::index_sequence_for<int, int, int, int>::size() == 4);
}


[format.py] reported by reviewdog 🐶

{
return true;
}


[format.py] reported by reviewdog 🐶

{
return false;
}


[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_rvalue_reference<decltype(rocm::move(42))>{});
}

@github-actions github-actions Bot 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.

Remaining comments which cannot be posted as a review comment to avoid GitHub Rate Limit

format.py

[format.py] reported by reviewdog 🐶

{
EXPECT(rocm::is_rvalue_reference<decltype(rocm::move(42))>{});
}

@gh-app-migraphx-bot-pr-write

gh-app-migraphx-bot-pr-write Bot commented Jun 24, 2026

Copy link
Copy Markdown
Test Batch New Rate (53e9a1) Old Rate (5c50d0)* Diff Status
torchvision-resnet50 64 3,273.91 3,278.37 -0.14%
torchvision-resnet50_fp16 64 7,607.22 7,611.38 -0.05%
torchvision-densenet121 32 2,502.19 2,501.41 0.03%
torchvision-densenet121_fp16 32 5,043.66 5,004.64 0.78%
torchvision-inceptionv3 32 2,061.62 2,059.27 0.11%
torchvision-inceptionv3_fp16 32 4,419.90 4,417.65 0.05%
cadene-inceptionv4 16 822.31 819.80 0.31%
cadene-resnext64x4 16 783.11 783.52 -0.05%
slim-mobilenet 64 8,431.47 8,394.63 0.44%
slim-nasnetalarge 64 229.39 197.60 16.08% 🔆
slim-resnet50v2 64 3,198.38 3,185.87 0.39%
bert-mrpc-onnx 8 1,166.71 1,161.65 0.44%
bert-mrpc-tf 1 490.76 486.30 0.92%
pytorch-examples-wlang-gru 1 487.91 469.65 3.89%
pytorch-examples-wlang-lstm 1 391.39 379.72 3.07%
torchvision-resnet50_1 1 1,038.22 1,023.59 1.43%
cadene-dpn92_1 1 477.69 436.69 9.39% 🔆
cadene-resnext101_1 1 364.57 364.25 0.09%
onnx-taau-downsample 1 848.90 845.97 0.35%
dlrm-criteoterabyte 1 32.68 32.54 0.42%
dlrm-criteoterabyte_fp16 1 52.58 52.59 -0.02%
agentmodel 1 11,504.92 9,452.06 21.72% 🔆
unet_fp16 2 59.16 59.01 0.24%
resnet50v1_fp16 1 1,376.97 1,378.39 -0.10%
resnet50v1_int8 1 1,839.90 1,626.43 13.12% 🔆
bert_base_cased_fp16 64 1,102.10 1,102.97 -0.08%
bert_large_uncased_fp16 32 346.77 346.63 0.04%
bert_large_fp16 1 206.26 205.51 0.36%
distilgpt2_fp16 16 2,093.73 2,098.82 -0.24%
yolov5s 1 561.13 562.00 -0.15%
tinyllama 1 45.98 45.93 0.11%
vicuna-fastchat 1 44.12 44.06 0.13%
whisper-tiny-encoder 1 414.49 415.56 -0.26%
whisper-tiny-decoder 1 409.14 410.79 -0.40%
llama2_7b 1 20.96 21.01 -0.25%
qwen1.5-7b 1 23.65 23.60 0.20%
phi3-3.8b 1 26.89 26.80 0.33%
llama3-8b 1 21.84 21.70 0.63%
whisper-large-encoder 1 10.21 10.22 -0.05%
whisper-large-decoder 1 104.02 104.52 -0.48%
mistral-7b 1 23.86 23.74 0.50%
FLUX.1-schnell 1 770.93 723.54 6.55% 🔆

Check flagged results 🔆

* No develop baseline was found for this PR's branch point; compared against the latest available develop run instead.

@gh-app-migraphx-bot-pr-write

gh-app-migraphx-bot-pr-write Bot commented Jun 24, 2026

Copy link
Copy Markdown
Test Status Result
bert-mrpc-onnx PASSED: MIGraphX meets tolerance
bert-mrpc-tf PASSED: MIGraphX meets tolerance
pytorch-examples-wlang-gru PASSED: MIGraphX meets tolerance
pytorch-examples-wlang-lstm PASSED: MIGraphX meets tolerance
dlrm-criteoterabyte PASSED: MIGraphX meets tolerance
agentmodel PASSED: MIGraphX meets tolerance
unet PASSED: MIGraphX meets tolerance
resnet50v1 PASSED: MIGraphX meets tolerance
bert_base_cased_fp16 PASSED: MIGraphX meets tolerance
bert_large_uncased_fp16 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
bert_large PASSED: MIGraphX meets tolerance
yolov5s PASSED: MIGraphX meets tolerance
tinyllama PASSED: MIGraphX meets tolerance
vicuna-fastchat PASSED: MIGraphX meets tolerance
whisper-tiny-encoder PASSED: MIGraphX meets tolerance
whisper-tiny-decoder PASSED: MIGraphX meets tolerance
distilgpt2_fp16 🔴 FAILED: MIGraphX is not within tolerance - check verbose output
llama2_7b PASSED: MIGraphX meets tolerance
qwen1.5-7b PASSED: MIGraphX meets tolerance
phi3-3.8b PASSED: MIGraphX meets tolerance
llama3-8b PASSED: MIGraphX meets tolerance
whisper-large-encoder PASSED: MIGraphX meets tolerance
whisper-large-decoder PASSED: MIGraphX meets tolerance
mistral-7b PASSED: MIGraphX meets tolerance
FLUX.1-schnell PASSED: MIGraphX meets tolerance

@pfultz2
pfultz2 marked this pull request as ready for review July 24, 2026 14:16
@pfultz2
pfultz2 requested a review from causten as a code owner July 24, 2026 14:16
Copilot AI review requested due to automatic review settings July 24, 2026 14:16

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 introduces a rocm::-namespaced, device-friendly subset of common C++ standard-library components (type traits, utility, iterators, functional, algorithms, limits, etc.) under the GPU kernel headers, and adds/expands GPU kernel tests to validate the new APIs. It also updates the GPU kernel test harness and build wiring to discover tests recursively and to propagate the originating source filename into HIP compilation for improved diagnostics.

Changes:

  • Add new src/targets/gpu/kernels/include/rocm/* headers providing rocm:: equivalents of common std utilities (type traits, utility helpers, iterators, functional ops, algorithms, limits/stdint/stddef, etc.).
  • Add GPU kernel unit tests under test/gpu/kernels/rocm/** for the new rocm:: components.
  • Update GPU kernel test/build plumbing (recursive test discovery, suite naming, and hip_compile_options::src_file propagation).

Reviewed changes

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

Show a summary per file
File Description
test/gpu/kernels/rocm/utility/swap.cpp New GPU kernel tests for rocm::swap.
test/gpu/kernels/rocm/utility/move.cpp New GPU kernel tests for rocm::move.
test/gpu/kernels/rocm/utility/integer_sequence.cpp New GPU kernel tests for rocm::integer_sequence and related aliases.
test/gpu/kernels/rocm/utility/forward.cpp New GPU kernel tests for rocm::forward.
test/gpu/kernels/rocm/type_traits_relationships.cpp New GPU kernel tests covering a variety of rocm::type_traits relationship traits.
test/gpu/kernels/rocm/stdint.cpp New GPU kernel tests validating rocm::stdint type sizes.
test/gpu/kernels/rocm/std_numeric_limits.cpp New GPU kernel tests comparing rocm::numeric_limits to std::numeric_limits (host path).
test/gpu/kernels/rocm/numeric_limits.cpp New GPU kernel tests validating rocm::numeric_limits API surface and types.
test/gpu/kernels/rocm/iterator/reverse_iterator.cpp New GPU kernel tests for rocm::reverse_iterator.
test/gpu/kernels/rocm/iterator/iterator_traits.cpp New GPU kernel tests for rocm::iterator_traits and iterator tags.
test/gpu/kernels/rocm/integral_constant.cpp New GPU kernel tests for rocm::integral_constant operators and conversions.
test/gpu/kernels/rocm/functional/operations.cpp New GPU kernel tests for rocm::functional operation objects and transparency.
test/gpu/kernels/rocm/enable_if.cpp New GPU kernel tests for rocm::enable_if / enable_if_t.
test/gpu/kernels/rocm/.clang-tidy New clang-tidy overrides for the rocm kernel tests subtree.
test/gpu/kernels/main.cpp Enhance kernel test discovery (templates/register macros) and suite naming; pass src_file into HIP compile options.
test/gpu/kernels/CMakeLists.txt Switch to recursive discovery of kernel test sources.
src/targets/gpu/kernels/include/rocm/utility/swap.hpp New rocm::swap implementation.
src/targets/gpu/kernels/include/rocm/utility/move.hpp New rocm::move implementation.
src/targets/gpu/kernels/include/rocm/utility/integer_sequence.hpp New rocm::integer_sequence and helpers (index_sequence, etc.).
src/targets/gpu/kernels/include/rocm/utility/forward.hpp New rocm::forward implementation.
src/targets/gpu/kernels/include/rocm/utility/declval.hpp New rocm::declval implementation.
src/targets/gpu/kernels/include/rocm/utility.hpp Umbrella include for rocm utility headers.
src/targets/gpu/kernels/include/rocm/type_traits.hpp New rocm-flavored type traits and helpers/macros for kernels.
src/targets/gpu/kernels/include/rocm/stdint.hpp New rocm stdint typedefs (host vs RTC handling).
src/targets/gpu/kernels/include/rocm/stddef.hpp New rocm stddef typedefs (size_t, ptrdiff_t, etc.).
src/targets/gpu/kernels/include/rocm/limits.hpp New rocm::numeric_limits and related enums/helpers for kernels.
src/targets/gpu/kernels/include/rocm/iterator/reverse_iterator.hpp New rocm::reverse_iterator implementation.
src/targets/gpu/kernels/include/rocm/iterator/iterator_traits.hpp New rocm::iterator_traits plus iterator tag hierarchy.
src/targets/gpu/kernels/include/rocm/iterator.hpp Umbrella include for rocm iterator headers.
src/targets/gpu/kernels/include/rocm/integral_constant.hpp New rocm::integral_constant and boolean constants.
src/targets/gpu/kernels/include/rocm/functional/operations.hpp New rocm functional operation objects (plus, less, etc.).
src/targets/gpu/kernels/include/rocm/functional.hpp Umbrella include for rocm functional headers.
src/targets/gpu/kernels/include/rocm/config.hpp New rocm config macros (inline namespace, host/device annotations, deduction guide workaround hook).
src/targets/gpu/kernels/include/rocm/bit.hpp New rocm bit utilities (bit_cast, popcount, rotations, etc.).
src/targets/gpu/kernels/include/rocm/assert.hpp New rocm assert/check helpers (host/device compatible printing + abort).
src/targets/gpu/kernels/include/rocm/array.hpp New rocm::array and helpers (iterators, swap, to_array).
src/targets/gpu/kernels/include/rocm/algorithm/upper_bound.hpp New rocm upper_bound algorithm.
src/targets/gpu/kernels/include/rocm/algorithm/transform.hpp New rocm transform algorithms (unary/binary).
src/targets/gpu/kernels/include/rocm/algorithm/stable_sort.hpp New rocm stable_sort implementation.
src/targets/gpu/kernels/include/rocm/algorithm/sort.hpp New rocm sort implementation.
src/targets/gpu/kernels/include/rocm/algorithm/search.hpp New rocm search implementation.
src/targets/gpu/kernels/include/rocm/algorithm/rotate.hpp New rocm rotate implementation.
src/targets/gpu/kernels/include/rocm/algorithm/none_of.hpp New rocm none_of implementation.
src/targets/gpu/kernels/include/rocm/algorithm/min_element.hpp New rocm min_element implementation.
src/targets/gpu/kernels/include/rocm/algorithm/merge.hpp New rocm merge implementation.
src/targets/gpu/kernels/include/rocm/algorithm/max_element.hpp New rocm max_element implementation.
src/targets/gpu/kernels/include/rocm/algorithm/lower_bound.hpp New rocm lower_bound implementation.
src/targets/gpu/kernels/include/rocm/algorithm/iter_swap.hpp New rocm iter_swap implementation.
src/targets/gpu/kernels/include/rocm/algorithm/is_sorted.hpp New rocm is_sorted implementation.
src/targets/gpu/kernels/include/rocm/algorithm/is_sorted_until.hpp New rocm is_sorted_until implementation.
src/targets/gpu/kernels/include/rocm/algorithm/iota.hpp New rocm iota implementation.
src/targets/gpu/kernels/include/rocm/algorithm/inner_product.hpp New rocm inner_product implementation.
src/targets/gpu/kernels/include/rocm/algorithm/for_each.hpp New rocm for_each implementation.
src/targets/gpu/kernels/include/rocm/algorithm/find.hpp New rocm find implementation.
src/targets/gpu/kernels/include/rocm/algorithm/find_if.hpp New rocm find_if implementation.
src/targets/gpu/kernels/include/rocm/algorithm/fill.hpp New rocm fill implementation.
src/targets/gpu/kernels/include/rocm/algorithm/equal.hpp New rocm equal implementation.
src/targets/gpu/kernels/include/rocm/algorithm/copy.hpp New rocm copy implementation.
src/targets/gpu/kernels/include/rocm/algorithm/copy_if.hpp New rocm copy_if implementation.
src/targets/gpu/kernels/include/rocm/algorithm/any_of.hpp New rocm any_of implementation.
src/targets/gpu/kernels/include/rocm/algorithm/all_of.hpp New rocm all_of implementation.
src/targets/gpu/kernels/include/rocm/algorithm/accumulate.hpp New rocm accumulate implementation.
src/targets/gpu/kernels/include/rocm/algorithm.hpp Umbrella include for rocm algorithm headers.
src/targets/gpu/kernels/include/rocm/.clang-tidy New clang-tidy overrides for rocm kernel headers subtree.
src/targets/gpu/kernels/include/migraphx/kernels/test.hpp Add no-op template/register test macros for parsing/registration.
src/targets/gpu/include/migraphx/gpu/compile_hip_code_object.hpp Add hip_compile_options::src_file for labeling the main compilation unit.
src/targets/gpu/compile_hip_code_object.cpp Use options.src_file for the main source instead of hardcoding main.cpp.
src/targets/gpu/CMakeLists.txt Broaden kernel header scanning, add deduction-guide capability check, and adjust clang-tidy file-check stubs.
src/compile_src.cpp Pass full relative source paths to the compiler for better traceability/diagnostics.
CMakeLists.txt Exclude rocm kernel header/test define-prefix regions from cppcheck definePrefix heuristics.

Comment on lines +59 to +61
using intmax_t = int64_t;
using uintmax_t = uint64_t;
using intmax_t = int64_t;
Comment on lines +70 to +75
constexpr pointer operator->() const
{
iterator_type tmp = current;
--tmp;
return tmp;
}

} // namespace ROCM_INLINE_NS
} // namespace rocm
#endif // MIGRAPHX_GUARD_FUNCTIONAL_OPERATIONS_HPP
Comment on lines +214 to +215
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/kernels/include/${KERNEL_DIR}/${KERNEL_BASE_FILE}.cpp "#include <${KERNEL_DIR}/${KERNEL_BASE_FILE}.hpp>\n")
target_sources(migraphx_gpu_kernel_file_check PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/kernels/include/${KERNEL_DIR}/${KERNEL_BASE_FILE}.cpp)
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.

4 participants