【发布时间】:2021-05-27 06:28:09
【问题描述】:
我正在编写代码,它将减去两个数组中的相应字节并计算超过给定阈值的结果字节数。 AFAIU,它确实会从 .NET SIMD 中受益,但是当我在 Raspberry Pi 4 上编译 C# 时,System.Numerics.Vector.IsHardwareAccelerated 返回 false。
我的dotnet版本是3.1.406,我加了
<PropertyGroup>
<Optimize>true</Optimize>
</PropertyGroup>
到 csproj 并运行 release 配置。
有什么方法可以在 Raspberry Pi 4 上利用 .NET 中的 SIMD 支持?也许使用 .NET 5?
更新 我安装了 .NET 5 并尝试了 .NET Intrinsics,但都不支持:
Console.WriteLine(System.Runtime.Intrinsics.Arm.AdvSimd.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Aes.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.ArmBase.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Crc32.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Dp.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Rdm.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Sha1.IsSupported); //false
Console.WriteLine(System.Runtime.Intrinsics.Arm.Sha256.IsSupported); //false
我使用的是 32 位 Raspbian(Debian 衍生产品),我是否需要 64 位版本才能使用它?
附:澄清一下,在纯 C# 中,算法如下所示:
public static int ScalarTest(byte[] lhs, byte[] rhs)
{
var result = 0;
for (int index = 0; index < lhs.Length; index++)
{
var a = lhs[index];
var b = rhs[index];
if (b > a)
{
(b, a) = (a, b);
}
result += ((a - b) >= 16) ? 1 : 0;
}
return result;
}
【问题讨论】:
-
"..减去相应字节..." 两个相应字节的减法总是为零,对吧? ????
-
@JHBonarius 我不是这个最好的术语,我的意思是
arr1[i] - arr2[i]。我将添加 C# 循环实现来解释我的意思。
标签: c# raspberry-pi arm simd neon