Open axeabc opened 1 week ago
I'm wondering if it's worth adding a verifier for tosa.reshape
, such as:
if (inputType.hasStaticShape()) {
int64_t inputElementsNum = inputType.getNumElements();
if (outputType.hasStaticShape()) {
int64_t outputElementsNum = outputType.getNumElements();
if (inputElementsNum != outputElementsNum) {
return emitOpError() << "cannot reshape " << inputElementsNum
<< " elements into " << outputElementsNum;
}
}
int64_t newShapeElementsNum = std::accumulate(
getNewShape().begin(), getNewShape().end(), 1LL,
[](int64_t acc, int64_t dim) { return (dim > 0) ? acc * dim : acc; });
bool isStaticNewShape =
llvm::all_of(getNewShape(), [](int64_t s) { return s > 0; });
if ((isStaticNewShape && inputElementsNum != newShapeElementsNum) ||
(!isStaticNewShape && newShapeElementsNum > inputElementsNum)) {
return emitOpError() << "cannot reshape " << inputElementsNum
<< " elements into " << newShapeElementsNum;
}
}
@joker-eph @eric-k256
It depends on the kind of type inference that TOSA is expected to do: the tricky part is that if you validate shapes in the verifier, then shape inference has to know about these validity rule before updating the result of an operation.
git version: 761bf333e378b52614c
system:
Ubuntu 18.04.6 LTS
reproduce with:
mlir-opt -tosa-to-tensor a.mlir
a.mlir:
stack trace: