Skip to content
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

feat: Add Reason attribute to Subgraph #57

Draft
wants to merge 1 commit into
base: feature/fused-ops
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions include/xten/Dialect/XTenNN/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ mlir_tablegen(XTenNNBase.h.inc -gen-dialect-decls)
mlir_tablegen(XTenNNBase.cpp.inc -gen-dialect-defs)
mlir_tablegen(XTenNNOps.h.inc -gen-op-decls)
mlir_tablegen(XTenNNOps.cpp.inc -gen-op-defs)
mlir_tablegen(XTenNNEnums.h.inc -gen-enum-decls)
mlir_tablegen(XTenNNEnums.cpp.inc -gen-enum-defs)

add_public_tablegen_target(XTenNNDialectIncGen)
add_dependencies(XTenNNIncGen XTenNNDialectIncGen)
Expand Down
3 changes: 3 additions & 0 deletions include/xten/Dialect/XTenNN/IR/XTenNNOps.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "mlir/Interfaces/SideEffectInterfaces.h"
#include "xten/Dialect/XTenNN/Interfaces/EnclaveOpInterfaces.h"

// Include enums
#include "xten/Dialect/XTenNN/IR/XTenNNEnums.h.inc"

namespace mlir::OpTrait {
template <typename ConcreteType>
class TosaExtension : public TraitBase<ConcreteType, TosaExtension> {};
Expand Down
26 changes: 25 additions & 1 deletion include/xten/Dialect/XTenNN/IR/XTenNNOps.td
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
include "xten/Dialect/XTenNN/IR/XTenNNBase.td"
include "xten/Dialect/XTenNN/IR/XTenNNTypes.td"

include "mlir/IR/EnumAttr.td"
include "mlir/Interfaces/FunctionInterfaces.td"
include "mlir/IR/OpAsmInterface.td"
include "mlir/IR/RegionKindInterface.td"
Expand All @@ -35,6 +36,29 @@ class XTenNN_Op<string mnemonic, list<Trait> traits = []>
// SubgraphOp
//===----------------------------------------------------------------------===//

def MicroKernel: I32EnumAttrCase<"MicroKernel", 0>;
def TemplatedGraph: I32EnumAttrCase<"TemplatedGraph", 1>;
def InCoreChain: I32EnumAttrCase<"InCoreChain", 2>;
def MllibKernel: I32EnumAttrCase<"MllibKernel", 3>;
def PseudoOp: I32EnumAttrCase<"PseudoOp", 4>;
def MemTileChain: I32EnumAttrCase<"MemTileChain", 5>;
def Interface: I32EnumAttrCase<"Interface", 6>;
def CpuBecause: I32EnumAttrCase<"CpuBecause", 7>;

def ReasonEnum : I32EnumAttr<"ReasonEnum", "List of possible reasons for a subgraph to exist",
[MicroKernel,
TemplatedGraph,
InCoreChain,
MllibKernel,
PseudoOp,
MemTileChain,
Interface,
CpuBecause]> {
let cppNamespace = "amd::xten_nn";
let stringToSymbolFnName = "reasonStrToEnum";
let symbolToStringFnName = "toString";
}

def XTenNN_SubgraphOp : XTenNN_Op<"subgraph", [
DeclareOpInterfaceMethods<InferShapedTypeOpInterface,
["inferReturnTypeComponents"]>,
Expand Down Expand Up @@ -71,7 +95,7 @@ def XTenNN_SubgraphOp : XTenNN_Op<"subgraph", [
```
}];

let arguments = (ins Variadic<AnyType>:$captures);
let arguments = (ins Variadic<AnyType>:$captures, StrAttr:$Reason);
let results = (outs Variadic<AnyType>:$results);
let regions = (region MaxSizedRegion<1>:$content);

Expand Down
1 change: 1 addition & 0 deletions lib/Dialect/XTenNN/IR/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

add_mlir_dialect_library(XTenNNDialect
XTenNNBase.cpp
XTenNNEnums.cpp
XTenNNOps.cpp

DEPENDS
Expand Down
16 changes: 16 additions & 0 deletions lib/Dialect/XTenNN/IR/XTenNNEnums.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//===- XTenNNEnums.cpp ------------------------------------------*- C++ -*-===//
//
// This file is licensed 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
//

// (c) Copyright 2024 Advanced Micro Devices, Inc. All Rights reserved.

//
//===----------------------------------------------------------------------===//

#include "mlir/IR/BuiltinOps.h"

#include "xten/Dialect/XTenNN/IR/XTenNNEnums.h.inc"
#include "xten/Dialect/XTenNN/IR/XTenNNEnums.cpp.inc"
21 changes: 21 additions & 0 deletions lib/Dialect/XTenNN/IR/XTenNNOps.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,27 @@ LogicalResult SubgraphOp::verify() {
<< ") does not match argument type (" << argType << ")";
}
}

std::optional<ReasonEnum> reason = reasonStrToEnum(getReason());
if (!reason) {
SmallVector<llvm::StringRef> validReasons;
validReasons.reserve(getMaxEnumValForReasonEnum());

for (unsigned i = 0; i <= getMaxEnumValForReasonEnum(); i++) {
validReasons.push_back(toString(static_cast<ReasonEnum>(i)));
}

std::string commaSeparatedReasons;
{
llvm::raw_string_ostream rso(commaSeparatedReasons);
llvm::interleaveComma(validReasons, rso);
}

return emitOpError() << "invalid provided Reason '" << getReason()
<< "'. Valid Reasons are: [" << commaSeparatedReasons
<< "]";
}

return success();
}

Expand Down