Merged
refactor(interface): Remove UpdateTensorDataUsage() #5451
lidongshengAdd on Aug 14
refactor(interface): Remove UpdateTensorDataUsage() #5451
Merged
lidongshengAdd on Aug 14
Total: 9 files changed+35-72
@@ -585,23 +585,16 @@ GetTensorDataIODescDict Function::GetTensorDataForTensorGraph()
585 if (!CheckEmuOpcode(&op, EMUOP_TENSOR_GETDATA_IMPORT)) {585 if (!CheckEmuOpcode(&op, EMUOP_TENSOR_GETDATA_IMPORT)) {
586 continue;586 continue;
587 }587 }
588- int getTensorDataIndex = GetTensorDataGetIndex(&op);588+ int index = GetTensorDataGetIndex(&op);
589- FE_ASSERT(FeError::INVALID_VAL, getTensorDataIndex != -1) << "Failed to get tensor data index for operation";589+ FE_ASSERT(FeError::INVALID_VAL, index != -1) << "Invalid import index";
590- FE_ASSERT(FeError::NOT_EXIST, currDynAttr->getTensorDataUsageDict.count(this))590+ int outcastIndex = GetTensorDataLookupOutcast(this, &op);
591- << "Current function not found in getTensorDataUsageDict";
592- std::unordered_map<int, Operation*>& importDict = currDynAttr->getTensorDataUsageDict[this].importDict;
593- FE_ASSERT(FeError::NOT_EXIST, importDict.count(getTensorDataIndex))
594- << "Import index " << getTensorDataIndex << " not found in importDict";
595- auto import = importDict[getTensorDataIndex];
596- int outcastIndex = GetTensorDataLookupOutcast(this, import);
597 if (outcastIndex != INVALID_IOINDEX) {591 if (outcastIndex != INVALID_IOINDEX) {
598- iodescDict[getTensorDataIndex] = GetTensorDataIODesc(GET_TENSOR_DATA_OPERAND_IOTYPE_OUTCAST, outcastIndex,592+ iodescDict[index] = GetTensorDataIODesc(GET_TENSOR_DATA_OPERAND_IOTYPE_OUTCAST, outcastIndex, 0);
599- 0);
600 } else {593 } else {
601- int incastIndex = GetTensorDataLookupIncast(this, import);594+ int incastIndex = GetTensorDataLookupIncast(this, &op);
602 FE_ASSERT(FeError::INVALID_VAL, incastIndex != INVALID_IOINDEX)595 FE_ASSERT(FeError::INVALID_VAL, incastIndex != INVALID_IOINDEX)
603 << "Both outcast and incast indices are invalid";596 << "Both outcast and incast indices are invalid";
604- iodescDict[getTensorDataIndex] = GetTensorDataIODesc(GET_TENSOR_DATA_OPERAND_IOTYPE_INCAST, incastIndex, 0);597+ iodescDict[index] = GetTensorDataIODesc(GET_TENSOR_DATA_OPERAND_IOTYPE_INCAST, incastIndex, 0);
605 }598 }
606 }599 }
607 return iodescDict;600 return iodescDict;
@@ -928,6 +921,7 @@ FunctionCallArgs Function::EndFunction(const std::shared_ptr<TensorSlotScope>& s
928 if (IsGraphType(GraphType::TENSOR_GRAPH) ||921 if (IsGraphType(GraphType::TENSOR_GRAPH) ||
929 IsFunctionTypeAndGraphType(FunctionType::STATIC, GraphType::TILE_GRAPH)) {922 IsFunctionTypeAndGraphType(FunctionType::STATIC, GraphType::TILE_GRAPH)) {
930 SetCallOpSlot();923 SetCallOpSlot();
924+ CreateTensorDataImportOp();
931 inArgumentList = MakeIncasts(scope);925 inArgumentList = MakeIncasts(scope);
932 outArgumentList = MakeOutcasts(scope);926 outArgumentList = MakeOutcasts(scope);
933 auto iodescDict = GetTensorDataForTensorGraph();927 auto iodescDict = GetTensorDataForTensorGraph();
@@ -1799,34 +1793,30 @@ Operation& Function::AddOperation(const Opcode opCode, LogicalTensors iOperands,
1799 return ret;1793 return ret;
1800}1794}
1801 1795 
1802-void Function::UpdateTensorDataUsage(Operation& op)1796+void Function::CreateTensorDataImportOp()
1803{1797{
1804- auto dynFunc = Program::GetInstance().GetCurrentDynamicFunction();
1805- if (dynFunc == nullptr) {
1806- return;
1807- }
1808- auto dynDevAttr = dynFunc->GetDyndevAttribute();
1809- if (dynDevAttr == nullptr) {
1810- return;
1811- }
1812- auto& importDict = dynDevAttr->getTensorDataUsageDict[this].importDict;
1813 IRBuilder builder;1798 IRBuilder builder;
1814 1799 
1815- auto dynAttrList = op.GetDynamicAttributeList();1800+ std::unordered_set<int> visited;
1816- auto dict = GetTensorDataDict(dynAttrList);1801+ auto n = operations_.size();
1817- for (auto& [index, callList] : dict) {1802+ for (size_t i = 0; i < n; i++) {
1818- (void)callList;1803+ auto& op = operations_[i];
1819- if (importDict.count(index)) {1804+ auto dynAttrList = op->GetDynamicAttributeList();
1820- continue;1805+ auto dict = GetTensorDataDict(dynAttrList);
1806+ for (auto& [index, callList] : dict) {
1807+ (void)callList;
1808+ if (visited.count(index)) {
1809+ continue;
1810+ }
1811+ auto assemble = builder.GetTensorDataDesc(index);
1812+ std::vector<int64_t> importShape(assemble->GetShape().size(), 1);
1813+ std::vector<int64_t> importOffset(assemble->GetShape().size(), 0);
1814+ auto import = View(*assemble, importShape, importOffset);
atomgit-bot

🟠 High Priority

变更行:function.cpp:1801 for (auto& op : operations_)。operations_ 是 std::vector<std::shared_ptr<Operation>>(function.h:1004-1005),循环体内第 1811 行调用 View(*assemble, importShape, importOffset)。View(operation_impl.cpp:1234-1235)通过 Program::GetInstance().GetCurrentFunction()->AddOperation(...) 最终走到 AddRawOperation(function.cpp:1828)执行 operations_.emplace_back(...),而 EndFunction 期间 GetCurrentFunction() == this(program.cpp:418 调用 currentFunctionPtr_->EndFunction(scope)),即向正在遍历的同一个 vector 追加元素。

影响:当 emplace_back 触发扩容(capacity 不足)时,range-for 缓存的 begin/end 迭代器以及循环变量 op(对 vector 内部元素的引用)全部失效。触发条件:函数内 operation 数量使 operations_ 容量被新 import 的 View op 撑爆(真实大图/多个 GetTensorData index 时很常见)。

失败模式:迭代器失效后继续 ++begin 或解引用属于未定义行为,可能导致崩溃或内存破坏。

修复方向:先记录原始大小,用下标遍历并按值拷贝 shared_ptr(不要持有对 vector 元素的引用),避免遍历期间 View 追加元素导致失效。

建议:将 range-for 改为基于下标的遍历并预先记录原始数量,同时按值拷贝 shared_ptr,避免 vector 扩容导致引用/迭代器失效。例如:const size_t originalOpCount = operations_.size(); for (size_t i = 0; i < originalOpCount; ++i) { auto op = operations_[i]; ... }

likedislike
Incorrect?
1815+ auto importOp = *import.GetStorage()->GetProducers().begin();
1816+ SetEmuOpcode(importOp, EMUOP_TENSOR_GETDATA_IMPORT);
1817+ GetTensorDataSetIndex(importOp, index);
1818+ visited.insert(index);
1821 }1819 }
1822- auto assemble = builder.GetTensorDataDesc(index);
1823- std::vector<int64_t> importShape(assemble->GetShape().size(), 1);
1824- std::vector<int64_t> importOffset(assemble->GetShape().size(), 0);
1825- auto import = View(*assemble, importShape, importOffset);
1826- auto importOp = *import.GetStorage()->GetProducers().begin();
1827- SetEmuOpcode(importOp, EMUOP_TENSOR_GETDATA_IMPORT);
1828- GetTensorDataSetIndex(importOp, index);
1829- importDict[index] = importOp;
1830 }1820 }
1831}1821}
1832 1822 
@@ -369,13 +369,6 @@ struct DyndevFunctionAttribute {
369 };369 };
370 std::unordered_map<Function*, ValueDependDesc> valueDependDescDict;370 std::unordered_map<Function*, ValueDependDesc> valueDependDescDict;
371 371 
372- struct GetTensorDataUsage {
373- // In each function, one usage at most correpond to one import
374- // Mapping from the GetTensorData index to the View operation
375- std::unordered_map<int, Operation*> importDict;
376- };
377- std::unordered_map<Function*, GetTensorDataUsage> getTensorDataUsageDict;
378- 
379 struct FunctionGroup {372 struct FunctionGroup {
380 /* loop */373 /* loop */
381 OrderedSet<Function*> loopList;374 OrderedSet<Function*> loopList;
@@ -943,7 +936,7 @@ public:
943 GetTensorDataIODescDict GetTensorDataForTensorGraph();936 GetTensorDataIODescDict GetTensorDataForTensorGraph();
944 GetTensorDataIODescDict GetTensorDataForLeafGraph();937 GetTensorDataIODescDict GetTensorDataForLeafGraph();
945 void GetTensorDataRefreshIO(const GetTensorDataIODescDict& descDict);938 void GetTensorDataRefreshIO(const GetTensorDataIODescDict& descDict);
946- void UpdateTensorDataUsage(Operation& op);939+ void CreateTensorDataImportOp();
947 940 
948 void SetSpan(const ir::Span& span) { span_ = span; }941 void SetSpan(const ir::Span& span) { span_ = span; }
949 942 
@@ -286,7 +286,7 @@ static Tensor ShmemPutImpl(const Tensor& src, const ShmemTensor& dst, const Symb
286 fromType, OpImmediate::Specified({0, 0}), OpImmediate::Specified({src.GetShape()}),286 fromType, OpImmediate::Specified({0, 0}), OpImmediate::Specified({src.GetShape()}),
287 OpImmediate::Specified({src.GetShape()}), OpImmediate::Specified(src.GetValidShape())));287 OpImmediate::Specified({src.GetShape()}), OpImmediate::Specified(src.GetValidShape())));
288 op.SetAttr(OpAttributeKey::isDistCopyOut, true);288 op.SetAttr(OpAttributeKey::isDistCopyOut, true);
289- function.UpdateTensorDataUsage(op);289+ 
290 ShmemPutAttr distOpAttr;290 ShmemPutAttr distOpAttr;
291 distOpAttr.atomicType = putOp;291 distOpAttr.atomicType = putOp;
292 distOpAttr.ownerRank = dstRank;292 distOpAttr.ownerRank = dstRank;
@@ -327,7 +327,7 @@ Tensor ShmemGet(const ShmemTensor& src, const SymbolicScalar& srcRank, const Ten
327 op.SetOpAttribute(std::make_shared<CopyOpAttribute>(327 op.SetOpAttribute(std::make_shared<CopyOpAttribute>(
328 MemoryType::MEM_DEVICE_DDR, OpImmediate::Specified({0, 0}), OpImmediate::Specified(src.data.GetShape()),328 MemoryType::MEM_DEVICE_DDR, OpImmediate::Specified({0, 0}), OpImmediate::Specified(src.data.GetShape()),
329 OpImmediate::Specified(src.data.GetShape()), OpImmediate::Specified(src.data.GetValidShape())));329 OpImmediate::Specified(src.data.GetShape()), OpImmediate::Specified(src.data.GetValidShape())));
330- function.UpdateTensorDataUsage(op);330+ 
331 ShmemGetAttr distOpAttr;331 ShmemGetAttr distOpAttr;
332 distOpAttr.ownerRank = srcRank;332 distOpAttr.ownerRank = srcRank;
333 distOpAttr.group = src.group;333 distOpAttr.group = src.group;
@@ -356,7 +356,7 @@ Tensor ShmemLoad(const ShmemTensor& src, const SymbolicScalar& srcRank, const Te
356 op.SetOpAttribute(std::make_shared<CopyOpAttribute>(356 op.SetOpAttribute(std::make_shared<CopyOpAttribute>(
357 OpImmediate::Specified({0, 0}), MEM_UB, OpImmediate::Specified(src.data.GetShape()),357 OpImmediate::Specified({0, 0}), MEM_UB, OpImmediate::Specified(src.data.GetShape()),
358 OpImmediate::Specified(out->shape), OpImmediate::Specified(src.data.GetValidShape())));358 OpImmediate::Specified(out->shape), OpImmediate::Specified(src.data.GetValidShape())));
359- function.UpdateTensorDataUsage(op);359+ 
360 ShmemGetAttr distOpAttr;360 ShmemGetAttr distOpAttr;
361 distOpAttr.ownerRank = srcRank;361 distOpAttr.ownerRank = srcRank;
362 distOpAttr.group = src.group;362 distOpAttr.group = src.group;
@@ -529,7 +529,6 @@ void experimental::Print(SymbolicScalar cond, const std::string& format, const s
529 op.SetAttr(OP_ATTR_PREFIX + "format", format);529 op.SetAttr(OP_ATTR_PREFIX + "format", format);
530 op.SetAttr(OP_ATTR_PREFIX + "scalars", scalars);530 op.SetAttr(OP_ATTR_PREFIX + "scalars", scalars);
531 op.SetAttribute(OP_ATTR_PREFIX + "cond", cond);531 op.SetAttribute(OP_ATTR_PREFIX + "cond", cond);
532- function->UpdateTensorDataUsage(op);
533}532}
534 533 
535void ToFile(const Tensor& operand, const std::string& fname, const std::vector<SymbolicScalar>& scalars,534void ToFile(const Tensor& operand, const std::string& fname, const std::vector<SymbolicScalar>& scalars,
@@ -541,7 +540,6 @@ void ToFile(const Tensor& operand, const std::string& fname, const std::vector<S
541 op.SetAttribute(OP_ATTR_PREFIX + "fname", fname);540 op.SetAttribute(OP_ATTR_PREFIX + "fname", fname);
542 op.SetAttribute(OP_ATTR_PREFIX + "scalars", scalars);541 op.SetAttribute(OP_ATTR_PREFIX + "scalars", scalars);
543 op.SetAttribute(OP_ATTR_PREFIX + "cond", cond);542 op.SetAttribute(OP_ATTR_PREFIX + "cond", cond);
544- function->UpdateTensorDataUsage(op);
545}543}
546 544 
547Tensor Unsqueeze(const Tensor& old, int unsqueezeDimNum)545Tensor Unsqueeze(const Tensor& old, int unsqueezeDimNum)
@@ -1239,7 +1237,6 @@ Tensor View(const Tensor& operand, const std::vector<int64_t>& shapes, const std
1239 result.GetStorage()->UpdateDynValidShape(validShape);1237 result.GetStorage()->UpdateDynValidShape(validShape);
1240 std::vector<int64_t> newOffsetsConcrete = SymbolicScalar::Concrete(newOffsets, 0);1238 std::vector<int64_t> newOffsetsConcrete = SymbolicScalar::Concrete(newOffsets, 0);
1241 op.SetOpAttribute(std::make_shared<ViewOpAttribute>(newOffsetsConcrete, newOffsets, validShape));1239 op.SetOpAttribute(std::make_shared<ViewOpAttribute>(newOffsetsConcrete, newOffsets, validShape));
1242- function->UpdateTensorDataUsage(op);
1243 return result;1240 return result;
1244}1241}
1245 1242 
@@ -1270,7 +1267,6 @@ Tensor View(const Tensor& operand, const std::vector<int64_t>& shapes,
1270 std::vector<int64_t> newOffsetsConcrete = SymbolicScalar::Concrete(newOffsets, 0);1267 std::vector<int64_t> newOffsetsConcrete = SymbolicScalar::Concrete(newOffsets, 0);
1271 op.SetOpAttribute(std::make_shared<ViewOpAttribute>(newOffsetsConcrete, newOffsets, newValidShapes));1268 op.SetOpAttribute(std::make_shared<ViewOpAttribute>(newOffsetsConcrete, newOffsets, newValidShapes));
1272 result.GetStorage()->UpdateDynValidShape(newValidShapes);1269 result.GetStorage()->UpdateDynValidShape(newValidShapes);
1273- function->UpdateTensorDataUsage(op);
1274 return result;1270 return result;
1275}1271}
1276 1272 
@@ -1347,7 +1343,6 @@ Operation& TensorDInnerAssemble(Function& function, const LogicalTensorPtr& oper
1347 op.SetAssembleOpAttribute(offset, dynOffset);1343 op.SetAssembleOpAttribute(offset, dynOffset);
1348 op.SetAttribute("dassemble", true);1344 op.SetAttribute("dassemble", true);
1349 op.SetAttribute(OpAttributeKey::parallel, parallel);1345 op.SetAttribute(OpAttributeKey::parallel, parallel);
1350- function.UpdateTensorDataUsage(op);
1351 return op;1346 return op;
1352}1347}
1353 1348 
@@ -1398,7 +1393,6 @@ void AtomicRMW(const Tensor& t, const std::vector<SymbolicScalar>& dynOffset, Te
1398 auto& op = func.AddOperation(Opcode::OP_ATOMIC_RMW, {t.GetStorage()}, {dest.GetStorage()});1393 auto& op = func.AddOperation(Opcode::OP_ATOMIC_RMW, {t.GetStorage()}, {dest.GetStorage()});
1399 op.SetAssembleOpAttribute(offset, dynOffset);1394 op.SetAssembleOpAttribute(offset, dynOffset);
1400 op.SetAttribute(OpAttributeKey::rmwMode, (int)mode);1395 op.SetAttribute(OpAttributeKey::rmwMode, (int)mode);
1401- func.UpdateTensorDataUsage(op);
1402 1396 
1403 Program::GetInstance().GetTensorSlotManager()->TensorWrite(dest, SlotProperty::ASSEMBLE_DST);1397 Program::GetInstance().GetTensorSlotManager()->TensorWrite(dest, SlotProperty::ASSEMBLE_DST);
1404}1398}
@@ -1453,7 +1447,6 @@ void TensorInnerAssemble(Function& function, const LogicalTensorPtr& value, cons
1453 auto& op = function.AddOperation(Opcode::OP_ASSEMBLE_SSA, {value, dst}, {result});1447 auto& op = function.AddOperation(Opcode::OP_ASSEMBLE_SSA, {value, dst}, {result});
1454 op.SetAssembleOpAttribute(staticOffsets, offsets);1448 op.SetAssembleOpAttribute(staticOffsets, offsets);
1455 op.SetAttribute(OpAttributeKey::inplaceIdx, 1);1449 op.SetAttribute(OpAttributeKey::inplaceIdx, 1);
1456- function.UpdateTensorDataUsage(op);
1457}1450}
1458 1451 
1459void Assemble(const std::vector<AssembleItem>& items, Tensor& src, bool parallelInAssemble)1452void Assemble(const std::vector<AssembleItem>& items, Tensor& src, bool parallelInAssemble)
@@ -1409,7 +1409,6 @@ void TensorIndexPut(Function& function, const LogicalTensorPtr& self, const Logi
1409 op.SetAttribute(OpAttributeKey::inplaceIdx, 0);1409 op.SetAttribute(OpAttributeKey::inplaceIdx, 0);
1410 op.SetAttribute(OpAttributeKey::accumulate, accumulate);1410 op.SetAttribute(OpAttributeKey::accumulate, accumulate);
1411 op.SetAttribute(OpAttributeKey::indicesSize, static_cast<int>(indices.size()));1411 op.SetAttribute(OpAttributeKey::indicesSize, static_cast<int>(indices.size()));
1412- function.UpdateTensorDataUsage(op);
1413}1412}
1414 1413 
1415static void CheckIndexPutParamsInvalid(const Tensor& self, const std::vector<Tensor>& indices, const Tensor& values)1414static void CheckIndexPutParamsInvalid(const Tensor& self, const std::vector<Tensor>& indices, const Tensor& values)
@@ -370,6 +370,7 @@ Tensor Log(const Tensor& self, LogBaseType base, PrecisionType precisionType)
370Tensor Log1p(const Tensor& self)370Tensor Log1p(const Tensor& self)
371{371{
372 DECLARE_TRACER();372 DECLARE_TRACER();
373+ auto& function = *Program::GetInstance().GetCurrentFunction();
373 CheckTensorFormat(self.GetStorage(), {TileOpFormat::TILEOP_NZ}, "Log1p");374 CheckTensorFormat(self.GetStorage(), {TileOpFormat::TILEOP_NZ}, "Log1p");
374 375 
375 std::unordered_set<DataType> supportedTypes = {DT_BF16, DT_FP16, DT_FP32};376 std::unordered_set<DataType> supportedTypes = {DT_BF16, DT_FP16, DT_FP32};
@@ -386,9 +387,7 @@ Tensor Log1p(const Tensor& self)
386 auto resTensorBeforeCast = std::make_shared<LogicalTensor>(*Program::GetInstance().GetCurrentFunction(),387 auto resTensorBeforeCast = std::make_shared<LogicalTensor>(*Program::GetInstance().GetCurrentFunction(),
387 DataType::DT_FP32, self.GetShape(),388 DataType::DT_FP32, self.GetShape(),
388 self.GetStorage()->GetDynValidShape());389 self.GetStorage()->GetDynValidShape());
389- auto& op = Program::GetInstance().GetCurrentFunction()->AddOperation(Opcode::OP_LOG1P, {operandCast},390+ function.AddOperation(Opcode::OP_LOG1P, {operandCast}, {resTensorBeforeCast});
390- {resTensorBeforeCast});
391- Program::GetInstance().GetCurrentFunction()->UpdateTensorDataUsage(op);
392 391 
393 if (self.GetStorage()->Datatype() == DataType::DT_FP16) {392 if (self.GetStorage()->Datatype() == DataType::DT_FP16) {
394 RETURN_CALL(CastOperation<CastOpType::CAST>, *Program::GetInstance().GetCurrentFunction(), resTensorBeforeCast,393 RETURN_CALL(CastOperation<CastOpType::CAST>, *Program::GetInstance().GetCurrentFunction(), resTensorBeforeCast,
@@ -645,7 +644,6 @@ Tensor TensorOneHot(Function& function, const LogicalTensorPtr& self, int numCla
645 auto result = std::make_shared<LogicalTensor>(function, DataType::DT_INT64, shape, validShape);644 auto result = std::make_shared<LogicalTensor>(function, DataType::DT_INT64, shape, validShape);
646 auto& op = function.AddOperation(Opcode::OP_ONEHOT, {self}, {result});645 auto& op = function.AddOperation(Opcode::OP_ONEHOT, {self}, {result});
647 op.SetAttribute(OP_ATTR_PREFIX + "numClasses", numClasses);646 op.SetAttribute(OP_ATTR_PREFIX + "numClasses", numClasses);
648- function.UpdateTensorDataUsage(op);
649 return result;647 return result;
650}648}
651 649 
@@ -1409,8 +1407,7 @@ Tensor TensorExp2(Function& function, const LogicalTensorPtr& self)
1409 if (self->Datatype() == DataType::DT_INT32 || self->Datatype() == DataType::DT_INT16) {1407 if (self->Datatype() == DataType::DT_INT32 || self->Datatype() == DataType::DT_INT16) {
1410 result = std::make_shared<LogicalTensor>(function, DT_FP32, self->GetShape(), self->GetDynValidShape());1408 result = std::make_shared<LogicalTensor>(function, DT_FP32, self->GetShape(), self->GetDynValidShape());
1411 }1409 }
1412- auto& op = function.AddOperation(Opcode::OP_EXP2, {self}, {result});1410+ function.AddOperation(Opcode::OP_EXP2, {self}, {result});
1413- function.UpdateTensorDataUsage(op);
1414 return result;1411 return result;
1415}1412}
1416 1413 
@@ -1495,7 +1492,6 @@ Tensor TensorRound(Function& function, const LogicalTensorPtr& self, const int&
1495 self->GetDynValidShape());1492 self->GetDynValidShape());
1496 auto& op = function.AddOperation(Opcode::OP_ROUND, {self}, {result});1493 auto& op = function.AddOperation(Opcode::OP_ROUND, {self}, {result});
1497 op.SetAttribute(OP_ATTR_PREFIX + "decimals", decimals);1494 op.SetAttribute(OP_ATTR_PREFIX + "decimals", decimals);
1498- function.UpdateTensorDataUsage(op);
1499 return result;1495 return result;
1500}1496}
1501 1497 
@@ -1580,8 +1576,7 @@ Tensor TensorExpm1(Function& function, const LogicalTensorPtr& self)
1580 if (self->Datatype() == DataType::DT_INT32 || self->Datatype() == DataType::DT_INT16) {1576 if (self->Datatype() == DataType::DT_INT32 || self->Datatype() == DataType::DT_INT16) {
1581 result = std::make_shared<LogicalTensor>(function, DT_FP32, self->GetShape(), self->GetDynValidShape());1577 result = std::make_shared<LogicalTensor>(function, DT_FP32, self->GetShape(), self->GetDynValidShape());
1582 }1578 }
1583- auto& op = function.AddOperation(Opcode::OP_EXPM1, {self}, {result});1579+ function.AddOperation(Opcode::OP_EXPM1, {self}, {result});
1584- function.UpdateTensorDataUsage(op);
1585 return result;1580 return result;
1586}1581}
1587 1582 
@@ -122,7 +122,6 @@ Tensor TensorPermuteOperation(Function& function, LogicalTensorPtr self, const s
122 auto result = MakePermutedLogicalTensor(function, self, perm);122 auto result = MakePermutedLogicalTensor(function, self, perm);
123 auto& op = function.AddOperation(Opcode::OP_PERMUTE, {self}, {result});123 auto& op = function.AddOperation(Opcode::OP_PERMUTE, {self}, {result});
124 op.SetAttribute(OpAttributeKey::perm, perm);124 op.SetAttribute(OpAttributeKey::perm, perm);
125- function.UpdateTensorDataUsage(op);
126 return result;125 return result;
127}126}
128 127 
@@ -178,7 +177,6 @@ Tensor TensorElementPermuteOperation(Function& function, LogicalTensorPtr self,
178 auto result = MakePermutedLogicalTensor(function, self, perm);177 auto result = MakePermutedLogicalTensor(function, self, perm);
179 auto& op = function.AddOperation(Opcode::OP_PERMUTE_ELEMENT, {self}, {result});178 auto& op = function.AddOperation(Opcode::OP_PERMUTE_ELEMENT, {self}, {result});
180 op.SetAttribute(OpAttributeKey::perm, perm);179 op.SetAttribute(OpAttributeKey::perm, perm);
181- function.UpdateTensorDataUsage(op);
182 return result;180 return result;
183}181}
184 182 
@@ -702,7 +702,6 @@ LogicalTensorPtr TensorQuantizeSymmetricOperation(Function& function, const Logi
702 auto result = std::make_shared<LogicalTensor>(function, DataType::DT_INT8, src->shape, src->GetDynValidShape());702 auto result = std::make_shared<LogicalTensor>(function, DataType::DT_INT8, src->shape, src->GetDynValidShape());
703 auto& op = function.AddOperation(Opcode::OP_QUANTIZE_SYM, {src, scale}, {result});703 auto& op = function.AddOperation(Opcode::OP_QUANTIZE_SYM, {src, scale}, {result});
704 op.SetAttribute(OP_ATTR_PREFIX + "axis", axis);704 op.SetAttribute(OP_ATTR_PREFIX + "axis", axis);
705- function.UpdateTensorDataUsage(op);
706 return result;705 return result;
707}706}
708 707 
@@ -714,7 +713,6 @@ LogicalTensorPtr TensorQuantizeAsymmetricOperation(Function& function, const Log
714 auto result = std::make_shared<LogicalTensor>(function, DataType::DT_UINT8, src->shape, src->GetDynValidShape());713 auto result = std::make_shared<LogicalTensor>(function, DataType::DT_UINT8, src->shape, src->GetDynValidShape());
715 auto& op = function.AddOperation(Opcode::OP_QUANTIZE_ASYM, {src, scale, offset}, {result});714 auto& op = function.AddOperation(Opcode::OP_QUANTIZE_ASYM, {src, scale, offset}, {result});
716 op.SetAttribute(OP_ATTR_PREFIX + "axis", axis);715 op.SetAttribute(OP_ATTR_PREFIX + "axis", axis);
717- function.UpdateTensorDataUsage(op);
718 return result;716 return result;
719}717}
720 718 
@@ -1010,7 +1008,6 @@ LogicalTensorPtr TensorDequantizeOperation(Function& function, const LogicalTens
1010 auto result = std::make_shared<LogicalTensor>(function, DataType::DT_FP32, src->shape, src->GetDynValidShape());1008 auto result = std::make_shared<LogicalTensor>(function, DataType::DT_FP32, src->shape, src->GetDynValidShape());
1011 auto& op = function.AddOperation(Opcode::OP_DEQUANTIZE, {src, scale, offset}, {result});1009 auto& op = function.AddOperation(Opcode::OP_DEQUANTIZE, {src, scale, offset}, {result});
1012 op.SetAttribute(OP_ATTR_PREFIX + "axis", axis);1010 op.SetAttribute(OP_ATTR_PREFIX + "axis", axis);
1013- function.UpdateTensorDataUsage(op);
1014 return result;1011 return result;
1015}1012}
1016 1013 
@@ -181,7 +181,6 @@ Tensor TensorExpandOperation(Function& function, const LogicalTensorPtr& operand
181 181 
182 op.SetAttribute(OP_ATTR_PREFIX + "shape", dstShape);182 op.SetAttribute(OP_ATTR_PREFIX + "shape", dstShape);
183 op.SetAttribute(OP_ATTR_PREFIX + "validShape", validShape);183 op.SetAttribute(OP_ATTR_PREFIX + "validShape", validShape);
184- function.UpdateTensorDataUsage(op);
185 return result;184 return result;
186}185}
187 186 
@@ -1466,7 +1465,6 @@ Tensor TensorFullOperation(Function& function, const Element& src, const Symboli
1466 }1465 }
1467 op.SetAttribute(OP_ATTR_PREFIX + "shape", dstShape);1466 op.SetAttribute(OP_ATTR_PREFIX + "shape", dstShape);
1468 op.SetAttribute(OP_ATTR_PREFIX + "validShape", validShape);1467 op.SetAttribute(OP_ATTR_PREFIX + "validShape", validShape);
1469- function.UpdateTensorDataUsage(op);
1470 return result;1468 return result;
1471}1469}
1472 1470