UIUC-ChenLab / scalehls

A scalable High-Level Synthesis framework on MLIR
Other
228 stars 47 forks source link

<stdin>:12:58: error: expected operation name in quotes #58

Closed tiffinyk closed 9 months ago

tiffinyk commented 1 year ago

Hi, when I run the DSE of gemm in README.md, an error occurs:

:12:58: error: expected operation name in quotes %2 = hls.affine.select #set(%arg5) %1, %0 : f32 {timing = #hls.t<10 -> 10, 0, 0>} I don't know how to locate this error.
w6225656 commented 1 year ago

me too

aferikoglou commented 1 year ago

Hi. I am also having this problem.

anniezfy commented 1 year ago

I have struggled with this problem

ilgazer commented 1 year ago

I am having the same issue :(

jiex-liu commented 1 year ago

i think mlir dialect always require the variable datatype to be at the end of the line so for example:

%2 = hls.affine.select #set(%arg5) %1, %0 : f32 {timing = #hls.t<10 -> 10, 0, 0>} should be %2 = hls.affine.select #set(%arg5) %1, %0 {timing = #hls.t<10 -> 10, 0, 0>}: f32

I changed all the related lines and it works for me. I also tried deleting the timing thingy and it seems to generate the same code. There is probably a bug in hls.affine.select but I could not locate it.

HahaLan97 commented 1 year ago

There is probably a bug in hls.affine.select but I could not locate it.

OK, I've find the cause of this error. It's because that the parser and the printer work differently. Let's take a look at the code snippet from lib/Dialect/HLS/HLS.cpp:

ParseResult AffineSelectOp::parse(OpAsmParser &parser, OperationState &result) {
  // Parse the condition attribute set.
  IntegerSetAttr conditionAttr;
  unsigned numDims;
  if (parser.parseAttribute(conditionAttr,
                            AffineSelectOp::getConditionAttrStrName(),
                            result.attributes) ||
      parseDimAndSymbolList(parser, result.operands, numDims))
    return failure();

  // Verify the condition operands.
  auto set = conditionAttr.getValue();
  if (set.getNumDims() != numDims)
    return parser.emitError(
        parser.getNameLoc(),
        "dim operand count and integer set dim count must match");
  if (numDims + set.getNumSymbols() != result.operands.size())
    return parser.emitError(
        parser.getNameLoc(),
        "symbol operand count and integer set symbol count must match");

  SmallVector<OpAsmParser::UnresolvedOperand, 4> values;
  SMLoc valuesLoc = parser.getCurrentLocation();
  Type resultType;
  if (parser.parseOperandList(values) ||
      parser.parseOptionalAttrDict(result.attributes) ||
      parser.parseColonType(resultType))
    return failure();
  result.types.push_back(resultType);

  if (values.size() != 2)
    return parser.emitError(valuesLoc, "should only have two input values");
  if (parser.resolveOperands(values, {resultType, resultType}, valuesLoc,
                             result.operands))
    return failure();
  return success();
}

void AffineSelectOp::print(OpAsmPrinter &p) {
  auto conditionAttr =
      (*this)->getAttrOfType<IntegerSetAttr>(getConditionAttrStrName());
  p << " " << conditionAttr;
  printDimAndSymbolList(getArgs().begin(), getArgs().end(),
                        conditionAttr.getValue().getNumDims(), p);

  p << " ";
  p.printOperand(getTrueValue());
  p << ", ";
  p.printOperand(getFalseValue());
  // p << " : ";
  // p.printType(getType());

  // Print the attribute list.
  p.printOptionalAttrDict((*this)->getAttrs(),
                          /*elidedAttrs=*/getConditionAttrStrName());
  p << " : ";
  p.printType(getType());
}

It's quite clear that the parser always parse the attribute first and then the type, but the printer will print the type first and then the attribute. So when this Op is created, it'll print out like %2 = hls.affine.select #set(%arg5) %1, %0 : f32 {timing = #hls.t<10 -> 10, 0, 0>}, but at the mean time the parser parse the type and say: "hey, there is something not right". Then we have this error.

The solution is quite easy, just use the commented one I wrote in the code above and delete or comment the other print and everything will be nicely working.

hanchenye commented 9 months ago

Fixed in b69f334c9c122fad3759fcf388d3f039689b6fc0