Merged
test(ir): Add text check for test_merge_pass #5209
lidongshengAdd on Jul 30
test(ir): Add text check for test_merge_pass #5209
Merged
Merged fromtsungl4/pypto-openirintocann/pyptomaster
Total: 24 files changed+851-256
| @@ -293,13 +293,20 @@ private: | |||
| 293 | auto elseDefs = utils::CollectDefinedVars(elseBody); | 293 | auto elseDefs = utils::CollectDefinedVars(elseBody); |
| 294 | 294 | ||
| 295 | VarExprMap cloneMap; | 295 | VarExprMap cloneMap; |
| 296 | + std::vector<VarPtr> varList; | ||
| 296 | for (auto& v : thenDefs) { | 297 | for (auto& v : thenDefs) { |
| 297 | if (elseDefs.count(v) && !IsExternalVar(v->name_)) { | 298 | if (elseDefs.count(v) && !IsExternalVar(v->name_)) { |
| 298 | - if (auto lt = std::dynamic_pointer_cast<const LogicalTensor>(v)) { | 299 | + varList.push_back(v); |
| 299 | - cloneMap[v] = lt->Clone(true); // shared raw tensor, distinct LogicalTensor identity | 300 | + } |
| 300 | - } else { | 301 | + } |
| 301 | - cloneMap[v] = v->Clone(); | 302 | + |
| 302 | - } | 303 | + // use varList to ensure clone order and naming is deterministic |
| 304 | + std::sort(varList.begin(), varList.end(), [](auto& a, auto& b) { return a->name_ < b->name_; }); | ||
| 305 | + for (auto& v : varList) { | ||
| 306 | + if (auto lt = std::dynamic_pointer_cast<const LogicalTensor>(v)) { | ||
| 307 | + cloneMap[v] = lt->Clone(true); // shared raw tensor, distinct LogicalTensor identity | ||
| 308 | + } else { | ||
| 309 | + cloneMap[v] = v->Clone(); | ||
| 303 | } | 310 | } |
| 304 | } | 311 | } |
| 305 | 312 | ||
| @@ -16,7 +16,6 @@ | |||
| 16 | #include <vector> | 16 | #include <vector> |
| 17 | 17 | ||
| 18 | #include "core/error.h" | 18 | #include "core/error.h" |
| 19 | -#include "interface/tensor/logical_tensor.h" | ||
| 20 | #include "ir/expr.h" | 19 | #include "ir/expr.h" |
| 21 | #include "ir/kind_traits.h" | 20 | #include "ir/kind_traits.h" |
| 22 | #include "ir/program.h" | 21 | #include "ir/program.h" |
| @@ -51,8 +50,6 @@ std::string ErrorTypeToString(ErrorType type) | |||
| 51 | 50 | ||
| 52 | namespace { | 51 | namespace { |
| 53 | 52 | ||
| 54 | -using npu::tile_fwk::LogicalTensor; | ||
| 55 | - | ||
| 56 | StmtPtr GetLastStmtFromSeq(const StmtPtr& stmt) | 53 | StmtPtr GetLastStmtFromSeq(const StmtPtr& stmt) |
| 57 | { | 54 | { |
| 58 | auto seq = As<SeqStmts>(stmt); | 55 | auto seq = As<SeqStmts>(stmt); |
| @@ -177,9 +174,6 @@ private: | |||
| 177 | 174 | ||
| 178 | void SSAVerifier::CheckVariableAssignment(const VarPtr& var) | 175 | void SSAVerifier::CheckVariableAssignment(const VarPtr& var) |
| 179 | { | 176 | { |
| 180 | - if (!var) | ||
| 181 | - return; | ||
| 182 | - | ||
| 183 | const Var* key = var.get(); | 177 | const Var* key = var.get(); |
| 184 | var_assignment_count_[key]++; | 178 | var_assignment_count_[key]++; |
| 185 | 179 | ||
| @@ -198,9 +192,6 @@ void SSAVerifier::RecordError(ssa::ErrorType type, const std::string& message, c | |||
| 198 | 192 | ||
| 199 | void SSAVerifier::RecordUseBeforeDef(const VarPtr& var) | 193 | void SSAVerifier::RecordUseBeforeDef(const VarPtr& var) |
| 200 | { | 194 | { |
| 201 | - if (!var) { | ||
| 202 | - return; | ||
| 203 | - } | ||
| 204 | std::ostringstream msg; | 195 | std::ostringstream msg; |
| 205 | msg << "Variable '" << var->name_ | 196 | msg << "Variable '" << var->name_ |
| 206 | << "' is used before its dominating definition (out of scope), violating SSA dominance"; | 197 | << "' is used before its dominating definition (out of scope), violating SSA dominance"; |
| @@ -211,9 +202,6 @@ StmtPtr SSAVerifier::GetLastStmt(const StmtPtr& stmt) { return GetLastStmtFromSe | |||
| 211 | 202 | ||
| 212 | void SSAVerifier::VerifyForStmt(const ForStmtPtr& for_stmt) | 203 | void SSAVerifier::VerifyForStmt(const ForStmtPtr& for_stmt) |
| 213 | { | 204 | { |
| 214 | - if (!for_stmt) | ||
| 215 | - return; | ||
| 216 | - | ||
| 217 | // iter_args and return_vars correspond one-to-one. | 205 | // iter_args and return_vars correspond one-to-one. |
| 218 | if (for_stmt->iterArgs_.size() != for_stmt->returnVars_.size()) { | 206 | if (for_stmt->iterArgs_.size() != for_stmt->returnVars_.size()) { |
| 219 | RecordError(ssa::ErrorType::ARITY_MISMATCH, "ForStmt iter_args count must equal return_vars count", | 207 | RecordError(ssa::ErrorType::ARITY_MISMATCH, "ForStmt iter_args count must equal return_vars count", |
| @@ -236,9 +224,6 @@ void SSAVerifier::VerifyForStmt(const ForStmtPtr& for_stmt) | |||
| 236 | 224 | ||
| 237 | void SSAVerifier::VerifyWhileStmt(const WhileStmtPtr& while_stmt) | 225 | void SSAVerifier::VerifyWhileStmt(const WhileStmtPtr& while_stmt) |
| 238 | { | 226 | { |
| 239 | - if (!while_stmt) | ||
| 240 | - return; | ||
| 241 | - | ||
| 242 | // iter_args and return_vars correspond one-to-one. | 227 | // iter_args and return_vars correspond one-to-one. |
| 243 | if (while_stmt->iterArgs_.size() != while_stmt->returnVars_.size()) { | 228 | if (while_stmt->iterArgs_.size() != while_stmt->returnVars_.size()) { |
| 244 | RecordError(ssa::ErrorType::ARITY_MISMATCH, "WhileStmt iter_args count must equal return_vars count", | 229 | RecordError(ssa::ErrorType::ARITY_MISMATCH, "WhileStmt iter_args count must equal return_vars count", |
| @@ -261,9 +246,6 @@ void SSAVerifier::VerifyWhileStmt(const WhileStmtPtr& while_stmt) | |||
| 261 | 246 | ||
| 262 | void SSAVerifier::VerifyIfStmt(const IfStmtPtr& if_stmt) | 247 | void SSAVerifier::VerifyIfStmt(const IfStmtPtr& if_stmt) |
| 263 | { | 248 | { |
| 264 | - if (!if_stmt) | ||
| 265 | - return; | ||
| 266 | - | ||
| 267 | // Check only if return_vars is not empty | 249 | // Check only if return_vars is not empty |
| 268 | if (if_stmt->returnVars_.empty()) { | 250 | if (if_stmt->returnVars_.empty()) { |
| 269 | return; | 251 | return; |
| @@ -305,40 +287,36 @@ void SSAVerifier::VisitExpr_(const VarPtr& op) | |||
| 305 | // Scalar/symbolic vars (symbolic scalars, shape-dim vars) have no explicit def site in the IR and | 287 | // Scalar/symbolic vars (symbolic scalars, shape-dim vars) have no explicit def site in the IR and |
| 306 | // are intentionally skipped to avoid false positives. Shape dims are not recursed into for the | 288 | // are intentionally skipped to avoid false positives. Shape dims are not recursed into for the |
| 307 | // same reason (IRVisitor::VisitExpr_ is deliberately not called). | 289 | // same reason (IRVisitor::VisitExpr_ is deliberately not called). |
| 308 | - if (op && std::dynamic_pointer_cast<const LogicalTensor>(op) && !IsDefined(op.get())) { | 290 | + if (op && ir::IsA<LogicalTensorType>(op->GetType()) && !IsDefined(op.get())) { |
| 309 | RecordUseBeforeDef(op); | 291 | RecordUseBeforeDef(op); |
| 310 | } | 292 | } |
| 311 | } | 293 | } |
| 312 | 294 | ||
| 313 | void SSAVerifier::VisitStmt_(const TensorOpStmtPtr& op) | 295 | void SSAVerifier::VisitStmt_(const TensorOpStmtPtr& op) |
| 314 | { | 296 | { |
| 315 | - if (!op) { | ||
| 316 | - return; | ||
| 317 | - } | ||
| 318 | // Operands/tokens are uses; results are defs and must not be visited as uses. | 297 | // Operands/tokens are uses; results are defs and must not be visited as uses. |
| 319 | for (const auto& arg : op->args_) { | 298 | for (const auto& arg : op->args_) { |
| 320 | - if (arg) { | 299 | + VisitExpr(ir::As<Var>(arg)); |
| 321 | - VisitExpr(arg); | ||
| 322 | - } | ||
| 323 | } | 300 | } |
| 324 | for (const auto& token : op->tokens_) { | 301 | for (const auto& token : op->tokens_) { |
| 325 | - if (token) { | 302 | + VisitExpr(ir::As<Var>(token)); |
| 326 | - VisitExpr(token); | ||
| 327 | - } | ||
| 328 | } | 303 | } |
| 304 | + | ||
| 329 | for (const auto& result : op->result_) { | 305 | for (const auto& result : op->result_) { |
| 306 | + if (op->opcode_ != "ASSEMBLE") { | ||
| 307 | + // ASSEMBLE currently not generare new variable now | ||
| 308 | + CheckVariableAssignment(result); | ||
| 309 | + } | ||
| 330 | Define(result); | 310 | Define(result); |
| 331 | } | 311 | } |
| 332 | if (op->result_token_) { | 312 | if (op->result_token_) { |
| 313 | + CheckVariableAssignment(op->result_token_); | ||
| 333 | Define(op->result_token_); | 314 | Define(op->result_token_); |
| 334 | } | 315 | } |
| 335 | } | 316 | } |
| 336 | 317 | ||
| 337 | void SSAVerifier::VisitStmt_(const AssignStmtPtr& op) | 318 | void SSAVerifier::VisitStmt_(const AssignStmtPtr& op) |
| 338 | { | 319 | { |
| 339 | - if (!op || !op->var_) | ||
| 340 | - return; | ||
| 341 | - | ||
| 342 | // value_ is a use; var_ is a def (defined here, not visited as a use). | 320 | // value_ is a use; var_ is a def (defined here, not visited as a use). |
| 343 | if (op->value_) { | 321 | if (op->value_) { |
| 344 | VisitExpr(op->value_); | 322 | VisitExpr(op->value_); |
| @@ -351,9 +329,6 @@ void SSAVerifier::VisitStmt_(const AssignStmtPtr& op) | |||
| 351 | 329 | ||
| 352 | void SSAVerifier::VisitStmt_(const ForStmtPtr& op) | 330 | void SSAVerifier::VisitStmt_(const ForStmtPtr& op) |
| 353 | { | 331 | { |
| 354 | - if (!op) | ||
| 355 | - return; | ||
| 356 | - | ||
| 357 | // Check return_vars for multiple assignments | 332 | // Check return_vars for multiple assignments |
| 358 | for (const auto& return_var : op->returnVars_) { | 333 | for (const auto& return_var : op->returnVars_) { |
| 359 | if (return_var) { | 334 | if (return_var) { |
| @@ -399,9 +374,6 @@ void SSAVerifier::VisitStmt_(const ForStmtPtr& op) | |||
| 399 | 374 | ||
| 400 | void SSAVerifier::VisitStmt_(const WhileStmtPtr& op) | 375 | void SSAVerifier::VisitStmt_(const WhileStmtPtr& op) |
| 401 | { | 376 | { |
| 402 | - if (!op) | ||
| 403 | - return; | ||
| 404 | - | ||
| 405 | // Check return_vars for multiple assignments | 377 | // Check return_vars for multiple assignments |
| 406 | for (const auto& return_var : op->returnVars_) { | 378 | for (const auto& return_var : op->returnVars_) { |
| 407 | if (return_var) { | 379 | if (return_var) { |
| @@ -443,9 +415,6 @@ void SSAVerifier::VisitStmt_(const WhileStmtPtr& op) | |||
| 443 | 415 | ||
| 444 | void SSAVerifier::VisitStmt_(const IfStmtPtr& op) | 416 | void SSAVerifier::VisitStmt_(const IfStmtPtr& op) |
| 445 | { | 417 | { |
| 446 | - if (!op) | ||
| 447 | - return; | ||
| 448 | - | ||
| 449 | // Check return_vars for multiple assignments | 418 | // Check return_vars for multiple assignments |
| 450 | for (const auto& return_var : op->returnVars_) { | 419 | for (const auto& return_var : op->returnVars_) { |
| 451 | if (return_var) { | 420 | if (return_var) { |
| @@ -95,6 +95,7 @@ void Program::Reset() | |||
| 95 | functionmap_.clear(); | 95 | functionmap_.clear(); |
| 96 | functionMagicNameStack_.clear(); | 96 | functionMagicNameStack_.clear(); |
| 97 | currentFunctionMagicName_ = PROGRAM_ENTRY_FUNCTION_NAME; | 97 | currentFunctionMagicName_ = PROGRAM_ENTRY_FUNCTION_NAME; |
| 98 | + IdGen<IdType::RAW_TENSOR>::Inst().Reset(); | ||
| 98 | IdGen<IdType::LOGICAL_TENSOR>::Inst().Reset(); | 99 | IdGen<IdType::LOGICAL_TENSOR>::Inst().Reset(); |
| 99 | IdGen<IdType::FUNCTION>::Inst().SetId(1); | 100 | IdGen<IdType::FUNCTION>::Inst().SetId(1); |
| 100 | aliveTensors_.clear(); | 101 | aliveTensors_.clear(); |
| @@ -65,6 +65,13 @@ public: | |||
| 65 | std::string origin = name; | 65 | std::string origin = name; |
| 66 | if (origin.empty()) { | 66 | if (origin.empty()) { |
| 67 | origin = "$" + std::to_string(temp_counter_++); | 67 | origin = "$" + std::to_string(temp_counter_++); |
| 68 | + } else { | ||
| 69 | + // Propagate: if `name` is an existing unique var name, carry its origin forward | ||
| 70 | + // so clones/substitutes share the source var's base name. | ||
| 71 | + auto it = all_vars_.find(origin); | ||
| 72 | + if (it != all_vars_.end()) { | ||
| 73 | + origin = it->second; | ||
| 74 | + } | ||
| 68 | } | 75 | } |
| 69 | 76 | ||
| 70 | auto var_name = origin; | 77 | auto var_name = origin; |
| @@ -17,8 +17,9 @@ | |||
| 17 | * - Only LT/LE/GT/GE/EQ/NE atoms; callers should pre-simplify Not/Or | 17 | * - Only LT/LE/GT/GE/EQ/NE atoms; callers should pre-simplify Not/Or |
| 18 | * (e.g. ~(x>=0) -> x<0). | 18 | * (e.g. ~(x>=0) -> x<0). |
| 19 | * - int64 arithmetic, unguarded against overflow. | 19 | * - int64 arithmetic, unguarded against overflow. |
| 20 | - * - Returns kUnknown for non-affine atoms (Div/Mod/Min/Max/Call), nonlinear | 20 | + * - Returns kUnknown for non-affine atoms (Div/Mod/Min/Max/Call) and nonlinear |
| 21 | - * terms (x*y), and multi-symbol inequality contradictions (x+y>=0 && x+y<=-1). | 21 | + * terms (x*y). Multi-symbol affine inequalities ARE compared when they share |
| 22 | + * one symbolic part (x+2>=n && x+8<=n). | ||
| 22 | */ | 23 | */ |
| 23 | #pragma once | 24 | #pragma once |
| 24 | 25 | ||
| @@ -646,6 +647,10 @@ private: | |||
| 646 | return std::nullopt; | 647 | return std::nullopt; |
| 647 | } | 648 | } |
| 648 | 649 | ||
| 650 | + // Detect lo > hi contradictions. Bounds are keyed on a canonical affine | ||
| 651 | + // signature (gcd-reduced, sign-fixed) so that inequalities sharing one | ||
| 652 | + // symbolic part -- including multi-symbol ones such as x+2>=n and x+8<=n, | ||
| 653 | + // both "n - x" -- are compared against each other. | ||
| 649 | bool PropagateBounds() const | 654 | bool PropagateBounds() const |
| 650 | { | 655 | { |
| 651 | std::map<std::string, IntBound> bounds; | 656 | std::map<std::string, IntBound> bounds; |
| @@ -659,33 +664,19 @@ private: | |||
| 659 | continue; // handled by the equality path | 664 | continue; // handled by the equality path |
| 660 | } | 665 | } |
| 661 | auto la = AffineForm::Sub(ce->OperandList()[0], ce->OperandList()[1]); // coeffs*s + bias OP 0 | 666 | auto la = AffineForm::Sub(ce->OperandList()[0], ce->OperandList()[1]); // coeffs*s + bias OP 0 |
| 662 | - if (!la.ok || !la.ApplySubst(subst_) || la.coeffs.size() != 1) { | 667 | + if (!la.ok || !la.ApplySubst(subst_) || la.coeffs.empty()) { |
| 663 | - continue; // non-affine, subst cycle, or multi-symbol: undecidable here | 668 | + continue; // non-affine, subst cycle, or ground (handled elsewhere) |
| 664 | } | 669 | } |
| 665 | - const auto& row = *la.coeffs.begin(); | 670 | + int64_t thr = 0; |
| 666 | - int64_t coef = row.second; | 671 | + std::string key; |
| 667 | - if (coef == 0) { | 672 | + if (!NormalizeAtom(la, op, thr, key)) { |
| 668 | continue; | 673 | continue; |
| 669 | } | 674 | } |
| 670 | - int64_t t = -la.bias; // coef*s OP t | 675 | + IntBound& bd = bounds[key]; |
| 671 | - if (coef < 0) { // normalize to coef > 0 | ||
| 672 | - coef = -coef; | ||
| 673 | - t = -t; | ||
| 674 | - op = FlipRel(op); | ||
| 675 | - } | ||
| 676 | - // Strict -> non-strict on t (integers): a > t <=> a >= t+1; a < t <=> a <= t-1. | ||
| 677 | - if (op == SymbolicOpcode::T_BOP_GT) { | ||
| 678 | - op = SymbolicOpcode::T_BOP_GE; | ||
| 679 | - ++t; | ||
| 680 | - } else if (op == SymbolicOpcode::T_BOP_LT) { | ||
| 681 | - op = SymbolicOpcode::T_BOP_LE; | ||
| 682 | - --t; | ||
| 683 | - } | ||
| 684 | - IntBound& bd = bounds[row.first]; | ||
| 685 | if (op == SymbolicOpcode::T_BOP_GE) { | 676 | if (op == SymbolicOpcode::T_BOP_GE) { |
| 686 | - bd.TightenLo(CeilDiv(t, coef)); | 677 | + bd.TightenLo(thr); // D >= thr |
| 687 | - } else { // LE | 678 | + } else { // LE |
| 688 | - bd.TightenHi(FloorDiv(t, coef)); | 679 | + bd.TightenHi(thr); // D <= thr |
| 689 | } | 680 | } |
| 690 | } | 681 | } |
| 691 | for (const auto& kv : bounds) { | 682 | for (const auto& kv : bounds) { |
| @@ -696,6 +687,47 @@ private: | |||
| 696 | return false; | 687 | return false; |
| 697 | } | 688 | } |
| 698 | 689 | ||
| 690 | + // Reduce `la OP 0` to an inclusive integer bound on D = sum (coeff/g)*s, | ||
| 691 | + // where g = gcd(coeffs) and the sign is fixed so the lexicographically | ||
| 692 | + // smallest coefficient is positive. Emits thr (D >= thr for GE, D <= thr | ||
| 693 | + // for LE) and a delimiter-safe canonical signature key. Strict comparisons | ||
| 694 | + // are folded to non-strict BEFORE dividing by g (over the integers), | ||
| 695 | + // matching the single-symbol path; dividing first would over-tighten atoms | ||
| 696 | + // such as 2*x > 5 and yield a false UNSAT. Returns false if la is ground. | ||
| 697 | + static bool NormalizeAtom(AffineForm la, SymbolicOpcode& op, int64_t& thr, std::string& key) | ||
| 698 | + { | ||
| 699 | + int64_t g = 0; | ||
| 700 | + for (const auto& kv : la.coeffs) { | ||
| 701 | + g = std::gcd(g, kv.second); // std::gcd is non-negative; gcd(0, x) = |x| | ||
| 702 | + } | ||
| 703 | + if (g <= 0) { | ||
| 704 | + return false; | ||
| 705 | + } | ||
| 706 | + if (la.coeffs.begin()->second < 0) { // canonical sign: first key positive | ||
| 707 | + for (auto& kv : la.coeffs) { | ||
| 708 | + kv.second = -kv.second; | ||
| 709 | + } | ||
| 710 | + la.bias = -la.bias; | ||
| 711 | + op = FlipRel(op); | ||
| 712 | + } | ||
| 713 | + int64_t t = -la.bias; // g * D OP t | ||
| 714 | + if (op == SymbolicOpcode::T_BOP_GT) { // strict -> non-strict in the g*D space | ||
| 715 | + op = SymbolicOpcode::T_BOP_GE; | ||
| 716 | + ++t; | ||
| 717 | + } else if (op == SymbolicOpcode::T_BOP_LT) { | ||
| 718 | + op = SymbolicOpcode::T_BOP_LE; | ||
| 719 | + --t; | ||
| 720 | + } | ||
| 721 | + thr = (op == SymbolicOpcode::T_BOP_GE) ? CeilDiv(t, g) : FloorDiv(t, g); | ||
| 722 | + for (const auto& kv : la.coeffs) { | ||
| 723 | + key += kv.first; | ||
| 724 | + key += '='; | ||
| 725 | + key += std::to_string(kv.second / g); | ||
| 726 | + key += ';'; | ||
| 727 | + } | ||
| 728 | + return true; | ||
| 729 | + } | ||
| 730 | + | ||
| 699 | struct IntBound { | 731 | struct IntBound { |
| 700 | std::optional<int64_t> lo; // inclusive lower bound | 732 | std::optional<int64_t> lo; // inclusive lower bound |
| 701 | std::optional<int64_t> hi; // inclusive upper bound | 733 | std::optional<int64_t> hi; // inclusive upper bound |
| @@ -30,8 +30,8 @@ from pypto.cost_model import _cost_model_run_once_data_from_host | |||
| 30 | from pypto.error import FeError, _catch_and_wrap_error | 30 | from pypto.error import FeError, _catch_and_wrap_error |
| 31 | from pypto.frontend.parser.diagnostics import Source | 31 | from pypto.frontend.parser.diagnostics import Source |
| 32 | from pypto.frontend.parser.parser import NestedFunctionMarker, Parser | 32 | from pypto.frontend.parser.parser import NestedFunctionMarker, Parser |
| 33 | -from pypto.ir.compile_pipeline import compile_new_ir | ||
| 34 | from pypto.logging import log_debug | 33 | from pypto.logging import log_debug |
| 34 | +from pypto.pil.compile_pipeline import compile_new_ir | ||
| 35 | from pypto.runtime import _pto_verify_datas, setup_verify_data | 35 | from pypto.runtime import _pto_verify_datas, setup_verify_data |
| 36 | 36 | ||
| 37 | 37 | ||
| @@ -120,7 +120,7 @@ __all__ = [ | |||
| 120 | ] | 120 | ] |
| 121 | 121 | ||
| 122 | # --- Type classes --- | 122 | # --- Type classes --- |
| 123 | -from ..pypto_impl import LogicalTensor | 123 | +from .pypto_impl import LogicalTensor |
| 124 | 124 | ||
| 125 | # --- Data types --- | 125 | # --- Data types --- |
| 126 | # --- Enums --- | 126 | # --- Enums --- |
| @@ -129,7 +129,7 @@ from ..pypto_impl import LogicalTensor | |||
| 129 | # --- Unary expression ops --- | 129 | # --- Unary expression ops --- |
| 130 | # --- Statement classes --- | 130 | # --- Statement classes --- |
| 131 | # --- Function / Program --- | 131 | # --- Function / Program --- |
| 132 | -from ..pypto_impl.ir import ( | 132 | +from .pypto_impl.ir import ( |
| 133 | Abs, | 133 | Abs, |
| 134 | AccPhase, | 134 | AccPhase, |
| 135 | AccToVecMode, | 135 | AccToVecMode, |
| @@ -1,169 +0,0 @@ | |||
| 1 | -#!/usr/bin/env python3 | ||
| 2 | -# coding: utf-8 | ||
| 3 | -# Copyright (c) PyPTO Contributors. | ||
| 4 | -# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 5 | -# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 6 | -# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 7 | -# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 8 | -# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 9 | -# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 10 | -# See LICENSE in the root of the software repository for the full text of the License. | ||
| 11 | -# ----------------------------------------------------------------------------------------------------------- | ||
| 12 | -import inspect | ||
| 13 | - | ||
| 14 | -from .pypto_impl import ir as _ir | ||
| 15 | -from .pypto_impl.ir import DataType | ||
| 16 | - | ||
| 17 | - | ||
| 18 | -def _normalize_expr( | ||
| 19 | - value: int | float | _ir.Expr, | ||
| 20 | - span: _ir.Span | None = None, | ||
| 21 | - int_dtype: DataType = DataType.INDEX, | ||
| 22 | - float_dtype: DataType = DataType.FP32, | ||
| 23 | -) -> _ir.Expr: | ||
| 24 | - """Convert Python values to IR expressions. | ||
| 25 | - | ||
| 26 | - Args: | ||
| 27 | - value: Python int/float or existing Expr | ||
| 28 | - span: Optional span for created constants | ||
| 29 | - int_dtype: Data type to use for integer constants (default: INDEX) | ||
| 30 | - float_dtype: Data type to use for float constants (default: FP32) | ||
| 31 | - | ||
| 32 | - Returns: | ||
| 33 | - IR expression node | ||
| 34 | - | ||
| 35 | - Raises: | ||
| 36 | - TypeError: If value is not int, float, or ir.Expr | ||
| 37 | - """ | ||
| 38 | - if isinstance(value, _ir.Expr): | ||
| 39 | - return value | ||
| 40 | - | ||
| 41 | - actual_span = span if span is not None else _ir.Span.unknown() | ||
| 42 | - | ||
| 43 | - if isinstance(value, int): | ||
| 44 | - return _ir.ConstInt(value, int_dtype, actual_span) | ||
| 45 | - elif isinstance(value, float): | ||
| 46 | - return _ir.ConstFloat(value, float_dtype, actual_span) | ||
| 47 | - else: | ||
| 48 | - raise TypeError(f"Cannot convert {type(value)} to IR expression") | ||
| 49 | - | ||
| 50 | - | ||
| 51 | -def _capture_call_span() -> _ir.Span: | ||
| 52 | - """Capture span from the caller's location. | ||
| 53 | - | ||
| 54 | - Goes back through the call stack to find the actual user code that invoked the operator. | ||
| 55 | - | ||
| 56 | - Returns: | ||
| 57 | - Span: Source location of the caller | ||
| 58 | - """ | ||
| 59 | - frame = inspect.currentframe() | ||
| 60 | - if frame is not None and frame.f_back is not None: | ||
| 61 | - frame = frame.f_back.f_back | ||
| 62 | - | ||
| 63 | - if frame is not None: | ||
| 64 | - info = inspect.getframeinfo(frame) | ||
| 65 | - return _ir.Span(info.filename, info.lineno, -1) | ||
| 66 | - | ||
| 67 | - return _ir.Span.unknown() | ||
| 68 | - | ||
| 69 | - | ||
| 70 | -def _make_binary_op(op_name: str): | ||
| 71 | - """Create a binary operator wrapper with span capture and normalization. | ||
| 72 | - | ||
| 73 | - Args: | ||
| 74 | - op_name: Name of the operator (e.g., "add") | ||
| 75 | - | ||
| 76 | - Returns: | ||
| 77 | - Wrapper function | ||
| 78 | - """ | ||
| 79 | - | ||
| 80 | - def wrapper(self: _ir.Expr, other: int | float | _ir.Expr) -> _ir.Expr: | ||
| 81 | - span = _capture_call_span() | ||
| 82 | - other_expr = _normalize_expr(other, span) | ||
| 83 | - return getattr(_ir, op_name)(self, other_expr, span) | ||
| 84 | - | ||
| 85 | - return wrapper | ||
| 86 | - | ||
| 87 | - | ||
| 88 | -def _make_reverse_binary_op(op_name: str): | ||
| 89 | - """Create a binary operator wrapper with span capture and normalization. | ||
| 90 | - | ||
| 91 | - Args: | ||
| 92 | - op_name: Name of the operator (e.g., "add") | ||
| 93 | - | ||
| 94 | - Returns: | ||
| 95 | - Wrapper function | ||
| 96 | - """ | ||
| 97 | - | ||
| 98 | - def wrapper(self: _ir.Expr, other: int | float | _ir.Expr) -> _ir.Expr: | ||
| 99 | - span = _capture_call_span() | ||
| 100 | - other_expr = _normalize_expr(other, span) | ||
| 101 | - return getattr(_ir, op_name)(other_expr, self, span) | ||
| 102 | - | ||
| 103 | - return wrapper | ||
| 104 | - | ||
| 105 | - | ||
| 106 | -def _make_unary_op(op_name: str): | ||
| 107 | - """Create a unary operator wrapper with span capture. | ||
| 108 | - | ||
| 109 | - Args: | ||
| 110 | - op_name: Name of the operator (e.g., "neg") | ||
| 111 | - | ||
| 112 | - Returns: | ||
| 113 | - Wrapper function | ||
| 114 | - """ | ||
| 115 | - | ||
| 116 | - def wrapper(self) -> _ir.Expr: | ||
| 117 | - span = _capture_call_span() | ||
| 118 | - return getattr(_ir, op_name)(self, span) | ||
| 119 | - | ||
| 120 | - return wrapper | ||
| 121 | - | ||
| 122 | - | ||
| 123 | -def _patch_operators(): | ||
| 124 | - """Patch Expr and Var classes with operator overloads.""" | ||
| 125 | - | ||
| 126 | - # Binary operators for Expr | ||
| 127 | - _ir.Expr.__add__ = _make_binary_op("add") | ||
| 128 | - _ir.Expr.__sub__ = _make_binary_op("sub") | ||
| 129 | - _ir.Expr.__mul__ = _make_binary_op("mul") | ||
| 130 | - _ir.Expr.__truediv__ = _make_binary_op("truediv") | ||
| 131 | - _ir.Expr.__floordiv__ = _make_binary_op("floordiv") | ||
| 132 | - _ir.Expr.__mod__ = _make_binary_op("mod") | ||
| 133 | - _ir.Expr.__pow__ = _make_binary_op("pow") | ||
| 134 | - | ||
| 135 | - # Comparison operators for Expr | ||
| 136 | - _ir.Expr.__eq__ = _make_binary_op("eq") | ||
| 137 | - _ir.Expr.__ne__ = _make_binary_op("ne") | ||
| 138 | - _ir.Expr.__lt__ = _make_binary_op("lt") | ||
| 139 | - _ir.Expr.__le__ = _make_binary_op("le") | ||
| 140 | - _ir.Expr.__gt__ = _make_binary_op("gt") | ||
| 141 | - _ir.Expr.__ge__ = _make_binary_op("ge") | ||
| 142 | - | ||
| 143 | - # Bitwise operators for Expr | ||
| 144 | - _ir.Expr.__and__ = _make_binary_op("bit_and") | ||
| 145 | - _ir.Expr.__or__ = _make_binary_op("bit_or") | ||
| 146 | - _ir.Expr.__xor__ = _make_binary_op("bit_xor") | ||
| 147 | - _ir.Expr.__lshift__ = _make_binary_op("bit_shift_left") | ||
| 148 | - _ir.Expr.__rshift__ = _make_binary_op("bit_shift_right") | ||
| 149 | - | ||
| 150 | - # Unary operators for Expr | ||
| 151 | - _ir.Expr.__neg__ = _make_unary_op("neg") | ||
| 152 | - _ir.Expr.__invert__ = _make_unary_op("bit_not") | ||
| 153 | - | ||
| 154 | - # Reverse operators for Expr (when Expr is on right side) | ||
| 155 | - _ir.Expr.__radd__ = _make_reverse_binary_op("add") | ||
| 156 | - _ir.Expr.__rmul__ = _make_reverse_binary_op("mul") | ||
| 157 | - _ir.Expr.__rsub__ = _make_reverse_binary_op("sub") | ||
| 158 | - _ir.Expr.__rtruediv__ = _make_reverse_binary_op("truediv") | ||
| 159 | - _ir.Expr.__rfloordiv__ = _make_reverse_binary_op("floordiv") | ||
| 160 | - _ir.Expr.__rmod__ = _make_reverse_binary_op("mod") | ||
| 161 | - _ir.Expr.__rpow__ = _make_reverse_binary_op("pow") | ||
| 162 | - _ir.Expr.__rand__ = _make_reverse_binary_op("bit_and") | ||
| 163 | - _ir.Expr.__ror__ = _make_reverse_binary_op("bit_or") | ||
| 164 | - _ir.Expr.__rxor__ = _make_reverse_binary_op("bit_xor") | ||
| 165 | - _ir.Expr.__rlshift__ = _make_reverse_binary_op("bit_shift_left") | ||
| 166 | - _ir.Expr.__rrshift__ = _make_reverse_binary_op("bit_shift_right") | ||
| 167 | - | ||
| 168 | - | ||
| 169 | -_patch_operators() | ||
| @@ -235,8 +235,10 @@ def is_loop_begin_impl(ctx: BuildContext, scalar: SymbolicScalar): | |||
| 235 | @impl(pypto.is_loop_end) | 235 | @impl(pypto.is_loop_end) |
| 236 | def is_loop_end_impl(ctx: BuildContext, scalar: SymbolicScalar): | 236 | def is_loop_end_impl(ctx: BuildContext, scalar: SymbolicScalar): |
| 237 | end = Scope.current()["_loop_end"] | 237 | end = Scope.current()["_loop_end"] |
| 238 | + step = Scope.current()["_loop_step"] | ||
| 238 | assert isinstance(end, (SymbolicScalar, int)), "is_loop_end() must be called in a pypto.loop" | 239 | assert isinstance(end, (SymbolicScalar, int)), "is_loop_end() must be called in a pypto.loop" |
| 239 | - return scalar == (end - 1) | 240 | + assert isinstance(step, (SymbolicScalar, int)), "is_loop_end() must be called in a pypto.loop" |
| 241 | + return scalar + step >= end | ||
| 240 | 242 | ||
| 241 | 243 | ||
| 242 | def _add_jump_stmt(ctx: BuildContext, jump, operands: Optional[list[ir.Expr]] = None): | 244 | def _add_jump_stmt(ctx: BuildContext, jump, operands: Optional[list[ir.Expr]] = None): |
| @@ -293,9 +295,8 @@ def _loop_unroll(body: Block, loop: LoopRange, factor, stop, ctx: BuildContext): | |||
| 293 | loop_var = ctx.create_scalar_var(loop_var_name) | 295 | loop_var = ctx.create_scalar_var(loop_var_name) |
| 294 | scope.varmap[loop_val.id] = loop_var | 296 | scope.varmap[loop_val.id] = loop_var |
| 295 | 297 | ||
| 296 | - # Save initial values as iterArgs, convert to Vars in scope | ||
| 297 | iter_args, return_var_names = [], [] | 298 | iter_args, return_var_names = [], [] |
| 298 | - for name in body.store_names: | 299 | + for name in sorted(body.store_names): |
| 299 | val = scope.locals.get(name) | 300 | val = scope.locals.get(name) |
| 300 | var = ctx.create_var_like(name, ctx.unwrap(val)) | 301 | var = ctx.create_var_like(name, ctx.unwrap(val)) |
| 301 | iter_arg = ctx.create_iter_arg(var, initValue=ctx.unwrap(val)) | 302 | iter_arg = ctx.create_iter_arg(var, initValue=ctx.unwrap(val)) |
| @@ -381,6 +382,7 @@ def loop_impl(ctx, body: Block, loop): | |||
| 381 | scope = Scope.current() | 382 | scope = Scope.current() |
| 382 | scope["_loop_begin"] = loop.start | 383 | scope["_loop_begin"] = loop.start |
| 383 | scope["_loop_end"] = loop.stop | 384 | scope["_loop_end"] = loop.stop |
| 385 | + scope["_loop_step"] = loop.step | ||
| 384 | _dyn_for(body, loop, ctx) | 386 | _dyn_for(body, loop, ctx) |
| 385 | elif loop is not None: | 387 | elif loop is not None: |
| 386 | _static_for(body, loop) | 388 | _static_for(body, loop) |
| @@ -43,15 +43,36 @@ def find_feasible_paths(conds, pre_conds): | |||
| 43 | dfs(0, pre_conds) | 43 | dfs(0, pre_conds) |
| 44 | return ans | 44 | return ans |
| 45 | 45 | ||
| 46 | +# origin fa pattern | ||
| 47 | +# | ||
| 48 | +# for (i = 0; i < n; i += step, unroll_list=[4, 1]) { | ||
| 49 | +# if (i == 0) { do something0 } else { do something1 } | ||
| 50 | +# if (i + step >= n) { do something2 } else { do something3 } | ||
| 51 | +# | ||
| 46 | 52 | ||
| 53 | +# unrolled from origin fa pattern | ||
| 54 | +# for (i = 0; i + step * 4 <= n; i += step * 4) { | ||
| 55 | +# if (i == 0) { do something0 } else { do something1 } | ||
| 56 | +# if (i + step >= n) { do something2 } else { do something3 } | ||
| 57 | +# if (i == step) { do something0 } else { do something1 } | ||
| 58 | +# if (i + step *2 >= n) { do something2 } else { do something3 } | ||
| 59 | +# if (i == step *2) { do something0 } else { do something1 } | ||
| 60 | +# if (i + step *3 >= n) { do something2 } else { do something3 } | ||
| 61 | +# if (i == step *3) { do something0 } else { do something1 } | ||
| 62 | +# if (i + step *4 >= n) { do something2 } else { do something3 } | ||
| 47 | def test_find_feasible_paths(): | 63 | def test_find_feasible_paths(): |
| 48 | - unroll = 32 | 64 | + unroll, step = 32, 10 |
| 49 | x = pypto.symbolic_scalar('x') # loop var | 65 | x = pypto.symbolic_scalar('x') # loop var |
| 50 | n = pypto.symbolic_scalar('n') # loop end | 66 | n = pypto.symbolic_scalar('n') # loop end |
| 51 | s = pypto.symbolic_scalar('s') # loop start | 67 | s = pypto.symbolic_scalar('s') # loop start |
| 52 | n = (n + 8 - 1) // 8 | 68 | n = (n + 8 - 1) // 8 |
| 53 | - pre_cond = [x >= s, x + unroll <= n] | 69 | + |
| 54 | - conds = [x + k == s for k in range(unroll)] + [x + k == n - 1 for k in range(unroll)] | 70 | + # simulate loop unroll, [0, unroll) |
| 71 | + pre_cond = [x >= s, x + unroll * step <= n] | ||
| 72 | + # x + k == s simulate is loop begin | ||
| 73 | + conds = [x + k * step == s for k in range(unroll)] | ||
| 74 | + # x + k * step >= n simulate is loop end (inequality) | ||
| 75 | + conds += [x + (k + 1) * step >= n for k in range(unroll)] | ||
| 55 | choices = find_feasible_paths(conds, pre_cond) | 76 | choices = find_feasible_paths(conds, pre_cond) |
| 56 | assert len(choices) == 4 | 77 | assert len(choices) == 4 |
| 57 | 78 | ||
| @@ -115,8 +136,9 @@ def test_linear_feasibility(): | |||
| 115 | assert check([x > 10, x < 10]) == SatStatus.UNSAT | 136 | assert check([x > 10, x < 10]) == SatStatus.UNSAT |
| 116 | 137 | ||
| 117 | # --- Satisfiable conjunctions that must NOT regress to UNSAT --- | 138 | # --- Satisfiable conjunctions that must NOT regress to UNSAT --- |
| 118 | - # Multi-symbol inequalities are skipped (not decidable per-symbol). | 139 | + # Multi-symbol inequalities sharing one symbolic part are now compared, |
| 119 | - assert check([x + y >= 0, x + y <= -1]) != SatStatus.UNSAT | 140 | + # so this lo(0) > hi(-1) contradiction on (x + y) is detected. |
| 141 | + assert check([x + y >= 0, x + y <= -1]) == SatStatus.UNSAT | ||
| 120 | # Equality pin collapses an inequality to single-symbol, with a feasible range. | 142 | # Equality pin collapses an inequality to single-symbol, with a feasible range. |
| 121 | assert check([y == -1, x + y >= 0, x <= 5]) != SatStatus.UNSAT | 143 | assert check([y == -1, x + y >= 0, x <= 5]) != SatStatus.UNSAT |
| 122 | # Negative-coefficient bound that is satisfiable: -2*x <= -4 => x >= 2. | 144 | # Negative-coefficient bound that is satisfiable: -2*x <= -4 => x >= 2. |
| @@ -125,6 +147,33 @@ def test_linear_feasibility(): | |||
| 125 | assert check([y == x, x - y >= 0]) != SatStatus.UNSAT | 147 | assert check([y == x, x - y >= 0]) != SatStatus.UNSAT |
| 126 | 148 | ||
| 127 | 149 | ||
| 150 | +def test_multisymbol_inequality_bounds(): | ||
| 151 | + x, y, n = _sym("x y n") | ||
| 152 | + | ||
| 153 | + # --- Strict atoms with |coeff| > 1: must stay satisfiable (no false UNSAT). | ||
| 154 | + # The strict->non-strict fold must happen BEFORE dividing by the gcd, or | ||
| 155 | + # 2*x > 5 would tighten to x >= 4 instead of x >= 3. | ||
| 156 | + assert check([2 * x > 5, x <= 3]) != SatStatus.UNSAT # x = 3 | ||
| 157 | + assert check([2 * x < 5, x >= 2]) != SatStatus.UNSAT # x = 2 | ||
| 158 | + assert check([-2 * x > 5, x >= -3]) != SatStatus.UNSAT # x = -3 | ||
| 159 | + assert check([2 * x + 2 * y > 5, x + y <= 3]) != SatStatus.UNSAT # x + y = 3 | ||
| 160 | + | ||
| 161 | + # --- Multi-symbol contradictions sharing a symbolic part -> UNSAT --- | ||
| 162 | + assert check([x + 2 >= n, x + 8 <= n]) == SatStatus.UNSAT # lo 8 > hi 2 on n - x | ||
| 163 | + assert check([2 * x + 2 * y >= 6, x + y <= 2]) == SatStatus.UNSAT # gcd(2, 2) = 2 | ||
| 164 | + | ||
| 165 | + # --- Non-strict |coeff| > 1, incl. Euclidean rounding on negatives --- | ||
| 166 | + assert check([2 * x >= 5, x <= 2]) == SatStatus.UNSAT # x >= 3 | ||
| 167 | + assert check([2 * x >= -5, x <= -3]) == SatStatus.UNSAT # x >= -2 | ||
| 168 | + assert check([2 * x >= -5, x <= -2]) != SatStatus.UNSAT # x = -2 | ||
| 169 | + | ||
| 170 | + # --- A single-point bound (lo == hi) must NOT be UNSAT --- | ||
| 171 | + assert check([x + 8 >= n, x + 8 <= n]) != SatStatus.UNSAT # n - x == 8 | ||
| 172 | + | ||
| 173 | + # --- Canonicalization: n - 2 <= x is the same hi bound as x + 2 >= n --- | ||
| 174 | + assert check([n - 2 <= x, x + 8 <= n]) == SatStatus.UNSAT | ||
| 175 | + | ||
| 176 | + | ||
| 128 | def test_non_unit_equality(): | 177 | def test_non_unit_equality(): |
| 129 | # Non-±1-coefficient equalities now feed integer reasoning: a residual row | 178 | # Non-±1-coefficient equalities now feed integer reasoning: a residual row |
| 130 | # c*x + bias == 0 either pins x (c | bias) or is integer-unsat (c ∤ bias). | 179 | # c*x + bias == 0 either pins x (c | bias) or is integer-unsat (c ∤ bias). |
| @@ -0,0 +1,28 @@ | |||
| 1 | +@ir.function | ||
| 2 | +def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | ||
| 3 | + for loop_idx_10 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 4 | + if (loop_idx_10==0): | ||
| 5 | + View_x@3 = VIEW(x@0) | ||
| 6 | + View_y@4 = VIEW(y@1) | ||
| 7 | + $0@5 = ADD(View_x@3, View_y@4) | ||
| 8 | + $4@8 = SUB($0@5, View_x@3) | ||
| 9 | + z@2 = ASSEMBLE($4@8) | ||
| 10 | + ir.yield_() | ||
| 11 | + else: | ||
| 12 | + if (loop_idx_10==1): | ||
| 13 | + View_x_8@3 = VIEW(x@0) | ||
| 14 | + View_y_8@4 = VIEW(y@1) | ||
| 15 | + $1@6 = SUB(View_x_8@3, View_y_8@4) | ||
| 16 | + $3@7 = ADD($1@6, View_x_8@3) | ||
| 17 | + z@2 = ASSEMBLE($3@7) | ||
| 18 | + ir.yield_() | ||
| 19 | + else: | ||
| 20 | + View_x_6@3 = VIEW(x@0) | ||
| 21 | + View_y_6@4 = VIEW(y@1) | ||
| 22 | + $1_1@6 = SUB(View_x_6@3, View_y_6@4) | ||
| 23 | + $4_0@8 = SUB($1_1@6, View_x_6@3) | ||
| 24 | + z@2 = ASSEMBLE($4_0@8) | ||
| 25 | + ir.yield_() | ||
| 26 | + ir.yield_() | ||
| 27 | + continue | ||
| 28 | + return x@0, y@1, z@2 | ||
| @@ -0,0 +1,15 @@ | |||
| 1 | +@ir.function | ||
| 2 | +def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | ||
| 3 | + View_x@3 = VIEW(x@0) | ||
| 4 | + View_y@4 = VIEW(y@1) | ||
| 5 | + for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 6 | + if (loop_idx_32==0): | ||
| 7 | + $1@6 = SUB(View_x@3, View_y@4) | ||
| 8 | + z@2 = ASSEMBLE($1@6) | ||
| 9 | + ir.yield_() | ||
| 10 | + else: | ||
| 11 | + $3@7 = ADD(View_x@3, View_y@4) | ||
| 12 | + z@2 = ASSEMBLE($3@7) | ||
| 13 | + ir.yield_() | ||
| 14 | + continue | ||
| 15 | + return x@0, y@1, z@2 | ||
| @@ -0,0 +1,9 @@ | |||
| 1 | +@ir.function | ||
| 2 | +def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | ||
| 3 | + View_x@3 = VIEW(x@0) | ||
| 4 | + View_y@4 = VIEW(y@1) | ||
| 5 | + for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 6 | + $1@6 = SUB(View_x@3, View_y@4) | ||
| 7 | + z@2 = ASSEMBLE($1@6) | ||
| 8 | + continue | ||
| 9 | + return x@0, y@1, z@2 | ||
| @@ -0,0 +1,24 @@ | |||
| 1 | +@ir.function | ||
| 2 | +def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | ||
| 3 | + View_x@3 = VIEW(x@0) | ||
| 4 | + View_y@4 = VIEW(y@1) | ||
| 5 | + for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 6 | + if (loop_idx_32==0): | ||
| 7 | + $0@5 = ADD(View_x@3, View_y@4) | ||
| 8 | + a_0 = ir.yield_($0@5) | ||
| 9 | + else: | ||
| 10 | + $1@6 = SUB(View_x@3, View_y@4) | ||
| 11 | + a_0 = ir.yield_($1@6) | ||
| 12 | + for loop_idx_50 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 13 | + z@2 = ASSEMBLE(a_0@5) | ||
| 14 | + continue | ||
| 15 | + if (loop_idx_32==1): | ||
| 16 | + $3@7 = ADD(a_0@5, View_y@4) | ||
| 17 | + z@2 = ASSEMBLE($3@7) | ||
| 18 | + ir.yield_() | ||
| 19 | + else: | ||
| 20 | + $4@8 = SUB(a_0@5, View_y@4) | ||
| 21 | + z@2 = ASSEMBLE($4@8) | ||
| 22 | + ir.yield_() | ||
| 23 | + continue | ||
| 24 | + return x@0, y@1, z@2 | ||
| @@ -0,0 +1,17 @@ | |||
| 1 | +@ir.function | ||
| 2 | +def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | ||
| 3 | + View_x@3 = VIEW(x@0) | ||
| 4 | + View_y@4 = VIEW(y@1) | ||
| 5 | + for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 6 | + if (loop_idx_32==0): | ||
| 7 | + $0@5 = ADD(View_x@3, View_y@4) | ||
| 8 | + $3@7 = ADD($0@5, View_x@3) | ||
| 9 | + z@2 = ASSEMBLE($3@7) | ||
| 10 | + ir.yield_() | ||
| 11 | + else: | ||
| 12 | + $1@6 = SUB(View_x@3, View_y@4) | ||
| 13 | + $3_1@7 = ADD($1@6, View_x@3) | ||
| 14 | + z@2 = ASSEMBLE($3_1@7) | ||
| 15 | + ir.yield_() | ||
| 16 | + continue | ||
| 17 | + return x@0, y@1, z@2 | ||
| @@ -0,0 +1,15 @@ | |||
| 1 | +@ir.function | ||
| 2 | +def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | ||
| 3 | + View_x@3 = VIEW(x@0) | ||
| 4 | + View_y@4 = VIEW(y@1) | ||
| 5 | + for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 6 | + if (loop_idx_32==0): | ||
| 7 | + $0@5 = ADD(View_x@3, View_y@4) | ||
| 8 | + z@2 = ASSEMBLE($0@5) | ||
| 9 | + ir.yield_() | ||
| 10 | + else: | ||
| 11 | + $3@7 = SUB(View_x@3, View_y@4) | ||
| 12 | + z@2 = ASSEMBLE($3@7) | ||
| 13 | + ir.yield_() | ||
| 14 | + continue | ||
| 15 | + return x@0, y@1, z@2 | ||
| @@ -0,0 +1,92 @@ | |||
| 1 | +@ir.function | ||
| 2 | +def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | ||
| 3 | + View_x@3 = VIEW(x@0) | ||
| 4 | + for loop_idx_37 in ir.range(0, (((RUNTIME_GetInputShapeDim(ARG_x,0)-0)/4)*4), 4, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 4}): | ||
| 5 | + if (loop_idx_37==0): | ||
| 6 | + if ((loop_idx_37+3)==(RUNTIME_GetInputShapeDim(ARG_x,0)-1)): | ||
| 7 | + $0@5 = ADDS(View_x@3) | ||
| 8 | + $5@9 = SUBS(View_x@3) | ||
| 9 | + z@2 = ASSEMBLE($5@9) | ||
| 10 | + $8@11 = SUBS(View_x@3) | ||
| 11 | + $12@14 = SUBS(View_x@3) | ||
| 12 | + z@2 = ASSEMBLE($12@14) | ||
| 13 | + $15@16 = SUBS(View_x@3) | ||
| 14 | + $19@19 = SUBS(View_x@3) | ||
| 15 | + z@2 = ASSEMBLE($19@19) | ||
| 16 | + $22@21 = SUBS(View_x@3) | ||
| 17 | + $25@23 = ADDS(View_x@3) | ||
| 18 | + z@2 = ASSEMBLE($25@23) | ||
| 19 | + ir.yield_() | ||
| 20 | + else: | ||
| 21 | + $0_1@5 = ADDS(View_x@3) | ||
| 22 | + $5_2@9 = SUBS(View_x@3) | ||
| 23 | + z@2 = ASSEMBLE($5_2@9) | ||
| 24 | + $8_2@11 = SUBS(View_x@3) | ||
| 25 | + $12_2@14 = SUBS(View_x@3) | ||
| 26 | + z@2 = ASSEMBLE($12_2@14) | ||
| 27 | + $15_2@16 = SUBS(View_x@3) | ||
| 28 | + $19_2@19 = SUBS(View_x@3) | ||
| 29 | + z@2 = ASSEMBLE($19_2@19) | ||
| 30 | + $22_2@21 = SUBS(View_x@3) | ||
| 31 | + $26@24 = SUBS(View_x@3) | ||
| 32 | + z@2 = ASSEMBLE($26@24) | ||
| 33 | + ir.yield_() | ||
| 34 | + ir.yield_() | ||
| 35 | + else: | ||
| 36 | + if ((loop_idx_37+3)==(RUNTIME_GetInputShapeDim(ARG_x,0)-1)): | ||
| 37 | + $1@6 = SUBS(View_x@3) | ||
| 38 | + $5_5@9 = SUBS(View_x@3) | ||
| 39 | + z@2 = ASSEMBLE($5_5@9) | ||
| 40 | + $8_5@11 = SUBS(View_x@3) | ||
| 41 | + $12_5@14 = SUBS(View_x@3) | ||
| 42 | + z@2 = ASSEMBLE($12_5@14) | ||
| 43 | + $15_5@16 = SUBS(View_x@3) | ||
| 44 | + $19_5@19 = SUBS(View_x@3) | ||
| 45 | + z@2 = ASSEMBLE($19_5@19) | ||
| 46 | + $22_5@21 = SUBS(View_x@3) | ||
| 47 | + $25_0@23 = ADDS(View_x@3) | ||
| 48 | + z@2 = ASSEMBLE($25_0@23) | ||
| 49 | + ir.yield_() | ||
| 50 | + else: | ||
| 51 | + $1_1@6 = SUBS(View_x@3) | ||
| 52 | + $5_4@9 = SUBS(View_x@3) | ||
| 53 | + z@2 = ASSEMBLE($5_4@9) | ||
| 54 | + $8_4@11 = SUBS(View_x@3) | ||
| 55 | + $12_4@14 = SUBS(View_x@3) | ||
| 56 | + z@2 = ASSEMBLE($12_4@14) | ||
| 57 | + $15_4@16 = SUBS(View_x@3) | ||
| 58 | + $19_4@19 = SUBS(View_x@3) | ||
| 59 | + z@2 = ASSEMBLE($19_4@19) | ||
| 60 | + $22_4@21 = SUBS(View_x@3) | ||
| 61 | + $26_0@24 = SUBS(View_x@3) | ||
| 62 | + z@2 = ASSEMBLE($26_0@24) | ||
| 63 | + ir.yield_() | ||
| 64 | + ir.yield_() | ||
| 65 | + continue | ||
| 66 | + for loop_idx_37_0 in ir.range((((RUNTIME_GetInputShapeDim(ARG_x,0)-0)/4)*4), RUNTIME_GetInputShapeDim(ARG_x,0), 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 67 | + if (loop_idx_37_0==0): | ||
| 68 | + if (loop_idx_37_0==(RUNTIME_GetInputShapeDim(ARG_x,0)-1)): | ||
| 69 | + $30@25 = ADDS(View_x@3) | ||
| 70 | + $34@28 = ADDS(View_x@3) | ||
| 71 | + z@2 = ASSEMBLE($34@28) | ||
| 72 | + ir.yield_() | ||
| 73 | + else: | ||
| 74 | + $30_1@25 = ADDS(View_x@3) | ||
| 75 | + $35@29 = SUBS(View_x@3) | ||
| 76 | + z@2 = ASSEMBLE($35@29) | ||
| 77 | + ir.yield_() | ||
| 78 | + ir.yield_() | ||
| 79 | + else: | ||
| 80 | + if (loop_idx_37_0==(RUNTIME_GetInputShapeDim(ARG_x,0)-1)): | ||
| 81 | + $31@26 = SUBS(View_x@3) | ||
| 82 | + $34_0@28 = ADDS(View_x@3) | ||
| 83 | + z@2 = ASSEMBLE($34_0@28) | ||
| 84 | + ir.yield_() | ||
| 85 | + else: | ||
| 86 | + $31_1@26 = SUBS(View_x@3) | ||
| 87 | + $35_0@29 = SUBS(View_x@3) | ||
| 88 | + z@2 = ASSEMBLE($35_0@29) | ||
| 89 | + ir.yield_() | ||
| 90 | + ir.yield_() | ||
| 91 | + continue | ||
| 92 | + return x@0, y@1, z@2 | ||
| @@ -0,0 +1,92 @@ | |||
| 1 | +@ir.function | ||
| 2 | +def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | ||
| 3 | + View_x@3 = VIEW(x@0) | ||
| 4 | + for loop_idx_37 in ir.range(0, (((RUNTIME_GetInputShapeDim(ARG_x,0)-0)/4)*4), 4, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 4}): | ||
| 5 | + if (loop_idx_37==0): | ||
| 6 | + if (RUNTIME_GetInputShapeDim(ARG_x,0)<=(loop_idx_37+4)): | ||
| 7 | + $0@5 = ADDS(View_x@3) | ||
| 8 | + $5@9 = SUBS(View_x@3) | ||
| 9 | + z@2 = ASSEMBLE($5@9) | ||
| 10 | + $8@11 = SUBS(View_x@3) | ||
| 11 | + $12@14 = SUBS(View_x@3) | ||
| 12 | + z@2 = ASSEMBLE($12@14) | ||
| 13 | + $15@16 = SUBS(View_x@3) | ||
| 14 | + $19@19 = SUBS(View_x@3) | ||
| 15 | + z@2 = ASSEMBLE($19@19) | ||
| 16 | + $22@21 = SUBS(View_x@3) | ||
| 17 | + $25@23 = ADDS(View_x@3) | ||
| 18 | + z@2 = ASSEMBLE($25@23) | ||
| 19 | + ir.yield_() | ||
| 20 | + else: | ||
| 21 | + $0_1@5 = ADDS(View_x@3) | ||
| 22 | + $5_2@9 = SUBS(View_x@3) | ||
| 23 | + z@2 = ASSEMBLE($5_2@9) | ||
| 24 | + $8_2@11 = SUBS(View_x@3) | ||
| 25 | + $12_2@14 = SUBS(View_x@3) | ||
| 26 | + z@2 = ASSEMBLE($12_2@14) | ||
| 27 | + $15_2@16 = SUBS(View_x@3) | ||
| 28 | + $19_2@19 = SUBS(View_x@3) | ||
| 29 | + z@2 = ASSEMBLE($19_2@19) | ||
| 30 | + $22_2@21 = SUBS(View_x@3) | ||
| 31 | + $26@24 = SUBS(View_x@3) | ||
| 32 | + z@2 = ASSEMBLE($26@24) | ||
| 33 | + ir.yield_() | ||
| 34 | + ir.yield_() | ||
| 35 | + else: | ||
| 36 | + if (RUNTIME_GetInputShapeDim(ARG_x,0)<=(loop_idx_37+4)): | ||
| 37 | + $1@6 = SUBS(View_x@3) | ||
| 38 | + $5_5@9 = SUBS(View_x@3) | ||
| 39 | + z@2 = ASSEMBLE($5_5@9) | ||
| 40 | + $8_5@11 = SUBS(View_x@3) | ||
| 41 | + $12_5@14 = SUBS(View_x@3) | ||
| 42 | + z@2 = ASSEMBLE($12_5@14) | ||
| 43 | + $15_5@16 = SUBS(View_x@3) | ||
| 44 | + $19_5@19 = SUBS(View_x@3) | ||
| 45 | + z@2 = ASSEMBLE($19_5@19) | ||
| 46 | + $22_5@21 = SUBS(View_x@3) | ||
| 47 | + $25_0@23 = ADDS(View_x@3) | ||
| 48 | + z@2 = ASSEMBLE($25_0@23) | ||
| 49 | + ir.yield_() | ||
| 50 | + else: | ||
| 51 | + $1_1@6 = SUBS(View_x@3) | ||
| 52 | + $5_4@9 = SUBS(View_x@3) | ||
| 53 | + z@2 = ASSEMBLE($5_4@9) | ||
| 54 | + $8_4@11 = SUBS(View_x@3) | ||
| 55 | + $12_4@14 = SUBS(View_x@3) | ||
| 56 | + z@2 = ASSEMBLE($12_4@14) | ||
| 57 | + $15_4@16 = SUBS(View_x@3) | ||
| 58 | + $19_4@19 = SUBS(View_x@3) | ||
| 59 | + z@2 = ASSEMBLE($19_4@19) | ||
| 60 | + $22_4@21 = SUBS(View_x@3) | ||
| 61 | + $26_0@24 = SUBS(View_x@3) | ||
| 62 | + z@2 = ASSEMBLE($26_0@24) | ||
| 63 | + ir.yield_() | ||
| 64 | + ir.yield_() | ||
| 65 | + continue | ||
| 66 | + for loop_idx_37_0 in ir.range((((RUNTIME_GetInputShapeDim(ARG_x,0)-0)/4)*4), RUNTIME_GetInputShapeDim(ARG_x,0), 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 67 | + if (loop_idx_37_0==0): | ||
| 68 | + if (RUNTIME_GetInputShapeDim(ARG_x,0)<=(loop_idx_37_0+1)): | ||
| 69 | + $30@25 = ADDS(View_x@3) | ||
| 70 | + $34@28 = ADDS(View_x@3) | ||
| 71 | + z@2 = ASSEMBLE($34@28) | ||
| 72 | + ir.yield_() | ||
| 73 | + else: | ||
| 74 | + $30_1@25 = ADDS(View_x@3) | ||
| 75 | + $35@29 = SUBS(View_x@3) | ||
| 76 | + z@2 = ASSEMBLE($35@29) | ||
| 77 | + ir.yield_() | ||
| 78 | + ir.yield_() | ||
| 79 | + else: | ||
| 80 | + if (RUNTIME_GetInputShapeDim(ARG_x,0)<=(loop_idx_37_0+1)): | ||
| 81 | + $31@26 = SUBS(View_x@3) | ||
| 82 | + $34_0@28 = ADDS(View_x@3) | ||
| 83 | + z@2 = ASSEMBLE($34_0@28) | ||
| 84 | + ir.yield_() | ||
| 85 | + else: | ||
| 86 | + $31_1@26 = SUBS(View_x@3) | ||
| 87 | + $35_0@29 = SUBS(View_x@3) | ||
| 88 | + z@2 = ASSEMBLE($35_0@29) | ||
| 89 | + ir.yield_() | ||
| 90 | + ir.yield_() | ||
| 91 | + continue | ||
| 92 | + return x@0, y@1, z@2 | ||
| @@ -0,0 +1,56 @@ | |||
| 1 | +@ir.function | ||
| 2 | +def foo(a@0: ir.Tensor, b@1: ir.Tensor): | ||
| 3 | + for loop_idx_10, (b_1,) in ir.range(0, 10, 1, init_values=(b@1,), attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 4 | + for loop_idx_16, (b_3,) in ir.range(0, 10, 1, init_values=(b_1@1,), attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 5 | + oi_update_1@2 = TENSOR_ALLOC() | ||
| 6 | + for loop_idx_34, (b_5, oi_update_3) in ir.range(0, (((n-0)/2)*2), 2, init_values=(b_3@1, oi_update_1@2), attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 2}): | ||
| 7 | + if (loop_idx_34==0): | ||
| 8 | + if (n<=(loop_idx_34+2)): | ||
| 9 | + oi_update_4@2 = ADDS(a@0) | ||
| 10 | + oi_update_9@2 = SUBS(oi_update_4@2) | ||
| 11 | + $6@9 = DIVS(oi_update_9@2) | ||
| 12 | + b_9@1 = FLOOR($6@9) | ||
| 13 | + oi_update_31, b_11 = ir.yield_(oi_update_9@2, b_9@1) | ||
| 14 | + else: | ||
| 15 | + oi_update_33@2 = ADDS(a@0) | ||
| 16 | + oi_update_35@2 = SUBS(oi_update_33@2) | ||
| 17 | + oi_update_31, b_11 = ir.yield_(oi_update_35@2, b_5@1) | ||
| 18 | + oi_update_27, b_26 = ir.yield_(oi_update_31@2, b_11@1) | ||
| 19 | + else: | ||
| 20 | + if (n<=(loop_idx_34+2)): | ||
| 21 | + oi_update_5@2 = SUBS(oi_update_3@2) | ||
| 22 | + oi_update_45@2 = SUBS(oi_update_5@2) | ||
| 23 | + $6_0@9 = DIVS(oi_update_45@2) | ||
| 24 | + b_30@1 = FLOOR($6_0@9) | ||
| 25 | + oi_update_39, b_28 = ir.yield_(oi_update_45@2, b_30@1) | ||
| 26 | + else: | ||
| 27 | + oi_update_41@2 = SUBS(oi_update_3@2) | ||
| 28 | + oi_update_43@2 = SUBS(oi_update_41@2) | ||
| 29 | + oi_update_39, b_28 = ir.yield_(oi_update_43@2, b_5@1) | ||
| 30 | + oi_update_27, b_26 = ir.yield_(oi_update_39@2, b_28@1) | ||
| 31 | + b_13, oi_update_13 = continue b_26@1, oi_update_27@2 | ||
| 32 | + for loop_idx_34_0, (b_15, oi_update_15) in ir.range((((n-0)/2)*2), n, 1, init_values=(b_13@1, oi_update_13@2), attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 33 | + if (loop_idx_34_0==0): | ||
| 34 | + if (n<=(loop_idx_34_0+1)): | ||
| 35 | + oi_update_16@2 = ADDS(a@0) | ||
| 36 | + $10@13 = DIVS(oi_update_16@2) | ||
| 37 | + b_16@1 = FLOOR($10@13) | ||
| 38 | + oi_update_47, b_18 = ir.yield_(oi_update_16@2, b_16@1) | ||
| 39 | + else: | ||
| 40 | + oi_update_49@2 = ADDS(a@0) | ||
| 41 | + oi_update_47, b_18 = ir.yield_(oi_update_49@2, b_15@1) | ||
| 42 | + oi_update_19, b_32 = ir.yield_(oi_update_47@2, b_18@1) | ||
| 43 | + else: | ||
| 44 | + if (n<=(loop_idx_34_0+1)): | ||
| 45 | + oi_update_17@2 = SUBS(oi_update_15@2) | ||
| 46 | + $10_0@13 = DIVS(oi_update_17@2) | ||
| 47 | + b_34@1 = FLOOR($10_0@13) | ||
| 48 | + oi_update_51, b_36 = ir.yield_(oi_update_17@2, b_34@1) | ||
| 49 | + else: | ||
| 50 | + oi_update_53@2 = SUBS(oi_update_15@2) | ||
| 51 | + oi_update_51, b_36 = ir.yield_(oi_update_53@2, b_15@1) | ||
| 52 | + oi_update_19, b_32 = ir.yield_(oi_update_51@2, b_36@1) | ||
| 53 | + b_20, oi_update_21 = continue b_32@1, oi_update_19@2 | ||
| 54 | + b_22 = continue b_20@1 | ||
| 55 | + b_24 = continue b_22@1 | ||
| 56 | + return a@0, b_24@1 | ||
| @@ -0,0 +1,309 @@ | |||
| 1 | +@ir.function | ||
这些用例对应的算子源码在哪里? ![]() ![]() | |||
| 2 | +def foo(a@0: ir.Tensor, b@1: ir.Tensor, c@2: ir.Tensor): | ||
| 3 | + for loop_idx_18, (b_1,) in ir.range(0, 10, 1, init_values=(b@1,), attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 4 | + for loop_idx_24, (b_3,) in ir.range(0, 10, 1, init_values=(b_1@1,), attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 5 | + for loop_idx_30, (b_5,) in ir.range(0, RUNTIME_GetInputShapeDim(ARG_a,1), 1, init_values=(b_3@1,), attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 6 | + for loop_idx_54, (b_7,) in ir.range(0, (((((((RUNTIME_GetInputShapeDim(ARG_a,0)-((RUNTIME_GetInputShapeDim(ARG_a,1)-1)-loop_idx_30))+32)-1)/32)-0)/32)*32), 32, init_values=(b_5@1,), attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 32}): | ||
| 7 | + if (loop_idx_54==0): | ||
| 8 | + if ((loop_idx_54+31)==(((RUNTIME_GetInputShapeDim(ARG_a,0)+loop_idx_30)-RUNTIME_GetInputShapeDim(ARG_a,1))/32)): | ||
| 9 | + $0@3 = ADDS(c@2) | ||
| 10 | + $1@4 = ADDS($0@3) | ||
| 11 | + $7@8 = ADDS(c@2) | ||
| 12 | + $9@10 = ADDS($7@8) | ||
| 13 | + $14@13 = ADDS(c@2) | ||
| 14 | + $16@15 = ADDS($14@13) | ||
| 15 | + $21@18 = ADDS(c@2) | ||
| 16 | + $23@20 = ADDS($21@18) | ||
| 17 | + $28@23 = ADDS(c@2) | ||
| 18 | + $30@25 = ADDS($28@23) | ||
| 19 | + $35@28 = ADDS(c@2) | ||
| 20 | + $37@30 = ADDS($35@28) | ||
| 21 | + $42@33 = ADDS(c@2) | ||
| 22 | + $44@35 = ADDS($42@33) | ||
| 23 | + $49@38 = ADDS(c@2) | ||
| 24 | + $51@40 = ADDS($49@38) | ||
| 25 | + $56@43 = ADDS(c@2) | ||
| 26 | + $58@45 = ADDS($56@43) | ||
| 27 | + $63@48 = ADDS(c@2) | ||
| 28 | + $65@50 = ADDS($63@48) | ||
| 29 | + $70@53 = ADDS(c@2) | ||
| 30 | + $72@55 = ADDS($70@53) | ||
| 31 | + $77@58 = ADDS(c@2) | ||
| 32 | + $79@60 = ADDS($77@58) | ||
| 33 | + $84@63 = ADDS(c@2) | ||
| 34 | + $86@65 = ADDS($84@63) | ||
| 35 | + $91@68 = ADDS(c@2) | ||
| 36 | + $93@70 = ADDS($91@68) | ||
| 37 | + $98@73 = ADDS(c@2) | ||
| 38 | + $100@75 = ADDS($98@73) | ||
| 39 | + $105@78 = ADDS(c@2) | ||
| 40 | + $107@80 = ADDS($105@78) | ||
| 41 | + $112@83 = ADDS(c@2) | ||
| 42 | + $114@85 = ADDS($112@83) | ||
| 43 | + $119@88 = ADDS(c@2) | ||
| 44 | + $121@90 = ADDS($119@88) | ||
| 45 | + $126@93 = ADDS(c@2) | ||
| 46 | + $128@95 = ADDS($126@93) | ||
| 47 | + $133@98 = ADDS(c@2) | ||
| 48 | + $135@100 = ADDS($133@98) | ||
| 49 | + $140@103 = ADDS(c@2) | ||
| 50 | + $142@105 = ADDS($140@103) | ||
| 51 | + $147@108 = ADDS(c@2) | ||
| 52 | + $149@110 = ADDS($147@108) | ||
| 53 | + $154@113 = ADDS(c@2) | ||
| 54 | + $156@115 = ADDS($154@113) | ||
| 55 | + $161@118 = ADDS(c@2) | ||
| 56 | + $163@120 = ADDS($161@118) | ||
| 57 | + $168@123 = ADDS(c@2) | ||
| 58 | + $170@125 = ADDS($168@123) | ||
| 59 | + $175@128 = ADDS(c@2) | ||
| 60 | + $177@130 = ADDS($175@128) | ||
| 61 | + $182@133 = ADDS(c@2) | ||
| 62 | + $184@135 = ADDS($182@133) | ||
| 63 | + $189@138 = ADDS(c@2) | ||
| 64 | + $191@140 = ADDS($189@138) | ||
| 65 | + $196@143 = ADDS(c@2) | ||
| 66 | + $198@145 = ADDS($196@143) | ||
| 67 | + $203@148 = ADDS(c@2) | ||
| 68 | + $205@150 = ADDS($203@148) | ||
| 69 | + $210@153 = ADDS(c@2) | ||
| 70 | + $212@155 = ADDS($210@153) | ||
| 71 | + $217@158 = ADDS(c@2) | ||
| 72 | + $219@160 = ADDS($217@158) | ||
| 73 | + $221@1 = ADDS($219@160) | ||
| 74 | + b_39 = ir.yield_($221@1) | ||
| 75 | + else: | ||
| 76 | + $0_2@3 = ADDS(c@2) | ||
| 77 | + $1_1@4 = ADDS($0_2@3) | ||
| 78 | + $7_2@8 = ADDS(c@2) | ||
| 79 | + $9_2@10 = ADDS($7_2@8) | ||
| 80 | + $14_2@13 = ADDS(c@2) | ||
| 81 | + $16_2@15 = ADDS($14_2@13) | ||
| 82 | + $21_2@18 = ADDS(c@2) | ||
| 83 | + $23_2@20 = ADDS($21_2@18) | ||
| 84 | + $28_2@23 = ADDS(c@2) | ||
| 85 | + $30_2@25 = ADDS($28_2@23) | ||
| 86 | + $35_2@28 = ADDS(c@2) | ||
| 87 | + $37_2@30 = ADDS($35_2@28) | ||
| 88 | + $42_2@33 = ADDS(c@2) | ||
| 89 | + $44_2@35 = ADDS($42_2@33) | ||
| 90 | + $49_2@38 = ADDS(c@2) | ||
| 91 | + $51_2@40 = ADDS($49_2@38) | ||
| 92 | + $56_2@43 = ADDS(c@2) | ||
| 93 | + $58_2@45 = ADDS($56_2@43) | ||
| 94 | + $63_2@48 = ADDS(c@2) | ||
| 95 | + $65_2@50 = ADDS($63_2@48) | ||
| 96 | + $70_2@53 = ADDS(c@2) | ||
| 97 | + $72_2@55 = ADDS($70_2@53) | ||
| 98 | + $77_2@58 = ADDS(c@2) | ||
| 99 | + $79_2@60 = ADDS($77_2@58) | ||
| 100 | + $84_2@63 = ADDS(c@2) | ||
| 101 | + $86_2@65 = ADDS($84_2@63) | ||
| 102 | + $91_2@68 = ADDS(c@2) | ||
| 103 | + $93_2@70 = ADDS($91_2@68) | ||
| 104 | + $98_2@73 = ADDS(c@2) | ||
| 105 | + $100_2@75 = ADDS($98_2@73) | ||
| 106 | + $105_2@78 = ADDS(c@2) | ||
| 107 | + $107_2@80 = ADDS($105_2@78) | ||
| 108 | + $112_2@83 = ADDS(c@2) | ||
| 109 | + $114_2@85 = ADDS($112_2@83) | ||
| 110 | + $119_2@88 = ADDS(c@2) | ||
| 111 | + $121_2@90 = ADDS($119_2@88) | ||
| 112 | + $126_2@93 = ADDS(c@2) | ||
| 113 | + $128_2@95 = ADDS($126_2@93) | ||
| 114 | + $133_2@98 = ADDS(c@2) | ||
| 115 | + $135_2@100 = ADDS($133_2@98) | ||
| 116 | + $140_2@103 = ADDS(c@2) | ||
| 117 | + $142_2@105 = ADDS($140_2@103) | ||
| 118 | + $147_2@108 = ADDS(c@2) | ||
| 119 | + $149_2@110 = ADDS($147_2@108) | ||
| 120 | + $154_2@113 = ADDS(c@2) | ||
| 121 | + $156_2@115 = ADDS($154_2@113) | ||
| 122 | + $161_2@118 = ADDS(c@2) | ||
| 123 | + $163_2@120 = ADDS($161_2@118) | ||
| 124 | + $168_2@123 = ADDS(c@2) | ||
| 125 | + $170_2@125 = ADDS($168_2@123) | ||
| 126 | + $175_2@128 = ADDS(c@2) | ||
| 127 | + $177_2@130 = ADDS($175_2@128) | ||
| 128 | + $182_2@133 = ADDS(c@2) | ||
| 129 | + $184_2@135 = ADDS($182_2@133) | ||
| 130 | + $189_2@138 = ADDS(c@2) | ||
| 131 | + $191_2@140 = ADDS($189_2@138) | ||
| 132 | + $196_2@143 = ADDS(c@2) | ||
| 133 | + $198_2@145 = ADDS($196_2@143) | ||
| 134 | + $203_2@148 = ADDS(c@2) | ||
| 135 | + $205_2@150 = ADDS($203_2@148) | ||
| 136 | + $210_2@153 = ADDS(c@2) | ||
| 137 | + $212_2@155 = ADDS($210_2@153) | ||
| 138 | + $217_2@158 = ADDS(c@2) | ||
| 139 | + $219_2@160 = ADDS($217_2@158) | ||
| 140 | + $222@162 = ADDS($219_2@160) | ||
| 141 | + b_39 = ir.yield_($222@162) | ||
| 142 | + b_54 = ir.yield_(b_39@1) | ||
| 143 | + else: | ||
| 144 | + if ((loop_idx_54+31)==(((RUNTIME_GetInputShapeDim(ARG_a,0)+loop_idx_30)-RUNTIME_GetInputShapeDim(ARG_a,1))/32)): | ||
| 145 | + $0_5@3 = ADDS(c@2) | ||
| 146 | + $2@5 = ADDS($0_5@3) | ||
| 147 | + $7_5@8 = ADDS(c@2) | ||
| 148 | + $9_5@10 = ADDS($7_5@8) | ||
| 149 | + $14_5@13 = ADDS(c@2) | ||
| 150 | + $16_5@15 = ADDS($14_5@13) | ||
| 151 | + $21_5@18 = ADDS(c@2) | ||
| 152 | + $23_5@20 = ADDS($21_5@18) | ||
| 153 | + $28_5@23 = ADDS(c@2) | ||
| 154 | + $30_5@25 = ADDS($28_5@23) | ||
| 155 | + $35_5@28 = ADDS(c@2) | ||
| 156 | + $37_5@30 = ADDS($35_5@28) | ||
| 157 | + $42_5@33 = ADDS(c@2) | ||
| 158 | + $44_5@35 = ADDS($42_5@33) | ||
| 159 | + $49_5@38 = ADDS(c@2) | ||
| 160 | + $51_5@40 = ADDS($49_5@38) | ||
| 161 | + $56_5@43 = ADDS(c@2) | ||
| 162 | + $58_5@45 = ADDS($56_5@43) | ||
| 163 | + $63_5@48 = ADDS(c@2) | ||
| 164 | + $65_5@50 = ADDS($63_5@48) | ||
| 165 | + $70_5@53 = ADDS(c@2) | ||
| 166 | + $72_5@55 = ADDS($70_5@53) | ||
| 167 | + $77_5@58 = ADDS(c@2) | ||
| 168 | + $79_5@60 = ADDS($77_5@58) | ||
| 169 | + $84_5@63 = ADDS(c@2) | ||
| 170 | + $86_5@65 = ADDS($84_5@63) | ||
| 171 | + $91_5@68 = ADDS(c@2) | ||
| 172 | + $93_5@70 = ADDS($91_5@68) | ||
| 173 | + $98_5@73 = ADDS(c@2) | ||
| 174 | + $100_5@75 = ADDS($98_5@73) | ||
| 175 | + $105_5@78 = ADDS(c@2) | ||
| 176 | + $107_5@80 = ADDS($105_5@78) | ||
| 177 | + $112_5@83 = ADDS(c@2) | ||
| 178 | + $114_5@85 = ADDS($112_5@83) | ||
| 179 | + $119_5@88 = ADDS(c@2) | ||
| 180 | + $121_5@90 = ADDS($119_5@88) | ||
| 181 | + $126_5@93 = ADDS(c@2) | ||
| 182 | + $128_5@95 = ADDS($126_5@93) | ||
| 183 | + $133_5@98 = ADDS(c@2) | ||
| 184 | + $135_5@100 = ADDS($133_5@98) | ||
| 185 | + $140_5@103 = ADDS(c@2) | ||
| 186 | + $142_5@105 = ADDS($140_5@103) | ||
| 187 | + $147_5@108 = ADDS(c@2) | ||
| 188 | + $149_5@110 = ADDS($147_5@108) | ||
| 189 | + $154_5@113 = ADDS(c@2) | ||
| 190 | + $156_5@115 = ADDS($154_5@113) | ||
| 191 | + $161_5@118 = ADDS(c@2) | ||
| 192 | + $163_5@120 = ADDS($161_5@118) | ||
| 193 | + $168_5@123 = ADDS(c@2) | ||
| 194 | + $170_5@125 = ADDS($168_5@123) | ||
| 195 | + $175_5@128 = ADDS(c@2) | ||
| 196 | + $177_5@130 = ADDS($175_5@128) | ||
| 197 | + $182_5@133 = ADDS(c@2) | ||
| 198 | + $184_5@135 = ADDS($182_5@133) | ||
| 199 | + $189_5@138 = ADDS(c@2) | ||
| 200 | + $191_5@140 = ADDS($189_5@138) | ||
| 201 | + $196_5@143 = ADDS(c@2) | ||
| 202 | + $198_5@145 = ADDS($196_5@143) | ||
| 203 | + $203_5@148 = ADDS(c@2) | ||
| 204 | + $205_5@150 = ADDS($203_5@148) | ||
| 205 | + $210_5@153 = ADDS(c@2) | ||
| 206 | + $212_5@155 = ADDS($210_5@153) | ||
| 207 | + $217_5@158 = ADDS(c@2) | ||
| 208 | + $219_5@160 = ADDS($217_5@158) | ||
| 209 | + $221_0@1 = ADDS($219_5@160) | ||
| 210 | + b_57 = ir.yield_($221_0@1) | ||
| 211 | + else: | ||
| 212 | + $0_4@3 = ADDS(c@2) | ||
| 213 | + $2_1@5 = ADDS($0_4@3) | ||
| 214 | + $7_4@8 = ADDS(c@2) | ||
| 215 | + $9_4@10 = ADDS($7_4@8) | ||
| 216 | + $14_4@13 = ADDS(c@2) | ||
| 217 | + $16_4@15 = ADDS($14_4@13) | ||
| 218 | + $21_4@18 = ADDS(c@2) | ||
| 219 | + $23_4@20 = ADDS($21_4@18) | ||
| 220 | + $28_4@23 = ADDS(c@2) | ||
| 221 | + $30_4@25 = ADDS($28_4@23) | ||
| 222 | + $35_4@28 = ADDS(c@2) | ||
| 223 | + $37_4@30 = ADDS($35_4@28) | ||
| 224 | + $42_4@33 = ADDS(c@2) | ||
| 225 | + $44_4@35 = ADDS($42_4@33) | ||
| 226 | + $49_4@38 = ADDS(c@2) | ||
| 227 | + $51_4@40 = ADDS($49_4@38) | ||
| 228 | + $56_4@43 = ADDS(c@2) | ||
| 229 | + $58_4@45 = ADDS($56_4@43) | ||
| 230 | + $63_4@48 = ADDS(c@2) | ||
| 231 | + $65_4@50 = ADDS($63_4@48) | ||
| 232 | + $70_4@53 = ADDS(c@2) | ||
| 233 | + $72_4@55 = ADDS($70_4@53) | ||
| 234 | + $77_4@58 = ADDS(c@2) | ||
| 235 | + $79_4@60 = ADDS($77_4@58) | ||
| 236 | + $84_4@63 = ADDS(c@2) | ||
| 237 | + $86_4@65 = ADDS($84_4@63) | ||
| 238 | + $91_4@68 = ADDS(c@2) | ||
| 239 | + $93_4@70 = ADDS($91_4@68) | ||
| 240 | + $98_4@73 = ADDS(c@2) | ||
| 241 | + $100_4@75 = ADDS($98_4@73) | ||
| 242 | + $105_4@78 = ADDS(c@2) | ||
| 243 | + $107_4@80 = ADDS($105_4@78) | ||
| 244 | + $112_4@83 = ADDS(c@2) | ||
| 245 | + $114_4@85 = ADDS($112_4@83) | ||
| 246 | + $119_4@88 = ADDS(c@2) | ||
| 247 | + $121_4@90 = ADDS($119_4@88) | ||
| 248 | + $126_4@93 = ADDS(c@2) | ||
| 249 | + $128_4@95 = ADDS($126_4@93) | ||
| 250 | + $133_4@98 = ADDS(c@2) | ||
| 251 | + $135_4@100 = ADDS($133_4@98) | ||
| 252 | + $140_4@103 = ADDS(c@2) | ||
| 253 | + $142_4@105 = ADDS($140_4@103) | ||
| 254 | + $147_4@108 = ADDS(c@2) | ||
| 255 | + $149_4@110 = ADDS($147_4@108) | ||
| 256 | + $154_4@113 = ADDS(c@2) | ||
| 257 | + $156_4@115 = ADDS($154_4@113) | ||
| 258 | + $161_4@118 = ADDS(c@2) | ||
| 259 | + $163_4@120 = ADDS($161_4@118) | ||
| 260 | + $168_4@123 = ADDS(c@2) | ||
| 261 | + $170_4@125 = ADDS($168_4@123) | ||
| 262 | + $175_4@128 = ADDS(c@2) | ||
| 263 | + $177_4@130 = ADDS($175_4@128) | ||
| 264 | + $182_4@133 = ADDS(c@2) | ||
| 265 | + $184_4@135 = ADDS($182_4@133) | ||
| 266 | + $189_4@138 = ADDS(c@2) | ||
| 267 | + $191_4@140 = ADDS($189_4@138) | ||
| 268 | + $196_4@143 = ADDS(c@2) | ||
| 269 | + $198_4@145 = ADDS($196_4@143) | ||
| 270 | + $203_4@148 = ADDS(c@2) | ||
| 271 | + $205_4@150 = ADDS($203_4@148) | ||
| 272 | + $210_4@153 = ADDS(c@2) | ||
| 273 | + $212_4@155 = ADDS($210_4@153) | ||
| 274 | + $217_4@158 = ADDS(c@2) | ||
| 275 | + $219_4@160 = ADDS($217_4@158) | ||
| 276 | + $222_0@162 = ADDS($219_4@160) | ||
| 277 | + b_57 = ir.yield_($222_0@162) | ||
| 278 | + b_54 = ir.yield_(b_57@1) | ||
| 279 | + b_41 = continue b_54@1 | ||
| 280 | + for loop_idx_54_0, (b_43,) in ir.range((((((((RUNTIME_GetInputShapeDim(ARG_a,0)-((RUNTIME_GetInputShapeDim(ARG_a,1)-1)-loop_idx_30))+32)-1)/32)-0)/32)*32), ((((RUNTIME_GetInputShapeDim(ARG_a,0)-((RUNTIME_GetInputShapeDim(ARG_a,1)-1)-loop_idx_30))+32)-1)/32), 1, init_values=(b_41@1,), attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 281 | + if (loop_idx_54_0==0): | ||
| 282 | + if (loop_idx_54_0==(((RUNTIME_GetInputShapeDim(ARG_a,0)+loop_idx_30)-RUNTIME_GetInputShapeDim(ARG_a,1))/32)): | ||
| 283 | + $224@163 = ADDS(c@2) | ||
| 284 | + $225@164 = ADDS($224@163) | ||
| 285 | + $228@1 = ADDS($225@164) | ||
| 286 | + b_44 = ir.yield_($228@1) | ||
| 287 | + else: | ||
| 288 | + $224_2@163 = ADDS(c@2) | ||
| 289 | + $225_1@164 = ADDS($224_2@163) | ||
| 290 | + $229@167 = ADDS($225_1@164) | ||
| 291 | + b_44 = ir.yield_($229@167) | ||
| 292 | + b_59 = ir.yield_(b_44@1) | ||
| 293 | + else: | ||
| 294 | + if (loop_idx_54_0==(((RUNTIME_GetInputShapeDim(ARG_a,0)+loop_idx_30)-RUNTIME_GetInputShapeDim(ARG_a,1))/32)): | ||
| 295 | + $224_5@163 = ADDS(c@2) | ||
| 296 | + $226@165 = ADDS($224_5@163) | ||
| 297 | + $228_0@1 = ADDS($226@165) | ||
| 298 | + b_62 = ir.yield_($228_0@1) | ||
| 299 | + else: | ||
| 300 | + $224_4@163 = ADDS(c@2) | ||
| 301 | + $226_1@165 = ADDS($224_4@163) | ||
| 302 | + $229_0@167 = ADDS($226_1@165) | ||
| 303 | + b_62 = ir.yield_($229_0@167) | ||
| 304 | + b_59 = ir.yield_(b_62@1) | ||
| 305 | + b_46 = continue b_59@1 | ||
| 306 | + b_48 = continue b_46@1 | ||
| 307 | + b_50 = continue b_48@1 | ||
| 308 | + b_52 = continue b_50@1 | ||
| 309 | + return a@0, b_52@1, c@2 | ||
| @@ -10,7 +10,7 @@ | |||
| 10 | import pytest | 10 | import pytest |
| 11 | 11 | ||
| 12 | import pypto | 12 | import pypto |
| 13 | -from pypto.ir.compile_pipeline import compile_new_ir | 13 | +from pypto.pil.compile_pipeline import compile_new_ir |
| 14 | 14 | ||
| 15 | 15 | ||
| 16 | def test_assemble(): | 16 | def test_assemble(): |
| @@ -9,7 +9,7 @@ | |||
| 9 | from dataclasses import dataclass | 9 | from dataclasses import dataclass |
| 10 | 10 | ||
| 11 | import pypto | 11 | import pypto |
| 12 | -from pypto.ir.compile_pipeline import compile_new_ir | 12 | +from pypto.pil.compile_pipeline import compile_new_ir |
| 13 | 13 | ||
| 14 | 14 | ||
| 15 | @dataclass | 15 | @dataclass |
| @@ -8,7 +8,10 @@ | |||
| 8 | # See LICENSE in the root of the software repository for the full text of the License. | 8 | # See LICENSE in the root of the software repository for the full text of the License. |
| 9 | """Comprehensive tests for ir.Pass.merge_stmts_into_if.""" | 9 | """Comprehensive tests for ir.Pass.merge_stmts_into_if.""" |
| 10 | 10 | ||
| 11 | +import difflib | ||
| 12 | +import inspect | ||
| 11 | import logging | 13 | import logging |
| 14 | +import os | ||
| 12 | 15 | ||
| 13 | import pypto | 16 | import pypto |
| 14 | from pypto import ir, pil | 17 | from pypto import ir, pil |
| @@ -33,6 +36,39 @@ def _collect_stmts(stmt, cls): | |||
| 33 | return result | 36 | return result |
| 34 | 37 | ||
| 35 | 38 | ||
| 39 | +def _check_snapshot(test_name, func): | ||
| 40 | + module_name = os.path.splitext(os.path.basename(__file__))[0] | ||
| 41 | + path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "snapshot", | ||
| 42 | + "%s.%s.pir" % (module_name, test_name)) | ||
| 43 | + | ||
| 44 | + def normalize(x): | ||
| 45 | + return x.rstrip("\n") + "\n" | ||
| 46 | + | ||
| 47 | + with open(path) as f: | ||
| 48 | + golden = normalize(f.read()) | ||
| 49 | + | ||
| 50 | + actual = str(func) + "\n" | ||
| 51 | + actual = normalize(actual) | ||
| 52 | + if golden != actual: | ||
| 53 | + diff = "".join( | ||
| 54 | + difflib.unified_diff( | ||
| 55 | + golden.splitlines(keepends=True), | ||
| 56 | + actual.splitlines(keepends=True), | ||
| 57 | + fromfile="%s (golden)" % path, | ||
| 58 | + tofile="%s (actual)" % path, | ||
| 59 | + ) | ||
| 60 | + ) | ||
| 61 | + raise AssertionError("IR snapshot mismatch in %s:\n%s" % (test_name, diff)) | ||
| 62 | + | ||
| 63 | + | ||
| 64 | +def _ssa_verify(verifier, prog): | ||
| 65 | + diagnostic = verifier.verify(prog) | ||
| 66 | + if diagnostic: | ||
| 67 | + print(prog) | ||
| 68 | + print(ir.IRVerifier.generate_report(diagnostic)) | ||
| 69 | + raise | ||
| 70 | + | ||
| 71 | + | ||
| 36 | def _run_merge(func, *args): | 72 | def _run_merge(func, *args): |
| 37 | """Compile a kernel and run canonicalize + dce + merge_stmts_into_if, stopping before lowering | 73 | """Compile a kernel and run canonicalize + dce + merge_stmts_into_if, stopping before lowering |
| 38 | so the resulting if-tree (func.body) is inspectable. Mirrors compile_new_ir's first half.""" | 74 | so the resulting if-tree (func.body) is inspectable. Mirrors compile_new_ir's first half.""" |
| @@ -43,11 +79,15 @@ def _run_merge(func, *args): | |||
| 43 | canonical = ir.Pass.canonicalize() | 79 | canonical = ir.Pass.canonicalize() |
| 44 | merge = ir.Pass.merge_stmts_into_if() | 80 | merge = ir.Pass.merge_stmts_into_if() |
| 45 | verifier = ir.IRVerifier.create_default() | 81 | verifier = ir.IRVerifier.create_default() |
| 82 | + _ssa_verify(verifier, prog) | ||
| 46 | prog = dce(canonical(prog)) | 83 | prog = dce(canonical(prog)) |
| 84 | + _ssa_verify(verifier, prog) | ||
| 47 | prog = canonical(merge(prog)) | 85 | prog = canonical(merge(prog)) |
| 48 | - verifier.verify_or_throw(prog) | 86 | + _ssa_verify(verifier, prog) |
| 49 | - logging.info("\nmerged:\n%s" % prog.functions[func.name].body) | 87 | + func = prog.functions[func.name] |
| 50 | - return prog.functions[func.name] | 88 | + logging.info("\nmerged:\n%s" % func.body) |
| 89 | + _check_snapshot(inspect.stack()[1].function, func) | ||
| 90 | + return func | ||
| 51 | 91 | ||
| 52 | 92 | ||
| 53 | def test_merge_pass1(): | 93 | def test_merge_pass1(): |
| @@ -300,7 +340,7 @@ def test_oi_update(): | |||
| 300 | oi_update[:] = a + 1 | 340 | oi_update[:] = a + 1 |
| 301 | else: | 341 | else: |
| 302 | oi_update[:] = oi_update - 1 | 342 | oi_update[:] = oi_update - 1 |
| 303 | - if i == n - 1: | 343 | + if i + 1 >= n: |
| 304 | b[:] = oi_update // 2 | 344 | b[:] = oi_update // 2 |
| 305 | 345 | ||
| 306 | y = pypto.Tensor((32, 32), pypto.DT_FP32) | 346 | y = pypto.Tensor((32, 32), pypto.DT_FP32) |


🟡 Medium Priority
在
SSAVerifier::VisitStmt_(const TensorOpStmtPtr& op)(第313-335行)中,对于op->result_和op->result_token_仅调用了Define()将其加入作用域,但未调用CheckVariableAssignment()。与此对比,同一文件中的
VisitStmt_(const AssignStmtPtr& op)(第348行)在Define()之前先调用了CheckVariableAssignment(op->var_);VisitStmt_(const ForStmtPtr& op)/VisitStmt_(const WhileStmtPtr& op)/VisitStmt_(const IfStmtPtr& op)也都对returnVars_调用了CheckVariableAssignment()。这意味着:如果同一个 Var 指针被两个不同的 TensorOpStmt 作为 result 产出(SSA 违规),该违规不会被 MULTIPLE_ASSIGNMENT 错误类型检测到。这是一个验证覆盖缺口,使 SSA 校验器的完整性降低。