
同一个Tensor进行View和Assemble导致图成环报错【免费下载链接】pyptoPyPTO发音: pai p-t-oParallel Tensor/Tile Operation编程范式。项目地址: https://gitcode.com/cann/pypto问题现象描述示例代码如下pypto.frontend.jit def foo_kernel(x, y): pypto.set_vec_tile_shapes(16, 16) a pypto.zeros([32, 32]) b a[:16, :16] # 从a中view获取数据 a[16:, 16:] b.exp() # 计算后assemble写回a y[:] x a torch.npu.set_device(0) x torch.ones(32, 32, dtypetorch.float32) y torch.empty(32, 32, dtypetorch.float32) foo_kernel(pypto.from_torch(x), pypto.from_torch(y))执行时报错ASSERTION FAILEDERROR:root:Record function foo_kernel failed: ASSERTION FAILED: outDegree[opToIndex[op.get()]] 0详细报错如下ERROR:root:Record function foo_kernel failed: ASSERTION FAILED: outDegree[opToIndex[op.get()]] 0 Operation not fully processed: /* /home/pypto-dev/a.py:9 */ 32 x 32 x DT_FP32 / 32 x 32 x DT_FP32 %02#(-1)MEM_UNKNOWN::MEM_UNKNOWN !10000 VEC_DUP(g:-1, s:-1) #SCALAR{0.000000} #op_attr_shape{[32, 32]} #op_attr_validShape{[32,32]} , func GetSortedOperations, file function.cpp, line 1105 libtile_fwk_interface.so(npu::tile_fwk::Function::GetSortedOperations() const0xb3c) [0xffff9c2f6650] libtile_fwk_interface.so(npu::tile_fwk::Function::SortOperations()0x38) [0xffff9c2f6f28] libtile_fwk_interface.so(npu::tile_fwk::Function::EndFunction(std::shared_ptrnpu::tile_fwk::TensorSlotScope const)0x960) [0xffff9c31b8d0] libtile_fwk_interface.so(npu::tile_fwk::Program::FinishCurrentFunction(std::shared_ptrnpu::tile_fwk::TensorSlotScope const, bool)0x1b0) [0xffff9c532274] libtile_fwk_interface.so(npu::tile_fwk::Program::EndFunction(std::string const, bool)0x10c) [0xffff9c536dcc] libtile_fwk_interface.so(npu::tile_fwk::Program::EndHiddenLoop(npu::tile_fwk::Function*, bool)0xb0) [0xffff9c537384] libtile_fwk_interface.so(npu::tile_fwk::Program::EndFunction(std::string const, bool)0x5c) [0xffff9c536d1c] libtile_fwk_interface.so(npu::tile_fwk::RecordLoopFunc::IterationEnd()0x44) [0xffff9c5399c4] libtile_fwk_interface.so(npu::tile_fwk::RecordLoopFunc::Iterator::operator!(npu::tile_fwk::RecordLoopFunc::IteratorEnd const)0xfc) [0xffff9c539ea0]原因分析该报错的原因是内部在对基本算子做拓扑排序时发现存在环路的报错。这是由于数据从a中读取又写回a导致的。由于PyPTO描述的是一个图表达在读取和写入的时候当前认为a是一个整体因此创建的连接关系会形成一个环路即a → b → b.exp() → a而PyPTO不允许构造出的图内存在环路必须为DAG有向无环图所以才有这个报错。解决措施当前需要将读取和写入a的逻辑拆分成两个图去定义避免一个图内存在环路。后续等Assemble的SSA语义上线后使用该写法不会有问题。【免费下载链接】pyptoPyPTO发音: pai p-t-oParallel Tensor/Tile Operation编程范式。项目地址: https://gitcode.com/cann/pypto创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考