Intrinsic编译指导
Intrinsic编译是指将内置函数(intrinsic function)转换为机器代码的过程。内置函数是一些在编程语言中预定义的函数,它们通常用于执行一些底层操作或者优化特定的任务。在编译过程中,编译器会将这些内置函数转换为对应的机器指令,以便在运行时能够更高效地执行。ARM Intrinsic函数参考:https://developer.arm.com/architectures/instruction-sets/intrinsics
查看硬件信息
通过 lscpu 命令可以查看硬件的 flag 信息。
$lscpu | grep sme
预期输出:
Flags: fp asimd evtstrm aes pmull sha1 sha2 crc32 atomics fphp asimdhp cpuid asimdrdm jscvt fcma lrcpc dcpop sha3 sm3 sm4 asimddp sha512 sve asimdfhm dit uscat ilrcpc flagm ssbs sb paca pacg dcpodp sve2 sveaes svepmull svebitperm svesha3 svesm4 flagm2 frint svei8mm svebf16 i8mm bf16 dgh ecv afp rpres sme smef64f64 smei8i32 smef16f32 smeb16f32 smef32f32 smefa64 wfxt
查看硬件矩阵算力向量长度
查看 /proc/sys/abi/sme_default_vector_length 信息确认当前硬件的默认向量长度。
$cat /proc/sys/abi/sme_default_vector_length 64
如果向量长度不为64则需要修改:
$echo 64 > /proc/sys/abi/sme_default_vector_length
如果执行代码后,向量变量的后面几个元素结果不正确,可能说明向量长度信息不正确。
编译选项
通过编译选项传入 ARM arch 目标平台信息使能矩阵算力特性。
例如: -mcpu=native 等
代码示例
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;
}
父主题: 鲲鹏920专业版矩阵算力编程