System.Numerics.Vector.GreaterThan 和 bool 结果
System.Numerics.Vector.GreaterThan and bool results
我正在尝试转换一些可以使用 SIMD 指令优化的现有代码。有一个掩码生成代码,我正在测试转换后我可以从 SIMD 中获得多少性能,下面是我用来分析它的过于简化的块。
Random r = new Random();
var random1 = new double[65536000*4];
var random2 = new double[random1.Length];
var result = new bool[random1.Length];
for (i = 0; i < random1.Length; i++)
{
random1[i] = r.Next();
random2[i] = r.Next();
}
var longRes = new long[random1.Length];
for (int i = 0; i < result.Length; i += Vector<double>.Count)
{
Vector<double> v1 = new Vector<double>(random1, i);
Vector<double> v2 = new Vector<double>(random2, i);
Vector<long> res = System.Numerics.Vector.GreaterThan(v1, v2);
res.CopyTo(longRes, i);
}
有没有一种技术可以有效地将结果 res
放入 result
数组?
本来我以为我可以忍受Vector<long>
并把面具留在long[]
,但我意识到这也许是不可行的。
正如对原始问题的评论,我意识到 System.Numberics.Vector.GreaterThan
和其他类似方法如 LesserThan
等是为与 ConditionalSelect()
一起使用而设计的。
在我的例子中,我试图生成一个 bool
数组,该数组表示稍后在 API 中使用的图像掩码,并且将 long 转换为 bool 是不可行的。
换句话说,这些比较方法不适合一般用途。
我正在尝试转换一些可以使用 SIMD 指令优化的现有代码。有一个掩码生成代码,我正在测试转换后我可以从 SIMD 中获得多少性能,下面是我用来分析它的过于简化的块。
Random r = new Random();
var random1 = new double[65536000*4];
var random2 = new double[random1.Length];
var result = new bool[random1.Length];
for (i = 0; i < random1.Length; i++)
{
random1[i] = r.Next();
random2[i] = r.Next();
}
var longRes = new long[random1.Length];
for (int i = 0; i < result.Length; i += Vector<double>.Count)
{
Vector<double> v1 = new Vector<double>(random1, i);
Vector<double> v2 = new Vector<double>(random2, i);
Vector<long> res = System.Numerics.Vector.GreaterThan(v1, v2);
res.CopyTo(longRes, i);
}
有没有一种技术可以有效地将结果 res
放入 result
数组?
本来我以为我可以忍受Vector<long>
并把面具留在long[]
,但我意识到这也许是不可行的。
正如对原始问题的评论,我意识到 System.Numberics.Vector.GreaterThan
和其他类似方法如 LesserThan
等是为与 ConditionalSelect()
一起使用而设计的。
在我的例子中,我试图生成一个 bool
数组,该数组表示稍后在 API 中使用的图像掩码,并且将 long 转换为 bool 是不可行的。
换句话说,这些比较方法不适合一般用途。