Exemplo n.º 1
0
        public void FillNativeArray()
        {
            SafeArray <T> nativeArray = GetValue <SafeArray <T> >("nativeArray");
            T             fill        = GetValue <T>("fill");

            nativeArray.Fill(fill);
        }
Exemplo n.º 2
0
        public void ArithmeticMultiplyCleanup()
        {
            InfoThis();
            int index = GM <T> .Rng.Next(0, ArraySize);

            SafeArray <T> nativeArray = GetValue <SafeArray <T> >("nativeArray");

            T[] managedArray = GetValue <T[]>("managedArray");
            T   mul          = GetValue <T>("mul");
            T   fill         = GetValue <T>("fill");
            T   val          = GM <T> .Multiply(fill, mul);

            if (!nativeArray[index].Equals(val))
            {
                Log.WriteLineError($"Native array at index {index} is {nativeArray[index]} not {val}.");
                throw new Exception();
            }
            else if (!managedArray[index].Equals(val))
            {
                Log.WriteLineError($"Managed array at index {index} is {managedArray[index]} not {val}.");
                throw new Exception();
            }
            managedArray = null;
            nativeArray.Release();
            RemoveValue("managedArray");
            RemoveValue("nativeArray");
            RemoveValue("fill");
            RemoveValue("mul");
        }
Exemplo n.º 3
0
 public UDTTests()
 {
     Employees = new SafeArray <TestUDT>(1024 * 1024);
     for (int i = 0; i < Employees.Length; i++)
     {
         Employees[i] = TestUDT.MakeTestRecord(JemUtil.Rng);
     }
 }
Exemplo n.º 4
0
        public void ArithmeticMultiplyNativeArray()
        {
            T             mul   = GetValue <T>("mul");
            T             fill  = GetValue <T>("fill");
            SafeArray <T> array = GetValue <SafeArray <T> >("nativeArray");

            array.Fill(fill);
            array.VectorMultiply(mul);
        }
Exemplo n.º 5
0
 public void GlobalSetup()
 {
     managedArray = new T[ArraySize];
     nativeArray  = new SafeArray <T>(ArraySize);
     fill         = GetArrayFillValue();
     mul          = GetArrayMulValue();
     Console.WriteLine("Managed array fill value is {0}.", fill);
     Console.WriteLine("Multiply factor is {0}", mul);
 }
Exemplo n.º 6
0
        public void FragmentNativeHeap()
        {
            Info($"Dirty decay time: {Jem.GetMallCtlSInt64("arenas.dirty_decay_ms")} ms");
            int largeBlockSize = InitialLargeBlockSize;
            SafeArray <FixedBuffer <T> > smallBlocks = new SafeArray <FixedBuffer <T> >(LoopCount);
            int             i        = 0;
            FixedBuffer <T> bigBlock = default;

            try
            {
                for (i = 0; i < LoopCount; i++)
                {
                    bigBlock = new FixedBuffer <T>(largeBlockSize);
                    FixedBuffer <T> smallBlock = new FixedBuffer <T>(SmallBlockSize);
                    int             j          = JemUtil.Rng.Next(0, ArraySize);
                    T r = GM <T> .Random();

                    smallBlock[j]  = r;
                    smallBlocks[i] = smallBlock;
                    if (!smallBlocks[i][j].Equals(r))
                    {
                        throw new Exception($"Cannot validate small block at index {i}.");
                    }
                    if (!bigBlock.Free())
                    {
                        throw new Exception("Cannot free bigBlock.");
                    }
                    largeBlockSize = largeBlockSize + (1 * 1024 * 1024);
                }
                this.SetStatistic($"{nameof(FragmentNativeHeap)}_WorkingSet", JemUtil.PrintBytes(JemUtil.ProcessWorkingSet));
                this.SetStatistic($"{nameof(FragmentNativeHeap)}_JemResident", JemUtil.PrintBytes(Jem.ResidentBytes));
                this.SetStatistic($"{nameof(FragmentNativeHeap)}_PrivateMemory", JemUtil.PrintBytes(JemUtil.ProcessPrivateMemory));
                this.SetStatistic($"{nameof(FragmentNativeHeap)}_JemAllocated", JemUtil.PrintBytes(Jem.AllocatedBytes));
                foreach (FixedBuffer <T> b in smallBlocks)
                {
                    if (!b.Free())
                    {
                        throw new Exception($"Cannot free small block at index {i}.");
                    }
                }
            }
            catch (OutOfMemoryException)
            {
                Info(Jem.MallocStats);
                Error($"Out-of-Memory at index {i} with large block size {largeBlockSize}.");
                foreach (FixedBuffer <T> b in smallBlocks)
                {
                    b.Free();
                }
                throw;
            }
            finally
            {
                GC.Collect();
            }
        }
Exemplo n.º 7
0
        public void FillNativeArrayWithCreate()
        {
            SafeArray <T> nativeArray = new SafeArray <T>(ArraySize);
            T             fill        = GetValue <T>("fill");

            nativeArray.Fill(fill);
            nativeArray.Release();
            nativeArray.Close();
            nativeArray = null;
        }
Exemplo n.º 8
0
        public void CanVectorizedMultiply()
        {
            SafeArray <uint> a = new SafeArray <uint>(8, 1, 2, 3, 4, 5, 6, 7, 8);
            SafeArray <int>  b = new SafeArray <int>(8, 111, 22, 345, 40888, 3, 777, 99, 6);

            a.VectorMultiply(2);
            Assert.Equal(2u, a[0]);
            Assert.Equal(8u, a[3]);
            Assert.Equal(16u, a[7]);
            b.VectorMultiply(6);
            Assert.Equal(666, b[0]);
        }
Exemplo n.º 9
0
 static MethodDefinitionName MakeAssertNotNull()
 {
     return(MethodDefinitionName.FromTypeMethod(
                0,
                Type_Assert.Definition,
                true,
                "NotNull",
                SafeArray.Empty <string>(),
                SystemTypes.Void.SerializableName,
                new ParameterDefinitionName(SystemTypes.Object.SerializableName, "condition", 0, false, ParameterDirection.ByValueOrRef)
                ));
 }
Exemplo n.º 10
0
        public void CanConvertToVector()
        {
            SafeArray <uint> a = new SafeArray <uint>(8, 1, 11, 94, 5, 0, 0, 0, 8);
            Vector <uint>    v = a.AcquireAsSingleVector();

            Assert.Equal(a[0], v[0]);
            Assert.Equal(a[3], v[3]);
            Assert.Equal(a[7], v[7]);
            SafeArray <uint> a2 = new SafeArray <uint>(12, 11, 112, 594, 65, 0, 0, 0, 8, 14, 90, 2, 8);
            Vector <uint>    v2 = a2.AcquireSliceAsVector(2);

            Assert.Equal(594u, v2[0]);
        }
Exemplo n.º 11
0
        public void FillSetup()
        {
            InfoThis();
            T fill = GM <T> .Random();

            Info($"Array fill value is {fill}.");
            SetValue("fill", fill);
            SetValue("managedArray", new T[ArraySize]);
            SafeArray <T> nativeArray = new SafeArray <T>(ArraySize);

            nativeArray.Acquire();
            SetValue("nativeArray", new SafeArray <T>(ArraySize));
        }
Exemplo n.º 12
0
        private FixedBuffer <int> Mandelbrotv1Unmanaged()
        {
            SafeArray <Vector <float> > Vectors = new SafeArray <Vector <float> >(8);                                      // New unmanaged array of vectors
            FixedBuffer <int>           output  = new FixedBuffer <int>(((int)Mandelbrot_Width * (int)Mandelbrot_Height)); //New unmanaged array for bitmap output
            Span <float>   VectorSpan           = Vectors.GetSpan <float>();                                               //Lets us write to individual vector elements
            Span <Vector2> Vector2Span          = Vectors.GetSpan <Vector2>();                                             //Lets us read to individual vectors

            VectorSpan[0] = -2f;
            VectorSpan[1] = -1f;
            VectorSpan[2] = 1f;
            VectorSpan[3] = 1f;
            VectorSpan[4] = Mandelbrot_Width;
            VectorSpan[5] = Mandelbrot_Height;

            ref Vector2 C0 = ref Vector2Span[0];
Exemplo n.º 13
0
        public void CanConstructSafeArray()
        {
            SafeArray <int> a = new SafeArray <int>(500);

            a[1] = 1000;
            Assert.Equal(1000, a[1]);
            a.Acquire();
            Assert.Equal(1000, a[1]);
            a.Acquire();
            a.Release();
            Assert.Equal(1000, a[1]);
            a.Release();
            Assert.Equal(1000, a[1]);
            a.Close();
            Assert.True(a.IsClosed);
            Assert.Throws <ObjectDisposedException>(() => a[1] == 1000);
            //int r = a[(2,3)]
        }
Exemplo n.º 14
0
        public void CleanupFillArray()
        {
            Info(nameof(CleanupFillArray));
            T[]           managedArray = GetValue <T[]>("managedArray");
            SafeArray <T> nativeArray  = GetValue <SafeArray <T> >("nativeArray");
            T             fill         = GetValue <T>("fill");
            int           index        = GM <T> .Rng.Next(0, ArraySize);

            if (!nativeArray[index].Equals(managedArray[index]))
            {
                Log.WriteLineError($"Native array at index {index} is {nativeArray[index]} not {fill}.");
                throw new Exception();
            }
            nativeArray.Release();
            managedArray = null;
            RemoveValue("managedArray");
            RemoveValue("nativeArray");
            RemoveValue("fill");
        }
Exemplo n.º 15
0
        public void ArithmeticMutiplyGlobalSetup()
        {
            InfoThis();
            (T mul, T fill) = GM <T> .RandomMultiplyFactorAndValue();

            SafeArray <T> na = new SafeArray <T>(ArraySize);

            T[] ma = new T[ArraySize];
            Info($"Array fill value is {fill}.");
            Info($"Array mul value is {mul}.");
            na.Fill(fill);
            for (int i = 0; i < ma.Length; i++)
            {
                ma[i] = fill;
            }
            na.Acquire();
            SetValue("fill", fill);
            SetValue("mul", mul);
            SetValue("managedArray", ma);
            SetValue("nativeArray", na);
        }
Exemplo n.º 16
0
 public TCPClientData(uint maxCount)
 {
     RecvList = new SafeArray <TCPRecvData>(maxCount);
     SendList = new SafeArray <byte[]>(maxCount);
 }
 public TestClass()
 {
     Ids       = new SafeArray <int>(5);
     Instances = new SafeArray <MyClass>(5);
 }
Exemplo n.º 18
0
 public void CreateNativeArray()
 {
     SafeArray <T> array = new SafeArray <T>(ArraySize);
 }