Changeset View
Changeset View
Standalone View
Standalone View
mlir/lib/Dialect/Linalg/IR/LinalgInterfaces.cpp
Show First 20 Lines • Show All 332 Lines • ▼ Show 20 Lines | LogicalResult mlir::linalg::detail::verifyStructuredOpInterface(Operation *op) { | ||||
// LinalgOp at the moment. For now this will have to be a special op until we | // LinalgOp at the moment. For now this will have to be a special op until we | ||||
// have output shape operands that are not tensors. | // have output shape operands that are not tensors. | ||||
int64_t numInputs = linalgOp.getNumInputs(); | int64_t numInputs = linalgOp.getNumInputs(); | ||||
int64_t numOutputs = linalgOp.getNumOutputs(); | int64_t numOutputs = linalgOp.getNumOutputs(); | ||||
if (numOutputs == 0) | if (numOutputs == 0) | ||||
return op->emitOpError("expected at least one output operand"); | return op->emitOpError("expected at least one output operand"); | ||||
if (failed(OpTrait::impl::verifyNOperands(op, numInputs + numOutputs))) | if (failed(OpTrait::impl::verifyNOperands(op, numInputs + numOutputs))) | ||||
return failure(); | return failure(); | ||||
// Should have at least one output tensor per result tensor. | // Verify the number of results matches the number of output tensors. | ||||
// Can also have outbut buffers that do not correspond to results. | if (op->getNumResults() != linalgOp.getOutputTensorOperands().size()) | ||||
if (op->getNumResults() > linalgOp.getOutputTensorOperands().size()) | return op->emitOpError("expected the number of results (") | ||||
return op->emitOpError("unexpected #results > #outputs"); | << op->getNumResults() | ||||
<< ") to be equal to the number of output tensors (" | |||||
<< linalgOp.getOutputTensorOperands().size() << ")"; | |||||
// Before checking indexing maps, we need to make sure the attributes | // Before checking indexing maps, we need to make sure the attributes | ||||
// referenced by it are valid. | // referenced by it are valid. | ||||
if (linalgOp.hasDynamicIndexingMaps()) | if (linalgOp.hasDynamicIndexingMaps()) | ||||
if (failed(linalgOp.verifyIndexingMapRequiredAttributes())) | if (failed(linalgOp.verifyIndexingMapRequiredAttributes())) | ||||
return failure(); | return failure(); | ||||
// All input/output operands must be indexed. | // All input/output operands must be indexed. | ||||
Show All 36 Lines | LogicalResult mlir::linalg::detail::verifyStructuredOpInterface(Operation *op) { | ||||
// TODO: relax when mixed-mode needs to pass verification. | // TODO: relax when mixed-mode needs to pass verification. | ||||
if (!linalgOp.getOutputBufferOperands().empty() && | if (!linalgOp.getOutputBufferOperands().empty() && | ||||
!linalgOp.getOutputTensorOperands().empty()) | !linalgOp.getOutputTensorOperands().empty()) | ||||
return op->emitOpError( | return op->emitOpError( | ||||
"expected output operands to all have tensor type or " | "expected output operands to all have tensor type or " | ||||
"all have buffer type"); | "all have buffer type"); | ||||
for (OpOperand *opOperand : linalgOp.getOutputTensorOperands()) { | for (OpOperand *opOperand : linalgOp.getOutputTensorOperands()) { | ||||
// TODO: Enforce one output tensor per result? | |||||
if (opOperand->getOperandNumber() - linalgOp.getNumInputs() >= | |||||
linalgOp->getNumResults()) | |||||
continue; | |||||
OpResult result = linalgOp.getTiedOpResult(opOperand); | OpResult result = linalgOp.getTiedOpResult(opOperand); | ||||
if (result.getType() != opOperand->get().getType()) | if (result.getType() != opOperand->get().getType()) | ||||
return op->emitOpError("expected type of operand #") | return op->emitOpError("expected type of operand #") | ||||
<< opOperand->getOperandNumber() << " (" | << opOperand->getOperandNumber() << " (" | ||||
<< opOperand->get().getType() << ")" | << opOperand->get().getType() << ")" | ||||
<< " to match type of corresponding result (" << result.getType() | << " to match type of corresponding result (" << result.getType() | ||||
<< ")"; | << ")"; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 128 Lines • Show Last 20 Lines |