Skip to content

[MLIR] reverse int8 type's printing logic #69361

New issue

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

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

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions mlir/include/mlir/Dialect/Mesh/IR/MeshBase.td
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def MeshSharding : AttrDef<Mesh_Dialect, "MeshSharding"> {

let parameters = (ins
AttrParameter<"::mlir::SymbolRefAttr", "cluster placed">:$cluster,
ArrayRefParameter<"::mlir::DenseI8ArrayAttr">:$split_axes,
OptionalArrayRefParameter<"int8_t">:$partial_axes,
ArrayRefParameter<"::mlir::DenseI32ArrayAttr">:$split_axes,
OptionalArrayRefParameter<"int32_t">:$partial_axes,
OptionalParameter<"::mlir::mesh::Partial">:$partial_type
);

Expand Down
2 changes: 1 addition & 1 deletion mlir/include/mlir/Dialect/Mesh/IR/MeshOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def Mesh_ClusterOp : Mesh_Op<"cluster", [Symbol]> {
}];
let arguments = (ins
SymbolNameAttr:$sym_name,
I8Attr:$rank,
I64Attr:$rank,
DefaultValuedAttr<DenseI64ArrayAttr, "{}">:$dim_sizes
);
let assemblyFormat = [{
Expand Down
14 changes: 1 addition & 13 deletions mlir/include/mlir/IR/OpImplementation.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,8 +350,7 @@ template <typename AsmPrinterT, typename T,
!std::is_convertible<T &, Attribute &>::value &&
!std::is_convertible<T &, ValueRange>::value &&
!std::is_convertible<T &, APFloat &>::value &&
!llvm::is_one_of<T, bool, int8_t, uint8_t, float,
double>::value,
!llvm::is_one_of<T, bool, float, double>::value,
T> * = nullptr>
inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
AsmPrinterT &>
Expand All @@ -367,17 +366,6 @@ operator<<(AsmPrinterT &p, bool value) {
return p << (value ? StringRef("true") : "false");
}

/// Specialization for 8-bit integers to ensure values are printed as integers
// and not characters.
template <
typename AsmPrinterT, typename T,
std::enable_if_t<llvm::is_one_of<T, int8_t, uint8_t>::value, T> * = nullptr>
inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
AsmPrinterT &>
operator<<(AsmPrinterT &p, T value) {
return p << static_cast<int16_t>(value);
}

template <typename AsmPrinterT, typename ValueRangeT>
inline std::enable_if_t<std::is_base_of<AsmPrinter, AsmPrinterT>::value,
AsmPrinterT &>
Expand Down
16 changes: 8 additions & 8 deletions mlir/lib/Dialect/Mesh/IR/MeshOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Operation *MeshDialect::materializeConstant(OpBuilder &builder, Attribute value,

LogicalResult ClusterOp::verify() {
ArrayRef<int64_t> dimSizes = getDimSizes();
uint8_t rank = getRank();
uint64_t rank = getRank();

if (rank == 0)
return emitOpError("rank of cluster is expected to be a positive integer");
Expand All @@ -71,15 +71,15 @@ LogicalResult ClusterOp::verify() {

LogicalResult
MeshShardingAttr::verify(function_ref<InFlightDiagnostic()> emitError,
SymbolRefAttr, ArrayRef<DenseI8ArrayAttr> splitAxes,
ArrayRef<int8_t> partialAxes, Partial) {
SymbolRefAttr, ArrayRef<DenseI32ArrayAttr> splitAxes,
ArrayRef<int32_t> partialAxes, Partial) {
// TODO: At present cluster symbol ref is not verified. This is due to the
// difficulty in fetching the corresponding symbol op based on an attribute.

llvm::SmallSet<int8_t, 4> visitedAxes;
llvm::SmallSet<int32_t, 4> visitedAxes;

auto checkMeshAxis = [&](ArrayRef<int8_t> axesArray) -> LogicalResult {
for (int8_t axis : axesArray) {
auto checkMeshAxis = [&](ArrayRef<int32_t> axesArray) -> LogicalResult {
for (int32_t axis : axesArray) {
if (axis < 0)
return emitError() << "mesh axis is expected to be non-negative";
if (!visitedAxes.insert(axis).second)
Expand All @@ -88,8 +88,8 @@ MeshShardingAttr::verify(function_ref<InFlightDiagnostic()> emitError,
return success();
};

for (DenseI8ArrayAttr subAxes : splitAxes) {
ArrayRef<int8_t> subAxesArray = subAxes.asArrayRef();
for (DenseI32ArrayAttr subAxes : splitAxes) {
ArrayRef<int32_t> subAxesArray = subAxes.asArrayRef();
if (failed(checkMeshAxis(subAxesArray)))
return failure();
}
Expand Down