---
title: ARM Intrinsic使能矩阵计算加速
description: "Intrinsic编译是指将内置函数（intrinsic function）转换为机器代码的过程。内置函数是一些在编程语言中预定义的函数，它们通常用于执行一些底层操作或者优化特定的任务。在编译过程中，编译器会将这些内置函数转换为对应的机器指令，以便在运行时能够更高效地执行。同样地，ARM也提供了一组编译器内置的Intrinsic 函数，以便C/C++程序使能矩阵算力。"
url: https://www.hikunpeng.com/document/detail/zh/kunpenghpcs/KunpengDeveloper/usermanual/topic_0000002535616010.html
sourcePath: /source/zh/kunpenghpcs/KunpengDeveloper/usermanual/topic_0000002535616010.html
indexId: 7c4cc2519d53f9ad764413771d99774b4ebba41f2c65867239ff484c9bfc100078
---
# ARM Intrinsic使能矩阵计算加速

Intrinsic编译是指将内置函数（intrinsic function）转换为机器代码的过程。内置函数是一些在编程语言中预定义的函数，它们通常用于执行一些底层操作或者优化特定的任务。在编译过程中，编译器会将这些内置函数转换为对应的机器指令，以便在运行时能够更高效地执行。同样地，ARM也提供了一组编译器内置的Intrinsic 函数，以便C/C++程序使能矩阵算力。

常用的矩阵算力使能的Intrinsic 函数可以分为4类，分别是2D 累加器ZA清空函数、READ函数、ADDHA/ADDVA函数以及MOPA/MOPS函数。具体的ARM Intrinsic函数可以在ARM官方查阅：《ARM Intrinsics》(https://developer.arm.com/architectures/instruction-sets/intrinsics)，也可以参考ARM提供的 C/C++ 语言扩展标准文档：《 Arm C Language Extensions (ACLE)》(https://developer.arm.com/architectures/system-architectures/software-standards/acle)。

以下为一个简单的使用Arm intrinsic实现的一次单精度浮点数据向量外积操作示例：

```
void mopa(svfloat32_t v1, const float *src) __arm_streaming     // This function enters and returns in streaming-SVE mode.
{
svzero_za();                                                // Initialize ZA by zeroing all tiles.
svbool_t p1 = svwhilelt_b32(0, 16);                         // Initialize predicate p1 with every element is active.
svbool_t p2 = svwhilelt_b32(0, 16);                         // Initialize predicate p2 with every element is active.
svfloat32_t v2 = svld1_f32(p2, src);                        // Load vector v2.
svmopa_za32_m(/*tile*/0, p1, p2, v1, v2);                   // Sum of outer products and accumulate in ZA tile 0.
for (int t = 0; t < 16; t++) {                              // write the ZA0 to output.
svst1_hor_za32(0, t, p1, &output[t * 16]);              // svst1_hor_za32("0 for ZA0", "hor", p, "target addr");
}
return;
}
```

更多不同数据类型的Arm intrinsic实现可以参考hpckit-sample(https://gitcode.com/kunpengcompute/hpckit-sample)开源仓中综合用例目录下的Arm intrinsic用例。
