public TensorBase(long length, TensorConfig conf) { this.Length = length; this.ArrayReturned = false; this.Config = conf; var ptr = TensorPool.GetDevicePool(this.Config.Device).Rent(length, this.Config.GetUnitLength()); this.Array = ptr; }
public void Dispose(bool gc) { if (!gc && ArrayReturned) { System.Diagnostics.StackTrace t = new System.Diagnostics.StackTrace(); Console.WriteLine("StackTrace: '{0}'", Environment.StackTrace); throw new Exception("The tensor base is already disposed!"); } if (!ArrayReturned) { ArrayReturned = true; TensorPool.GetDevicePool(this.Config.Device).Return(Array, Length, this.Config.GetUnitLength()); if (!gc) { GC.SuppressFinalize(this); } Interlocked.Increment(ref TensorBase.DisposedCount); } }