Skip to content

[Feature]: Better preprocessor macros to detect RDNA/CDNA family at compile time #59

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
benrichard-amd opened this issue Apr 8, 2024 · 2 comments
Assignees
Labels
generic Build error, or some other issue not caused by an LLVM bug Under Investigation

Comments

@benrichard-amd
Copy link

benrichard-amd commented Apr 8, 2024

Suggestion Description

As new instructions/features are added with each new arch, it is useful to know the target architecture at compile time to employ separate code paths. For example: FP64 MFMA was added in CDNA2, so CDNA2 and later can use one code path while CDNA1 uses a different code path.

It gets tedious because all the archs need to be enumerated, and code needs to be updated as new archs become available:

#if __gfx940__ || __gfx941__ || __gfx942__
// Code path for CDNA3
#elif __gfx90a__
// Code path for CNDA2
#elif __gfx908__
// Code path for CDNA1
#endif

It would be nice if we had something like:

#if CDNA_VERSION >= 3
// Code path for CDNA3 and later
#elif CDNA_VERSION >= 2
// Code path for CDNA2
#else
// Code path for CDNA1
#endif

This would mirror the way it is done in CUDA:

__device__ func()
{
#if __CUDA_ARCH__ >= 800
   // Code path for compute capability 8.x and later
#elif __CUDA_ARCH__ >= 700
   // Code path for compute capability 7.x
#else
  // Code path for compute capability < 7.0
#endif
}

Operating System

No response

GPU

No response

ROCm Component

No response

@mangupta mangupta transferred this issue from ROCm/hip Apr 9, 2024
yxsamliu added a commit to yxsamliu/llvm-project that referenced this issue Apr 10, 2024
If a processor belongs to CDNA generation, pre-define macro
`__AMDGCN_CDNA_VERSION__` as an integer.

Fixes: ROCm#59
@yxsamliu yxsamliu self-assigned this Apr 10, 2024
@yxsamliu
Copy link

There are some concerns about introducing a macro for CDNA version.

Using #if __has_builtin may be a better way to determine whether a feature is available (https://clang.llvm.org/docs/LanguageExtensions.html#feature-checking-macros). It works for all GPUs, even for future generations.

@ppanchad-amd ppanchad-amd added Under Investigation generic Build error, or some other issue not caused by an LLVM bug labels Jan 13, 2025
@ppanchad-amd
Copy link

Hi @benrichard-amd. Compiler team had internal discussion and the consensus is not to implement this. Closing ticket.

@ppanchad-amd ppanchad-amd closed this as not planned Won't fix, can't repro, duplicate, stale Mar 19, 2025
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
generic Build error, or some other issue not caused by an LLVM bug Under Investigation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants