| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
Upgrade the infrastructure to support future extensions Co-authored-by: Vlasov Maxim<vlasov.maxim@huawei-partners.com> # message auto-generated for no-merge-commit merge: !157 merge mv/upstreamasc into master Upgrade the infrastructure to support future extensions Created-by: vla5924 Commit-by: Vlasov Maxim Merged-by: cann-robot Description: # PyAsc Infrastructure Changes This patch introduces modifications to the **existing** PyAsc infrastructure required by the tile-based programming add-on. Currently, there are no changes in public API or user experience. All existing features remain fully functional, as well as unit and system tests. --- ## 1. MLIR Changes ### 1.1 Asc Dialect — IR - **New operations**: Broadcast, Reduction (reduce_sum/max/min/prod with ReducePattern), register-based API (~40 ops for C310: binary, unary, vec-scalar, reduce, utility), LayerNorm, Log2, get_buf/rls_buf (BufId sync for C310), data_copy_nd_dma + NdDmaParams, set_loop_mode_para/reset_loop_mode_para, trans_data_to_5hd_tensor, local_tensor_v3, local_tensor.get_phy_addr_v2. - **New types**: FixpipeParamsC310, MaskReg, RegTensor, NdDmaParams. - **New attributes**: MaskPattern, MemType, ReducePattern, DataCopyMVType. - **New API types**: LayerNormTiling, LoopModeParams. - **New interfaces**: OpWithSrcInterface (get source tensors), OpWithReusableSrcInterface (marker for safe same-op reuse), CopyToL0OpInterface, MicroAPIOpInterface (+ Binary/Unary/VecScalar variants), ReduceOpInterface, BinaryL0OpInterface, BinaryL2OpInterface. - **Extended interfaces**: OpWithDstInterface gained getDstTensors() default; UnaryOpInterface/BinaryOpInterface/VecScalarOpInterface now include OpWithSrcInterface and OpWithReusableSrcInterface; L0/L2 interfaces gained mutable operand accessors and setIsSetMask. - **CopyDirection enum**: Replaced with corresponding methods GlobalToLocal/LocalToGlobal/LocalToLocal/GlobalToGlobal. - **Modified operations**: SoftMax/SimpleSoftMax changed to VectorOp with src interface, sumTensor/maxTensor made Optional; RmsNorm renamed mnemonic to rms_norm, changed to VectorOp; Fixpipe changed to DataCopyOp with generalized dst type and C310 params support; DataCopyL0/L2 gained src interface; LocalTensorAutoOp gained position attribute; SubIndex ops gained folders (zero-index identity); ReinterpretCastOp fold enhanced to eliminate double-cast chains; MulCast ops moved to BinaryCast templates; VecScalar ops gained Subs and Divs variants; all unary/binary/vec-scalar/math base classes gained default getSrcTensors()/getDstTensors(). ### 1.2 Asc Dialect — Passes - **Renamed**: HoistUBAllocation → HoistTensorAllocation (added exclude-in-out option), InsertSync → InsertQueSync. - **Modified**: MaterializeTensor (added always-buf option), LegalizeKernelArgs (added set-ffts-addr option, conditional on architecture), DetectKernelType (now classifies as "vector"/"cube"/"mixed" instead of binary flag), InsertSync (extended with V_S/S_V event sync for get_value/set_value), InputOutputTensor (handles input-only tensors used for ubuf_gm copy). - All existing passes received detailed description fields in TableGen. ### 1.3 EmitAsc Dialect - **New ops**: init_struct (struct initialization with named fields), mask (create bit-by-bit mask pair). - **New type**: mask (2-element i64 array for high/low mask). - **variable**: Removed Pure trait; added canonicalizer support. - **New utility**: InitStructBuilder helper class. ### 1.4 Code Emitter (Target/AscendC) - **New emitters** for all new Asc operations (Broadcast, Reduction, LayerNorm, MicroAPI suite, BufId sync, NdDma, etc.) and arith::NegFOp. - **CodeEmitter**: Added methods for C310 types (CO2Layout, FixpipeParamsC310, RegTensor, MaskReg, NdDmaParams). - **Fixpipe emission**: Generalized dst type handling; config emitted by name instead of hardcoded constant. - **VecScalar ops**: Added Subs and Divs variants to all L0/L1/L2 emitter lists. ### 1.5 Build System & Tools - Removed C language requirement from project; added atomic profile update for GCC coverage. - Added LIT tests for passes and emitters that didn't have them initially. - ConstantOpBuilder: Widened parameter types to int64_t; added i1() helper. --- ## 2. Python Changes ### 2.1 Codegen (asc/codegen/) - **FunctionVisitor**: - Added CustomBuiltins support for injecting custom builtins into the name scope. - Added MatMult (@ operator) support. - Boolean operators (and/or/not) and IfExp: compile-time constant folding before falling back to IR. - visit_Call: Handles ast.Starred arguments (*args unpacking). - visit_For: Generalized to accept any BaseRange subclass; calls handle_op() on the range object. - compute_inout: Materializes initial handles outside the block; accepts init_handles for if/else merge. - visit_If: Else-branch inherits init handles from then-branch. - **NameScope**: builtins → default_builtins; constructor accepts custom_builtins; inherit() propagates them. - **Function**: Added compute_globals() for closure variable resolution; improved AST line number tracking for decorated functions; ConstExpr detection checks runtime isinstance in addition to annotations. - **Specialization**: PointerArgType.to_ir() switched to get_unranked_memref_type. ### 2.2 Runtime & Compiler (asc/runtime/) - **Platform support**: Added C310 architecture — CompilationArch enum (C220/C310), platform_to_arch() mapping, 12 new platforms (Ascend950PR_95xx); set_platform() accepts string values; CompilePlatform enum removed in favor of CompilationArch. - **Compiler**: Compiler sets compilation_arch, soc_version on the module before passes; added -fcce-vf-vl Bisheng flag for C310; bisheng_options type fixed to Tuple[str, ...]; opt_level default changed to int = 3; compilation pipeline extended with new pass stages. - **JIT**: Refactored compile/cache/launch into separated phases using CompilePrereqs dataclass; kernel handles cached and reused across calls (LaunchedKernel); __getitem__ returns self; compute_globals() used for closures; jit() injects CustomBuiltins(range=asc_range) by default; 0-dim torch tensors treated as scalars; LaunchOptions.core_num changed to Optional[int] = None (auto-detect). Cache hash algorithm abstracted via HashDriver protocol (default: Blake2b instead of SHA-256). - **Launcher**: expand_kernel_args handles torch 0-dim tensors as scalars; core_num auto-detected if None; DRY_RUN env var renamed to PYASC_DRY_RUN; kernel binary handles optionally cached and unregistered after use. ### 2.3 Language Core (asc/language/core/) - **bfloat16 dtype**: Added throughout — DataType regex/kind mapping, KnownTypes, exports, builder bindings. - **IRValue/PlainValue/materialize_ir_value**: __bool__ raises TypeError on IR values; __not__ replaced by logical_not(); added max()/min() methods; type inference refactored (bool→int1, int→int_, float→float_). - **BaseRange/range**: BaseRange extracted as base class with handle_op() hook; range inherits from it. ### 2.4 Pybind11 Bindings (python/src/) - **IR.cpp**: Added ir.attr submodule, bindings for more builtin types (bfloat16, math dialect), clone_shaped_type, TypedAttr, get_splat_attr, get_dict_of_int_attr, ub_block_size; registered math dialect in context. - **OpBuilder.cpp**: New PyOpBuilder(Operation*) constructor; new bindings for bfloat16 type/constants/attrs, bool/i8/i16/f16/f32/f64 attrs, i32/bool array attrs; new arith ops (MaxSI, MinSI, MaximumF, MinimumF, ShLI, ShRSI, generic ConstantOp); full math dialect op bindings. - **Passes.cpp**: New pass bindings for all new Asc passes (with parameterized options for hoist_tensor_allocation, legalize_kernel_args, materialize_tensor, reuse_ub_allocation); add_hoist_ub_allocation removed (replaced by add_hoist_tensor_allocation). ### 2.5 Build System (setup.py) - LLVM auto-download removed; LLVM must be provided via LLVM_INSTALL_PREFIX. - Compiler/linker configuration generalized: PYASC_SETUP_COMPILER, PYASC_SETUP_LINKER, PYASC_SETUP_CMAKE_APPEND, PYASC_SETUP_JOBS env vars; PYASC_SETUP_CLANG_LLD now sets defaults instead of hardcoding. See merge request: cann/pyasc!157 | 21 天前 | |
Add Linear and fused infer attention examples with required API support Co-authored-by: liranr<2501185979@qq.com> # message auto-generated for no-merge-commit merge: !139 merge dev630 into master Add Linear and fused infer attention examples with required API support Created-by: liranr Commit-by: liranr Merged-by: cann-robot Description: ## 描述 新增了 Linear 和 Fused Infer Attention 样例。 本 PR 同时补充和修正了以下基础能力: 1. **新增了高阶api SoftmaxFlashV2**。 2. **完善 Matmul 配置和代码生成** - 修正 get_mm_config 未正确遍历位置参数和关键字参数的问题。 - 修正 en_vec_nd2_nz 字段读取错误,并补充 double cache、channel split 等配置传递。 - 修正 MDL、Special MDL 和 IBShare 模式下配置模式未正确生效的问题。 - 支持在同一作用域中生成多个名称不同的 Matmul 配置,满足样例 10 同时使用 QK 和 PV 两个 Matmul 对象的需求。 - 支持静态 Matmul tiling 的代码生成,并为相应的 register_matmul 调用选择正确重载。 - 修正 MmadParams.unit_flag 的类型,使其与 Ascend C 接口定义一致。 3. **完善嵌套 JIT 函数处理** - 保留空的返回类型访问状态,支持无返回值 JIT 辅助函数的嵌套调用。 - 样例 10 使用多个 JIT 辅助函数拆分复杂的 Attention 流水,因此需要该能力保证函数声明和调用正确生成。 4. **补充样例与 CI 支持** - 将样例 9 和样例 10加入 NPU presmoke 测试列表。 - 扩展样例路径匹配规则,使两位数编号的样例能够使用 NPU 模式运行。 - 修正样例 7、8 的 Ascend C 构建脚本在未传入参数时访问未定义位置参数的问题。 - 修复样例8的Model仿真模式。 ## 关联的Issue 无。 ## 测试 1. python/test/unit/language/adv/test_activation.py 2. test/Target/AscendC/adv.mlir 3. test/run_presmoke_npu_test.sh ## 文档更新 1. docs/python-api/language/generated/asc.language.adv.softmax_flash_v2.md 2. examples/09_linear/README.md 3. examples/10_fused_infer_attention/README.md ## 类型标签 - [x] Bug修复 - [x] 新特性 - [ ] 性能优化 - [x] 文档更新 - [ ] 其他,请描述:新增 Linear 和 Fused Infer Attention 样例 See merge request: cann/pyasc!139 | 17 天前 | |
Upgrade the infrastructure to support future extensions Co-authored-by: Vlasov Maxim<vlasov.maxim@huawei-partners.com> # message auto-generated for no-merge-commit merge: !157 merge mv/upstreamasc into master Upgrade the infrastructure to support future extensions Created-by: vla5924 Commit-by: Vlasov Maxim Merged-by: cann-robot Description: # PyAsc Infrastructure Changes This patch introduces modifications to the **existing** PyAsc infrastructure required by the tile-based programming add-on. Currently, there are no changes in public API or user experience. All existing features remain fully functional, as well as unit and system tests. --- ## 1. MLIR Changes ### 1.1 Asc Dialect — IR - **New operations**: Broadcast, Reduction (reduce_sum/max/min/prod with ReducePattern), register-based API (~40 ops for C310: binary, unary, vec-scalar, reduce, utility), LayerNorm, Log2, get_buf/rls_buf (BufId sync for C310), data_copy_nd_dma + NdDmaParams, set_loop_mode_para/reset_loop_mode_para, trans_data_to_5hd_tensor, local_tensor_v3, local_tensor.get_phy_addr_v2. - **New types**: FixpipeParamsC310, MaskReg, RegTensor, NdDmaParams. - **New attributes**: MaskPattern, MemType, ReducePattern, DataCopyMVType. - **New API types**: LayerNormTiling, LoopModeParams. - **New interfaces**: OpWithSrcInterface (get source tensors), OpWithReusableSrcInterface (marker for safe same-op reuse), CopyToL0OpInterface, MicroAPIOpInterface (+ Binary/Unary/VecScalar variants), ReduceOpInterface, BinaryL0OpInterface, BinaryL2OpInterface. - **Extended interfaces**: OpWithDstInterface gained getDstTensors() default; UnaryOpInterface/BinaryOpInterface/VecScalarOpInterface now include OpWithSrcInterface and OpWithReusableSrcInterface; L0/L2 interfaces gained mutable operand accessors and setIsSetMask. - **CopyDirection enum**: Replaced with corresponding methods GlobalToLocal/LocalToGlobal/LocalToLocal/GlobalToGlobal. - **Modified operations**: SoftMax/SimpleSoftMax changed to VectorOp with src interface, sumTensor/maxTensor made Optional; RmsNorm renamed mnemonic to rms_norm, changed to VectorOp; Fixpipe changed to DataCopyOp with generalized dst type and C310 params support; DataCopyL0/L2 gained src interface; LocalTensorAutoOp gained position attribute; SubIndex ops gained folders (zero-index identity); ReinterpretCastOp fold enhanced to eliminate double-cast chains; MulCast ops moved to BinaryCast templates; VecScalar ops gained Subs and Divs variants; all unary/binary/vec-scalar/math base classes gained default getSrcTensors()/getDstTensors(). ### 1.2 Asc Dialect — Passes - **Renamed**: HoistUBAllocation → HoistTensorAllocation (added exclude-in-out option), InsertSync → InsertQueSync. - **Modified**: MaterializeTensor (added always-buf option), LegalizeKernelArgs (added set-ffts-addr option, conditional on architecture), DetectKernelType (now classifies as "vector"/"cube"/"mixed" instead of binary flag), InsertSync (extended with V_S/S_V event sync for get_value/set_value), InputOutputTensor (handles input-only tensors used for ubuf_gm copy). - All existing passes received detailed description fields in TableGen. ### 1.3 EmitAsc Dialect - **New ops**: init_struct (struct initialization with named fields), mask (create bit-by-bit mask pair). - **New type**: mask (2-element i64 array for high/low mask). - **variable**: Removed Pure trait; added canonicalizer support. - **New utility**: InitStructBuilder helper class. ### 1.4 Code Emitter (Target/AscendC) - **New emitters** for all new Asc operations (Broadcast, Reduction, LayerNorm, MicroAPI suite, BufId sync, NdDma, etc.) and arith::NegFOp. - **CodeEmitter**: Added methods for C310 types (CO2Layout, FixpipeParamsC310, RegTensor, MaskReg, NdDmaParams). - **Fixpipe emission**: Generalized dst type handling; config emitted by name instead of hardcoded constant. - **VecScalar ops**: Added Subs and Divs variants to all L0/L1/L2 emitter lists. ### 1.5 Build System & Tools - Removed C language requirement from project; added atomic profile update for GCC coverage. - Added LIT tests for passes and emitters that didn't have them initially. - ConstantOpBuilder: Widened parameter types to int64_t; added i1() helper. --- ## 2. Python Changes ### 2.1 Codegen (asc/codegen/) - **FunctionVisitor**: - Added CustomBuiltins support for injecting custom builtins into the name scope. - Added MatMult (@ operator) support. - Boolean operators (and/or/not) and IfExp: compile-time constant folding before falling back to IR. - visit_Call: Handles ast.Starred arguments (*args unpacking). - visit_For: Generalized to accept any BaseRange subclass; calls handle_op() on the range object. - compute_inout: Materializes initial handles outside the block; accepts init_handles for if/else merge. - visit_If: Else-branch inherits init handles from then-branch. - **NameScope**: builtins → default_builtins; constructor accepts custom_builtins; inherit() propagates them. - **Function**: Added compute_globals() for closure variable resolution; improved AST line number tracking for decorated functions; ConstExpr detection checks runtime isinstance in addition to annotations. - **Specialization**: PointerArgType.to_ir() switched to get_unranked_memref_type. ### 2.2 Runtime & Compiler (asc/runtime/) - **Platform support**: Added C310 architecture — CompilationArch enum (C220/C310), platform_to_arch() mapping, 12 new platforms (Ascend950PR_95xx); set_platform() accepts string values; CompilePlatform enum removed in favor of CompilationArch. - **Compiler**: Compiler sets compilation_arch, soc_version on the module before passes; added -fcce-vf-vl Bisheng flag for C310; bisheng_options type fixed to Tuple[str, ...]; opt_level default changed to int = 3; compilation pipeline extended with new pass stages. - **JIT**: Refactored compile/cache/launch into separated phases using CompilePrereqs dataclass; kernel handles cached and reused across calls (LaunchedKernel); __getitem__ returns self; compute_globals() used for closures; jit() injects CustomBuiltins(range=asc_range) by default; 0-dim torch tensors treated as scalars; LaunchOptions.core_num changed to Optional[int] = None (auto-detect). Cache hash algorithm abstracted via HashDriver protocol (default: Blake2b instead of SHA-256). - **Launcher**: expand_kernel_args handles torch 0-dim tensors as scalars; core_num auto-detected if None; DRY_RUN env var renamed to PYASC_DRY_RUN; kernel binary handles optionally cached and unregistered after use. ### 2.3 Language Core (asc/language/core/) - **bfloat16 dtype**: Added throughout — DataType regex/kind mapping, KnownTypes, exports, builder bindings. - **IRValue/PlainValue/materialize_ir_value**: __bool__ raises TypeError on IR values; __not__ replaced by logical_not(); added max()/min() methods; type inference refactored (bool→int1, int→int_, float→float_). - **BaseRange/range**: BaseRange extracted as base class with handle_op() hook; range inherits from it. ### 2.4 Pybind11 Bindings (python/src/) - **IR.cpp**: Added ir.attr submodule, bindings for more builtin types (bfloat16, math dialect), clone_shaped_type, TypedAttr, get_splat_attr, get_dict_of_int_attr, ub_block_size; registered math dialect in context. - **OpBuilder.cpp**: New PyOpBuilder(Operation*) constructor; new bindings for bfloat16 type/constants/attrs, bool/i8/i16/f16/f32/f64 attrs, i32/bool array attrs; new arith ops (MaxSI, MinSI, MaximumF, MinimumF, ShLI, ShRSI, generic ConstantOp); full math dialect op bindings. - **Passes.cpp**: New pass bindings for all new Asc passes (with parameterized options for hoist_tensor_allocation, legalize_kernel_args, materialize_tensor, reuse_ub_allocation); add_hoist_ub_allocation removed (replaced by add_hoist_tensor_allocation). ### 2.5 Build System (setup.py) - LLVM auto-download removed; LLVM must be provided via LLVM_INSTALL_PREFIX. - Compiler/linker configuration generalized: PYASC_SETUP_COMPILER, PYASC_SETUP_LINKER, PYASC_SETUP_CMAKE_APPEND, PYASC_SETUP_JOBS env vars; PYASC_SETUP_CLANG_LLD now sets defaults instead of hardcoding. See merge request: cann/pyasc!157 | 21 天前 | |
Initial commit | 9 个月前 | |
Initial commit | 9 个月前 | |
[UT] 实现UT精准触发机制,支持增量测试和测试跳过 Co-authored-by: chenma<chenminan@hisilicon.com> # message auto-generated for no-merge-commit merge: !114 merge UT_spilit into master [UT] 实现UT精准触发机制,支持增量测试和测试跳过 Created-by: chenma Commit-by: chenma Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> ## 功能概述 实现UT精准触发机制,根据PR修改文件智能决定执行哪些测试,避免全量测试的资源浪费。 ## 主要变更 ### 1. 白名单机制 添加 NO_TEST_WHITE list 配置,对于非源码文件(docs、LICENSE、shell脚本等)不触发测试: - docs/、*.md、*.txt、*.rst 等文档文件 - .github/、images/ 等配置资源文件 ### 2. PR文件分析 新增 -f(--filelist 参数,支持传入PR修改文件列表,通过 analyze_pr_filelist() 函数分析: - 白名单文件:跳过测试 - 核心路径(include/、bin/、CMakeLists.txt等):触发全量测试 - 模块子目录(lib/Target/AscendC/{Adv,Basic,Core,External,Fwk}/):触发对应模块精准测试 - Python路径(python/asc/{language.lib,codegen,runtime}/):触发对应模块精准测试 - 未知源码路径:触发全量测试(安全兜底) ### 3. 精准测试执行 - **C++测试**:根据 CPP_TEST_TARGET执行对应模块的Lit测试,或构建必要工具后运行特定测试文件 - **Python测试**:根据 PYTHON_TEST_TARGET执行对应模块目录下的pytest测试 ### 4. 测试跳过机制 - ut_cpp 和 ut_python 分开执行时,若对应测试不需触发,使用 exit 200 标识跳过状态 - CI脚本识别 exit 200 后跳过覆盖率生成,避免报错 ## 使用方式 ### 带PR文件列表执行 bash build_llt.sh --cov --check-ascir -f pr_filelist.txt ### 不带文件列表(默认全量测试) bash build_llt.sh --cov --check-ascir 测试场景覆盖 | 场景 | 行为 | | :--- | :--- | | 仅修改 docs/*.md | 白名单 → exit 200 → 跳过测试 | | 仅修改 lib/Target/AscendC/Adv/*.cpp | 精准执行 Adv 模块Lit测试 | | 仅修改 python/asc/language/core/*.py | 精准执行 language/core 模块pytest | | 修改 include/*.h | 核心路径 → 全量测试 | ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #123--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> [#33](https://gitcode.com/cann/pyasc/issues/33) ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [ ] 新特性 - [x] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/pyasc!114 | 4 个月前 | |
Upgrade the infrastructure to support future extensions Co-authored-by: Vlasov Maxim<vlasov.maxim@huawei-partners.com> # message auto-generated for no-merge-commit merge: !157 merge mv/upstreamasc into master Upgrade the infrastructure to support future extensions Created-by: vla5924 Commit-by: Vlasov Maxim Merged-by: cann-robot Description: # PyAsc Infrastructure Changes This patch introduces modifications to the **existing** PyAsc infrastructure required by the tile-based programming add-on. Currently, there are no changes in public API or user experience. All existing features remain fully functional, as well as unit and system tests. --- ## 1. MLIR Changes ### 1.1 Asc Dialect — IR - **New operations**: Broadcast, Reduction (reduce_sum/max/min/prod with ReducePattern), register-based API (~40 ops for C310: binary, unary, vec-scalar, reduce, utility), LayerNorm, Log2, get_buf/rls_buf (BufId sync for C310), data_copy_nd_dma + NdDmaParams, set_loop_mode_para/reset_loop_mode_para, trans_data_to_5hd_tensor, local_tensor_v3, local_tensor.get_phy_addr_v2. - **New types**: FixpipeParamsC310, MaskReg, RegTensor, NdDmaParams. - **New attributes**: MaskPattern, MemType, ReducePattern, DataCopyMVType. - **New API types**: LayerNormTiling, LoopModeParams. - **New interfaces**: OpWithSrcInterface (get source tensors), OpWithReusableSrcInterface (marker for safe same-op reuse), CopyToL0OpInterface, MicroAPIOpInterface (+ Binary/Unary/VecScalar variants), ReduceOpInterface, BinaryL0OpInterface, BinaryL2OpInterface. - **Extended interfaces**: OpWithDstInterface gained getDstTensors() default; UnaryOpInterface/BinaryOpInterface/VecScalarOpInterface now include OpWithSrcInterface and OpWithReusableSrcInterface; L0/L2 interfaces gained mutable operand accessors and setIsSetMask. - **CopyDirection enum**: Replaced with corresponding methods GlobalToLocal/LocalToGlobal/LocalToLocal/GlobalToGlobal. - **Modified operations**: SoftMax/SimpleSoftMax changed to VectorOp with src interface, sumTensor/maxTensor made Optional; RmsNorm renamed mnemonic to rms_norm, changed to VectorOp; Fixpipe changed to DataCopyOp with generalized dst type and C310 params support; DataCopyL0/L2 gained src interface; LocalTensorAutoOp gained position attribute; SubIndex ops gained folders (zero-index identity); ReinterpretCastOp fold enhanced to eliminate double-cast chains; MulCast ops moved to BinaryCast templates; VecScalar ops gained Subs and Divs variants; all unary/binary/vec-scalar/math base classes gained default getSrcTensors()/getDstTensors(). ### 1.2 Asc Dialect — Passes - **Renamed**: HoistUBAllocation → HoistTensorAllocation (added exclude-in-out option), InsertSync → InsertQueSync. - **Modified**: MaterializeTensor (added always-buf option), LegalizeKernelArgs (added set-ffts-addr option, conditional on architecture), DetectKernelType (now classifies as "vector"/"cube"/"mixed" instead of binary flag), InsertSync (extended with V_S/S_V event sync for get_value/set_value), InputOutputTensor (handles input-only tensors used for ubuf_gm copy). - All existing passes received detailed description fields in TableGen. ### 1.3 EmitAsc Dialect - **New ops**: init_struct (struct initialization with named fields), mask (create bit-by-bit mask pair). - **New type**: mask (2-element i64 array for high/low mask). - **variable**: Removed Pure trait; added canonicalizer support. - **New utility**: InitStructBuilder helper class. ### 1.4 Code Emitter (Target/AscendC) - **New emitters** for all new Asc operations (Broadcast, Reduction, LayerNorm, MicroAPI suite, BufId sync, NdDma, etc.) and arith::NegFOp. - **CodeEmitter**: Added methods for C310 types (CO2Layout, FixpipeParamsC310, RegTensor, MaskReg, NdDmaParams). - **Fixpipe emission**: Generalized dst type handling; config emitted by name instead of hardcoded constant. - **VecScalar ops**: Added Subs and Divs variants to all L0/L1/L2 emitter lists. ### 1.5 Build System & Tools - Removed C language requirement from project; added atomic profile update for GCC coverage. - Added LIT tests for passes and emitters that didn't have them initially. - ConstantOpBuilder: Widened parameter types to int64_t; added i1() helper. --- ## 2. Python Changes ### 2.1 Codegen (asc/codegen/) - **FunctionVisitor**: - Added CustomBuiltins support for injecting custom builtins into the name scope. - Added MatMult (@ operator) support. - Boolean operators (and/or/not) and IfExp: compile-time constant folding before falling back to IR. - visit_Call: Handles ast.Starred arguments (*args unpacking). - visit_For: Generalized to accept any BaseRange subclass; calls handle_op() on the range object. - compute_inout: Materializes initial handles outside the block; accepts init_handles for if/else merge. - visit_If: Else-branch inherits init handles from then-branch. - **NameScope**: builtins → default_builtins; constructor accepts custom_builtins; inherit() propagates them. - **Function**: Added compute_globals() for closure variable resolution; improved AST line number tracking for decorated functions; ConstExpr detection checks runtime isinstance in addition to annotations. - **Specialization**: PointerArgType.to_ir() switched to get_unranked_memref_type. ### 2.2 Runtime & Compiler (asc/runtime/) - **Platform support**: Added C310 architecture — CompilationArch enum (C220/C310), platform_to_arch() mapping, 12 new platforms (Ascend950PR_95xx); set_platform() accepts string values; CompilePlatform enum removed in favor of CompilationArch. - **Compiler**: Compiler sets compilation_arch, soc_version on the module before passes; added -fcce-vf-vl Bisheng flag for C310; bisheng_options type fixed to Tuple[str, ...]; opt_level default changed to int = 3; compilation pipeline extended with new pass stages. - **JIT**: Refactored compile/cache/launch into separated phases using CompilePrereqs dataclass; kernel handles cached and reused across calls (LaunchedKernel); __getitem__ returns self; compute_globals() used for closures; jit() injects CustomBuiltins(range=asc_range) by default; 0-dim torch tensors treated as scalars; LaunchOptions.core_num changed to Optional[int] = None (auto-detect). Cache hash algorithm abstracted via HashDriver protocol (default: Blake2b instead of SHA-256). - **Launcher**: expand_kernel_args handles torch 0-dim tensors as scalars; core_num auto-detected if None; DRY_RUN env var renamed to PYASC_DRY_RUN; kernel binary handles optionally cached and unregistered after use. ### 2.3 Language Core (asc/language/core/) - **bfloat16 dtype**: Added throughout — DataType regex/kind mapping, KnownTypes, exports, builder bindings. - **IRValue/PlainValue/materialize_ir_value**: __bool__ raises TypeError on IR values; __not__ replaced by logical_not(); added max()/min() methods; type inference refactored (bool→int1, int→int_, float→float_). - **BaseRange/range**: BaseRange extracted as base class with handle_op() hook; range inherits from it. ### 2.4 Pybind11 Bindings (python/src/) - **IR.cpp**: Added ir.attr submodule, bindings for more builtin types (bfloat16, math dialect), clone_shaped_type, TypedAttr, get_splat_attr, get_dict_of_int_attr, ub_block_size; registered math dialect in context. - **OpBuilder.cpp**: New PyOpBuilder(Operation*) constructor; new bindings for bfloat16 type/constants/attrs, bool/i8/i16/f16/f32/f64 attrs, i32/bool array attrs; new arith ops (MaxSI, MinSI, MaximumF, MinimumF, ShLI, ShRSI, generic ConstantOp); full math dialect op bindings. - **Passes.cpp**: New pass bindings for all new Asc passes (with parameterized options for hoist_tensor_allocation, legalize_kernel_args, materialize_tensor, reuse_ub_allocation); add_hoist_ub_allocation removed (replaced by add_hoist_tensor_allocation). ### 2.5 Build System (setup.py) - LLVM auto-download removed; LLVM must be provided via LLVM_INSTALL_PREFIX. - Compiler/linker configuration generalized: PYASC_SETUP_COMPILER, PYASC_SETUP_LINKER, PYASC_SETUP_CMAKE_APPEND, PYASC_SETUP_JOBS env vars; PYASC_SETUP_CLANG_LLD now sets defaults instead of hardcoding. See merge request: cann/pyasc!157 | 21 天前 | |
添加 clang/lld编译器支持和覆盖率生成/ccache 编译缓存/优化lcov错误处理 Co-authored-by: chenma<chenminan@hisilicon.com> # message auto-generated for no-merge-commit merge: !99 merge master into master 添加 clang/lld编译器支持和覆盖率生成/ccache 编译缓存/优化lcov错误处理 Created-by: chenma Commit-by: chenma Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> 添加 clang/lld编译器支持和覆盖率生成/ccache 编译缓存/优化lcov错误处理 **主要变更:** <span style="color:#000000;">1. CMakeLists.txt - 扩展 ASCIR_COVERAGE 选项,支持 Clang 和 GCC 两种编译器的覆盖率编译选项 - Clang: -fprofile-instr-generate -fcoverage-mapping - GCC: 保持原有 -fprofile-arcs -ftest-coverage 2. test/build_llt.sh - 新增 --clang 命令行参数,启用 Clang/LLD 编译器 - 新增 check_clang_available() 检查 clang/ld 工具可用性 - 新增 generate_llvm_coverage() 生成 Clang 覆盖率报告 - 重构 generate_coverage() 分离 GCC 和 Clang 代码路径 - 支持 llvm-profdata/llvm-cov 版本自动检测(v10-v19) - 优化 lcov 错误处理,兼容 lcov v1/v2 版本 3. test/lit.site.cfg.in - 配置 LLVM 工具路径和覆盖率环境变量 4. docs/quick_start.md - 添加编译器选择说明文档 - 添加 Clang 覆盖率使用示例</span> ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #123--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> Issue [#32](https://gitcode.com/cann/pyasc/issues/32) ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> 本地已验证gcc和clang UT全部执行成功,覆盖率生成正常。 cpp UT验证时间从28min(gcc编译)优化至3min内(clang编译) ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> docs/quick_start.md - 添加编译器选择说明文档 - 添加 Clang 覆盖率使用示例 ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [x]其他,请描述:llt编译效率优化 See merge request: cann/pyasc!99 | 4 个月前 | |
添加 clang/lld编译器支持和覆盖率生成/ccache 编译缓存/优化lcov错误处理 Co-authored-by: chenma<chenminan@hisilicon.com> # message auto-generated for no-merge-commit merge: !99 merge master into master 添加 clang/lld编译器支持和覆盖率生成/ccache 编译缓存/优化lcov错误处理 Created-by: chenma Commit-by: chenma Merged-by: cann-robot Description: ## 描述 <!--在这里详细描述你的改动,包括改动的原因和所采取的方法。--> 添加 clang/lld编译器支持和覆盖率生成/ccache 编译缓存/优化lcov错误处理 **主要变更:** <span style="color:#000000;">1. CMakeLists.txt - 扩展 ASCIR_COVERAGE 选项,支持 Clang 和 GCC 两种编译器的覆盖率编译选项 - Clang: -fprofile-instr-generate -fcoverage-mapping - GCC: 保持原有 -fprofile-arcs -ftest-coverage 2. test/build_llt.sh - 新增 --clang 命令行参数,启用 Clang/LLD 编译器 - 新增 check_clang_available() 检查 clang/ld 工具可用性 - 新增 generate_llvm_coverage() 生成 Clang 覆盖率报告 - 重构 generate_coverage() 分离 GCC 和 Clang 代码路径 - 支持 llvm-profdata/llvm-cov 版本自动检测(v10-v19) - 优化 lcov 错误处理,兼容 lcov v1/v2 版本 3. test/lit.site.cfg.in - 配置 LLVM 工具路径和覆盖率环境变量 4. docs/quick_start.md - 添加编译器选择说明文档 - 添加 Clang 覆盖率使用示例</span> ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #123--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> Issue [#32](https://gitcode.com/cann/pyasc/issues/32) ## 测试 <!--描述进行了哪些测试来验证你的改动。包括但不限于二级冒烟、算子泛化等。--> 本地已验证gcc和clang UT全部执行成功,覆盖率生成正常。 cpp UT验证时间从28min(gcc编译)优化至3min内(clang编译) ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> docs/quick_start.md - 添加编译器选择说明文档 - 添加 Clang 覆盖率使用示例 ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [x]其他,请描述:llt编译效率优化 See merge request: cann/pyasc!99 | 4 个月前 | |
rename test scripts Co-authored-by: li-yuanjie-da<liyuanjie5@h-partners.com> | 9 个月前 | |
fix bug of simulator mode when import torch Co-authored-by: hyolee<lihongbo14@huawei.com> # message auto-generated for no-merge-commit merge: !71 merge master into master fix bug of simulator mode when import torch Created-by: hyolee Commit-by: hyolee Merged-by: cann-robot Description: ## 描述 如果安装了torch_npu,import torch(2.5.1及以后版本)默认会加载libruntime.so,会先于仿真模式下的libruntime_camodel.so的加载,两者存在相同的函数符号,但是全局符号表里存的是libruntime.so的符号,导致实际运行的并非仿真模式,mix场景甚至会报错,解决方案是仿真模式下通过LD_PRELOAD环境变量提前加载libruntime_camodel.so ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #123--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 1、test目录下的ut测试用例(build_llt.sh脚本) 2、python/tutorials目录下的单算子用例 ## 文档更新 docs/op_debug_prof.md docs/quick_start.md ## 类型标签 <!-- [x] 表示选中 --> - [x] Bug修复 - [ ] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/pyasc!71 | 6 个月前 | |
Add Linear and fused infer attention examples with required API support Co-authored-by: liranr<2501185979@qq.com> # message auto-generated for no-merge-commit merge: !139 merge dev630 into master Add Linear and fused infer attention examples with required API support Created-by: liranr Commit-by: liranr Merged-by: cann-robot Description: ## 描述 新增了 Linear 和 Fused Infer Attention 样例。 本 PR 同时补充和修正了以下基础能力: 1. **新增了高阶api SoftmaxFlashV2**。 2. **完善 Matmul 配置和代码生成** - 修正 get_mm_config 未正确遍历位置参数和关键字参数的问题。 - 修正 en_vec_nd2_nz 字段读取错误,并补充 double cache、channel split 等配置传递。 - 修正 MDL、Special MDL 和 IBShare 模式下配置模式未正确生效的问题。 - 支持在同一作用域中生成多个名称不同的 Matmul 配置,满足样例 10 同时使用 QK 和 PV 两个 Matmul 对象的需求。 - 支持静态 Matmul tiling 的代码生成,并为相应的 register_matmul 调用选择正确重载。 - 修正 MmadParams.unit_flag 的类型,使其与 Ascend C 接口定义一致。 3. **完善嵌套 JIT 函数处理** - 保留空的返回类型访问状态,支持无返回值 JIT 辅助函数的嵌套调用。 - 样例 10 使用多个 JIT 辅助函数拆分复杂的 Attention 流水,因此需要该能力保证函数声明和调用正确生成。 4. **补充样例与 CI 支持** - 将样例 9 和样例 10加入 NPU presmoke 测试列表。 - 扩展样例路径匹配规则,使两位数编号的样例能够使用 NPU 模式运行。 - 修正样例 7、8 的 Ascend C 构建脚本在未传入参数时访问未定义位置参数的问题。 - 修复样例8的Model仿真模式。 ## 关联的Issue 无。 ## 测试 1. python/test/unit/language/adv/test_activation.py 2. test/Target/AscendC/adv.mlir 3. test/run_presmoke_npu_test.sh ## 文档更新 1. docs/python-api/language/generated/asc.language.adv.softmax_flash_v2.md 2. examples/09_linear/README.md 3. examples/10_fused_infer_attention/README.md ## 类型标签 - [x] Bug修复 - [x] 新特性 - [ ] 性能优化 - [x] 文档更新 - [ ] 其他,请描述:新增 Linear 和 Fused Infer Attention 样例 See merge request: cann/pyasc!139 | 17 天前 | |
Upgrade the infrastructure to support future extensions Co-authored-by: Vlasov Maxim<vlasov.maxim@huawei-partners.com> # message auto-generated for no-merge-commit merge: !157 merge mv/upstreamasc into master Upgrade the infrastructure to support future extensions Created-by: vla5924 Commit-by: Vlasov Maxim Merged-by: cann-robot Description: # PyAsc Infrastructure Changes This patch introduces modifications to the **existing** PyAsc infrastructure required by the tile-based programming add-on. Currently, there are no changes in public API or user experience. All existing features remain fully functional, as well as unit and system tests. --- ## 1. MLIR Changes ### 1.1 Asc Dialect — IR - **New operations**: Broadcast, Reduction (reduce_sum/max/min/prod with ReducePattern), register-based API (~40 ops for C310: binary, unary, vec-scalar, reduce, utility), LayerNorm, Log2, get_buf/rls_buf (BufId sync for C310), data_copy_nd_dma + NdDmaParams, set_loop_mode_para/reset_loop_mode_para, trans_data_to_5hd_tensor, local_tensor_v3, local_tensor.get_phy_addr_v2. - **New types**: FixpipeParamsC310, MaskReg, RegTensor, NdDmaParams. - **New attributes**: MaskPattern, MemType, ReducePattern, DataCopyMVType. - **New API types**: LayerNormTiling, LoopModeParams. - **New interfaces**: OpWithSrcInterface (get source tensors), OpWithReusableSrcInterface (marker for safe same-op reuse), CopyToL0OpInterface, MicroAPIOpInterface (+ Binary/Unary/VecScalar variants), ReduceOpInterface, BinaryL0OpInterface, BinaryL2OpInterface. - **Extended interfaces**: OpWithDstInterface gained getDstTensors() default; UnaryOpInterface/BinaryOpInterface/VecScalarOpInterface now include OpWithSrcInterface and OpWithReusableSrcInterface; L0/L2 interfaces gained mutable operand accessors and setIsSetMask. - **CopyDirection enum**: Replaced with corresponding methods GlobalToLocal/LocalToGlobal/LocalToLocal/GlobalToGlobal. - **Modified operations**: SoftMax/SimpleSoftMax changed to VectorOp with src interface, sumTensor/maxTensor made Optional; RmsNorm renamed mnemonic to rms_norm, changed to VectorOp; Fixpipe changed to DataCopyOp with generalized dst type and C310 params support; DataCopyL0/L2 gained src interface; LocalTensorAutoOp gained position attribute; SubIndex ops gained folders (zero-index identity); ReinterpretCastOp fold enhanced to eliminate double-cast chains; MulCast ops moved to BinaryCast templates; VecScalar ops gained Subs and Divs variants; all unary/binary/vec-scalar/math base classes gained default getSrcTensors()/getDstTensors(). ### 1.2 Asc Dialect — Passes - **Renamed**: HoistUBAllocation → HoistTensorAllocation (added exclude-in-out option), InsertSync → InsertQueSync. - **Modified**: MaterializeTensor (added always-buf option), LegalizeKernelArgs (added set-ffts-addr option, conditional on architecture), DetectKernelType (now classifies as "vector"/"cube"/"mixed" instead of binary flag), InsertSync (extended with V_S/S_V event sync for get_value/set_value), InputOutputTensor (handles input-only tensors used for ubuf_gm copy). - All existing passes received detailed description fields in TableGen. ### 1.3 EmitAsc Dialect - **New ops**: init_struct (struct initialization with named fields), mask (create bit-by-bit mask pair). - **New type**: mask (2-element i64 array for high/low mask). - **variable**: Removed Pure trait; added canonicalizer support. - **New utility**: InitStructBuilder helper class. ### 1.4 Code Emitter (Target/AscendC) - **New emitters** for all new Asc operations (Broadcast, Reduction, LayerNorm, MicroAPI suite, BufId sync, NdDma, etc.) and arith::NegFOp. - **CodeEmitter**: Added methods for C310 types (CO2Layout, FixpipeParamsC310, RegTensor, MaskReg, NdDmaParams). - **Fixpipe emission**: Generalized dst type handling; config emitted by name instead of hardcoded constant. - **VecScalar ops**: Added Subs and Divs variants to all L0/L1/L2 emitter lists. ### 1.5 Build System & Tools - Removed C language requirement from project; added atomic profile update for GCC coverage. - Added LIT tests for passes and emitters that didn't have them initially. - ConstantOpBuilder: Widened parameter types to int64_t; added i1() helper. --- ## 2. Python Changes ### 2.1 Codegen (asc/codegen/) - **FunctionVisitor**: - Added CustomBuiltins support for injecting custom builtins into the name scope. - Added MatMult (@ operator) support. - Boolean operators (and/or/not) and IfExp: compile-time constant folding before falling back to IR. - visit_Call: Handles ast.Starred arguments (*args unpacking). - visit_For: Generalized to accept any BaseRange subclass; calls handle_op() on the range object. - compute_inout: Materializes initial handles outside the block; accepts init_handles for if/else merge. - visit_If: Else-branch inherits init handles from then-branch. - **NameScope**: builtins → default_builtins; constructor accepts custom_builtins; inherit() propagates them. - **Function**: Added compute_globals() for closure variable resolution; improved AST line number tracking for decorated functions; ConstExpr detection checks runtime isinstance in addition to annotations. - **Specialization**: PointerArgType.to_ir() switched to get_unranked_memref_type. ### 2.2 Runtime & Compiler (asc/runtime/) - **Platform support**: Added C310 architecture — CompilationArch enum (C220/C310), platform_to_arch() mapping, 12 new platforms (Ascend950PR_95xx); set_platform() accepts string values; CompilePlatform enum removed in favor of CompilationArch. - **Compiler**: Compiler sets compilation_arch, soc_version on the module before passes; added -fcce-vf-vl Bisheng flag for C310; bisheng_options type fixed to Tuple[str, ...]; opt_level default changed to int = 3; compilation pipeline extended with new pass stages. - **JIT**: Refactored compile/cache/launch into separated phases using CompilePrereqs dataclass; kernel handles cached and reused across calls (LaunchedKernel); __getitem__ returns self; compute_globals() used for closures; jit() injects CustomBuiltins(range=asc_range) by default; 0-dim torch tensors treated as scalars; LaunchOptions.core_num changed to Optional[int] = None (auto-detect). Cache hash algorithm abstracted via HashDriver protocol (default: Blake2b instead of SHA-256). - **Launcher**: expand_kernel_args handles torch 0-dim tensors as scalars; core_num auto-detected if None; DRY_RUN env var renamed to PYASC_DRY_RUN; kernel binary handles optionally cached and unregistered after use. ### 2.3 Language Core (asc/language/core/) - **bfloat16 dtype**: Added throughout — DataType regex/kind mapping, KnownTypes, exports, builder bindings. - **IRValue/PlainValue/materialize_ir_value**: __bool__ raises TypeError on IR values; __not__ replaced by logical_not(); added max()/min() methods; type inference refactored (bool→int1, int→int_, float→float_). - **BaseRange/range**: BaseRange extracted as base class with handle_op() hook; range inherits from it. ### 2.4 Pybind11 Bindings (python/src/) - **IR.cpp**: Added ir.attr submodule, bindings for more builtin types (bfloat16, math dialect), clone_shaped_type, TypedAttr, get_splat_attr, get_dict_of_int_attr, ub_block_size; registered math dialect in context. - **OpBuilder.cpp**: New PyOpBuilder(Operation*) constructor; new bindings for bfloat16 type/constants/attrs, bool/i8/i16/f16/f32/f64 attrs, i32/bool array attrs; new arith ops (MaxSI, MinSI, MaximumF, MinimumF, ShLI, ShRSI, generic ConstantOp); full math dialect op bindings. - **Passes.cpp**: New pass bindings for all new Asc passes (with parameterized options for hoist_tensor_allocation, legalize_kernel_args, materialize_tensor, reuse_ub_allocation); add_hoist_ub_allocation removed (replaced by add_hoist_tensor_allocation). ### 2.5 Build System (setup.py) - LLVM auto-download removed; LLVM must be provided via LLVM_INSTALL_PREFIX. - Compiler/linker configuration generalized: PYASC_SETUP_COMPILER, PYASC_SETUP_LINKER, PYASC_SETUP_CMAKE_APPEND, PYASC_SETUP_JOBS env vars; PYASC_SETUP_CLANG_LLD now sets defaults instead of hardcoding. See merge request: cann/pyasc!157 | 21 天前 |
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 21 天前 | ||
| 17 天前 | ||
| 21 天前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 4 个月前 | ||
| 21 天前 | ||
| 4 个月前 | ||
| 4 个月前 | ||
| 9 个月前 | ||
| 6 个月前 | ||
| 17 天前 | ||
| 21 天前 |