public void FragmentLOHBaseline() { int largeBlockSize = InitialLargeBlockSize; int i = 0; try { for (i = 0; i < LoopCount; i++) { T[] bigBlock = new T[largeBlockSize]; T[] smallBlock = new T[SmallBlockSize]; largeBlockSize = largeBlockSize + (1 * 1024 * 1024); } this.SetStatistic($"{nameof(FragmentLOHBaseline)}_WorkingSet", JemUtil.PrintBytes(JemUtil.ProcessWorkingSet)); this.SetStatistic($"{nameof(FragmentLOHBaseline)}_JemResident", JemUtil.PrintBytes(Jem.ResidentBytes)); this.SetStatistic($"{nameof(FragmentLOHBaseline)}_PrivateMemory", JemUtil.PrintBytes(JemUtil.ProcessPrivateMemory)); this.SetStatistic($"{nameof(FragmentLOHBaseline)}_JemAllocated", JemUtil.PrintBytes(Jem.AllocatedBytes)); } catch (OutOfMemoryException) { Error($"OOM at index {i}."); throw; } finally { GC.Collect(); } }
public void SetMemoryStatistics([CallerMemberName] string memberName = "", [CallerFilePath] string fileName = "", [CallerLineNumber] int lineNumber = 0) { this.SetStatistic($"{memberName}_WorkingSet", JemUtil.PrintBytes(JemUtil.ProcessWorkingSet)); this.SetStatistic($"{memberName}_JemResident", JemUtil.PrintBytes(Jem.ResidentBytes)); this.SetStatistic($"{memberName}_PrivateMemory", JemUtil.PrintBytes(JemUtil.ProcessPrivateMemory)); this.SetStatistic($"{memberName}_JemAllocated", JemUtil.PrintBytes(Jem.AllocatedBytes)); }
public static unsafe TData GetArrayMulValue() { TData value = default; switch (value) { case Byte v: return(JemUtil.ValToGenericStruct <Byte, TData>(4)); case SByte v: return(JemUtil.ValToGenericStruct <SByte, TData>(4)); case UInt16 v: return(JemUtil.ValToGenericStruct <UInt16, TData>(4)); case Int16 v: return(JemUtil.ValToGenericStruct <Int16, TData>(4)); case UInt32 v: return(JemUtil.ValToGenericStruct <UInt32, TData>(4)); case Int32 v: return(JemUtil.ValToGenericStruct <Int32, TData>(4)); case UInt64 v: return(JemUtil.ValToGenericStruct <UInt64, TData>(4)); case Int64 v: return(JemUtil.ValToGenericStruct <Int64, TData>(4)); default: return(value); } }
public void ArithmeticMutiplyManagedArray() { for (int i = 0; i < managedArray.Length; i++) { managedArray[i] = JemUtil.GenericMultiply(managedArray[i], mul); } T r = managedArray[ArraySize / 2]; }
public void ArithmeticSqrtManagedArray() { for (int i = 0; i < managedArray.Length; i++) { managedArray[i] = JemUtil.ValToGenericStruct <uint, T>(256u); JemUtil.GenericSqrt(managedArray[i]); } }
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(); } }
public void CreateSpan() { ulong msize = (ulong)(ArraySize * JemUtil.SizeOfStruct <T>()); IntPtr ptr = Jem.Malloc(msize); unsafe { Span <T> s = new Span <T>(ptr.ToPointer(), ArraySize); } Jem.Free(ptr); }
public void FillSpan() { T fill = GetArrayFillValue(); ulong msize = (ulong)(ArraySize * JemUtil.SizeOfStruct <T>()); IntPtr ptr = Jem.Malloc(msize); Span <T> s = JemUtil.PtrToSpan <T>(ptr, ArraySize); s.Fill(fill); T r = s[ArraySize / 2]; Jem.Free(ptr); }
public void CanVectorize() { Span <byte> s = Employees.GetSpan <byte>(); int size = JemUtil.SizeOfStruct <TestUDT>(); /* * for (int i = 0; i < Employees.Length; i+= size * Employees[i].) * { * * //s.Slice * * } */ }
public void FragmentLOHWithCompact() { int largeBlockSize = InitialLargeBlockSize; List <T[]> smallBlocks = new List <T[]>(); int i = 0; try { for (i = 0; i < LoopCount; i++) { if ((i + 1) % 10 == 0) { //Info("Compacting LOH."); GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce; GC.Collect(); } T[] bigBlock = new T[largeBlockSize]; T[] smallBlock = new T[SmallBlockSize]; smallBlocks.Add(smallBlock); largeBlockSize = largeBlockSize + (1 * 1024 * 1024); } this.SetStatistic($"{nameof(FragmentLOHWithCompact)}_WorkingSet", JemUtil.PrintBytes(JemUtil.ProcessWorkingSet)); this.SetStatistic($"{nameof(FragmentLOHWithCompact)}_JemResident", JemUtil.PrintBytes(Jem.ResidentBytes)); this.SetStatistic($"{nameof(FragmentLOHWithCompact)}_PrivateMemory", JemUtil.PrintBytes(JemUtil.ProcessPrivateMemory)); this.SetStatistic($"{nameof(FragmentLOHWithCompact)}_JemAllocated", JemUtil.PrintBytes(Jem.AllocatedBytes)); } catch (OutOfMemoryException) { Error($"OOM at index {i}."); throw; } finally { smallBlocks = null; GC.Collect(); } }
public void ArithmeticSqrtNativeArray() { nativeArray.Fill(JemUtil.ValToGenericStruct <uint, T>(256u)); nativeArray.VectorSqrt(); }