OK, so we did the “Super-super fast point inclusion” thing, but now I need to find the fastest code for converting a List(Of Point3d)
to a “blittable” Array (being compatible with Gpu processing).
The follwowing code is way too slow in copying the a List(Of Point3d) to blittable arrays. So how is the array handled in the fastest possible way with .NET? (remake from first row until gpu.For(...)
)
[GpuManaged]
public Point3d GPU_SolveInstance()
{
// Prepare Point list as X, Y and Z arrays instead of Point List.
int Cnt = InPts.Count;
double[] x_arr = new double[Cnt];
double[] y_arr = new double[Cnt];
double[] z_arr = new double[Cnt];
// Copy to (blittable) Array
int i = 0;
foreach (Point3d pt in m_Pts)
{
x_arr[i] = pt.X;
y_arr[i] = pt.Y;
z_arr[i] = pt.Z;
i += 1;
}
double x_tmp = 0;
double y_tmp = 0;
double z_tmp = 0;
// ######################################
// Below is where blittable types matters, and this
// code compiles and runs fine, but slow.
// So, better/faster overall array handling is wanted :
// Add all axis values
Action<int> op = (j =>
{
x_tmp += x_arr[j];
y_tmp += y_arr[j];
z_tmp += z_arr[j];
});
gpu.For(0, Cnt, op);
// ##############################
// Average axis values
Point3d cpt = new Point3d();
cpt.X = x_tmp / Cnt;
cpt.Y = y_tmp / Cnt;
cpt.Z = z_tmp / Cnt;
return cpt;
}
This is BTW one of the nightmares with using a new language - learning the benefits and performance of different data types and processing.
// Rolf