Beispiel #1
0
        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;
        }
Beispiel #2
0
        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);
            }
        }