Skip to content

[spirv] Switch to use common target description - #17623

Merged
antiagainst merged 31 commits into
iree-org:mainfrom
antiagainst:vulkan-gpu-target
Jun 18, 2024
Merged

antiagainst merged 31 commits into
iree-org:mainfrom
antiagainst:vulkan-gpu-target

Conversation

@antiagainst

@antiagainst antiagainst commented Jun 9, 2024 •

Copy link
Copy Markdown
Member

This commit switches SPIR-V side to use the common
#iree_gpu.target to describe the GPU characteristics.
With it we can now remove the ad-hoc Vulkan attributes and
dialects and unify how GPU are described across various GPU
compiler backends in IREE.

SPIR-V

SPIR-V has some additional requirements that we need to
account for:

We have many vendors and APIs to handle there so this commit
adds various AMD/ARM/NVIDIA/Qualcomm targets for
development purposes so that we can specify them with
a shorthand.

In order to be extensible, leverage the feature field in
#iree_gpu.target to specify additional capabilities with
cap: prefix and extensions with ext: prefix. We also
use the feature field to specify what SPIR-V version to
target with the spirv:v1.x format.

Right now the SPIRVConvertGPUTarget pass is
invoked immediately before configuration. This is to
stage the changes. As a next step we need to move
it immediately before ConvertToSPIRV pass.

Vulkan

--iree-vulkan-target-env is dropped given now we
removed the whole Vulkan dialect and cannot control with
a #vk.target_env attribute anymore.

The default --iree-vulkan-target-triple now becomes
vp_android_baseline_2022, which is a a good lowest
common denominator to guarantee the generated SPIR-V
is widely accepted. We are not considering SwiftShader
now anymore like previously due to testing purposes.

The --iree-vulkan-target-triple should be renamed
given it's not a triple anymore--that will happen later
together with other GPU backends (i.e., cuda/hip) to
be consistent.

In order to support cooperative matrix conversion, we
added WMMA_F16_16x16x16_F16. For NVIDIA GPUs
we are abusing it right now without considering the
concrete explicit layout--that is fine given in Vulkan
they are opaque anyway. But this need to be fixed if
we are targeting WMMA in CUDA.

Metal / WebGPU

We now contruct a #iree_gpu.target to specify
the target to drive SPIR-V CodeGen.

Progress towards #16341

ci-extra: test_nvidia_gpu,test_nvidia_a100,test_amd_mi250, build_test_all_macos_arm64,build_and_test_android

@antiagainst antiagainst added hal/vulkan Runtime Vulkan GPU HAL backend codegen/spirv SPIR-V code generation compiler backend labels Jun 9, 2024
@antiagainst antiagainst changed the title [spirv][vulkan] Switch to use common target description [spirv] Switch to use common target description Jun 9, 2024
@antiagainst antiagainst added hal/metal Runtime Apple Metal HAL backend hal/webgpu Runtime WebGPU HAL backend labels Jun 9, 2024
def MFMA_F16_32x32x8_F32 : I32EnumAttrCase<"MFMA_F16_32x32x8_F32", 1>;
// TODO: Create separate WMMA ops for AMD and NVIDIA GPUs
def WMMA_F16_16x16x16_F32 : I32EnumAttrCase<"WMMA_F16_16x16x16_F32", 2>;
def WMMA_F16_16x16x16_F16 : I32EnumAttrCase<"WMMA_F16_16x16x16_F16", 3>;

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.

If this is supposed to be for cooperative matrix, we should define a separate attribute for it. This is not very clear from the descriptions below, but IREEGPU_MMAIntrinsic is effectively restricted to LLVMGPU. This is because lowering to amgpu.wmma/mfma (with an explicit layout) only makes sense for intrinsics used when targeting LLVM. We can make some of the interface methods on IREEGPU_MmaInterfaceAttr optional/FailureOr to allow opaque layouts. Then the KernelConfig logic will just look at shapes and doesn't have to care whether the mma kind is opaque or not.

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.

If it's possible to define external interface implementations on attributes, that sounds best and then we just define the interface on #spirv.coop_matrix_props_khr.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The goal is to unify all the different GPU backends with one set of targets. So ideally we should have one #iree_gpu.target that works for both cuda/hip and vulkan. That's largely upheld now--if you look at how getVulkanTargetDetails and getCUDATargetDetails/getHIPTargetDetails, they go to the same underlying getAMDTargetDtails/getNVIDIATargetDetails. This makes sure we have the same wgp = and chip = in #iree_gpu.target. It also conceptually makes sense--it's the same hardware no matter what apis we use to drive it. Though I saied before it's "largely upheld"--we have the feature = part of #iree_gpu.target doing separate things for separate underlying backends. E.g., +sramecc,-xnack for hip, spirv:v1.3 for spirv, etc. That's more controlling what the llvm/spirv backend compiler in llvm/mlir. It's a bit annoying but I don't ever see a way to avoid that.

So I'd be hesitant to create separate mma attributes for separate gpu apis. we can create separate ones for separate vendors, which makes sense because they are different layouts. so that's what I meant we want to create separate ones for nvidia in the comment. even though they are opaque in the vulkan side; they certainly have a hardware layout. for amd side, we know exactly what wmma layout are. for nvidia side, wmma layout is not encoded in their ptx spec but you can figure it out like https://github.com/ahennequ/cuda-tensorcores-register-mapping. though if it's only for vulkan we might not need that info. so I agree with you that we may want to turn some interface methods on IREEGPU_MmaInterfaceAttr as optional.

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.

we can create separate ones for separate vendors, which makes sense because they are different layouts. so that's what I meant we want to create separate ones for nvidia in the comment. even though they are opaque in the vulkan side; they certainly have a hardware layout. for amd side, we know exactly what wmma layout are.

+1

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.

Ok, I see your point. Agreed that excessive duplication is not wanted and somewhat defeats the purpose of this unification. I think it could still be worth adding a generic opaque_mma attribute so that plumbing through all possible intrinsics for a vendor doesn't have to blow up the enum set, assuming we don't want to jump straight to fully fledged non-opaque implementation, but makes sense to do that later as needed.

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.

Actually one other follow up, I see that the vulkan-target-env flag is being dropped, and only see a single WMMA type added here. Are the other (say WMMA_I8_16x16x16_I32) ones still targetable with IREE after this change?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think it could still be worth adding a generic opaque_mma attribute so that plumbing through all possible intrinsics for a vendor doesn't have to blow up the enum set, assuming we don't want to jump straight to fully fledged non-opaque implementation, but makes sense to do that later as needed.

Yeah. I'm trying to cut at a reasonable place for a few things as follow ups and don't want to use one commit to change the whole world. We can do that as a next step. I put an item in #16341.

Actually one other follow up, I see that the vulkan-target-env flag is being dropped, and only see a single WMMA type added here. Are the other (say WMMA_I8_16x16x16_I32) ones still targetable with IREE after this change?

It will fail support for i8 cases. We aren't supporting them anyway for Vulkan previously?

And I'm expecting we are gonna to add that on HIP side next for upcoming workloads so Vulkan picks it up "freely" anyway.

@antiagainst

Copy link
Copy Markdown
Member Author

Okay all tests are passing so this is ready for reviews now..

@ScottTodd
ScottTodd removed their request for review June 17, 2024 16:33
def MFMA_F16_32x32x8_F32 : I32EnumAttrCase<"MFMA_F16_32x32x8_F32", 1>;
// TODO: Create separate WMMA ops for AMD and NVIDIA GPUs
def WMMA_F16_16x16x16_F32 : I32EnumAttrCase<"WMMA_F16_16x16x16_F32", 2>;
def WMMA_F16_16x16x16_F16 : I32EnumAttrCase<"WMMA_F16_16x16x16_F16", 3>;

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.

we can create separate ones for separate vendors, which makes sense because they are different layouts. so that's what I meant we want to create separate ones for nvidia in the comment. even though they are opaque in the vulkan side; they certainly have a hardware layout. for amd side, we know exactly what wmma layout are.

+1

Comment on lines 255 to 256
.Case("mi300x", "gfx942")
.Case("mi300a", "gfx940")

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.

BTW, isn't this off? I thought that the final HW for mi300a and x use the same target triple?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

hmm, okay I didn't know that.. Are you sure about this?

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.

We can change that separately in another PR


StringRef normalizeARMGPUTarget(StringRef target) {
if (target == "valhall")
return "valhall1";

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.

Is this intentional?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yes. We don't have a formal established target naming scheme for arm (from llvm or something) so i'm just making it up for our own uses. Trying to be consistent here to use valhallN like rdnaN or cdnaN. If people give just valhall we default to the lowest level of support there.

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

Awesome cleanup! I will take a closer look tomorrow, but most of the removed code is outside what I have immediate context on, so I'm inclined to just approve it.

@@ -8,13 +8,13 @@
#include "iree/compiler/tool_entry_points_api.h"

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.

What is the reason these changes are included as a part of this PR?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

There are some header include changes in other places caused this file filed to compile. So I fixed some header include issue. And along the way dropped the llvm:: prefix which isn't necessary given using namespace.

def MFMA_F16_32x32x8_F32 : I32EnumAttrCase<"MFMA_F16_32x32x8_F32", 1>;
// TODO: Create separate WMMA ops for AMD and NVIDIA GPUs
def WMMA_F16_16x16x16_F32 : I32EnumAttrCase<"WMMA_F16_16x16x16_F32", 2>;
def WMMA_F16_16x16x16_F16 : I32EnumAttrCase<"WMMA_F16_16x16x16_F16", 3>;

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.

Ok, I see your point. Agreed that excessive duplication is not wanted and somewhat defeats the purpose of this unification. I think it could still be worth adding a generic opaque_mma attribute so that plumbing through all possible intrinsics for a vendor doesn't have to blow up the enum set, assuming we don't want to jump straight to fully fledged non-opaque implementation, but makes sense to do that later as needed.

static const WgpDetails valhallWgp = {
computeBitwdiths, allStorageBits, allSubgroupOps, allDotProductOps,
/*mmaCount=*/0, /*mmaOps=*/nullptr, {16}, {512, 512, 512},
512, 32 * 1024};

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.

What is the motivation behind the formatting here? I see the max threads per dim on the second line here, unlike about where it's on the third line (only commenting because I see clang-format off and trying to understand what this is trying to capture).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Just trying to organize this a bit better to avoid spanning many lines.. No particular reasons. You can call this formating a bit personal taste though. :)

def MFMA_F16_32x32x8_F32 : I32EnumAttrCase<"MFMA_F16_32x32x8_F32", 1>;
// TODO: Create separate WMMA ops for AMD and NVIDIA GPUs
def WMMA_F16_16x16x16_F32 : I32EnumAttrCase<"WMMA_F16_16x16x16_F32", 2>;
def WMMA_F16_16x16x16_F16 : I32EnumAttrCase<"WMMA_F16_16x16x16_F16", 3>;

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.

Actually one other follow up, I see that the vulkan-target-env flag is being dropped, and only see a single WMMA type added here. Are the other (say WMMA_I8_16x16x16_I32) ones still targetable with IREE after this change?

@antiagainst
antiagainst requested review from kuhar and qedawkins June 18, 2024 21:38
@antiagainst
antiagainst merged commit 7b9fb12 into iree-org:main Jun 18, 2024
@antiagainst
antiagainst deleted the vulkan-gpu-target branch June 18, 2024 22:16
@ScottTodd

Copy link
Copy Markdown
Member

This appears to have broken some benchmark builds: https://github.com/iree-org/iree/actions/runs/9572945480/job/26393626504#step:7:706

FAILED: e2e_test_artifacts/iree_module_MobileBertSquad_int8_tflite___arm-valhall-vulkan_android31-vulkan_spirv__default-flags_compile-stats_/module.vmfb /work/build-e2e-test-artifacts/e2e_test_artifacts/iree_module_MobileBertSquad_int8_tflite___arm-valhall-vulkan_android31-vulkan_spirv__default-flags_compile-stats_/module.vmfb 
cd /work/build-e2e-test-artifacts/tests/e2e/test_artifacts && /work/full-build-dir/install/bin/iree-compile --output-format=vm-bytecode --mlir-print-op-on-diagnostic=false --iree-hal-target-backends=vulkan-spirv --iree-input-type=tosa --iree-vulkan-target-triple=valhall-unknown-android31 --iree-vm-emit-polyglot-zip=true --iree-llvmcpu-debug-symbols=false --iree-scheduling-dump-statistics-format=json --iree-scheduling-dump-statistics-file=/work/build-e2e-test-artifacts/e2e_test_artifacts/iree_module_MobileBertSquad_int8_tflite___arm-valhall-vulkan_android31-vulkan_spirv__default-flags_compile-stats_/scheduling_stats.json /work/build-e2e-test-artifacts/e2e_test_artifacts/iree_MobileBertSquad_int8_tflite_.mlir -o /work/build-e2e-test-artifacts/e2e_test_artifacts/iree_module_MobileBertSquad_int8_tflite___arm-valhall-vulkan_android31-vulkan_spirv__default-flags_compile-stats_/module.vmfb --iree-hal-executable-object-search-path=\"/work/build-e2e-test-artifacts\"
failed to translate executables
failed to translate executables
failed to translate executables
failed to translate executables
failed to translate executables
failed to translate executables
failed to translate executables
failed to translate executables
failed to translate executables
<unknown>:0: error: loc(callsite("model/bert_span_labeler/mobile_bert_encoder/mobile_bert_embedding/embedding_norm/add" at "main")): 'spirv.VectorShuffle' op result #0 must be vector of bool or 8/16/32/64-bit integer or 16/32/64-bit float values of length 2/3/4/8/16, but got 'i32'
<unknown>:0: note: loc("main"): called from
<unknown>:0: error: loc(callsite("model/bert_span_labeler/mobile_bert_encoder/mobile_bert_embedding/embedding_norm/add" at "main")): failed to run translation of source executable to target executable for backend #hal.executable.target<"vulkan-spirv", "vulkan-spirv-fb", {iree.gpu.target = #iree_gpu.target<arch = "valhall1", features = "spirv:v1.4,cap:Shader", wgp = <compute =  fp32|fp16|int64|int32|int16|int8, storage =  b64|b32|b16|b8, subgroup =  shuffle|arithmetic, dot =  dp4xi8toi32, mma = [], subgroup_size_choices = [16, 0], max_workgroup_sizes = [512, 512, 512], max_thread_count_per_workgroup = 512, max_workgroup_memory_bytes = 32768>>, spirv.target_env = #spirv.target_env<#spirv.vce<v1.4, [Shader, Float16, Int64, Int16, Int8, StorageBuffer16BitAccess, StorageUniform16, StoragePushConstant16, StorageBuffer8BitAccess, UniformAndStorageBuffer8BitAccess, StoragePushConstant8, GroupNonUniformShuffle, GroupNonUniformShuffleRelative, GroupNonUniformArithmetic, DotProduct, DotProductInput4x8BitPacked, DotProductInputAll, DotProductInput4x8Bit], [SPV_KHR_16bit_storage, SPV_KHR_8bit_storage, SPV_KHR_integer_dot_product]>, #spirv.resource_limits<max_compute_shared_memory_size = 32768, max_compute_workgroup_invocations = 512, max_compute_workgroup_size = [512 : i32, 512 : i32, 512 : i32], subgroup_size = 16, min_subgroup_size = 0, max_subgroup_size = 16, cooperative_matrix_properties_khr = []>>}>

ScottTodd added a commit that referenced this pull request Jun 19, 2024
ScottTodd added a commit that referenced this pull request Jun 19, 2024
Reverts #17623

This appears to have broken some benchmark builds.
antiagainst added a commit to antiagainst/iree that referenced this pull request Jun 19, 2024
This relands iree-org#17623.

This commit switches SPIR-V side to use the common
`#iree_gpu.target` to describe the GPU characteristics.
With it we can now remove the ad-hoc Vulkan attributes and
dialects and unify how GPU are described across various GPU
compiler backends in IREE.

SPIR-V has some additional requirements that we need to
account for:

We have many vendors and APIs to handle there so this commit
adds various AMD/ARM/NVIDIA/Qualcomm targets for
development purposes so that we can specify them with
a shorthand.

In order to be extensible, leverage the `feature` field in
`#iree_gpu.target` to specify additional capabilities with
`cap:` prefix and extensions with `ext:` prefix. We also
use the `feature` field to specify what SPIR-V version to
target with the `spirv:v1.x` format.

Right now the `SPIRVConvertGPUTarget` pass is
invoked immediately before configuration. This is to
stage the changes. As a next step we need to move
it immediately before `ConvertToSPIRV` pass.

`--iree-vulkan-target-env` is dropped given now we
removed the whole Vulkan dialect and cannot control with
a `#vk.target_env` attribute anymore.

The default `--iree-vulkan-target-triple` now becomes
`vp_android_baseline_2022`, which is a a good lowest
common denominator to guarantee the generated SPIR-V
is widely accepted. We are not considering SwiftShader
now anymore like previously due to testing purposes.

The `--iree-vulkan-target-triple` should be renamed
given it's not a triple anymore--that will happen later
together with other GPU backends (i.e., cuda/hip) to
be consistent.

In order to support cooperative matrix conversion, we
added `WMMA_F16_16x16x16_F16`. For NVIDIA GPUs
we are abusing it right now without considering the
concrete explicit layout--that is fine given in Vulkan
they are opaque anyway. But this need to be fixed if
we are targeting WMMA in CUDA.

We now contruct a `#iree_gpu.target` to specify
the target to drive SPIR-V CodeGen.

Progress towards iree-org#16341

ci-extra: test_nvidia_gpu,test_nvidia_a100,test_amd_mi250,
build_test_all_macos_arm64,build_and_test_android
antiagainst added a commit to antiagainst/iree that referenced this pull request Jun 19, 2024
This relands iree-org#17623.

This commit switches SPIR-V side to use the common
`#iree_gpu.target` to describe the GPU characteristics.
With it we can now remove the ad-hoc Vulkan attributes and
dialects and unify how GPU are described across various GPU
compiler backends in IREE.

SPIR-V has some additional requirements that we need to
account for:

We have many vendors and APIs to handle there so this commit
adds various AMD/ARM/NVIDIA/Qualcomm targets for
development purposes so that we can specify them with
a shorthand.

In order to be extensible, leverage the `feature` field in
`#iree_gpu.target` to specify additional capabilities with
`cap:` prefix and extensions with `ext:` prefix. We also
use the `feature` field to specify what SPIR-V version to
target with the `spirv:v1.x` format.

Right now the `SPIRVConvertGPUTarget` pass is
invoked immediately before configuration. This is to
stage the changes. As a next step we need to move
it immediately before `ConvertToSPIRV` pass.

`--iree-vulkan-target-env` is dropped given now we
removed the whole Vulkan dialect and cannot control with
a `#vk.target_env` attribute anymore.

The default `--iree-vulkan-target-triple` now becomes
`vp_android_baseline_2022`, which is a a good lowest
common denominator to guarantee the generated SPIR-V
is widely accepted. We are not considering SwiftShader
now anymore like previously due to testing purposes.

The `--iree-vulkan-target-triple` should be renamed
given it's not a triple anymore--that will happen later
together with other GPU backends (i.e., cuda/hip) to
be consistent.

In order to support cooperative matrix conversion, we
added `WMMA_F16_16x16x16_F16`. For NVIDIA GPUs
we are abusing it right now without considering the
concrete explicit layout--that is fine given in Vulkan
they are opaque anyway. But this need to be fixed if
we are targeting WMMA in CUDA.

We now contruct a `#iree_gpu.target` to specify
the target to drive SPIR-V CodeGen.

Progress towards iree-org#16341

ci-extra: test_nvidia_gpu,test_nvidia_a100,test_amd_mi250,
build_test_all_macos_arm64,build_and_test_android

Signed-off-by: Lei Zhang <[email protected]>
ScottTodd pushed a commit that referenced this pull request Jun 20, 2024
This relands #17623.

This commit switches SPIR-V side to use the common `#iree_gpu.target` to
describe the GPU characteristics. With it we can now remove the ad-hoc
Vulkan attributes and dialects and unify how GPU are described across
various GPU compiler backends in IREE.

SPIR-V has some additional requirements that we need to account for:

We have many vendors and APIs to handle there so this commit adds
various AMD/ARM/NVIDIA/Qualcomm targets for
development purposes so that we can specify them with a shorthand.

In order to be extensible, leverage the `feature` field in
`#iree_gpu.target` to specify additional capabilities with `cap:` prefix
and extensions with `ext:` prefix. We also use the `feature` field to
specify what SPIR-V version to target with the `spirv:v1.x` format.

Right now the `SPIRVConvertGPUTarget` pass is
invoked immediately before configuration. This is to stage the changes.
As a next step we need to move
it immediately before `ConvertToSPIRV` pass.

`--iree-vulkan-target-env` is dropped given now we removed the whole
Vulkan dialect and cannot control with a `#vk.target_env` attribute
anymore.

The default `--iree-vulkan-target-triple` now becomes
`vp_android_baseline_2022`, which is a a good lowest common denominator
to guarantee the generated SPIR-V is widely accepted. We are not
considering SwiftShader now anymore like previously due to testing
purposes.

The `--iree-vulkan-target-triple` should be renamed given it's not a
triple anymore--that will happen later together with other GPU backends
(i.e., cuda/hip) to be consistent.

In order to support cooperative matrix conversion, we added
`WMMA_F16_16x16x16_F16`. For NVIDIA GPUs
we are abusing it right now without considering the concrete explicit
layout--that is fine given in Vulkan they are opaque anyway. But this
need to be fixed if we are targeting WMMA in CUDA.

We now contruct a `#iree_gpu.target` to specify
the target to drive SPIR-V CodeGen.

Progress towards #16341

ci-extra: test_nvidia_gpu,test_nvidia_a100,test_amd_mi250,
build_test_all_macos_arm64,build_and_test_android,test_on_moto-edge-x30

---------

Signed-off-by: Lei Zhang <[email protected]>
Groverkss pushed a commit to Groverkss/iree that referenced this pull request Jun 20, 2024
This commit switches SPIR-V side to use the common
`#iree_gpu.target` to describe the GPU characteristics.
With it we can now remove the ad-hoc Vulkan attributes and
dialects and unify how GPU are described across various GPU
compiler backends in IREE.

#### SPIR-V

SPIR-V has some additional requirements that we need to
account for:

We have many vendors and APIs to handle there so this commit
adds various AMD/ARM/NVIDIA/Qualcomm targets for
development purposes so that we can specify them with
a shorthand.

In order to be extensible, leverage the `feature` field in
`#iree_gpu.target` to specify additional capabilities with
`cap:` prefix and extensions with `ext:` prefix. We also
use the `feature` field to specify what SPIR-V version to
target with the `spirv:v1.x` format.

Right now the `SPIRVConvertGPUTarget` pass is
invoked immediately before configuration. This is to
stage the changes. As a next step we need to move
it immediately before `ConvertToSPIRV` pass.

#### Vulkan

`--iree-vulkan-target-env` is dropped given now we
removed the whole Vulkan dialect and cannot control with
a `#vk.target_env` attribute anymore.

The default `--iree-vulkan-target-triple` now becomes
`vp_android_baseline_2022`, which is a a good lowest
common denominator to guarantee the generated SPIR-V
is widely accepted. We are not considering SwiftShader
now anymore like previously due to testing purposes.

The `--iree-vulkan-target-triple` should be renamed
given it's not a triple anymore--that will happen later
together with other GPU backends (i.e., cuda/hip) to
be consistent.

In order to support cooperative matrix conversion, we
added `WMMA_F16_16x16x16_F16`. For NVIDIA GPUs
we are abusing it right now without considering the
concrete explicit layout--that is fine given in Vulkan
they are opaque anyway. But this need to be fixed if
we are targeting WMMA in CUDA.

#### Metal / WebGPU

We now contruct a `#iree_gpu.target` to specify
the target to drive SPIR-V CodeGen.

Progress towards iree-org#16341

ci-extra: test_nvidia_gpu,test_nvidia_a100,test_amd_mi250,
build_test_all_macos_arm64,build_and_test_android
Groverkss pushed a commit to Groverkss/iree that referenced this pull request Jun 20, 2024
)

Reverts iree-org#17623

This appears to have broken some benchmark builds.
LLITCHEV pushed a commit to LLITCHEV/iree that referenced this pull request Jul 30, 2024
This commit switches SPIR-V side to use the common
`#iree_gpu.target` to describe the GPU characteristics.
With it we can now remove the ad-hoc Vulkan attributes and
dialects and unify how GPU are described across various GPU
compiler backends in IREE.

#### SPIR-V

SPIR-V has some additional requirements that we need to
account for:

We have many vendors and APIs to handle there so this commit
adds various AMD/ARM/NVIDIA/Qualcomm targets for
development purposes so that we can specify them with
a shorthand.

In order to be extensible, leverage the `feature` field in
`#iree_gpu.target` to specify additional capabilities with
`cap:` prefix and extensions with `ext:` prefix. We also
use the `feature` field to specify what SPIR-V version to
target with the `spirv:v1.x` format.

Right now the `SPIRVConvertGPUTarget` pass is
invoked immediately before configuration. This is to
stage the changes. As a next step we need to move
it immediately before `ConvertToSPIRV` pass.

#### Vulkan

`--iree-vulkan-target-env` is dropped given now we
removed the whole Vulkan dialect and cannot control with
a `#vk.target_env` attribute anymore.

The default `--iree-vulkan-target-triple` now becomes
`vp_android_baseline_2022`, which is a a good lowest
common denominator to guarantee the generated SPIR-V
is widely accepted. We are not considering SwiftShader
now anymore like previously due to testing purposes.

The `--iree-vulkan-target-triple` should be renamed
given it's not a triple anymore--that will happen later
together with other GPU backends (i.e., cuda/hip) to
be consistent.

In order to support cooperative matrix conversion, we
added `WMMA_F16_16x16x16_F16`. For NVIDIA GPUs
we are abusing it right now without considering the
concrete explicit layout--that is fine given in Vulkan
they are opaque anyway. But this need to be fixed if
we are targeting WMMA in CUDA.

#### Metal / WebGPU

We now contruct a `#iree_gpu.target` to specify
the target to drive SPIR-V CodeGen.

Progress towards iree-org#16341

ci-extra: test_nvidia_gpu,test_nvidia_a100,test_amd_mi250,
build_test_all_macos_arm64,build_and_test_android

Signed-off-by: Lubo Litchev <[email protected]>
LLITCHEV pushed a commit to LLITCHEV/iree that referenced this pull request Jul 30, 2024
)

Reverts iree-org#17623

This appears to have broken some benchmark builds.

Signed-off-by: Lubo Litchev <[email protected]>
LLITCHEV pushed a commit to LLITCHEV/iree that referenced this pull request Jul 30, 2024
)

This relands iree-org#17623.

This commit switches SPIR-V side to use the common `#iree_gpu.target` to
describe the GPU characteristics. With it we can now remove the ad-hoc
Vulkan attributes and dialects and unify how GPU are described across
various GPU compiler backends in IREE.

SPIR-V has some additional requirements that we need to account for:

We have many vendors and APIs to handle there so this commit adds
various AMD/ARM/NVIDIA/Qualcomm targets for
development purposes so that we can specify them with a shorthand.

In order to be extensible, leverage the `feature` field in
`#iree_gpu.target` to specify additional capabilities with `cap:` prefix
and extensions with `ext:` prefix. We also use the `feature` field to
specify what SPIR-V version to target with the `spirv:v1.x` format.

Right now the `SPIRVConvertGPUTarget` pass is
invoked immediately before configuration. This is to stage the changes.
As a next step we need to move
it immediately before `ConvertToSPIRV` pass.

`--iree-vulkan-target-env` is dropped given now we removed the whole
Vulkan dialect and cannot control with a `#vk.target_env` attribute
anymore.

The default `--iree-vulkan-target-triple` now becomes
`vp_android_baseline_2022`, which is a a good lowest common denominator
to guarantee the generated SPIR-V is widely accepted. We are not
considering SwiftShader now anymore like previously due to testing
purposes.

The `--iree-vulkan-target-triple` should be renamed given it's not a
triple anymore--that will happen later together with other GPU backends
(i.e., cuda/hip) to be consistent.

In order to support cooperative matrix conversion, we added
`WMMA_F16_16x16x16_F16`. For NVIDIA GPUs
we are abusing it right now without considering the concrete explicit
layout--that is fine given in Vulkan they are opaque anyway. But this
need to be fixed if we are targeting WMMA in CUDA.

We now contruct a `#iree_gpu.target` to specify
the target to drive SPIR-V CodeGen.

Progress towards iree-org#16341

ci-extra: test_nvidia_gpu,test_nvidia_a100,test_amd_mi250,
build_test_all_macos_arm64,build_and_test_android,test_on_moto-edge-x30

---------

Signed-off-by: Lei Zhang <[email protected]>
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/spirv SPIR-V code generation compiler backend hal/metal Runtime Apple Metal HAL backend hal/vulkan Runtime Vulkan GPU HAL backend hal/webgpu Runtime WebGPU HAL backend

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants