| @@ -20,6 +20,7 @@ | |||
| 20 | #include <cstdint> | 20 | #include <cstdint> |
| 21 | #include <vector> | 21 | #include <vector> |
| 22 | #include <unordered_map> | 22 | #include <unordered_map> |
| 23 | +#include <unordered_set> | ||
| 23 | #include "error.h" | 24 | #include "error.h" |
| 24 | 25 | ||
| 25 | #include "ir/expr.h" | 26 | #include "ir/expr.h" |
| @@ -66,6 +67,8 @@ public: | |||
| 66 | 67 | ||
| 67 | pypto::ir::VarPtr AsVar() const; | 68 | pypto::ir::VarPtr AsVar() const; |
| 68 | pypto::ir::ExprPtr AsExpr() const; | 69 | pypto::ir::ExprPtr AsExpr() const; |
| 70 | + void GetVarRefs(std::unordered_set<const pypto::ir::Var*>& out) const; | ||
| 71 | + SymbolicScalar SubstituteVars(const std::unordered_map<pypto::ir::VarPtr, pypto::ir::ExprPtr>& vars); | ||
| 69 | 72 | ||
| 70 | operator int() const | 73 | operator int() const |
| 71 | { | 74 | { |
| @@ -17,6 +17,8 @@ | |||
| 17 | 17 | ||
| 18 | #include "tilefwk/symbolic_scalar.h" | 18 | #include "tilefwk/symbolic_scalar.h" |
| 19 | #include "interface/tensor/logical_tensor.h" | 19 | #include "interface/tensor/logical_tensor.h" |
| 20 | +#include "interface/operation/operation.h" | ||
| 21 | +#include "interface/tensor/ir_tensor_op_rebuild.h" | ||
| 20 | 22 | ||
| 21 | using npu::tile_fwk::SatStatus; | 23 | using npu::tile_fwk::SatStatus; |
| 22 | using npu::tile_fwk::SymbolicScalar; | 24 | using npu::tile_fwk::SymbolicScalar; |
| @@ -26,6 +28,7 @@ namespace pypto::ir { | |||
| 26 | namespace { | 28 | namespace { |
| 27 | 29 | ||
| 28 | using npu::tile_fwk::LogicalTensor; | 30 | using npu::tile_fwk::LogicalTensor; |
| 31 | +using npu::tile_fwk::Operation; | ||
| 29 | using utils::SubstituteVars; | 32 | using utils::SubstituteVars; |
| 30 | using utils::VarExprMap; | 33 | using utils::VarExprMap; |
| 31 | 34 | ||
| @@ -48,6 +51,46 @@ ExprPtr LookupVarInExpr(ExprPtr expr, const VarExprMap& varMap) | |||
| 48 | return expr; | 51 | return expr; |
| 49 | } | 52 | } |
| 50 | 53 | ||
| 54 | +StmtPtr SubstituteStmt(StmtPtr stmt, const VarExprMap& varMap) | ||
| 55 | +{ | ||
| 56 | + if (!stmt || varMap.empty()) { | ||
| 57 | + return stmt; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + stmt = SubstituteVars(stmt, varMap); | ||
| 61 | + auto top = As<TensorOpStmt>(stmt); | ||
| 62 | + if (!top) { | ||
| 63 | + return stmt; | ||
| 64 | + } | ||
| 65 | + | ||
| 66 | + auto op = std::dynamic_pointer_cast<Operation>(std::const_pointer_cast<TensorOpStmt>(top)); | ||
| 67 | + if (!op) { | ||
| 68 | + return stmt; | ||
| 69 | + } | ||
| 70 | + | ||
| 71 | + bool changed = false; | ||
| 72 | + for (auto& attr : op->GetDynamicAttributeList()) { | ||
| 73 | + // SubstituteVars returns a new SymbolicScalar; compare raw pointers | ||
| 74 | + auto& s = attr.get(); | ||
| 75 | + if (s.SubstituteVars(varMap).Raw() != s.Raw()) { | ||
| 76 | + changed = true; | ||
| 77 | + break; | ||
| 78 | + } | ||
| 79 | + } | ||
| 80 | + if (!changed) { | ||
| 81 | + return stmt; | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + auto cloned = npu::tile_fwk::RebuildTensorOpStmt(top, op->result_, op->result_token_, op->args_, op->tokens_, | ||
| 85 | + Span::Unknown()); | ||
| 86 | + op = std::dynamic_pointer_cast<Operation>(std::const_pointer_cast<Stmt>(cloned)); | ||
| 87 | + for (auto& attr : op->GetDynamicAttributeList()) { | ||
| 88 | + auto& s = attr.get(); | ||
| 89 | + s = s.SubstituteVars(varMap).Simplify(); | ||
| 90 | + } | ||
| 91 | + return cloned; | ||
| 92 | +} | ||
| 93 | + | ||
| 51 | void BuildYieldVarMap(IfStmtPtr ifStmt, SeqStmtsPtr body, VarExprMap& varMap) | 94 | void BuildYieldVarMap(IfStmtPtr ifStmt, SeqStmtsPtr body, VarExprMap& varMap) |
| 52 | { | 95 | { |
| 53 | if (body->stmts_.empty() || ifStmt->returnVars_.empty()) { | 96 | if (body->stmts_.empty() || ifStmt->returnVars_.empty()) { |
| @@ -154,7 +197,7 @@ SeqStmtsPtr BuildAppendedBranch(IfStmtPtr ifStmt, SeqStmtsPtr branch, const std: | |||
| 154 | BuildYieldVarMap(ifStmt, branch, yieldMap); | 197 | BuildYieldVarMap(ifStmt, branch, yieldMap); |
| 155 | } | 198 | } |
| 156 | for (auto& s : stmts) { | 199 | for (auto& s : stmts) { |
| 157 | - out.push_back(SubstituteVars(s, yieldMap)); | 200 | + out.push_back(SubstituteStmt(s, yieldMap)); |
| 158 | ExtendYieldMap(s, yieldMap); | 201 | ExtendYieldMap(s, yieldMap); |
| 159 | } | 202 | } |
| 160 | auto values = ExtractYieldValues(branch); | 203 | auto values = ExtractYieldValues(branch); |
| @@ -175,12 +218,12 @@ SeqStmtsPtr BuildPrependedBranch(const std::vector<StmtPtr>& stmts, std::optiona | |||
| 175 | std::vector<StmtPtr> out; | 218 | std::vector<StmtPtr> out; |
| 176 | VarExprMap yieldMap; | 219 | VarExprMap yieldMap; |
| 177 | for (auto& s : stmts) { | 220 | for (auto& s : stmts) { |
| 178 | - out.push_back(SubstituteVars(s, yieldMap)); | 221 | + out.push_back(SubstituteStmt(s, yieldMap)); |
| 179 | ExtendYieldMap(s, yieldMap); | 222 | ExtendYieldMap(s, yieldMap); |
| 180 | } | 223 | } |
| 181 | if (branch) { | 224 | if (branch) { |
| 182 | for (auto& s : RemoveLastYieldStmt(branch.value()->stmts_)) { | 225 | for (auto& s : RemoveLastYieldStmt(branch.value()->stmts_)) { |
| 183 | - out.push_back(SubstituteVars(s, yieldMap)); | 226 | + out.push_back(SubstituteStmt(s, yieldMap)); |
| 184 | } | 227 | } |
| 185 | } | 228 | } |
| 186 | std::vector<ExprPtr> values(newVars.begin(), newVars.end()); | 229 | std::vector<ExprPtr> values(newVars.begin(), newVars.end()); |
| @@ -302,6 +302,15 @@ static void PrintKwargValue(std::ostream& stream, const std::string& prefix, con | |||
| 302 | stream << values[j]; | 302 | stream << values[j]; |
| 303 | } | 303 | } |
| 304 | stream << "]"; | 304 | stream << "]"; |
| 305 | + } else if (value.type() == typeid(std::vector<int64_t>)) { | ||
| 306 | + const auto& values = AnyCast<std::vector<int64_t>>(value, key); | ||
| 307 | + stream << "["; | ||
| 308 | + for (size_t j = 0; j < values.size(); ++j) { | ||
| 309 | + if (j != 0) | ||
| 310 | + stream << ", "; | ||
| 311 | + stream << values[j]; | ||
| 312 | + } | ||
| 313 | + stream << "]"; | ||
| 305 | } else if (value.type() == typeid(std::vector<SymbolicScalar>)) { | 314 | } else if (value.type() == typeid(std::vector<SymbolicScalar>)) { |
| 306 | const auto& values = AnyCast<std::vector<SymbolicScalar>>(value, key); | 315 | const auto& values = AnyCast<std::vector<SymbolicScalar>>(value, key); |
| 307 | stream << "["; | 316 | stream << "["; |
| @@ -928,6 +937,19 @@ void IRPrinter::VisitStmt_(const TensorOpStmtPtr& op) | |||
| 928 | PrintKwargValue(stream_, prefix_, op->attrs_[i].first, op->attrs_[i].second); | 937 | PrintKwargValue(stream_, prefix_, op->attrs_[i].first, op->attrs_[i].second); |
| 929 | } | 938 | } |
| 930 | stream_ << "]"; | 939 | stream_ << "]"; |
| 940 | + } else { | ||
| 941 | + auto attrs = CollectTensorOpAttrs(op); | ||
| 942 | + if (!attrs.empty()) { | ||
| 943 | + stream_ << ", attrs=["; | ||
| 944 | + bool need_comma = false; | ||
| 945 | + for (auto [name, val] : attrs) { | ||
| 946 | + if (need_comma) | ||
| 947 | + stream_ << ", "; | ||
| 948 | + need_comma = true; | ||
| 949 | + PrintKwargValue(stream_, prefix_, name, val); | ||
| 950 | + } | ||
| 951 | + stream_ << "]"; | ||
| 952 | + } | ||
| 931 | } | 953 | } |
| 932 | stream_ << ")"; | 954 | stream_ << ")"; |
| 933 | } | 955 | } |
| @@ -18,6 +18,7 @@ | |||
| 18 | #include "ir/expr.h" | 18 | #include "ir/expr.h" |
| 19 | #include "ir/stmt.h" | 19 | #include "ir/stmt.h" |
| 20 | #include "ir/transforms/base/visitor.h" | 20 | #include "ir/transforms/base/visitor.h" |
| 21 | +#include "interface/operation/operation.h" | ||
| 21 | 22 | ||
| 22 | namespace pypto { | 23 | namespace pypto { |
| 23 | namespace ir { | 24 | namespace ir { |
| @@ -25,6 +26,8 @@ namespace utils { | |||
| 25 | 26 | ||
| 26 | namespace { | 27 | namespace { |
| 27 | 28 | ||
| 29 | +using npu::tile_fwk::Operation; | ||
| 30 | + | ||
| 28 | class VarUseCollector : public IRVisitor { | 31 | class VarUseCollector : public IRVisitor { |
| 29 | public: | 32 | public: |
| 30 | std::unordered_set<const Var*> var_uses; | 33 | std::unordered_set<const Var*> var_uses; |
| @@ -66,6 +69,18 @@ private: | |||
| 66 | } | 69 | } |
| 67 | } | 70 | } |
| 68 | 71 | ||
| 72 | + void VisitStmt_(const TensorOpStmtPtr& op) override | ||
| 73 | + { | ||
| 74 | + IRVisitor::VisitStmt_(op); | ||
| 75 | + | ||
| 76 | + auto operation = std::dynamic_pointer_cast<Operation>(std::const_pointer_cast<TensorOpStmt>(op)); | ||
| 77 | + if (operation) { | ||
| 78 | + for (auto& attr : operation->GetDynamicAttributeList()) { | ||
| 79 | + attr.get().GetVarRefs(var_uses); | ||
| 80 | + } | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + | ||
| 69 | bool skip_iter_updates_; | 84 | bool skip_iter_updates_; |
| 70 | }; | 85 | }; |
| 71 | 86 | ||
| @@ -39,6 +39,7 @@ public: | |||
| 39 | virtual Json DumpDynJson() = 0; | 39 | virtual Json DumpDynJson() = 0; |
| 40 | virtual void LoadJson(const Json& attrJson) = 0; | 40 | virtual void LoadJson(const Json& attrJson) = 0; |
| 41 | virtual std::shared_ptr<OpAttribute> Clone() const = 0; | 41 | virtual std::shared_ptr<OpAttribute> Clone() const = 0; |
| 42 | + virtual void CollectAttrs(std::map<std::string, std::any>&) const {} | ||
| 42 | 43 | ||
| 43 | virtual ~OpAttribute() = default; | 44 | virtual ~OpAttribute() = default; |
| 44 | }; | 45 | }; |
| @@ -245,6 +246,18 @@ public: | |||
| 245 | 246 | ||
| 246 | static std::shared_ptr<ViewOpAttribute> DeserializeFrom(const Json& attrJson, [[maybe_unused]] Function* function); | 247 | static std::shared_ptr<ViewOpAttribute> DeserializeFrom(const Json& attrJson, [[maybe_unused]] Function* function); |
| 247 | 248 | ||
| 249 | + void CollectAttrs(std::map<std::string, std::any>& attrs) const override | ||
| 250 | + { | ||
| 251 | + if (!fromDynOffset_.empty()) { | ||
| 252 | + attrs["fromOffset"] = fromDynOffset_; | ||
| 253 | + } else { | ||
| 254 | + attrs["fromOffset"] = fromOffset_; | ||
| 255 | + } | ||
| 256 | + if (!toDynValidShape_.empty()) { | ||
| 257 | + attrs["toValidShape"] = toDynValidShape_; | ||
| 258 | + } | ||
| 259 | + } | ||
| 260 | + | ||
| 248 | private: | 261 | private: |
| 249 | MemoryType to_; | 262 | MemoryType to_; |
| 250 | Offset fromOffset_; | 263 | Offset fromOffset_; |
| @@ -289,6 +302,18 @@ public: | |||
| 289 | static std::shared_ptr<AssembleOpAttribute> DeserializeFrom(const Json& attrJson, | 302 | static std::shared_ptr<AssembleOpAttribute> DeserializeFrom(const Json& attrJson, |
| 290 | [[maybe_unused]] Function* function); | 303 | [[maybe_unused]] Function* function); |
| 291 | 304 | ||
| 305 | + void CollectAttrs(std::map<std::string, std::any>& attrs) const override | ||
| 306 | + { | ||
| 307 | + if (!toDynOffset_.empty()) { | ||
| 308 | + attrs["toOffset"] = toDynOffset_; | ||
| 309 | + } else { | ||
| 310 | + attrs["toOffset"] = toOffset_; | ||
| 311 | + } | ||
| 312 | + if (!fromDynValidShape_.empty()) { | ||
| 313 | + attrs["fromValidShape"] = fromDynValidShape_; | ||
| 314 | + } | ||
| 315 | + } | ||
| 316 | + | ||
| 292 | private: | 317 | private: |
| 293 | MemoryType from_; | 318 | MemoryType from_; |
| 294 | Offset toOffset_; | 319 | Offset toOffset_; |
| @@ -24,8 +24,8 @@ | |||
| 24 | #include "ir_finalize.h" | 24 | #include "ir_finalize.h" |
| 25 | 25 | ||
| 26 | using npu::tile_fwk::LogicalTensor; | 26 | using npu::tile_fwk::LogicalTensor; |
| 27 | +using npu::tile_fwk::Operation; | ||
| 27 | using npu::tile_fwk::RawSymbolicExpression; | 28 | using npu::tile_fwk::RawSymbolicExpression; |
| 28 | -using npu::tile_fwk::RawTensor; | ||
| 29 | 29 | ||
| 30 | namespace pypto::ir { | 30 | namespace pypto::ir { |
| 31 | std::string DumpScalarExpr(const ScalarExprPtr& op) | 31 | std::string DumpScalarExpr(const ScalarExprPtr& op) |
| @@ -42,6 +42,18 @@ std::string DumpTensorVar(const VarPtr& var) | |||
| 42 | return var->name_ + "@" + std::to_string(t->tensor->memoryId); | 42 | return var->name_ + "@" + std::to_string(t->tensor->memoryId); |
| 43 | } | 43 | } |
| 44 | 44 | ||
| 45 | +std::map<std::string, std::any> CollectTensorOpAttrs(const TensorOpStmtPtr& top) | ||
| 46 | +{ | ||
| 47 | + std::map<std::string, std::any> attrs; | ||
| 48 | + | ||
| 49 | + auto op = std::dynamic_pointer_cast<Operation>(std::const_pointer_cast<TensorOpStmt>(top)); | ||
| 50 | + if (op && op->GetOpAttribute()) { | ||
| 51 | + auto opAttr = op->GetOpAttribute(); | ||
| 52 | + opAttr->CollectAttrs(attrs); | ||
| 53 | + } | ||
| 54 | + return attrs; | ||
| 55 | +} | ||
| 56 | + | ||
| 45 | Pass pass::AggressiveDCE() | 57 | Pass pass::AggressiveDCE() |
| 46 | { | 58 | { |
| 47 | return pass::CreateFunctionPass( | 59 | return pass::CreateFunctionPass( |
| @@ -10,10 +10,13 @@ | |||
| 10 | #pragma once | 10 | #pragma once |
| 11 | 11 | ||
| 12 | #include <string> | 12 | #include <string> |
| 13 | +#include <map> | ||
| 13 | 14 | ||
| 14 | #include "ir/scalar_expr.h" | 15 | #include "ir/scalar_expr.h" |
| 16 | +#include "ir/stmt.h" | ||
| 15 | 17 | ||
| 16 | namespace pypto::ir { | 18 | namespace pypto::ir { |
| 17 | std::string DumpScalarExpr(const ScalarExprPtr& op); | 19 | std::string DumpScalarExpr(const ScalarExprPtr& op); |
| 18 | std::string DumpTensorVar(const VarPtr& tensor); | 20 | std::string DumpTensorVar(const VarPtr& tensor); |
| 21 | +std::map<std::string, std::any> CollectTensorOpAttrs(const TensorOpStmtPtr& ptr); | ||
| 19 | } // namespace pypto::ir | 22 | } // namespace pypto::ir |
| @@ -591,6 +591,18 @@ bool SymbolicExpressionTable::CheckExprDependCore(const RawSymbolicScalarPtr& ra | |||
| 591 | } | 591 | } |
| 592 | } | 592 | } |
| 593 | 593 | ||
| 594 | +static RawSymbolicScalarPtr AsRawSymbolicScalar(const pypto::ir::ExprPtr& expr) | ||
| 595 | +{ | ||
| 596 | + if (auto val = ir::AsMut<ir::ConstInt>(expr)) | ||
| 597 | + return std::static_pointer_cast<RawSymbolicImmediate>(val); | ||
🟠 High Priority
触发条件: 当 建议:将 ![]() ![]() Incorrect? | |||
| 598 | + if (auto var = ir::AsMut<ir::Var>(expr)) | ||
| 599 | + return std::static_pointer_cast<RawSymbolicSymbol>(var); | ||
| 600 | + if (auto sexpr = ir::AsMut<ir::ScalarExpr>(expr)) { | ||
| 601 | + return std::static_pointer_cast<RawSymbolicExpression>(sexpr); | ||
| 602 | + } | ||
| 603 | + return nullptr; | ||
| 604 | +} | ||
| 605 | + | ||
| 594 | void RawSymbolicScalar::FlattenOperands(const std::vector<RawSymbolicScalarPtr>& inOperandList, | 606 | void RawSymbolicScalar::FlattenOperands(const std::vector<RawSymbolicScalarPtr>& inOperandList, |
| 595 | SymbolicOpcode objOpcode, std::vector<RawSymbolicScalarPtr>& outOperandList) | 607 | SymbolicOpcode objOpcode, std::vector<RawSymbolicScalarPtr>& outOperandList) |
| 596 | { | 608 | { |
| @@ -876,6 +888,67 @@ pypto::ir::ExprPtr SymbolicScalar::AsExpr() const | |||
| 876 | } | 888 | } |
| 877 | } | 889 | } |
| 878 | 890 | ||
| 891 | +void SymbolicScalar::GetVarRefs(std::unordered_set<const ir::Var*>& out) const | ||
| 892 | +{ | ||
| 893 | + std::function<void(RawSymbolicScalarPtr)> collect; | ||
| 894 | + | ||
| 895 | + collect = [&](const auto& raw) { | ||
| 896 | + if (!raw || raw->IsImmediate()) { | ||
| 897 | + return; | ||
| 898 | + } | ||
| 899 | + if (raw->IsSymbol()) { | ||
| 900 | + out.insert(std::dynamic_pointer_cast<RawSymbolicSymbol>(raw).get()); | ||
| 901 | + } else if (raw->IsExpression()) { | ||
| 902 | + for (const auto& operand : raw->GetExpressionOperandList()) { | ||
| 903 | + collect(operand); | ||
| 904 | + } | ||
| 905 | + } | ||
| 906 | + }; | ||
| 907 | + | ||
| 908 | + collect(raw_); | ||
| 909 | +} | ||
| 910 | + | ||
| 911 | +SymbolicScalar SymbolicScalar::SubstituteVars(const std::unordered_map<ir::VarPtr, ir::ExprPtr>& varMap) | ||
| 912 | +{ | ||
| 913 | + std::function<RawSymbolicScalarPtr(const RawSymbolicScalarPtr&)> substitute; | ||
| 914 | + std::unordered_map<RawSymbolicScalar*, RawSymbolicScalarPtr> exprMap; | ||
| 915 | + | ||
| 916 | + substitute = [&](const RawSymbolicScalarPtr& raw) -> RawSymbolicScalarPtr { | ||
| 917 | + if (!raw || raw->IsImmediate()) { | ||
| 918 | + return raw; | ||
| 919 | + } | ||
| 920 | + if (raw->IsSymbol()) { | ||
| 921 | + auto v = std::dynamic_pointer_cast<RawSymbolicSymbol>(raw); | ||
| 922 | + auto it = varMap.find(v); | ||
| 923 | + if (it != varMap.end()) { | ||
| 924 | + return AsRawSymbolicScalar(it->second); | ||
| 925 | + } | ||
| 926 | + return raw; | ||
| 927 | + } | ||
| 928 | + | ||
| 929 | + auto it = exprMap.find(raw.get()); | ||
| 930 | + if (it != exprMap.end()) { | ||
| 931 | + return it->second; | ||
| 932 | + } | ||
| 933 | + auto expr = std::dynamic_pointer_cast<RawSymbolicExpression>(raw); | ||
| 934 | + bool changed = false; | ||
| 935 | + std::vector<RawSymbolicScalarPtr> nops; | ||
| 936 | + for (auto& operand : expr->OperandList()) { | ||
| 937 | + auto nop = substitute(operand); | ||
| 938 | + nops.push_back(nop); | ||
| 939 | + changed = changed || (nop.get() != operand.get()); | ||
| 940 | + } | ||
| 941 | + if (!changed) { | ||
| 942 | + return raw; | ||
| 943 | + } | ||
| 944 | + expr = std::make_shared<RawSymbolicExpression>(expr->Opcode(), nops); | ||
| 945 | + exprMap[raw.get()] = expr; | ||
| 946 | + return expr; | ||
| 947 | + }; | ||
| 948 | + | ||
| 949 | + return SymbolicScalar(substitute(raw_)); | ||
| 950 | +} | ||
| 951 | + | ||
| 879 | SymbolicScalar SymbolicScalar::Min(const SymbolicScalar& sval) const | 952 | SymbolicScalar SymbolicScalar::Min(const SymbolicScalar& sval) const |
| 880 | { | 953 | { |
| 881 | if (ConcreteValid() && sval.ConcreteValid()) { | 954 | if (ConcreteValid() && sval.ConcreteValid()) { |
| @@ -920,14 +993,7 @@ SymbolicScalar::SymbolicScalar(RawSymbolicScalarPtr raw) : raw_(raw) | |||
| 920 | 993 | ||
| 921 | SymbolicScalar SymbolicScalar::FromExpr(const pypto::ir::ExprPtr& expr) | 994 | SymbolicScalar SymbolicScalar::FromExpr(const pypto::ir::ExprPtr& expr) |
| 922 | { | 995 | { |
| 923 | - if (auto val = ir::AsMut<ir::ConstInt>(expr)) | 996 | + return SymbolicScalar(AsRawSymbolicScalar(expr)); |
| 924 | - return SymbolicScalar(std::static_pointer_cast<RawSymbolicImmediate>(val)); | ||
| 925 | - if (auto var = ir::AsMut<ir::Var>(expr)) | ||
| 926 | - return SymbolicScalar(std::static_pointer_cast<RawSymbolicSymbol>(var)); | ||
| 927 | - if (auto sexpr = ir::AsMut<ir::ScalarExpr>(expr)) { | ||
| 928 | - return SymbolicScalar(std::static_pointer_cast<RawSymbolicExpression>(sexpr)); | ||
| 929 | - } | ||
| 930 | - return SymbolicScalar(); | ||
| 931 | } | 997 | } |
| 932 | 998 | ||
| 933 | std::vector<int64_t> SymbolicScalar::Concrete(const std::vector<SymbolicScalar>& scalarList, int64_t defValue) | 999 | std::vector<int64_t> SymbolicScalar::Concrete(const std::vector<SymbolicScalar>& scalarList, int64_t defValue) |
| @@ -23,6 +23,7 @@ def check_snapshot(func, golden): | |||
| 23 | actual.splitlines(keepends=True), | 23 | actual.splitlines(keepends=True), |
| 24 | ) | 24 | ) |
| 25 | ) | 25 | ) |
| 26 | + print(actual) | ||
| 26 | raise AssertionError("IR snapshot mismatch in %s:\n%s" % (func.name, diff)) | 27 | raise AssertionError("IR snapshot mismatch in %s:\n%s" % (func.name, diff)) |
| 27 | 28 | ||
| 28 | 29 | ||
| @@ -15,26 +15,26 @@ ir = """ | |||
| 15 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | 15 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): |
| 16 | for loop_idx_10 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | 16 | for loop_idx_10 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): |
| 17 | if (loop_idx_10==0): | 17 | if (loop_idx_10==0): |
| 18 | - View_x@3 = VIEW(x@0) | 18 | + View_x@3 = VIEW(x@0, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 19 | - View_y@4 = VIEW(y@1) | 19 | + View_y@4 = VIEW(y@1, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 20 | $0@5 = ADD(View_x@3, View_y@4) | 20 | $0@5 = ADD(View_x@3, View_y@4) |
| 21 | $4@8 = SUB($0@5, View_x@3) | 21 | $4@8 = SUB($0@5, View_x@3) |
| 22 | - z@2 = ASSEMBLE($4@8) | 22 | + z@2 = ASSEMBLE($4@8, attrs=["toOffset": [0, 0]]) |
| 23 | ir.yield_() | 23 | ir.yield_() |
| 24 | else: | 24 | else: |
| 25 | if (loop_idx_10==1): | 25 | if (loop_idx_10==1): |
| 26 | - View_x_8@3 = VIEW(x@0) | 26 | + View_x_8@3 = VIEW(x@0, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 27 | - View_y_8@4 = VIEW(y@1) | 27 | + View_y_8@4 = VIEW(y@1, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 28 | $1@6 = SUB(View_x_8@3, View_y_8@4) | 28 | $1@6 = SUB(View_x_8@3, View_y_8@4) |
| 29 | $3@7 = ADD($1@6, View_x_8@3) | 29 | $3@7 = ADD($1@6, View_x_8@3) |
| 30 | - z@2 = ASSEMBLE($3@7) | 30 | + z@2 = ASSEMBLE($3@7, attrs=["toOffset": [0, 0]]) |
| 31 | ir.yield_() | 31 | ir.yield_() |
| 32 | else: | 32 | else: |
| 33 | - View_x_6@3 = VIEW(x@0) | 33 | + View_x_6@3 = VIEW(x@0, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 34 | - View_y_6@4 = VIEW(y@1) | 34 | + View_y_6@4 = VIEW(y@1, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 35 | $1_1@6 = SUB(View_x_6@3, View_y_6@4) | 35 | $1_1@6 = SUB(View_x_6@3, View_y_6@4) |
| 36 | $4_0@8 = SUB($1_1@6, View_x_6@3) | 36 | $4_0@8 = SUB($1_1@6, View_x_6@3) |
| 37 | - z@2 = ASSEMBLE($4_0@8) | 37 | + z@2 = ASSEMBLE($4_0@8, attrs=["toOffset": [0, 0]]) |
| 38 | ir.yield_() | 38 | ir.yield_() |
| 39 | ir.yield_() | 39 | ir.yield_() |
| 40 | continue | 40 | continue |
| @@ -14,16 +14,16 @@ from ..test_common import check_snapshot, run_merge_pass | |||
| 14 | ir = """ | 14 | ir = """ |
| 15 | @ir.function | 15 | @ir.function |
| 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): |
| 17 | - View_x@3 = VIEW(x@0) | 17 | + View_x@3 = VIEW(x@0, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 18 | - View_y@4 = VIEW(y@1) | 18 | + View_y@4 = VIEW(y@1, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 19 | for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | 19 | for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): |
| 20 | if (loop_idx_32==0): | 20 | if (loop_idx_32==0): |
| 21 | $1@6 = SUB(View_x@3, View_y@4) | 21 | $1@6 = SUB(View_x@3, View_y@4) |
| 22 | - z@2 = ASSEMBLE($1@6) | 22 | + z@2 = ASSEMBLE($1@6, attrs=["toOffset": [0, 0]]) |
| 23 | ir.yield_() | 23 | ir.yield_() |
| 24 | else: | 24 | else: |
| 25 | $3@7 = ADD(View_x@3, View_y@4) | 25 | $3@7 = ADD(View_x@3, View_y@4) |
| 26 | - z@2 = ASSEMBLE($3@7) | 26 | + z@2 = ASSEMBLE($3@7, attrs=["toOffset": [0, 0]]) |
| 27 | ir.yield_() | 27 | ir.yield_() |
| 28 | continue | 28 | continue |
| 29 | return x@0, y@1, z@2 | 29 | return x@0, y@1, z@2 |
| @@ -14,11 +14,11 @@ from ..test_common import check_snapshot, run_merge_pass | |||
| 14 | ir = """ | 14 | ir = """ |
| 15 | @ir.function | 15 | @ir.function |
| 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): |
| 17 | - View_x@3 = VIEW(x@0) | 17 | + View_x@3 = VIEW(x@0, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 18 | - View_y@4 = VIEW(y@1) | 18 | + View_y@4 = VIEW(y@1, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 19 | for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | 19 | for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): |
| 20 | $1@6 = SUB(View_x@3, View_y@4) | 20 | $1@6 = SUB(View_x@3, View_y@4) |
| 21 | - z@2 = ASSEMBLE($1@6) | 21 | + z@2 = ASSEMBLE($1@6, attrs=["toOffset": [0, 0]]) |
| 22 | continue | 22 | continue |
| 23 | return x@0, y@1, z@2 | 23 | return x@0, y@1, z@2 |
| 24 | """ | 24 | """ |
| @@ -14,8 +14,8 @@ from ..test_common import check_snapshot, run_merge_pass | |||
| 14 | ir = """ | 14 | ir = """ |
| 15 | @ir.function | 15 | @ir.function |
| 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): |
| 17 | - View_x@3 = VIEW(x@0) | 17 | + View_x@3 = VIEW(x@0, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 18 | - View_y@4 = VIEW(y@1) | 18 | + View_y@4 = VIEW(y@1, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 19 | for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | 19 | for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): |
| 20 | if (loop_idx_32==0): | 20 | if (loop_idx_32==0): |
| 21 | $0@5 = ADD(View_x@3, View_y@4) | 21 | $0@5 = ADD(View_x@3, View_y@4) |
| @@ -24,15 +24,15 @@ def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | |||
| 24 | $1@6 = SUB(View_x@3, View_y@4) | 24 | $1@6 = SUB(View_x@3, View_y@4) |
| 25 | a_0 = ir.yield_($1@6) | 25 | a_0 = ir.yield_($1@6) |
| 26 | for loop_idx_50 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | 26 | for loop_idx_50 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): |
| 27 | - z@2 = ASSEMBLE(a_0@5) | 27 | + z@2 = ASSEMBLE(a_0@5, attrs=["toOffset": [(loop_idx_50*16), 0]]) |
| 28 | continue | 28 | continue |
| 29 | if (loop_idx_32==1): | 29 | if (loop_idx_32==1): |
| 30 | $3@7 = ADD(a_0@5, View_y@4) | 30 | $3@7 = ADD(a_0@5, View_y@4) |
| 31 | - z@2 = ASSEMBLE($3@7) | 31 | + z@2 = ASSEMBLE($3@7, attrs=["toOffset": [0, 0]]) |
| 32 | ir.yield_() | 32 | ir.yield_() |
| 33 | else: | 33 | else: |
| 34 | $4@8 = SUB(a_0@5, View_y@4) | 34 | $4@8 = SUB(a_0@5, View_y@4) |
| 35 | - z@2 = ASSEMBLE($4@8) | 35 | + z@2 = ASSEMBLE($4@8, attrs=["toOffset": [0, 0]]) |
| 36 | ir.yield_() | 36 | ir.yield_() |
| 37 | continue | 37 | continue |
| 38 | return x@0, y@1, z@2 | 38 | return x@0, y@1, z@2 |
| @@ -14,18 +14,18 @@ from ..test_common import check_snapshot, run_merge_pass | |||
| 14 | ir = """ | 14 | ir = """ |
| 15 | @ir.function | 15 | @ir.function |
| 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): |
| 17 | - View_x@3 = VIEW(x@0) | 17 | + View_x@3 = VIEW(x@0, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 18 | - View_y@4 = VIEW(y@1) | 18 | + View_y@4 = VIEW(y@1, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 19 | for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | 19 | for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): |
| 20 | if (loop_idx_32==0): | 20 | if (loop_idx_32==0): |
| 21 | $0@5 = ADD(View_x@3, View_y@4) | 21 | $0@5 = ADD(View_x@3, View_y@4) |
| 22 | $3@7 = ADD($0@5, View_x@3) | 22 | $3@7 = ADD($0@5, View_x@3) |
| 23 | - z@2 = ASSEMBLE($3@7) | 23 | + z@2 = ASSEMBLE($3@7, attrs=["toOffset": [0, 0]]) |
| 24 | ir.yield_() | 24 | ir.yield_() |
| 25 | else: | 25 | else: |
| 26 | $1@6 = SUB(View_x@3, View_y@4) | 26 | $1@6 = SUB(View_x@3, View_y@4) |
| 27 | $3_1@7 = ADD($1@6, View_x@3) | 27 | $3_1@7 = ADD($1@6, View_x@3) |
| 28 | - z@2 = ASSEMBLE($3_1@7) | 28 | + z@2 = ASSEMBLE($3_1@7, attrs=["toOffset": [0, 0]]) |
| 29 | ir.yield_() | 29 | ir.yield_() |
| 30 | continue | 30 | continue |
| 31 | return x@0, y@1, z@2 | 31 | return x@0, y@1, z@2 |
| @@ -14,16 +14,16 @@ from ..test_common import check_snapshot, run_merge_pass | |||
| 14 | ir = """ | 14 | ir = """ |
| 15 | @ir.function | 15 | @ir.function |
| 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): |
| 17 | - View_x@3 = VIEW(x@0) | 17 | + View_x@3 = VIEW(x@0, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 18 | - View_y@4 = VIEW(y@1) | 18 | + View_y@4 = VIEW(y@1, attrs=["fromOffset": [0, 0], "toValidShape": [16, 16]]) |
| 19 | for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | 19 | for loop_idx_32 in ir.range(0, 2, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): |
| 20 | if (loop_idx_32==0): | 20 | if (loop_idx_32==0): |
| 21 | $0@5 = ADD(View_x@3, View_y@4) | 21 | $0@5 = ADD(View_x@3, View_y@4) |
| 22 | - z@2 = ASSEMBLE($0@5) | 22 | + z@2 = ASSEMBLE($0@5, attrs=["toOffset": [0, 0]]) |
| 23 | ir.yield_() | 23 | ir.yield_() |
| 24 | else: | 24 | else: |
| 25 | $3@7 = SUB(View_x@3, View_y@4) | 25 | $3@7 = SUB(View_x@3, View_y@4) |
| 26 | - z@2 = ASSEMBLE($3@7) | 26 | + z@2 = ASSEMBLE($3@7, attrs=["toOffset": [0, 0]]) |
| 27 | ir.yield_() | 27 | ir.yield_() |
| 28 | continue | 28 | continue |
| 29 | return x@0, y@1, z@2 | 29 | return x@0, y@1, z@2 |
| @@ -14,66 +14,66 @@ from ..test_common import check_snapshot, run_merge_pass | |||
| 14 | ir = """ | 14 | ir = """ |
| 15 | @ir.function | 15 | @ir.function |
| 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): |
| 17 | - View_x@3 = VIEW(x@0) | 17 | + View_x@3 = VIEW(x@0, attrs=["fromOffset": [0, 0], "toValidShape": [RUNTIME_Min(RUNTIME_Max(RUNTIME_GetInputShapeDim(ARG_x,0), 0), 16), 16]]) |
| 18 | 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}): | 18 | 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}): |
| 19 | if (loop_idx_37==0): | 19 | if (loop_idx_37==0): |
| 20 | if ((loop_idx_37+3)==(RUNTIME_GetInputShapeDim(ARG_x,0)-1)): | 20 | if ((loop_idx_37+3)==(RUNTIME_GetInputShapeDim(ARG_x,0)-1)): |
| 21 | $0@5 = ADDS(View_x@3) | 21 | $0@5 = ADDS(View_x@3) |
| 22 | $5@9 = SUBS(View_x@3) | 22 | $5@9 = SUBS(View_x@3) |
| 23 | - z@2 = ASSEMBLE($5@9) | 23 | + z@2 = ASSEMBLE($5@9, attrs=["toOffset": [0, 0]]) |
| 24 | $8@11 = SUBS(View_x@3) | 24 | $8@11 = SUBS(View_x@3) |
| 25 | $12@14 = SUBS(View_x@3) | 25 | $12@14 = SUBS(View_x@3) |
| 26 | - z@2 = ASSEMBLE($12@14) | 26 | + z@2 = ASSEMBLE($12@14, attrs=["toOffset": [0, 0]]) |
| 27 | $15@16 = SUBS(View_x@3) | 27 | $15@16 = SUBS(View_x@3) |
| 28 | $19@19 = SUBS(View_x@3) | 28 | $19@19 = SUBS(View_x@3) |
| 29 | - z@2 = ASSEMBLE($19@19) | 29 | + z@2 = ASSEMBLE($19@19, attrs=["toOffset": [0, 0]]) |
| 30 | $22@21 = SUBS(View_x@3) | 30 | $22@21 = SUBS(View_x@3) |
| 31 | $25@23 = ADDS(View_x@3) | 31 | $25@23 = ADDS(View_x@3) |
| 32 | - z@2 = ASSEMBLE($25@23) | 32 | + z@2 = ASSEMBLE($25@23, attrs=["toOffset": [0, 0]]) |
| 33 | ir.yield_() | 33 | ir.yield_() |
| 34 | else: | 34 | else: |
| 35 | $0_1@5 = ADDS(View_x@3) | 35 | $0_1@5 = ADDS(View_x@3) |
| 36 | $5_2@9 = SUBS(View_x@3) | 36 | $5_2@9 = SUBS(View_x@3) |
| 37 | - z@2 = ASSEMBLE($5_2@9) | 37 | + z@2 = ASSEMBLE($5_2@9, attrs=["toOffset": [0, 0]]) |
| 38 | $8_2@11 = SUBS(View_x@3) | 38 | $8_2@11 = SUBS(View_x@3) |
| 39 | $12_2@14 = SUBS(View_x@3) | 39 | $12_2@14 = SUBS(View_x@3) |
| 40 | - z@2 = ASSEMBLE($12_2@14) | 40 | + z@2 = ASSEMBLE($12_2@14, attrs=["toOffset": [0, 0]]) |
| 41 | $15_2@16 = SUBS(View_x@3) | 41 | $15_2@16 = SUBS(View_x@3) |
| 42 | $19_2@19 = SUBS(View_x@3) | 42 | $19_2@19 = SUBS(View_x@3) |
| 43 | - z@2 = ASSEMBLE($19_2@19) | 43 | + z@2 = ASSEMBLE($19_2@19, attrs=["toOffset": [0, 0]]) |
| 44 | $22_2@21 = SUBS(View_x@3) | 44 | $22_2@21 = SUBS(View_x@3) |
| 45 | $26@24 = SUBS(View_x@3) | 45 | $26@24 = SUBS(View_x@3) |
| 46 | - z@2 = ASSEMBLE($26@24) | 46 | + z@2 = ASSEMBLE($26@24, attrs=["toOffset": [0, 0]]) |
| 47 | ir.yield_() | 47 | ir.yield_() |
| 48 | ir.yield_() | 48 | ir.yield_() |
| 49 | else: | 49 | else: |
| 50 | if ((loop_idx_37+3)==(RUNTIME_GetInputShapeDim(ARG_x,0)-1)): | 50 | if ((loop_idx_37+3)==(RUNTIME_GetInputShapeDim(ARG_x,0)-1)): |
| 51 | $1@6 = SUBS(View_x@3) | 51 | $1@6 = SUBS(View_x@3) |
| 52 | $5_5@9 = SUBS(View_x@3) | 52 | $5_5@9 = SUBS(View_x@3) |
| 53 | - z@2 = ASSEMBLE($5_5@9) | 53 | + z@2 = ASSEMBLE($5_5@9, attrs=["toOffset": [0, 0]]) |
| 54 | $8_5@11 = SUBS(View_x@3) | 54 | $8_5@11 = SUBS(View_x@3) |
| 55 | $12_5@14 = SUBS(View_x@3) | 55 | $12_5@14 = SUBS(View_x@3) |
| 56 | - z@2 = ASSEMBLE($12_5@14) | 56 | + z@2 = ASSEMBLE($12_5@14, attrs=["toOffset": [0, 0]]) |
| 57 | $15_5@16 = SUBS(View_x@3) | 57 | $15_5@16 = SUBS(View_x@3) |
| 58 | $19_5@19 = SUBS(View_x@3) | 58 | $19_5@19 = SUBS(View_x@3) |
| 59 | - z@2 = ASSEMBLE($19_5@19) | 59 | + z@2 = ASSEMBLE($19_5@19, attrs=["toOffset": [0, 0]]) |
| 60 | $22_5@21 = SUBS(View_x@3) | 60 | $22_5@21 = SUBS(View_x@3) |
| 61 | $25_0@23 = ADDS(View_x@3) | 61 | $25_0@23 = ADDS(View_x@3) |
| 62 | - z@2 = ASSEMBLE($25_0@23) | 62 | + z@2 = ASSEMBLE($25_0@23, attrs=["toOffset": [0, 0]]) |
| 63 | ir.yield_() | 63 | ir.yield_() |
| 64 | else: | 64 | else: |
| 65 | $1_1@6 = SUBS(View_x@3) | 65 | $1_1@6 = SUBS(View_x@3) |
| 66 | $5_4@9 = SUBS(View_x@3) | 66 | $5_4@9 = SUBS(View_x@3) |
| 67 | - z@2 = ASSEMBLE($5_4@9) | 67 | + z@2 = ASSEMBLE($5_4@9, attrs=["toOffset": [0, 0]]) |
| 68 | $8_4@11 = SUBS(View_x@3) | 68 | $8_4@11 = SUBS(View_x@3) |
| 69 | $12_4@14 = SUBS(View_x@3) | 69 | $12_4@14 = SUBS(View_x@3) |
| 70 | - z@2 = ASSEMBLE($12_4@14) | 70 | + z@2 = ASSEMBLE($12_4@14, attrs=["toOffset": [0, 0]]) |
| 71 | $15_4@16 = SUBS(View_x@3) | 71 | $15_4@16 = SUBS(View_x@3) |
| 72 | $19_4@19 = SUBS(View_x@3) | 72 | $19_4@19 = SUBS(View_x@3) |
| 73 | - z@2 = ASSEMBLE($19_4@19) | 73 | + z@2 = ASSEMBLE($19_4@19, attrs=["toOffset": [0, 0]]) |
| 74 | $22_4@21 = SUBS(View_x@3) | 74 | $22_4@21 = SUBS(View_x@3) |
| 75 | $26_0@24 = SUBS(View_x@3) | 75 | $26_0@24 = SUBS(View_x@3) |
| 76 | - z@2 = ASSEMBLE($26_0@24) | 76 | + z@2 = ASSEMBLE($26_0@24, attrs=["toOffset": [0, 0]]) |
| 77 | ir.yield_() | 77 | ir.yield_() |
| 78 | ir.yield_() | 78 | ir.yield_() |
| 79 | continue | 79 | continue |
| @@ -82,24 +82,24 @@ def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | |||
| 82 | if (loop_idx_37_0==(RUNTIME_GetInputShapeDim(ARG_x,0)-1)): | 82 | if (loop_idx_37_0==(RUNTIME_GetInputShapeDim(ARG_x,0)-1)): |
| 83 | $30@25 = ADDS(View_x@3) | 83 | $30@25 = ADDS(View_x@3) |
| 84 | $34@28 = ADDS(View_x@3) | 84 | $34@28 = ADDS(View_x@3) |
| 85 | - z@2 = ASSEMBLE($34@28) | 85 | + z@2 = ASSEMBLE($34@28, attrs=["toOffset": [0, 0]]) |
| 86 | ir.yield_() | 86 | ir.yield_() |
| 87 | else: | 87 | else: |
| 88 | $30_1@25 = ADDS(View_x@3) | 88 | $30_1@25 = ADDS(View_x@3) |
| 89 | $35@29 = SUBS(View_x@3) | 89 | $35@29 = SUBS(View_x@3) |
| 90 | - z@2 = ASSEMBLE($35@29) | 90 | + z@2 = ASSEMBLE($35@29, attrs=["toOffset": [0, 0]]) |
| 91 | ir.yield_() | 91 | ir.yield_() |
| 92 | ir.yield_() | 92 | ir.yield_() |
| 93 | else: | 93 | else: |
| 94 | if (loop_idx_37_0==(RUNTIME_GetInputShapeDim(ARG_x,0)-1)): | 94 | if (loop_idx_37_0==(RUNTIME_GetInputShapeDim(ARG_x,0)-1)): |
| 95 | $31@26 = SUBS(View_x@3) | 95 | $31@26 = SUBS(View_x@3) |
| 96 | $34_0@28 = ADDS(View_x@3) | 96 | $34_0@28 = ADDS(View_x@3) |
| 97 | - z@2 = ASSEMBLE($34_0@28) | 97 | + z@2 = ASSEMBLE($34_0@28, attrs=["toOffset": [0, 0]]) |
| 98 | ir.yield_() | 98 | ir.yield_() |
| 99 | else: | 99 | else: |
| 100 | $31_1@26 = SUBS(View_x@3) | 100 | $31_1@26 = SUBS(View_x@3) |
| 101 | $35_0@29 = SUBS(View_x@3) | 101 | $35_0@29 = SUBS(View_x@3) |
| 102 | - z@2 = ASSEMBLE($35_0@29) | 102 | + z@2 = ASSEMBLE($35_0@29, attrs=["toOffset": [0, 0]]) |
| 103 | ir.yield_() | 103 | ir.yield_() |
| 104 | ir.yield_() | 104 | ir.yield_() |
| 105 | continue | 105 | continue |
| @@ -14,66 +14,66 @@ from ..test_common import check_snapshot, run_merge_pass | |||
| 14 | ir = """ | 14 | ir = """ |
| 15 | @ir.function | 15 | @ir.function |
| 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | 16 | def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): |
| 17 | - View_x@3 = VIEW(x@0) | 17 | + View_x@3 = VIEW(x@0, attrs=["fromOffset": [0, 0], "toValidShape": [RUNTIME_Min(RUNTIME_Max(RUNTIME_GetInputShapeDim(ARG_x,0), 0), 16), 16]]) |
| 18 | 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}): | 18 | 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}): |
| 19 | if (loop_idx_37==0): | 19 | if (loop_idx_37==0): |
| 20 | if (RUNTIME_GetInputShapeDim(ARG_x,0)<=(loop_idx_37+4)): | 20 | if (RUNTIME_GetInputShapeDim(ARG_x,0)<=(loop_idx_37+4)): |
| 21 | $0@5 = ADDS(View_x@3) | 21 | $0@5 = ADDS(View_x@3) |
| 22 | $5@9 = SUBS(View_x@3) | 22 | $5@9 = SUBS(View_x@3) |
| 23 | - z@2 = ASSEMBLE($5@9) | 23 | + z@2 = ASSEMBLE($5@9, attrs=["toOffset": [0, 0]]) |
| 24 | $8@11 = SUBS(View_x@3) | 24 | $8@11 = SUBS(View_x@3) |
| 25 | $12@14 = SUBS(View_x@3) | 25 | $12@14 = SUBS(View_x@3) |
| 26 | - z@2 = ASSEMBLE($12@14) | 26 | + z@2 = ASSEMBLE($12@14, attrs=["toOffset": [0, 0]]) |
| 27 | $15@16 = SUBS(View_x@3) | 27 | $15@16 = SUBS(View_x@3) |
| 28 | $19@19 = SUBS(View_x@3) | 28 | $19@19 = SUBS(View_x@3) |
| 29 | - z@2 = ASSEMBLE($19@19) | 29 | + z@2 = ASSEMBLE($19@19, attrs=["toOffset": [0, 0]]) |
| 30 | $22@21 = SUBS(View_x@3) | 30 | $22@21 = SUBS(View_x@3) |
| 31 | $25@23 = ADDS(View_x@3) | 31 | $25@23 = ADDS(View_x@3) |
| 32 | - z@2 = ASSEMBLE($25@23) | 32 | + z@2 = ASSEMBLE($25@23, attrs=["toOffset": [0, 0]]) |
| 33 | ir.yield_() | 33 | ir.yield_() |
| 34 | else: | 34 | else: |
| 35 | $0_1@5 = ADDS(View_x@3) | 35 | $0_1@5 = ADDS(View_x@3) |
| 36 | $5_2@9 = SUBS(View_x@3) | 36 | $5_2@9 = SUBS(View_x@3) |
| 37 | - z@2 = ASSEMBLE($5_2@9) | 37 | + z@2 = ASSEMBLE($5_2@9, attrs=["toOffset": [0, 0]]) |
| 38 | $8_2@11 = SUBS(View_x@3) | 38 | $8_2@11 = SUBS(View_x@3) |
| 39 | $12_2@14 = SUBS(View_x@3) | 39 | $12_2@14 = SUBS(View_x@3) |
| 40 | - z@2 = ASSEMBLE($12_2@14) | 40 | + z@2 = ASSEMBLE($12_2@14, attrs=["toOffset": [0, 0]]) |
| 41 | $15_2@16 = SUBS(View_x@3) | 41 | $15_2@16 = SUBS(View_x@3) |
| 42 | $19_2@19 = SUBS(View_x@3) | 42 | $19_2@19 = SUBS(View_x@3) |
| 43 | - z@2 = ASSEMBLE($19_2@19) | 43 | + z@2 = ASSEMBLE($19_2@19, attrs=["toOffset": [0, 0]]) |
| 44 | $22_2@21 = SUBS(View_x@3) | 44 | $22_2@21 = SUBS(View_x@3) |
| 45 | $26@24 = SUBS(View_x@3) | 45 | $26@24 = SUBS(View_x@3) |
| 46 | - z@2 = ASSEMBLE($26@24) | 46 | + z@2 = ASSEMBLE($26@24, attrs=["toOffset": [0, 0]]) |
| 47 | ir.yield_() | 47 | ir.yield_() |
| 48 | ir.yield_() | 48 | ir.yield_() |
| 49 | else: | 49 | else: |
| 50 | if (RUNTIME_GetInputShapeDim(ARG_x,0)<=(loop_idx_37+4)): | 50 | if (RUNTIME_GetInputShapeDim(ARG_x,0)<=(loop_idx_37+4)): |
| 51 | $1@6 = SUBS(View_x@3) | 51 | $1@6 = SUBS(View_x@3) |
| 52 | $5_5@9 = SUBS(View_x@3) | 52 | $5_5@9 = SUBS(View_x@3) |
| 53 | - z@2 = ASSEMBLE($5_5@9) | 53 | + z@2 = ASSEMBLE($5_5@9, attrs=["toOffset": [0, 0]]) |
| 54 | $8_5@11 = SUBS(View_x@3) | 54 | $8_5@11 = SUBS(View_x@3) |
| 55 | $12_5@14 = SUBS(View_x@3) | 55 | $12_5@14 = SUBS(View_x@3) |
| 56 | - z@2 = ASSEMBLE($12_5@14) | 56 | + z@2 = ASSEMBLE($12_5@14, attrs=["toOffset": [0, 0]]) |
| 57 | $15_5@16 = SUBS(View_x@3) | 57 | $15_5@16 = SUBS(View_x@3) |
| 58 | $19_5@19 = SUBS(View_x@3) | 58 | $19_5@19 = SUBS(View_x@3) |
| 59 | - z@2 = ASSEMBLE($19_5@19) | 59 | + z@2 = ASSEMBLE($19_5@19, attrs=["toOffset": [0, 0]]) |
| 60 | $22_5@21 = SUBS(View_x@3) | 60 | $22_5@21 = SUBS(View_x@3) |
| 61 | $25_0@23 = ADDS(View_x@3) | 61 | $25_0@23 = ADDS(View_x@3) |
| 62 | - z@2 = ASSEMBLE($25_0@23) | 62 | + z@2 = ASSEMBLE($25_0@23, attrs=["toOffset": [0, 0]]) |
| 63 | ir.yield_() | 63 | ir.yield_() |
| 64 | else: | 64 | else: |
| 65 | $1_1@6 = SUBS(View_x@3) | 65 | $1_1@6 = SUBS(View_x@3) |
| 66 | $5_4@9 = SUBS(View_x@3) | 66 | $5_4@9 = SUBS(View_x@3) |
| 67 | - z@2 = ASSEMBLE($5_4@9) | 67 | + z@2 = ASSEMBLE($5_4@9, attrs=["toOffset": [0, 0]]) |
| 68 | $8_4@11 = SUBS(View_x@3) | 68 | $8_4@11 = SUBS(View_x@3) |
| 69 | $12_4@14 = SUBS(View_x@3) | 69 | $12_4@14 = SUBS(View_x@3) |
| 70 | - z@2 = ASSEMBLE($12_4@14) | 70 | + z@2 = ASSEMBLE($12_4@14, attrs=["toOffset": [0, 0]]) |
| 71 | $15_4@16 = SUBS(View_x@3) | 71 | $15_4@16 = SUBS(View_x@3) |
| 72 | $19_4@19 = SUBS(View_x@3) | 72 | $19_4@19 = SUBS(View_x@3) |
| 73 | - z@2 = ASSEMBLE($19_4@19) | 73 | + z@2 = ASSEMBLE($19_4@19, attrs=["toOffset": [0, 0]]) |
| 74 | $22_4@21 = SUBS(View_x@3) | 74 | $22_4@21 = SUBS(View_x@3) |
| 75 | $26_0@24 = SUBS(View_x@3) | 75 | $26_0@24 = SUBS(View_x@3) |
| 76 | - z@2 = ASSEMBLE($26_0@24) | 76 | + z@2 = ASSEMBLE($26_0@24, attrs=["toOffset": [0, 0]]) |
| 77 | ir.yield_() | 77 | ir.yield_() |
| 78 | ir.yield_() | 78 | ir.yield_() |
| 79 | continue | 79 | continue |
| @@ -82,24 +82,24 @@ def foo(x@0: ir.Tensor, y@1: ir.Tensor, z@2: ir.Tensor): | |||
| 82 | if (RUNTIME_GetInputShapeDim(ARG_x,0)<=(loop_idx_37_0+1)): | 82 | if (RUNTIME_GetInputShapeDim(ARG_x,0)<=(loop_idx_37_0+1)): |
| 83 | $30@25 = ADDS(View_x@3) | 83 | $30@25 = ADDS(View_x@3) |
| 84 | $34@28 = ADDS(View_x@3) | 84 | $34@28 = ADDS(View_x@3) |
| 85 | - z@2 = ASSEMBLE($34@28) | 85 | + z@2 = ASSEMBLE($34@28, attrs=["toOffset": [0, 0]]) |
| 86 | ir.yield_() | 86 | ir.yield_() |
| 87 | else: | 87 | else: |
| 88 | $30_1@25 = ADDS(View_x@3) | 88 | $30_1@25 = ADDS(View_x@3) |
| 89 | $35@29 = SUBS(View_x@3) | 89 | $35@29 = SUBS(View_x@3) |
| 90 | - z@2 = ASSEMBLE($35@29) | 90 | + z@2 = ASSEMBLE($35@29, attrs=["toOffset": [0, 0]]) |
| 91 | ir.yield_() | 91 | ir.yield_() |
| 92 | ir.yield_() | 92 | ir.yield_() |
| 93 | else: | 93 | else: |
| 94 | if (RUNTIME_GetInputShapeDim(ARG_x,0)<=(loop_idx_37_0+1)): | 94 | if (RUNTIME_GetInputShapeDim(ARG_x,0)<=(loop_idx_37_0+1)): |
| 95 | $31@26 = SUBS(View_x@3) | 95 | $31@26 = SUBS(View_x@3) |
| 96 | $34_0@28 = ADDS(View_x@3) | 96 | $34_0@28 = ADDS(View_x@3) |
| 97 | - z@2 = ASSEMBLE($34_0@28) | 97 | + z@2 = ASSEMBLE($34_0@28, attrs=["toOffset": [0, 0]]) |
| 98 | ir.yield_() | 98 | ir.yield_() |
| 99 | else: | 99 | else: |
| 100 | $31_1@26 = SUBS(View_x@3) | 100 | $31_1@26 = SUBS(View_x@3) |
| 101 | $35_0@29 = SUBS(View_x@3) | 101 | $35_0@29 = SUBS(View_x@3) |
| 102 | - z@2 = ASSEMBLE($35_0@29) | 102 | + z@2 = ASSEMBLE($35_0@29, attrs=["toOffset": [0, 0]]) |
| 103 | ir.yield_() | 103 | ir.yield_() |
| 104 | ir.yield_() | 104 | ir.yield_() |
| 105 | continue | 105 | continue |
| @@ -0,0 +1,39 @@ | |||
| 1 | +# -*- coding: utf-8 -*- | ||
| 2 | +# Copyright (c) 2026 Huawei Technologies Co., Ltd. | ||
| 3 | +# This program is free software, you can redistribute it and/or modify it under the terms and conditions of | ||
| 4 | +# CANN Open Software License Agreement Version 2.0 (the "License"). | ||
| 5 | +# Please refer to the License for details. You may not use this file except in compliance with the License. | ||
| 6 | +# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, | ||
| 7 | +# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. | ||
| 8 | +# See LICENSE in the root of the software repository for the full text of the License. | ||
| 9 | +import pypto | ||
| 10 | + | ||
| 11 | +from ..test_common import check_snapshot, run_merge_pass | ||
| 12 | + | ||
| 13 | +IR = """ | ||
| 14 | +@ir.function | ||
| 15 | +def foo(x@0: ir.Tensor, y@1: ir.Tensor): | ||
| 16 | + for loop_idx_5 in ir.range(0, 10, 1, attrs={"parallel": False, "submit_before_loop": False, "unroll_times": 1}): | ||
| 17 | + if (loop_idx_5==0): | ||
| 18 | + y@1 = ASSEMBLE(x@0, attrs=["toOffset": [32, 32]]) | ||
| 19 | + ir.yield_() | ||
| 20 | + else: | ||
| 21 | + y@1 = ASSEMBLE(x@0, attrs=["toOffset": [64, 64]]) | ||
| 22 | + ir.yield_() | ||
| 23 | + continue | ||
| 24 | + return x@0, y@1 | ||
| 25 | +""" | ||
| 26 | + | ||
| 27 | +def test_yield_symbolic_scalar(): | ||
| 28 | + def foo(x, y): | ||
| 29 | + for i in pypto.loop(10): | ||
| 30 | + if i == 0: | ||
| 31 | + off = 0 | ||
| 32 | + else: | ||
| 33 | + off = 32 | ||
| 34 | + y[off + 32:, off + 32:] = x | ||
| 35 | + | ||
| 36 | + a = pypto.Tensor((64, 32), pypto.DT_FP32, 'a') | ||
| 37 | + out = pypto.Tensor((32, 32), pypto.DT_FP32, 'out') | ||
| 38 | + func = run_merge_pass(foo, a, out) | ||
| 39 | + check_snapshot(func, IR) | ||


🟠 High Priority
在
ViewOpAttribute::CollectAttrs和AssembleOpAttribute::CollectAttrs的 else 分支中,将Offset(即std::vector<int64_t>)存入std::any。但在printer.cpp的PrintKwargValue中,只处理了typeid(std::vector<int>)(第296行),没有处理typeid(std::vector<int64_t>)。这意味着当动态偏移为空时,具体偏移量会打印为"Unsupported"。在
AssembleOpAttribute::SetToOffset中(第289行),toDynOffset_直接使用传入的toDynOffset参数,默认值为{}(空),因此toDynOffset_可以为空,触发 else 分支。ViewOpAttribute::SetFromOffset在空参情况下会通过OpImmediate::ToSpecified填充fromDynOffset_,所以其 else 分支更难触发,但仍存在代码脆弱性。触发条件: 构造 AssembleOpAttribute 时仅传具体偏移(如
AssembleOpAttribute(offset)),不传动态偏移。此后打印 IR 时,toOffset属性将显示"Unsupported"。修复方向: 在
PrintKwargValue中增加对typeid(std::vector<int64_t>)的处理,或确保CollectAttrs始终将具体偏移量转换为std::vector<SymbolicScalar>。