我正在编写一段代码,用于从两个数组中相应的字节进行减法运算,并计算超过给定阈值的结果字节数。据我所知,使用.NET SIMD会带来很大好处,但当我在Raspberry Pi 4上编译C#时,System.Numerics.Vector.IsHardwareAccelerated
返回false。
我的dotnet
版本是3.1.406,我已经添加了
<PropertyGroup>
<Optimize>true</Optimize>
</PropertyGroup>
将release
配置添加到csproj并运行。
有没有办法在树莓派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;
}
arr1[i] - arr2[i]
。我会添加C#循环实现来解释我的意思。 - Ivan Koshelev