Beispiel #1
0
        /// <summary>
        /// A simple 1D kernel using math functions.
        /// The <see cref="IntrinsicMath"/> class contains intrinsic math functions that -
        /// in contrast to the default .Net Math class - work on both floats and doubles. Note that
        /// the /// <see cref="IntrinsicMath"/> class is supported on all accelerators.
        /// The CompileUnitFlags.FastMath flag can be used during the creation of the compile unit
        /// to enable fast math intrinsics.
        /// Note that the full power of math functions on all accelerators is available via the
        /// Algorithms library (see ILGPU.Algorithms.Math sample).
        /// </summary>
        /// <param name="index">The current thread index.</param>
        /// <param name="dataView">The view pointing to our memory buffer.</param>
        /// <param name="constant">A uniform constant.</param>
        static void MathKernel(
            Index1D index,                  // The global thread index (1D in this case)
            ArrayView <float> singleView,   // A view of floats to store float results from GPUMath
            ArrayView <double> doubleView,  // A view of doubles to store double results from GPUMath
            ArrayView <double> doubleView2) // A view of doubles to store double results from .Net Math
        {
            // Note the different returns type of GPUMath.Sqrt and Math.Sqrt.
            singleView[index] = IntrinsicMath.Abs(index);
            doubleView[index] = IntrinsicMath.Clamp((double)(int)index, 0.0, 12.0);

            // Note that use can safely use functions from the Math class as long as they have a counterpart
            // in the IntrinsicMath class.
            doubleView2[index] = Math.Min(0.2, index);
        }
Beispiel #2
0
 public static ulong Clamp(ulong value, ulong min, ulong max) =>
 IntrinsicMath.Clamp(value, min, max);
Beispiel #3
0
 public static ushort Clamp(ushort value, ushort min, ushort max) =>
 IntrinsicMath.Clamp(value, min, max);
Beispiel #4
0
 public static uint Clamp(uint value, uint min, uint max) =>
 IntrinsicMath.Clamp(value, min, max);
Beispiel #5
0
 public static byte Clamp(byte value, byte min, byte max) =>
 IntrinsicMath.Clamp(value, min, max);
Beispiel #6
0
 public static long Clamp(long value, long min, long max) =>
 IntrinsicMath.Clamp(value, min, max);
Beispiel #7
0
 public static int Clamp(int value, int min, int max) =>
 IntrinsicMath.Clamp(value, min, max);
Beispiel #8
0
 public static float Clamp(float value, float min, float max) =>
 IntrinsicMath.Clamp(value, min, max);
Beispiel #9
0
 public static double Clamp(double value, double min, double max) =>
 IntrinsicMath.Clamp(value, min, max);