Skip to content

HIP Multi-arch and amdgcnspirv offload target update - #9384

Open
khuck-AMD wants to merge 21 commits into
kokkos:developfrom
khuck-AMD:multiarch-support
Open

khuck-AMD wants to merge 21 commits into
kokkos:developfrom
khuck-AMD:multiarch-support

Conversation

@khuck-AMD

Copy link
Copy Markdown
Contributor

This patch adds support for HIP multi-arch builds and adds amdgcnspirv as an explicit Kokkos architecture target.

What is done:

  • Adds Kokkos_ARCH_AMD_GCNSPIRV / KOKKOS_ARCH_AMD_GCNSPIRV.
  • Allows selecting multiple AMD GPU targets in CMake and propagates them to HIP offload flags.
  • Updates exported package checks so downstream GPU_TARGETS can be a subset of the enabled Kokkos HIP architectures.
  • Switches HIP warp-size-dependent host logic to runtime values from hipDeviceProp_t.
  • Moves HIP arch capability checks (including XNACK-related behavior) to runtime detection.
  • Updates HIP tests and adds TestHIP_RuntimeArch.cpp coverage.

Result:

  • Multi-arch HIP builds now supported
  • amdgcnspirv is recognized end-to-end.
  • Performance comparison vs the prior compile-time path shows no meaningful regression (largest observed changes were low single-digit percentages).

For this PR, the runtime HIP architecture path with multi-arch support was tested to perform essentially the same as the compile-time path on MI300A (within system noise).

  • STREAM: mixed small changes, best +0.95% (Set), worst -1.46% (Add)
  • Reduction: effectively unchanged (-0.65% and -0.06%)
  • Launch latency: +0.08% (V=1) and +1.13% (V=30000)

Related issues / PRs

none.

Changelog Entry

HIP configurations now support the HIP offload target architecture -DKokkos_ARCH_AMD_GCNSPIRV which provides runtime support for any architecture
HIP configurations now support multiple offload targets in the same configuration/build.
There is now one gfx942 binary target - there is runtime branching for APU-vs-descrete-GPU behavior using HIP properties rather than separate compile-time specialization for MI300A vs MI300X, although the existing Kokkos arch CMake options are still honored.

This patch adds support for HIP multi-arch builds and adds `amdgcnspirv` as
an explicit Kokkos architecture target.

What is done:
- Adds `Kokkos_ARCH_AMD_GCNSPIRV` / `KOKKOS_ARCH_AMD_GCNSPIRV`.
- Allows selecting multiple AMD GPU targets in CMake and propagates them to
  HIP offload flags.
- Updates exported package checks so downstream `GPU_TARGETS` can be a subset
  of the enabled Kokkos HIP architectures.
- Switches HIP warp-size-dependent host logic to runtime values from
  `hipDeviceProp_t`.
- Moves HIP arch capability checks (including XNACK-related behavior) to
  runtime detection.
- Updates HIP tests and adds `TestHIP_RuntimeArch.cpp` coverage.

Result:
- Multi-arch HIP builds now supported
- `amdgcnspirv` is recognized end-to-end.
- Performance comparison vs the prior compile-time path shows no meaningful
  regression (largest observed changes were low single-digit percentages).

For this PR, the runtime HIP architecture path performs essentially the same as
the compile-time path on MI300A.

- STREAM: mixed small changes, best +0.95% (`Set`), worst -1.46% (`Add`)
- Reduction: effectively unchanged (-0.65% and -0.06%)
- Launch latency: +0.08% (`V=1`) and +1.13% (`V=30000`)

Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Comment thread core/src/impl/Kokkos_Core.cpp
Comment thread core/src/HIP/Kokkos_HIP.cpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_IsXnack.cpp Outdated
khuck-AMD and others added 3 commits July 30, 2026 16:08
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Co-authored-by: Trévis Morvany <63788850+tretre91@users.noreply.github.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Co-authored-by: Trévis Morvany <63788850+tretre91@users.noreply.github.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Comment thread core/src/HIP/Kokkos_HIP.cpp
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>

@tretre91 tretre91 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There are some integer comparison warnings in the CI related to HIPTraits::WarpSize() https://cloud1.cees.ornl.gov/jenkins-ci/job/Kokkos/job/PR-9384/4/stages/

Comment thread cmake/kokkos_arch.cmake
Comment on lines +1165 to +1173
if(KOKKOS_HIP_ARCHITECTURES)
list(LENGTH KOKKOS_HIP_ARCHITECTURES KOKKOS_HIP_ARCH_COUNT_FOR_OPENACC)
if(KOKKOS_HIP_ARCH_COUNT_FOR_OPENACC GREATER 1)
message(
FATAL_ERROR
"Kokkos_ENABLE_OPENACC currently supports only one AMD GPU architecture, but got ${KOKKOS_HIP_ARCHITECTURES}."
)
endif()
endif()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Does SYCL support multiple archs? If not we should add the same check with KOKKOS_ENABLE_SYCL

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since multiple intel archs are not supported, I would assume the same for multiple AMD archs

macro(CHECK_MULTIPLE_INTEL_ARCH)
  if(KOKKOS_ARCH_INTEL_GPU)
    message(FATAL_ERROR "Specifying multiple Intel GPU architectures is not allowed!")
  endif()
  set(KOKKOS_ARCH_INTEL_GPU ON)
endmacro()

@masterleinad can you confirm ?

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.

Yes, we haven't allowed multiple GPU or CPU architectures for any backend.

Comment thread core/src/HIP/Kokkos_HIP.cpp Outdated
@khuck-AMD

Copy link
Copy Markdown
Contributor Author

There are some integer comparison warnings in the CI related to HIPTraits::WarpSize() https://cloud1.cees.ornl.gov/jenkins-ci/job/Kokkos/job/PR-9384/4/stages/

good catch. Fixing that now...

khuck-AMD and others added 3 commits August 4, 2026 13:00
Co-authored-by: Trévis Morvany <63788850+tretre91@users.noreply.github.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>

@dalg24 dalg24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(partial review)

Comment thread core/src/impl/Kokkos_Core.cpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_IsXnack.cpp
Comment thread core/src/HIP/Kokkos_HIP_Instance.hpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_Instance.cpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_Instance.hpp Outdated
}
block_size >>= 1;
} while (block_size >= HIPTraits::WarpSize);
} while (block_size >= static_cast<unsigned>(HIPTraits::WarpSize()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why were we not getting warnings before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Probably because it was replaced with a compile-time constant that did not have a type, just a value?

khuck-AMD and others added 2 commits August 25, 2026 13:30
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Comment thread core/src/HIP/Kokkos_HIP_IsXnack.cpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_IsXnack.cpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_IsXnack.hpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_ReduceScan.hpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_ParallelReduce_Team.hpp Outdated
khuck-AMD and others added 4 commits August 26, 2026 13:24
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Signed-off-by: Kevin Huck <kevin.huck@gmail.com>

@dalg24 dalg24 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(unfinished review but sending it now because I don't want to sit on these for too long)

Comment thread core/src/HIP/Kokkos_HIP_ReduceScan.hpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_ReduceScan.hpp
Comment thread core/src/impl/Kokkos_Core.cpp
Comment thread core/src/HIP/Kokkos_HIP_Instance.hpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_Instance.hpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_Instance.hpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_IsXnack.cpp Outdated
Comment thread core/src/HIP/Kokkos_HIP_IsXnack.cpp Outdated
khuck-AMD and others added 6 commits August 27, 2026 08:45
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Co-authored-by: Damien L-G <dalg24+github@gmail.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
Co-authored-by: Trévis Morvany <63788850+tretre91@users.noreply.github.com>
Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>
…as well as amdgcnspirv special case.

Signed-off-by: Kevin Huck <Kevin.Huck@amd.com>

@tretre91 tretre91 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Other than the comment below and a comment from Damien about mixing west-east const, LGTM

Comment thread cmake/kokkos_arch.cmake
Comment on lines +1165 to +1173
if(KOKKOS_HIP_ARCHITECTURES)
list(LENGTH KOKKOS_HIP_ARCHITECTURES KOKKOS_HIP_ARCH_COUNT_FOR_OPENACC)
if(KOKKOS_HIP_ARCH_COUNT_FOR_OPENACC GREATER 1)
message(
FATAL_ERROR
"Kokkos_ENABLE_OPENACC currently supports only one AMD GPU architecture, but got ${KOKKOS_HIP_ARCHITECTURES}."
)
endif()
endif()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since multiple intel archs are not supported, I would assume the same for multiple AMD archs

macro(CHECK_MULTIPLE_INTEL_ARCH)
  if(KOKKOS_ARCH_INTEL_GPU)
    message(FATAL_ERROR "Specifying multiple Intel GPU architectures is not allowed!")
  endif()
  set(KOKKOS_ARCH_INTEL_GPU ON)
endmacro()

@masterleinad can you confirm ?

@tretre91

Copy link
Copy Markdown
Member

You should also rebase to get some fixes for the CI failures

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.

6 participants