From 3287c1c17655a35e7f788214b684711aefdec10c Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 26 Jun 2025 13:51:57 +0200 Subject: [PATCH] [XeGPU] Move targetinfo constants to their own header file This breaks the dependency from Dialect to Utils, which would be cyclic. --- .../mlir/Dialect/XeGPU/IR/XeGPUTargetInfo.h | 30 +++++++++++++++++++ .../mlir/Dialect/XeGPU/Utils/XeGPUUtils.h | 16 ---------- mlir/lib/Dialect/XeGPU/IR/XeGPUDialect.cpp | 2 +- .../XeGPU/Transforms/XeGPUPropagateLayout.cpp | 1 + .../Transforms/XeGPUSubgroupDistribute.cpp | 1 + .../llvm-project-overlay/mlir/BUILD.bazel | 10 +++---- 6 files changed, 37 insertions(+), 23 deletions(-) create mode 100644 mlir/include/mlir/Dialect/XeGPU/IR/XeGPUTargetInfo.h diff --git a/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUTargetInfo.h b/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUTargetInfo.h new file mode 100644 index 000000000000..8aa9536cb67c --- /dev/null +++ b/mlir/include/mlir/Dialect/XeGPU/IR/XeGPUTargetInfo.h @@ -0,0 +1,30 @@ +//===- XeGPUTargetInfo.h - Target constants ---------------------*- C++ -*-===// +// +// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +// See https://llvm.org/LICENSE.txt for license information. +// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +// +//===----------------------------------------------------------------------===// + +#ifndef MLIR_DIALECT_XEGPU_IR_XEGPUTARGETINFO_H_ +#define MLIR_DIALECT_XEGPU_IR_XEGPUTARGETINFO_H_ + +namespace mlir { +namespace xegpu { +/// HW dependent constants. +/// TODO: These constants should be queried from the target information. +namespace targetinfo { +constexpr unsigned subgroupSize = 16; // How many lanes in a subgroup. +/// If DPAS A or B operands have low precision element types they must be packed +/// according to the following sizes. +constexpr unsigned packedSizeInBitsForDefault = + 16; // Minimum packing size per register for DPAS A. +constexpr unsigned packedSizeInBitsForDpasB = + 32; // Minimum packing size per register for DPAS B. +constexpr unsigned packedSizeInBitsForGatherScatter = + 32; // Minimum packing size per register for Gather and Scatter ops. +} // namespace targetinfo +} // namespace xegpu +} // namespace mlir + +#endif // MLIR_DIALECT_XEGPU_IR_XEGPUTARGETINFO_H_ diff --git a/mlir/include/mlir/Dialect/XeGPU/Utils/XeGPUUtils.h b/mlir/include/mlir/Dialect/XeGPU/Utils/XeGPUUtils.h index 09311e6017d0..6fea10185402 100644 --- a/mlir/include/mlir/Dialect/XeGPU/Utils/XeGPUUtils.h +++ b/mlir/include/mlir/Dialect/XeGPU/Utils/XeGPUUtils.h @@ -24,22 +24,6 @@ class LayoutAttr; class TensorDescType; } // namespace xegpu -namespace xegpu { -/// HW dependent constants. -/// TODO: These constants should be queried from the target information. -namespace targetinfo { -constexpr unsigned subgroupSize = 16; // How many lanes in a subgroup. -/// If DPAS A or B operands have low precision element types they must be packed -/// according to the following sizes. -constexpr unsigned packedSizeInBitsForDefault = - 16; // Minimum packing size per register for DPAS A. -constexpr unsigned packedSizeInBitsForDpasB = - 32; // Minimum packing size per register for DPAS B. -constexpr unsigned packedSizeInBitsForGatherScatter = - 32; // Minimum packing size per register for Gather and Scatter ops. -} // namespace targetinfo -} // namespace xegpu - namespace xegpu { /// Flatten a set of ValueRange into a single SmallVector diff --git a/mlir/lib/Dialect/XeGPU/IR/XeGPUDialect.cpp b/mlir/lib/Dialect/XeGPU/IR/XeGPUDialect.cpp index 649e0d453015..7ef61de190b4 100644 --- a/mlir/lib/Dialect/XeGPU/IR/XeGPUDialect.cpp +++ b/mlir/lib/Dialect/XeGPU/IR/XeGPUDialect.cpp @@ -8,7 +8,7 @@ #include "mlir/Dialect/Utils/IndexingUtils.h" #include "mlir/Dialect/XeGPU/IR/XeGPU.h" -#include "mlir/Dialect/XeGPU/Utils/XeGPUUtils.h" +#include "mlir/Dialect/XeGPU/IR/XeGPUTargetInfo.h" #include "mlir/IR/Builders.h" #include "mlir/IR/DialectImplementation.h" #include "llvm/ADT/TypeSwitch.h" diff --git a/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPropagateLayout.cpp b/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPropagateLayout.cpp index 3c77c83a863e..9558c08c079f 100644 --- a/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPropagateLayout.cpp +++ b/mlir/lib/Dialect/XeGPU/Transforms/XeGPUPropagateLayout.cpp @@ -15,6 +15,7 @@ #include "mlir/Dialect/MemRef/IR/MemRef.h" #include "mlir/Dialect/Vector/IR/VectorOps.h" #include "mlir/Dialect/XeGPU/IR/XeGPU.h" +#include "mlir/Dialect/XeGPU/IR/XeGPUTargetInfo.h" #include "mlir/Dialect/XeGPU/Transforms/Passes.h" #include "mlir/Dialect/XeGPU/Utils/XeGPUUtils.h" #include "mlir/IR/Attributes.h" diff --git a/mlir/lib/Dialect/XeGPU/Transforms/XeGPUSubgroupDistribute.cpp b/mlir/lib/Dialect/XeGPU/Transforms/XeGPUSubgroupDistribute.cpp index 42381ea2683e..c072557c2bd2 100644 --- a/mlir/lib/Dialect/XeGPU/Transforms/XeGPUSubgroupDistribute.cpp +++ b/mlir/lib/Dialect/XeGPU/Transforms/XeGPUSubgroupDistribute.cpp @@ -11,6 +11,7 @@ #include "mlir/Dialect/Vector/IR/VectorOps.h" #include "mlir/Dialect/Vector/Transforms/VectorDistribution.h" #include "mlir/Dialect/XeGPU/IR/XeGPU.h" +#include "mlir/Dialect/XeGPU/IR/XeGPUTargetInfo.h" #include "mlir/Dialect/XeGPU/Transforms/Passes.h" #include "mlir/Dialect/XeGPU/Transforms/Transforms.h" #include "mlir/Dialect/XeGPU/Utils/XeGPUUtils.h" diff --git a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel index 41720f132a9d..9b1089e09efb 100644 --- a/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel +++ b/utils/bazel/llvm-project-overlay/mlir/BUILD.bazel @@ -3519,11 +3519,8 @@ gentbl_cc_library( cc_library( name = "XeGPUDialect", - srcs = [ - "lib/Dialect/XeGPU/IR/XeGPUDialect.cpp", - "lib/Dialect/XeGPU/IR/XeGPUOps.cpp", - ], - hdrs = ["include/mlir/Dialect/XeGPU/IR/XeGPU.h"], + srcs = glob(["lib/Dialect/XeGPU/IR/*.cpp"]), + hdrs = glob(["include/mlir/Dialect/XeGPU/IR/*.h"]), includes = ["include"], deps = [ ":ArithDialect", @@ -4845,7 +4842,8 @@ cc_library( ]), hdrs = glob(["include/mlir/Support/*.h"]), includes = ["include"], - deps = ["//llvm:Support"],) + deps = ["//llvm:Support"], +) cc_library( name = "Debug",