c# - Trying to get pointers working -
i've never needed use pointers in c# before, however, library i'm using requires method parameters passed pointers. library allows usage of simd instruction sets.
to test how use library, i've attempted write method uses simd calculate cosine value of elements of array in 1 go.
this i've got:
double[] valuestocalculate = new double[max_size]; double[] calculatedcosines = new double[max_size]; long result; result = calculatecosinearray(valuestocalculate, calculatedcosines); public static long calculatecosinearraysimd(double[] array, double[] result) { stopwatch stopwatch = new stopwatch(); stopwatch.start(); (int = 0; < array.length; i++) { yeppp.math.cos_v64f_v64f(*array, result, max_size); } stopwatch.stop(); return stopwatch.elapsedmilliseconds; }
however, these errors:
the best overloaded method match 'yeppp.math.cos_v64f_v64f(double*, double*, int)' has invalid arguments argument 1: cannot convert 'double[]' 'double*' * or -> operator must applied pointer argument 2: cannot convert 'double[]' 'double*'
how pointers work in code? again, first time pointers has come while i've been using c#.
the methods in yeppp! library have 2 overloads: 1 takes array + offset , takes pointers (e.g. if want call them stackalloc'ed memory). e.g. cosine computation yeppp! offers 2 overloads:
yeppp.math.cos_v64f_v64f(double[] xarray, int xoffset, double[] yarray, int yoffset, int length)
operates on array argumentsyeppp.math.cos_v64f_v64f(double* x, double* y, int length)
operates on pointer arguments
thus, example should rewritten as:
double[] valuestocalculate = new double[max_size]; double[] calculatedcosines = new double[max_size]; long result; result = calculatecosinearray(valuestocalculate, calculatedcosines); public static long calculatecosinearraysimd(double[] array, double[] result) { stopwatch stopwatch = new stopwatch(); stopwatch.start(); yeppp.math.cos_v64f_v64f(array, 0, result, 0, max_size); stopwatch.stop(); return stopwatch.elapsedmilliseconds; }
note 1 call per array required (even if used pointers).
Comments
Post a Comment