-
Notifications
You must be signed in to change notification settings - Fork 15
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
Wrong argument generation for ttnn::pow op in ttmlir-translate --mlir-to-cpp pipeline #2037
Comments
If I run
I do get %10 = emitc.call_opaque "ttnn::pow"(%3, %6, %9) {args = [0 : index, 1 : index, #emitc.opaque<"std::nullopt">, #emitc.opaque<"std::nullopt">, 2 : index]} : (!emitc.opaque<"ttnn::Tensor">, !emitc.opaque<"ttnn::Tensor">, !emitc.opaque<"ttnn::Tensor">) -> !emitc.opaque<"ttnn::Tensor"> which is expected to turn into: ttnn::Tensor vSomething = ttnn::pow(v6, v9, std::nullopt, std::nullopt, v12); In order to create an Let's look at an example, I'll use concat op as it's succinct: class ConcatOpConversionPattern
: public TTNNToEmitCBaseOpConversionPattern<ttnn::ConcatOp> {
public:
using TTNNToEmitCBaseOpConversionPattern<
ttnn::ConcatOp>::TTNNToEmitCBaseOpConversionPattern;
LogicalResult
matchAndRewrite(ttnn::ConcatOp srcOp, OpAdaptor adaptor,
ConversionPatternRewriter &rewriter) const override {
// ttnn::concat op requires a `std::vector<>` of `Tensor` objects, but we
// can't really create a `std::vector<>` with `Value` objects without
// introducing an EmitC op that takes in these `Value` objects. We do this
// by creating a utility function within the IR that converts a list of
// `Tensor` objects into a `std::vector<ttnn::Tensor>`.
ttnn_to_emitc::utils::insertVecCreateFnIfNotExists(rewriter, srcOp);
mlir::emitc::CallOpaqueOp vectorOp = rewriter.create<emitc::CallOpaqueOp>(
srcOp.getLoc(),
emitc::OpaqueType::get(rewriter.getContext(),
"std::vector<ttnn::Tensor>"),
ttnn_to_emitc::utils::kCreateVectorFunctionName, nullptr, nullptr,
adaptor.getInputs());
ArrayAttr arrayAttrs = rewriter.getArrayAttr(
{mlir::IntegerAttr::get(rewriter.getIndexType(), 0),
srcOp.getDimAttr()});
rewriter.replaceOpWithNewOp<emitc::CallOpaqueOp>(
srcOp, this->getTypeConverter()->convertType(srcOp.getType()),
this->convertOpName(srcOp), arrayAttrs, nullptr,
ValueRange(vectorOp->getResults()));
return success();
}
}; Looking at rewriter.replaceOpWithNewOp<emitc::CallOpaqueOp>(
srcOp, this->getTypeConverter()->convertType(srcOp.getType()),
this->convertOpName(srcOp), arrayAttrs, nullptr,
ValueRange(vectorOp->getResults())); we can see that we're piping both the Before that, the ArrayAttr arrayAttrs = rewriter.getArrayAttr(
{mlir::IntegerAttr::get(rewriter.getIndexType(), 0),
srcOp.getDimAttr()}); So what's happening here is that we're piping both the attributes AND operands, but how will the To explain it a bit further, I'll comment the lines: ArrayAttr arrayAttrs = rewriter.getArrayAttr(
{mlir::IntegerAttr::get(rewriter.getIndexType(), 0), // for the first argument in call_opaque op, use operand at index 0 => use first element of ValueRange(vectorOp->getResults())
srcOp.getDimAttr()}); // for the second argument, use the dim attribute |
In case of |
Problem description and repro
While working on #2011 I added
test/ttmlir/EmitC/TTNN/eltwise_binary/power.mlir
Running
./build/bin/ttmlir-opt --ttir-to-emitc-pipeline test/ttmlir/EmitC/TTNN/eltwise_binary/power.mlir
yields IMO a good resultbut piping it to
./build/bin/ttmlir-translate --mlir-to-cpp
returnswhich has one excessive
std::nullopt
argument, and thus no matching call inthird_party/tt-metal/src/tt-metal/ttnn/cpp/ttnn/operations/eltwise/binary/binary_composite.hpp::ExecutePower
.I tried to fix it briefly but no luck, I am not familiar with that part of the code.
I opened this issue and commented out emitc test to get the PR going, since it was blocking an important model.
Note
ttnn has
ttnn::power
which is unary andttnn::pow
which is binary composite. The latter is the oneTTIR_PowerOp
andTTNN_PowerOp
map to.The text was updated successfully, but these errors were encountered: