asc-devkit:基于 Ascend C 的算子开发工具包项目

本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言,原生支持C和C++标准规范,主要由类库和语言扩展层构成,提供多层级API,满足多维场景算子开发诉求。

Branch11Tags7

Ascend C

Multi-level API built on C/C++, providing complete chip programming capabilities for极致performance

community repo examples asc-tools license contributing SIG

🔥Latest News

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

🚀 Key Features

📖 Documentation

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

🚀 Overview

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

Design Goals

Ascend C's design goals can be summarized as "high performance, completeness, ease of programming, debuggability, and compatibility". Through minimal extensions to C/C++ language standards, it supports both pointer-based C language development habits and Tensor-based C++ programming paradigm, seamlessly integrating with existing ecosystems while supporting efficient Ascend operator development and ensuring consistent development experience.

We adhere to the following core principles:

  • No silver bullet: Different scenarios have varying 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 for quick algorithm verification; experts can drill down for fine-tuning, leveraging complex interface features to fully exploit hardware potential.

API Levels

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

API Level Language Features Target Users Main Uses
Tpipe/Tque Framework Programming API C++ Tensor-based programming
Unified memory and synchronization management through Tpipe/Tque framework
Operator library developers Framework-based automatic synchronization and memory management for improved programming usability
Basic API C++ Tensor-based programming, providing C++ basic complete programming capabilities
Tensor allocation through MakeTensor/LocalMemoryAllocator, self-managed synchronization
Operator library developers Self-managed synchronization and memory
Matching C++ Tensor development habits for ultimate performance
Language Extension Layer
SIMD&SIMT API
C Pointer-based programming, providing C basic complete programming capabilities
Memory allocation through array [], self-managed synchronization
Operator library developers Self-managed synchronization and memory
Matching C language development habits for ultimate performance

In addition, Ascend C provides high-level API and operator template library to improve operator development efficiency.

API Level Target Users Main Uses
Operator Template Library (CATLASS/ATVOSS and so on) Algorithm developers Custom extensions based on typical operator implementations for specific scenario high-performance requirements
High-level API Algorithm developers Reusing common single-core algorithms for quick 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 computation interfaces, providing industry-consistent C language programming experience and complete chip programming capabilities. Atlas A2/A3 supports SIMD pure C interfaces; Ascend 950PR/Ascend 950DT will support industry-similar SIMT programming capabilities and SIMD/SIMT hybrid programming capabilities;
  • Basic API: Single-instruction abstracted C++ class library API, generally Tensor-based programming; gradually improving Tensor programming capabilities based on Layout;
  • High-level API: Abstraction and encapsulation based on single-core for common algorithms, providing implementations of public algorithms;
  • Operator Template Library: Complete implementation references for operators based on templates, simplifying Tiling development, supporting user-defined 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 for developing high-performance operators based on Python interfaces;

How to Choose Multi-level API for Operator Development

  • C/C++ language-based development: See Ascend C Multi-level API Selection Guide for details
  • Python language-based development, supporting complete programming capabilities for ultimate performance: Recommend Ascend C Python frontend PyAsc
  • Python language-based development, quick development verification, ease of use priority: Recommend PyPTO

🔍 Directory Structure

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

├── cmake                               # Ascend C build source code
├── docs                                # Project documentation introduction
├── 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
│   ├── experimental                    # Ascend C TENSOR API implementation source code
│   ├── simt_api                        # Ascend C SIMT API implementation source code
│   └── utils                           # Ascend C utility class 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
│   ├── experimental                    # Ascend C TENSOR API declaration source code
│   ├── simt_api                        # Ascend C SIMT API declaration source code
│   └── utils                           # Ascend C utility class declaration source code
├── scripts                             # Packaging related scripts
├── tests                               # Ascend C API UT cases
└── tools                               # Ascend C tool source code

⚡️ Quick Start

To quickly experience project build and operator sample execution, access the following documentation for simple tutorials.

  • Build and Compilation: Introduces environment setup, build 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 (recommended 15+, Ubuntu OS example) and VSCode plugin clangd

    sudo apt install -y clangd-15
    
  • 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 project root directory (example) Complete .clangd file is provided in this directory, where CANN header file directory needs to be replaced with actual installation location, default is /usr/local/Ascend in .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_type_name"
        - "undeclared_var_use"
        - "invalid_token_after_toplevel_declarator"
        - "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!

Introduction

本项目是CANN 推出的昇腾AI处理器专用的算子程序开发语言,原生支持C和C++标准规范,主要由类库和语言扩展层构成,提供多层级API,满足多维场景算子开发诉求。

Customize your domain