Ascend C

Build multi-level APIs based on C/C++, provide complete chip programming capabilities, and support achieving ultimate performance

community repo examples asc-tools license contributing SIG

🔥Latest News

[2026/03] Key features of v9.0.0-beta.2

🚀 Key Features

  • Ascend 950PR supports SIMD programming mode and provides over 200 API interfaces with cross-generation compatibility capabilities, enabling smooth operator migration between Atlas A2 series products and Atlas A3 series products.
  • Ascend 950PR adds Reg-based programming and provides over 90 Reg programming interfaces, including Reg datamove, basic arithmetic, reduction calculation, and synchronization control.
  • Atlas A2 series products, Atlas A3 series products, and Ascend 950PR support language extension layer pure C interfaces, supporting array-style memory allocation and pointer-based calculation interfaces, providing a native pure C programming experience.
  • Ascend 950PR supports SIMD and SIMT hybrid programming and provides approximately 700 SIMT API interfaces, including warp, atomic, basic mathematical calculation, type conversion, and other fundamental interfaces.
  • Ascend 950PR supports CCU communication interfaces for communication high-level APIs and provides mainstream communication primitives based on CCU, including Allreduce, Allgather, Reducescatter, AlltoAll, and others. Matmul high-level API adds support for MXFP4/8 low-bit data type matrix operations, achieving half memory usage and doubled computing throughput.
  • Ascend 950PR adds and supports approximately 260 sample cases in total, including SIMT samples, SIMD samples (framework, basic API, high-level API, best practices, and others), and adjusts the sample directory structure according to programming model and sample category to improve readability.
  • Fusion compilation and <<<>>> invocation support CPU mode and SIM simulation mode.

📖 Documentation

For detailed information about all historical versions and updates, see CHANGELOG.md

🚀 Overview

Ascend C is a specialized operator programming language for Ascend AI processors launched by CANN (Compute Architecture for Neural Networks), providing native support for C and C++ standard specifications. As a programming language designed for multiple scenarios, Ascend C not only focuses on opening complete chip programming capabilities to support achieving ultimate performance, but also enables flexible selection of the most appropriate API through multi-level programming API design based on project requirements, team skills, and performance goals, achieving the best balance between development efficiency and runtime performance.

Design Goals

The design goals of Ascend C can be summarized as "high performance, completeness, ease of programming, debuggability, and compatibility". Through minimal extension to C/C++ language standards, it supports both pointer-based C language development habits and Tensor-based C++ programming paradigms, achieving seamless integration with existing ecosystems while supporting efficient Ascend operator development and ensuring consistency in development experience.

We uphold the following core philosophies:

  • No silver bullet: Different scenarios have different requirements for performance and development efficiency. A single interface cannot optimally adapt to all scenarios.
  • Progressive learning: Beginners can start with ease-of-use interfaces to quickly verify algorithms, while experts can drill down and fine-tune, leveraging complex interface features to fully exploit hardware potential.

API Levels

Ascend C provides three types of interfaces, all capable of achieving complete low-level programming capabilities:

API Level Language Features Target Users Primary Use
Tpipe/Tque Framework Programming API C++ Based on Tensor programming
Unified management of memory and synchronization through Tpipe/Tque framework
Operator library developers Based on framework automatic synchronization and memory management
Improve programming ease of use
Basic API C++ Based on Tensor programming, providing C++ basic complete programming capabilities
Allocate Tensor through MakeTensor/LocalMemoryAllocator, manage synchronization independently
Operator library developers Manage synchronization and memory independently
Match C++ Tensor development habits, support achieving ultimate performance
Language Extension Layer
SIMD&SIMT API
C Based on pointer programming, providing C basic complete programming capabilities
Allocate memory through array[], manage synchronization independently
Operator library developers Manage synchronization and memory independently
Match C language development habits, support achieving ultimate performance

Additionally, Ascend C provides high-level APIs and operator template libraries to improve operator development efficiency.

API Level Target Users Primary Use
Operator Template Library (CATLASS/ATVOSS and others) Algorithm developers Perform custom extensions based on typical operator implementations to meet high-performance requirements in specific scenarios
High-level API Algorithm developers Reuse general single-core algorithms to quickly complete algorithm verification

The overall logical architecture diagram is shown below:

Architecture Diagram

  • Language Extension Layer C API: Pure C interfaces, supporting array memory allocation and pointer-based calculation interfaces, providing a C programming experience consistent with industry standards and opening complete chip programming capabilities. Atlas A2/A3 supports SIMD pure C interfaces; Ascend 950PR/Ascend 950DT will support SIMT programming capabilities similar to industry standards and SIMD/SIMT hybrid programming capabilities.
  • Basic API: Single-instruction abstracted C++ class library API, generally based on Tensor programming; gradually improving Tensor programming capabilities based on Layout.
  • High-level API: Abstraction and encapsulation of common algorithms based on single cores, providing implementations of public algorithms.
  • Operator Template Library: Complete implementation references for operators based on templates, simplifying Tiling development and supporting user custom extensions.
  • Python Frontend PyAsc: PyAsc provides complete low-level chip programming capabilities based on Python frontend, and will gradually improve Tensor programming capabilities based on Layout, adding SIMT programming and other capabilities to achieve high-performance operator development based on Python interfaces.

How to Choose Multi-level APIs for Operator Development

  • Based on C/C++ language development: For details, see Ascend C Multi-level API Selection Guide
  • Based on Python language development, supporting complete programming capabilities to achieve ultimate performance: Recommend Ascend C Python frontend PyAsc
  • Based on Python language development, quick development verification, ease of use priority: Recommend PyPTO

🔍 Directory Structure

This repository mainly contains Ascend C programming APIs and necessary cmake build scripts, which are the core modules required for operator development. The directory structure is as follows:

├── cmake                               # Ascend C build source code
├── docs                                # Project documentation
├── examples                            # Ascend C API sample projects
├── impl                                # Ascend C API implementation source code
│   ├── adv_api                         # Ascend C high-level API implementation source code
│   ├── aicpu_api                       # Ascend C AI CPU API implementation source code
│   ├── basic_api                       # Ascend C basic API implementation source code
│   ├── c_api                           # Ascend C language extension layer C API implementation source code
│   ├── simt_api                        # Ascend C SIMT API implementation source code
│   ├── tensor_api                      # Ascend C TENSOR API implementation source code
│   └── utils                           # Ascend C utility implementation source code
├── include                             # Ascend C API declaration source code
│   ├── adv_api                         # Ascend C high-level API declaration source code
│   ├── aicpu_api                       # Ascend C AI CPU API declaration source code
│   ├── basic_api                       # Ascend C basic API declaration source code
│   ├── c_api                           # Ascend C language extension layer C API declaration source code
│   ├── simt_api                        # Ascend C SIMT API declaration source code
│   ├── tensor_api                      # Ascend C TENSOR API declaration source code
│   └── utils                           # Ascend C utility declaration source code
├── scripts                             # Packaging-related scripts
├── tests                               # Ascend C API UT test cases
└── tools                               # Ascend C tool source code

⚡️ Quick Start

If you want to quickly experience project build and operator sample execution, access the following documentation for simple tutorials.

  • Build and Compile: Introduces environment setup, compilation execution, local verification, and other operations.
  • Sample Execution: Provides operator development samples and introduces end-to-end sample execution methods.

🧰 clangd/IDE Support

  • Install clangd (recommend 15+, using Ubuntu operating system as an example) and VSCode plugin clangd

    sudo apt install -y clangd-15
    sudo update-alternatives --install /usr/bin/clangd clangd /usr/bin/clangd-15 100
    
  • Configure local VSCode settings.json (example)

    {
      "clangd.path": "/usr/bin/clangd",
      "clangd.arguments": [
          "--background-index=0",
          "--clang-tidy=0"
      ],
      "C_Cpp.intelliSenseEngine": "disabled"
    }
    
  • Configure .clangd in the project root directory (example). The complete .clangd file is provided in this directory. CANN header file directories need to match actual installation locations. The default in .clangd is /usr/local/Ascend.

    If CANN is installed in a non-default path, or if you need to switch the NPU architecture macro, source CANN set_env.sh first, then generate a local config from .clangd.in:

    source /path/to/cann/set_env.sh
    python3 scripts/setup_clangd.py --npu-arch 2201 --output .clangd.local
    

    ASCEND_HOME_PATH is set by set_env.sh, and the script uses this environment variable to generate the real CANN path. If it is not set, the script prompts you to source set_env.sh and retry. The generated file defaults to .clangd.local and does not overwrite the built-in .clangd. To make project-level clangd config take effect, copy it to .clangd as needed and restart clangd.

    CompileFlags:
      Add:
        - "-std=c++17"
        - "-stdlib=libstdc++"
        - "-D__NPU_ARCH__=2201"
        - "-DASCENDC_CPU_DEBUG=1"
        ...
    
    ---
    If:
      PathMatch: ".*\\.(asc|aicpu)$"
    CompileFlags:
      CompilationDatabase: None
      Add:
        - "-x"
        - "c++"
    Diagnostics:
      Suppress:
        - "attributes_not_allowed"
        - "decomp_decl_template"
        - "ignored-attributes"
        - "unknown_typename"
        - "undeclared_var_use"
        - "invalid_token_after_toplevel_declarant"
        - "missing_type_specifier"
        - "typename_nested_not_found"
        - "redefinition"
    
  • Restart clangd (VSCode: Command Palette -> "Clangd: Restart language server")

  • 💡 For any suggestions or improvements regarding ASC language syntax highlighting and code navigation support, community developers are welcome to provide feedback!