public void EraseAll() { lock (Mutex) { foreach (var item in Stacks) { if (item.Value != null) { foreach (var arr in item.Value) { if (this.Device.Type == DeviceType.NvidiaGPU) { CudaManagement.SetDevice(this.Device.ID); CudaManagement.Free(arr.Ptr); } else if (this.Device.Type == DeviceType.Host) { GC.RemoveMemoryPressure((long)item.Key); MKL.MKL_free(arr.Ptr); } else { throw new Exception("Uknown Device in ArrayPool!"); } } item.Value.Clear(); } } Stacks.Clear(); } }
public void *Rent(long length, long unitlength) { lock (Mutex) { UnreturnedArrayCount++; length *= unitlength; if (Stacks.ContainsKey(length) && (Stacks[length] is Stack <PointerArray> x) && x.Count > 0) { PointerArray sr = x.Pop(); return(sr.Ptr); } else { if (this.Device.Type == DeviceType.NvidiaGPU) { GC.AddMemoryPressure(length); CudaManagement.SetDevice(this.Device.ID); return(CudaManagement.Allocate(length, Device.ID)); } else if (this.Device.Type == DeviceType.Host) { GC.AddMemoryPressure(length); return(MKL.MKL_malloc(length, 32)); } else { throw new Exception("Uknown Device in ArrayPool!"); } } } }
public static void MultiplyFloat32(Tensor res, Tensor a, Tensor b, float cofmul = 1, float cofadd = 0) { CudaManagement.SetDevice(res.Config.Device.ID); CudaKernels.MultiplyFloat32((float *)res.Base.Array, (float *)a.Base.Array, (float *)b.Base.Array, a.Shape.TotalSize, b.Shape.TotalSize, cofmul, cofadd); }