CANN/AsNumpy架构设计
Architecture【免费下载链接】asnumpy哈尔滨工业大学计算学部苏统华、王甜甜老师团队联合华为CANN团队开发的华为昇腾NPU原生Numpy仓库项目地址: https://gitcode.com/cann/asnumpyBack to READMEThis document describes the internal architecture of AsNumpy, including the three-layer design, the coreNPUArraydata structure, the API module layout, and the NPU extension strategy via OpenBOAT.Three-Layer ArchitectureAsNumpy is built on three layers that cleanly separate concerns:------------------------------------------ | Python Frontend (asnumpy/*.py) | | - __init__.py 122 exported symbols | | - array.py array creation (10 fn) | | - math.py math ops (80 fn) | | - linalg/ linear algebra | | - random/ random sampling | | - logic.py logic functions (16 fn) | | - nn.py neural network (softmax) | | - statistics.py statistics (mean) | ------------------------------------------ | pybind11 binding layer (python/*.cpp) PYBIND11_MODULE(asnumpy_core, ...) | ------------------------------------------ | C Core (src/, include/) | | - NPUArray core data structure | | - namespace asnumpy operator impls | | - Ascend ACL / ACLNN operator wrappers | | - CANN Runtime device management | ------------------------------------------ | Huawei CANN (ascendcl, runtime, nnopbase, opapi) | ------------------------------------------ | Ascend NPU Hardware (910B) | ------------------------------------------NPUArray DesignNPUArrayis the core data structure of AsNumpy. It is designed around three principles:CompatibilityNPUArrayexposes the same interface asnumpy.ndarrayat the Python level. Functions are named identically (add,multiply,matmul, …) so existing NumPy code can be migrated by changing the import and adding data transfer calls.EncapsulationInternally,NPUArrayholds:dtype— element type (aclDtype)shape— dimension sizesstrides— memory layouttensorPtr— pointer to the underlyingaclTensordevicePtr(private) — raw device memory address, exposed viadevice_address()Users never interact with these fields directly; the Python layer presents a clean ndarray-like interface.Resource ManagementNPUArrayfollows RAII: the destructor automatically callsaclDestroyTensorandaclrtFree, eliminating manual memory management. All four C value semantics are implemented (copy constructor, move constructor, copy assignment, move assignment).Data transfer:FromNumpy— usesACL_MEMCPY_HOST_TO_DEVICEToNumpy— usesACL_MEMCPY_DEVICE_TO_HOST;float16/BF16require specialuint16_tunpackingAPI ArchitectureAsNumpys API is divided intofunctional modulesandfoundation modules:Functional modulescover the primary scientific computing domains:ModulePythonC namespaceStatusMath (arithmetic, trig, exp, log)math.pyasnumpy::CompleteLinear algebralinalg/globalIn progressRandom samplingrandom/globalIn progressLogic functionslogic.pyasnumpy::CompleteArray creationarray.pyglobalCompleteSortingsorting.pyglobalCompleteNeural networknn.pyasnumpy::Complete (softmax)Statisticsstatistics.pyasnumpy::Complete (mean)I/Oio.pydelegated to NumPyCompleteFoundation modulessupport the functional layer:ModuleRoleNPUArray(src/utils/)Core data structureCANN driver(src/cann/)Device initialization and lifecycledtypes(src/dtypes/)Data type registrationpybind11 bindings(python/)Python-C interfaceNPU Extension ModuleCANNs built-in operators are primarily designed for deep learning (training and inference). AsNumpy targets general scientific computing — data analysis, numerical methods, signal processing — which requires a broader operator set than CANN alone provides.The gap:CANN built-in operators cannot cover all of NumPys API surface.The strategy:Wrap existing CANN built-in operators directlyDevelop missing operators manually (Ascend C)Supplement with the OpenBOAT open-source operator libraryThe value:This three-pronged approach progressively closes the compatibility gap toward the goal of covering the top 100 most-used NumPy APIs by v1.0.OpenBOATOpenBOATis an open-source Ascend C operator library built and maintained by theAISS Group, School of Computer Science, Harbin Institute of Technology(led by Prof. Su Tonghua).AttributeDetailProject URLhttps://link.gitcode.com/i/d43a06448f82629e470dfd500d8114bdTeamAISS Group, HIT — Prof. Su TonghuaTechnologyHuawei Ascend C programming languageRole in AsNumpyProvides operator implementations not covered by CANN built-ins, enabling broader NumPy API compatibilityAsNumpy and OpenBOAT are developed by the same research group, ensuring tight integration and coordinated roadmap planning.【免费下载链接】asnumpy哈尔滨工业大学计算学部苏统华、王甜甜老师团队联合华为CANN团队开发的华为昇腾NPU原生Numpy仓库项目地址: https://gitcode.com/cann/asnumpy创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考