Skip to content

[GPU] Thread through a common target description - #17217

Merged
antiagainst merged 38 commits into
iree-org:mainfrom
antiagainst:gpu-target
May 21, 2024
Merged

antiagainst merged 38 commits into
iree-org:mainfrom
antiagainst:gpu-target

Conversation

@antiagainst

@antiagainst antiagainst commented Apr 29, 2024 •

Copy link
Copy Markdown
Member

This commit starts threading through a common target description
for various GPU backends. The goal is to unify how we specify
the target across CUDA, HIP, Vulkan, and others, so that we can
be consistent and reuse the some facilities.

Concretely, we introduce a #iree_gpu.target attribute in the
IREEGPUDialect to describe the GPU target. It includes a few
fields:

  • The canonical target architecture for compilation, e.g.,
    sm_80 for cuda, gfx942 for hip
  • A TargetWgpAttr describing the GPU features and limits in a
    single GPU workgroup processsor (that is, AMD compute unit
    or NVIDIA streaming multiprocessor), e.g., compute/storage
    capabilities, subgroup sizes, and workgroup size limits
  • An optional TargetChipAttr describing GPU features for the
    final chip or product, e.g., wgp count

To help writing tests, we also introduce another command-line
option, --iree-gpu-test-target to specify the target. This option
will be queried if we cannot find the #iree_gpu.target attribute
in the wrapping IR. This avoids us to duplicate the full target
for each test to be concise and clear.

In order to support common development targets and the shorthand
attribute, we list some common AMD/NVIDIA GPU architectures
and their capabilities and limits. This is in general fine for
datacenter GPU use cases where we only ever care one architecture.

This starts with update both LLVMGPU backends (CUDA and ROCm)
to use the new target description. Vulkan side is untouched and
the next step to unify.

Progress towards #16341

ci-extra: test_nvidia_gpu,test_nvidia_a100,test_amd_mi250,test_amd_w7900

This commit cleans up some header includes and build dependencies:

* Created a new target for VectorLayoutAnalysis
* Dropped Codegen/Common and Codegen/Utils dependencies from
  IREEGPU dialect
* Removed various header includes not directly used

This is a preliminary step for plumbing through a target description,
to be defined in the IREEGPU dialect, for various GPU backends.
This commit starts threading through a common target description
for various GPU backends. The goal is to unify how we specify
the target across CUDA, HIP, Vulkan, and others, so that we can
be consistent and reuse the some facilities.

Concretely, we introduce a `#iree_gpu.target` attribute in the
`IREEGPUDialect` to describe the GPU target. It includes a few
fields:

* The target GPU API, e.g., cuda, hip, vulkan
* The canonical target architecture for compilation, e.g.,
  sm_80 for cuda, gfx942 for hip
* A TargetCoreAttr describing the GPU features and limits in a
  single GPU core (that is, AMD compute unit or NVIDIA streaming
  multiprocessor), e.g., compute/storage capabilities, subgroup
  sizes, and workgroup size limits
* An optional TargetChipAttr describing GPU features for the
  final chip or product, e.g., core count

To help writing tests, we also introduce another shorthand
`#iree_gpu.abbr_target` attribute which contains two fields--the
target API and the target arch/chip/product. The target
arch/chip/product must be known to the compiler.

In order to support common development targets and the shorthand
attribute, we list some common AMD/NVIDIA GPU architectures
and their capabilities and limits. This is in general fine for
datacenter GPU use cases where we only ever care one architecture.

This starts with update both LLVMGPU backends (CUDA and ROCm)
to use the new target description. Vulkan side is untouched and
the next step to unify.
@antiagainst antiagainst added codegen Shared code generation infrastructure and dialects codegen/rocm ROCm code generation compiler backend (HIP/HSA) codegen/nvvm NVVM code generation compiler backend labels Apr 29, 2024

@benvanik benvanik left a comment

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'm a bit concerned at how rigid this is with the enums - this makes it impossible to reuse the fields in plugins that may add additional information - for example, if a user wanted to experiment out of tree with a different API, a different DotProduct data type, etc they can't without upstreaming the new enum values first. Some of that we could probably fix by turning the enums into proper attribute interfaces (so a user could define their own target API that implemented an interface with whatever you're currently switching on the integer for), but something to keep in mind while designing this stuff: we don't want to end up preventing plugins that interoperate with our lowerings or require lock-step development between the plugins and upstream codebases or nasty patches to inject new enum values.

The enums also have a smell of artificial generality: that you need to know the runtime API is sketchy as it implies there will be common code that will switch on that and make decisions in a way a user cannot control without forking/patching. If common code won't be using the runtime API to switch on then it should be omitted and instead represented by construction: the CUDA target will be constructing all the pipelines and knows it's targeting CUDA, and no common passes it adds to its pipeline should care about the fact that the CUDA target created it and only whatever pass options are specified on it.

@antiagainst
antiagainst requested review from benvanik and kuhar and removed request for dcaballe, hanhanW and stellaraccident May 20, 2024 16:40
@antiagainst

antiagainst commented May 20, 2024 •

Copy link
Copy Markdown
Member Author

@benvanik I changed to 1) add an extra dictionary attr to allow better flexibility for out of tree targets, and 2) changed to use a cl option --iree-gpu-test-target to provide the target for lit tests instead of the alias target, as we chatted before. Could you take another look? thanks.

@kuhar kuhar 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.

LGTM

@qedawkins

Copy link
Copy Markdown
Contributor

Oh sorry, I think I caused those conflicts because I had the same problem with the enum definitions. Do you want me to fix them?

@antiagainst

Copy link
Copy Markdown
Member Author

Oh sorry, I think I caused those conflicts because I had the same problem with the enum definitions. Do you want me to fix them?

Don't worry. I think I fixed them. :)

@qedawkins

Copy link
Copy Markdown
Contributor

ok nice :D

@antiagainst

Copy link
Copy Markdown
Member Author

Oh actually new ones.. Let me see. :D

@antiagainst
antiagainst merged commit f6a38ac into iree-org:main May 21, 2024
@antiagainst
antiagainst deleted the gpu-target branch May 21, 2024 03:15
@raikonenfnu
raikonenfnu self-requested a review May 22, 2024 08:00
gglangg pushed a commit to gglangg/iree that referenced this pull request Jun 4, 2024
This commit starts threading through a common target description
for various GPU backends. The goal is to unify how we specify
the target across CUDA, HIP, Vulkan, and others, so that we can
be consistent and reuse the some facilities.

Concretely, we introduce a `#iree_gpu.target` attribute in the
`IREEGPUDialect` to describe the GPU target. It includes a few
fields:

* The canonical target architecture for compilation, e.g.,
  sm_80 for cuda, gfx942 for hip
* A TargetWgpAttr describing the GPU features and limits in a
  single GPU workgroup processsor (that is, AMD compute unit
  or NVIDIA streaming multiprocessor), e.g., compute/storage
  capabilities, subgroup sizes, and workgroup size limits
* An optional TargetChipAttr describing GPU features for the
  final chip or product, e.g., wgp count

To help writing tests, we also introduce another command-line
option, `--iree-gpu-test-target` to specify the target. This option
will be queried if we cannot find the `#iree_gpu.target` attribute
in the wrapping IR. This avoids us to duplicate the full target
for each test to be concise and clear.

In order to support common development targets and the shorthand
attribute, we list some common AMD/NVIDIA GPU architectures
and their capabilities and limits. This is in general fine for
datacenter GPU use cases where we only ever care one architecture.

This starts with update both LLVMGPU backends (CUDA and ROCm)
to use the new target description. Vulkan side is untouched and
the next step to unify.

Progress towards iree-org#16341

ci-extra: test_nvidia_gpu,test_nvidia_a100,test_amd_mi250,test_amd_w7900
gglangg pushed a commit to gglangg/iree that referenced this pull request Jun 4, 2024
This commit starts threading through a common target description
for various GPU backends. The goal is to unify how we specify
the target across CUDA, HIP, Vulkan, and others, so that we can
be consistent and reuse the some facilities.

Concretely, we introduce a `#iree_gpu.target` attribute in the
`IREEGPUDialect` to describe the GPU target. It includes a few
fields:

* The canonical target architecture for compilation, e.g.,
  sm_80 for cuda, gfx942 for hip
* A TargetWgpAttr describing the GPU features and limits in a
  single GPU workgroup processsor (that is, AMD compute unit
  or NVIDIA streaming multiprocessor), e.g., compute/storage
  capabilities, subgroup sizes, and workgroup size limits
* An optional TargetChipAttr describing GPU features for the
  final chip or product, e.g., wgp count

To help writing tests, we also introduce another command-line
option, `--iree-gpu-test-target` to specify the target. This option
will be queried if we cannot find the `#iree_gpu.target` attribute
in the wrapping IR. This avoids us to duplicate the full target
for each test to be concise and clear.

In order to support common development targets and the shorthand
attribute, we list some common AMD/NVIDIA GPU architectures
and their capabilities and limits. This is in general fine for
datacenter GPU use cases where we only ever care one architecture.

This starts with update both LLVMGPU backends (CUDA and ROCm)
to use the new target description. Vulkan side is untouched and
the next step to unify.

Progress towards iree-org#16341

ci-extra: test_nvidia_gpu,test_nvidia_a100,test_amd_mi250,test_amd_w7900
bangtianliu pushed a commit to bangtianliu/iree that referenced this pull request Jun 5, 2024
This commit starts threading through a common target description
for various GPU backends. The goal is to unify how we specify
the target across CUDA, HIP, Vulkan, and others, so that we can
be consistent and reuse the some facilities.

Concretely, we introduce a `#iree_gpu.target` attribute in the
`IREEGPUDialect` to describe the GPU target. It includes a few
fields:

* The canonical target architecture for compilation, e.g.,
  sm_80 for cuda, gfx942 for hip
* A TargetWgpAttr describing the GPU features and limits in a
  single GPU workgroup processsor (that is, AMD compute unit
  or NVIDIA streaming multiprocessor), e.g., compute/storage
  capabilities, subgroup sizes, and workgroup size limits
* An optional TargetChipAttr describing GPU features for the
  final chip or product, e.g., wgp count

To help writing tests, we also introduce another command-line
option, `--iree-gpu-test-target` to specify the target. This option
will be queried if we cannot find the `#iree_gpu.target` attribute
in the wrapping IR. This avoids us to duplicate the full target
for each test to be concise and clear.

In order to support common development targets and the shorthand
attribute, we list some common AMD/NVIDIA GPU architectures
and their capabilities and limits. This is in general fine for
datacenter GPU use cases where we only ever care one architecture.

This starts with update both LLVMGPU backends (CUDA and ROCm)
to use the new target description. Vulkan side is untouched and
the next step to unify.

Progress towards iree-org#16341

ci-extra: test_nvidia_gpu,test_nvidia_a100,test_amd_mi250,test_amd_w7900
LLITCHEV pushed a commit to LLITCHEV/iree that referenced this pull request Jul 30, 2024
This commit starts threading through a common target description
for various GPU backends. The goal is to unify how we specify
the target across CUDA, HIP, Vulkan, and others, so that we can
be consistent and reuse the some facilities.

Concretely, we introduce a `#iree_gpu.target` attribute in the
`IREEGPUDialect` to describe the GPU target. It includes a few
fields:

* The canonical target architecture for compilation, e.g.,
  sm_80 for cuda, gfx942 for hip
* A TargetWgpAttr describing the GPU features and limits in a
  single GPU workgroup processsor (that is, AMD compute unit
  or NVIDIA streaming multiprocessor), e.g., compute/storage
  capabilities, subgroup sizes, and workgroup size limits
* An optional TargetChipAttr describing GPU features for the
  final chip or product, e.g., wgp count

To help writing tests, we also introduce another command-line
option, `--iree-gpu-test-target` to specify the target. This option
will be queried if we cannot find the `#iree_gpu.target` attribute
in the wrapping IR. This avoids us to duplicate the full target
for each test to be concise and clear.

In order to support common development targets and the shorthand
attribute, we list some common AMD/NVIDIA GPU architectures
and their capabilities and limits. This is in general fine for
datacenter GPU use cases where we only ever care one architecture.

This starts with update both LLVMGPU backends (CUDA and ROCm)
to use the new target description. Vulkan side is untouched and
the next step to unify.

Progress towards iree-org#16341

ci-extra: test_nvidia_gpu,test_nvidia_a100,test_amd_mi250,test_amd_w7900
Signed-off-by: Lubo Litchev <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

codegen/nvvm NVVM code generation compiler backend codegen/rocm ROCm code generation compiler backend (HIP/HSA) codegen Shared code generation infrastructure and dialects

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants