| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
add DataCachePreload Co-authored-by: lbenedict<liuxinnan@stu.hit.edu.cn> | 7 个月前 | |
Initial commit | 9 个月前 | |
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 | 11 天前 | |
Move code from OpDataCache.td to OpCache.td Co-authored-by: liranr<2501185979@qq.com> | 7 个月前 | |
add common ops Co-authored-by: yuaner1057<zengjiayuan1@h-partners.com> Co-authored-by: cann-robot<songchangxia@cann.team> # message auto-generated for no-merge-commit merge: !78 merge dev into master add common ops Created-by: yuaner1057 Commit-by: yuaner1057;cann-robot Merged-by: cann-robot Description: ## 描述 新增common api ( get_store_atomic_config, init_soc_state, set_store_atomic_config, check_local_memory_ia), get_mrg_sort_result) ;修改gather_mask。 ## 测试 - UT:test目录下的ut测试用例(build_llt.sh脚本) - ST:python/tutorials目录下的单算子用例 ## 文档更新 docs/python-api/language/generated/asc.language.basic.check_local_memory_ia.md docs/python-api/language/generated/asc.language.basic.gather_mask.md docs/python-api/language/generated/asc.language.basic.get_mrg_sort_result.md docs/python-api/language/generated/asc.language.basic.get_store_atomic_config.md docs/python-api/language/generated/asc.language.basic.init_soc_state.md docs/python-api/language/generated/asc.language.basic.print_time_stamp.md docs/python-api/language/generated/asc.language.basic.set_store_atomic_config.md ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [x] 新特性 - [ ] 性能优化 - [x] 文档更新 - [ ] 其他,请描述: See merge request: cann/pyasc!78 | 6 个月前 | |
Initial commit | 9 个月前 | |
Initial commit | 9 个月前 | |
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 | 11 天前 | |
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 | 11 天前 | |
add inter-core sync(WaitPreBlock & NotifyNextBlock) Co-authored-by: lbenedict<liuxinnan@stu.hit.edu.cn> | 7 个月前 | |
add MetricsProfStart and MetricsProfStop Co-authored-by: JWJWJWJWW<1357697985@qq.com> Co-authored-by: JWJWJWJWW<24S103414@stu.hit.edu.cn> | 8 个月前 | |
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 | 11 天前 | |
Initial commit | 9 个月前 | |
Initial commit | 9 个月前 | |
Initial commit | 9 个月前 | |
add ListTensorDesc class Co-authored-by: gehaoxuan<2310314646@qq.com> | 7 个月前 | |
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 | 11 天前 | |
get_sort Co-authored-by: hyyisasleep<2106975800@qq.com> # message auto-generated for no-merge-commit merge: !56 merge getsort into master get_sort Created-by: li_zeran Commit-by: hyyisasleep Merged-by: cann-robot Description: ## 描述 add getsortoffset & getsortlen ## 关联的Issue <!-- 如果这个PR是为了解决特定的Issue,请在这里提供Issue链接。例如:关联Issue #123--> <!-- 如果这个PR是为了解决特定的问题单,请在这里描述问题单单号。--> ## 测试 python ut ascir ut ## 文档更新 <!--如果这个PR包含文档的更新,请在这里指出。例如:更新了README.md文件。--> ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [x] 新特性 - [ ] 性能优化 - [ ] 文档更新 - [ ] 其他,请描述: See merge request: cann/pyasc!56 | 6 个月前 | |
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 | 11 天前 | |
add ScalarGetCountOfValue,ScalarCountLeadingZero,CountBitsCntSameAsSignBit Co-authored-by: Hit_Lillia<Hit_Lillia@noreply.gitcode.com> Co-authored-by: Hit_Lillia<2939368991@qq.com> | 7 个月前 | |
transfer code from common to SetAtomic Co-authored-by: Sea--1024<18229820470@139.com> | 8 个月前 | |
Initial commit | 9 个月前 | |
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 | 11 天前 | |
Initial commit | 9 个月前 | |
Initial commit | 9 个月前 | |
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 | 11 天前 | |
Initial commit | 9 个月前 | |
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 | 11 天前 | |
Initial commit | 9 个月前 | |
Initial commit | 9 个月前 | |
Initial commit | 9 个月前 | |
add common ops Co-authored-by: yuaner1057<zengjiayuan1@h-partners.com> Co-authored-by: cann-robot<songchangxia@cann.team> # message auto-generated for no-merge-commit merge: !78 merge dev into master add common ops Created-by: yuaner1057 Commit-by: yuaner1057;cann-robot Merged-by: cann-robot Description: ## 描述 新增common api ( get_store_atomic_config, init_soc_state, set_store_atomic_config, check_local_memory_ia), get_mrg_sort_result) ;修改gather_mask。 ## 测试 - UT:test目录下的ut测试用例(build_llt.sh脚本) - ST:python/tutorials目录下的单算子用例 ## 文档更新 docs/python-api/language/generated/asc.language.basic.check_local_memory_ia.md docs/python-api/language/generated/asc.language.basic.gather_mask.md docs/python-api/language/generated/asc.language.basic.get_mrg_sort_result.md docs/python-api/language/generated/asc.language.basic.get_store_atomic_config.md docs/python-api/language/generated/asc.language.basic.init_soc_state.md docs/python-api/language/generated/asc.language.basic.print_time_stamp.md docs/python-api/language/generated/asc.language.basic.set_store_atomic_config.md ## 类型标签 <!-- [x] 表示选中 --> - [ ] Bug修复 - [x] 新特性 - [ ] 性能优化 - [x] 文档更新 - [ ] 其他,请描述: See merge request: cann/pyasc!78 | 6 个月前 | |
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 | 11 天前 | |
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 | 11 天前 | |
Initial commit | 9 个月前 | |
Initial commit | 9 个月前 | |
Initial commit | 9 个月前 | |
Initial commit | 9 个月前 | |
Initial commit | 9 个月前 | |
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 | 11 天前 | |
Initial commit | 9 个月前 | |
Initial commit | 9 个月前 |
| 文件 | 最后提交记录 | 最后更新时间 |
|---|---|---|
| 7 个月前 | ||
| 9 个月前 | ||
| 11 天前 | ||
| 7 个月前 | ||
| 6 个月前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 11 天前 | ||
| 11 天前 | ||
| 7 个月前 | ||
| 8 个月前 | ||
| 11 天前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 7 个月前 | ||
| 11 天前 | ||
| 6 个月前 | ||
| 11 天前 | ||
| 7 个月前 | ||
| 8 个月前 | ||
| 9 个月前 | ||
| 11 天前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 11 天前 | ||
| 9 个月前 | ||
| 11 天前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 6 个月前 | ||
| 11 天前 | ||
| 11 天前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 9 个月前 | ||
| 11 天前 | ||
| 9 个月前 | ||
| 9 个月前 |