Example #1
0
 public CpuMathUtilsUnitTests()
 {
     // Padded array whose length is a multiple of 4
     float[] testArray1 = new float[8] {
         1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f
     };
     // Unpadded array whose length is not a multiple of 4.
     float[] testArray2 = new float[7] {
         1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f
     };
     testArrays     = new float[][] { testArray1, testArray2 };
     testIndexArray = new int[4] {
         0, 2, 5, 6
     };
     comparer = new FloatEqualityComparer();
 }
Example #2
0
        public CpuMathUtilsUnitTests()
        {
            // Padded array whose length is a multiple of 4
            float[] testArray1 = new float[8] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f
            };
            // Unpadded array whose length is not a multiple of 4.
            float[] testArray2 = new float[7] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f
            };
            testArrays     = new float[][] { testArray1, testArray2 };
            testIndexArray = new int[4] {
                0, 2, 5, 6
            };
            comparer = new FloatEqualityComparer();

            // Padded matrices whose dimensions are multiples of 4
            float[] testMatrix1 = new float[4 * 4] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f
            };
            float[] testMatrix2 = new float[4 * 8];

            for (int i = 0; i < testMatrix2.Length; i++)
            {
                testMatrix2[i] = i + 1;
            }

            AlignedArray testMatrixAligned1 = new AlignedArray(4 * 4, SseCbAlign);
            AlignedArray testMatrixAligned2 = new AlignedArray(4 * 8, SseCbAlign);

            testMatrixAligned1.CopyFrom(testMatrix1, 0, testMatrix1.Length);
            testMatrixAligned2.CopyFrom(testMatrix2, 0, testMatrix2.Length);

            testMatrices = new AlignedArray[] { testMatrixAligned1, testMatrixAligned2 };

            // Padded source vectors whose dimensions are multiples of 4
            float[] testSrcVector1 = new float[4] {
                1f, 2f, 3f, 4f
            };
            float[] testSrcVector2 = new float[8] {
                1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f
            };

            AlignedArray testSrcVectorAligned1 = new AlignedArray(4, SseCbAlign);
            AlignedArray testSrcVectorAligned2 = new AlignedArray(8, SseCbAlign);

            testSrcVectorAligned1.CopyFrom(testSrcVector1, 0, testSrcVector1.Length);
            testSrcVectorAligned2.CopyFrom(testSrcVector2, 0, testSrcVector2.Length);

            testSrcVectors = new AlignedArray[] { testSrcVectorAligned1, testSrcVectorAligned2 };

            // Padded destination vectors whose dimensions are multiples of 4
            float[] testDstVector1 = new float[4] {
                0f, 1f, 2f, 3f
            };
            float[] testDstVector2 = new float[8] {
                0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f
            };

            AlignedArray testDstVectorAligned1 = new AlignedArray(4, SseCbAlign);
            AlignedArray testDstVectorAligned2 = new AlignedArray(8, SseCbAlign);

            testDstVectorAligned1.CopyFrom(testDstVector1, 0, testDstVector1.Length);
            testDstVectorAligned2.CopyFrom(testDstVector2, 0, testDstVector2.Length);

            testDstVectors = new AlignedArray[] { testDstVectorAligned1, testDstVectorAligned2 };
        }
Example #3
0
        static CpuMathUtilsUnitTests()
        {
            // Padded array whose length is a multiple of 4
            float[] testArray1 = new float[16] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f, 1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f
            };
            // Unpadded array whose length is not a multiple of 4.
            float[] testArray2 = new float[15] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f, 1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f
            };
            _testArrays     = new float[][] { testArray1, testArray2 };
            _testIndexArray = new int[9] {
                0, 2, 5, 6, 8, 11, 12, 13, 14
            };
            _comparer       = new FloatEqualityComparer();
            _matMulComparer = new FloatEqualityComparerForMatMul();

            // Padded matrices whose dimensions are multiples of 8
            float[] testMatrix1 = new float[8 * 8] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f
            };
            float[] testMatrix2 = new float[8 * 16];

            for (int i = 0; i < testMatrix2.Length; i++)
            {
                testMatrix2[i] = i + 1;
            }

            AlignedArray testMatrixAligned1 = new AlignedArray(8 * 8, _vectorAlignment);
            AlignedArray testMatrixAligned2 = new AlignedArray(8 * 16, _vectorAlignment);

            testMatrixAligned1.CopyFrom(testMatrix1);
            testMatrixAligned2.CopyFrom(testMatrix2);

            _testMatrices = new AlignedArray[] { testMatrixAligned1, testMatrixAligned2 };

            // Padded source vectors whose dimensions are multiples of 8
            float[] testSrcVector1 = new float[8] {
                1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f
            };
            float[] testSrcVector2 = new float[16] {
                1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f, 13f, 14f, 15f, 16f
            };

            AlignedArray testSrcVectorAligned1 = new AlignedArray(8, _vectorAlignment);
            AlignedArray testSrcVectorAligned2 = new AlignedArray(16, _vectorAlignment);

            testSrcVectorAligned1.CopyFrom(testSrcVector1);
            testSrcVectorAligned2.CopyFrom(testSrcVector2);

            _testSrcVectors = new AlignedArray[] { testSrcVectorAligned1, testSrcVectorAligned2 };

            // Padded destination vectors whose dimensions are multiples of 8
            float[] testDstVector1 = new float[8] {
                0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f
            };
            float[] testDstVector2 = new float[16] {
                0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f, 13f, 14f, 15f
            };

            AlignedArray testDstVectorAligned1 = new AlignedArray(8, _vectorAlignment);
            AlignedArray testDstVectorAligned2 = new AlignedArray(16, _vectorAlignment);

            testDstVectorAligned1.CopyFrom(testDstVector1);
            testDstVectorAligned2.CopyFrom(testDstVector2);

            _testDstVectors = new AlignedArray[] { testDstVectorAligned1, testDstVectorAligned2 };

#if NETCOREAPP3_0
            DisableAvxEnvironmentVariables = new Dictionary <string, string>()
            {
                { disableAvx, "0" }
            };

            DisableAvxAndSseEnvironmentVariables = new Dictionary <string, string>()
            {
                { disableAvx, "0" },
                { disableSse, "0" }
            };
#endif
        }
Example #4
0
        public CpuMathUtilsUnitTests()
        {
            // Padded array whose length is a multiple of 4
            float[] testArray1 = new float[16] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f, 1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f
            };
            // Unpadded array whose length is not a multiple of 4.
            float[] testArray2 = new float[15] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f, 1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f
            };
            _testArrays     = new float[][] { testArray1, testArray2 };
            _testIndexArray = new int[9] {
                0, 2, 5, 6, 8, 11, 12, 13, 14
            };
            _comparer       = new FloatEqualityComparer();
            _matMulComparer = new FloatEqualityComparerForMatMul();

            // Padded matrices whose dimensions are multiples of 8
            float[] testMatrix1 = new float[8 * 8] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f
            };
            float[] testMatrix2 = new float[8 * 16];

            for (int i = 0; i < testMatrix2.Length; i++)
            {
                testMatrix2[i] = i + 1;
            }

            AlignedArray testMatrixAligned1 = new AlignedArray(8 * 8, _vectorAlignment);
            AlignedArray testMatrixAligned2 = new AlignedArray(8 * 16, _vectorAlignment);

            testMatrixAligned1.CopyFrom(testMatrix1, 0, testMatrix1.Length);
            testMatrixAligned2.CopyFrom(testMatrix2, 0, testMatrix2.Length);

            _testMatrices = new AlignedArray[] { testMatrixAligned1, testMatrixAligned2 };

            // Padded source vectors whose dimensions are multiples of 8
            float[] testSrcVector1 = new float[8] {
                1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f
            };
            float[] testSrcVector2 = new float[16] {
                1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f, 13f, 14f, 15f, 16f
            };

            AlignedArray testSrcVectorAligned1 = new AlignedArray(8, _vectorAlignment);
            AlignedArray testSrcVectorAligned2 = new AlignedArray(16, _vectorAlignment);

            testSrcVectorAligned1.CopyFrom(testSrcVector1, 0, testSrcVector1.Length);
            testSrcVectorAligned2.CopyFrom(testSrcVector2, 0, testSrcVector2.Length);

            _testSrcVectors = new AlignedArray[] { testSrcVectorAligned1, testSrcVectorAligned2 };

            // Padded destination vectors whose dimensions are multiples of 8
            float[] testDstVector1 = new float[8] {
                0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f
            };
            float[] testDstVector2 = new float[16] {
                0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f, 13f, 14f, 15f
            };

            AlignedArray testDstVectorAligned1 = new AlignedArray(8, _vectorAlignment);
            AlignedArray testDstVectorAligned2 = new AlignedArray(16, _vectorAlignment);

            testDstVectorAligned1.CopyFrom(testDstVector1, 0, testDstVector1.Length);
            testDstVectorAligned2.CopyFrom(testDstVector2, 0, testDstVector2.Length);

            _testDstVectors = new AlignedArray[] { testDstVectorAligned1, testDstVectorAligned2 };
        }
Example #5
0
        static CpuMathUtilsUnitTests()
        {
            // Padded array whose length is a multiple of 4
            float[] testArray1 = new float[32] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f, 1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f, 13f, 14f, 15f, 16f
            };
            // Unpadded array whose length is not a multiple of 4.
            float[] testArray2 = new float[30] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f, 1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f, 13f, 14f, 15f
            };
            // Small Input Size Array
            float[] testArray3 = new float[15] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f, 1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f
            };
            _testArrays     = new float[][] { testArray1, testArray2, testArray3 };
            _testIndexArray = new int[18] {
                0, 2, 5, 6, 8, 11, 12, 13, 14, 16, 18, 21, 22, 24, 26, 27, 28, 29
            };
            _comparer       = new FloatEqualityComparer();
            _matMulComparer = new FloatEqualityComparerForMatMul();

            // Padded matrices whose dimensions are multiples of 8
            float[] testMatrix1 = new float[8 * 8] {
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f,
                1.96f, -2.38f, -9.76f, 13.84f, -106.37f, -26.93f, 32.45f, 3.29f
            };
            float[] testMatrix2 = new float[8 * 16];

            for (int i = 0; i < testMatrix2.Length; i++)
            {
                testMatrix2[i] = i + 1;
            }

            AlignedArray testMatrixAligned1 = new AlignedArray(8 * 8, _vectorAlignment);
            AlignedArray testMatrixAligned2 = new AlignedArray(8 * 16, _vectorAlignment);

            testMatrixAligned1.CopyFrom(testMatrix1);
            testMatrixAligned2.CopyFrom(testMatrix2);

            _testMatrices = new AlignedArray[] { testMatrixAligned1, testMatrixAligned2 };

            // Padded source vectors whose dimensions are multiples of 8
            float[] testSrcVector1 = new float[8] {
                1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f
            };
            float[] testSrcVector2 = new float[16] {
                1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f, 13f, 14f, 15f, 16f
            };

            AlignedArray testSrcVectorAligned1 = new AlignedArray(8, _vectorAlignment);
            AlignedArray testSrcVectorAligned2 = new AlignedArray(16, _vectorAlignment);

            testSrcVectorAligned1.CopyFrom(testSrcVector1);
            testSrcVectorAligned2.CopyFrom(testSrcVector2);

            _testSrcVectors = new AlignedArray[] { testSrcVectorAligned1, testSrcVectorAligned2 };

            // Padded destination vectors whose dimensions are multiples of 8
            float[] testDstVector1 = new float[8] {
                0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f
            };
            float[] testDstVector2 = new float[16] {
                0f, 1f, 2f, 3f, 4f, 5f, 6f, 7f, 8f, 9f, 10f, 11f, 12f, 13f, 14f, 15f
            };

            AlignedArray testDstVectorAligned1 = new AlignedArray(8, _vectorAlignment);
            AlignedArray testDstVectorAligned2 = new AlignedArray(16, _vectorAlignment);

            testDstVectorAligned1.CopyFrom(testDstVector1);
            testDstVectorAligned2.CopyFrom(testDstVector2);

            _testDstVectors = new AlignedArray[] { testDstVectorAligned1, testDstVectorAligned2 };

            if ((SkipAvxSse || IsNetCore) && !IsNetCore2OrOlder)
            {
                _disableAvxEnvironmentVariables = new Dictionary <string, string>()
                {
                    { _disableAvx, "0" }
                };

                _disableAvxAndSseEnvironmentVariables = new Dictionary <string, string>()
                {
                    { _disableAvx, "0" },
                    { _disableSse, "0" }
                };
            }
        }