/// <inheritdoc/>
        public virtual void Release(Tensor tensor, bool calledFromTensorDispose)
        {
            Profiler.BeginSample("Barracuda.SizeAllocator.Release");
            Assert.AreEqual(tensor.allocator, this);

            var detachedBuffer = tensor.Invalidate(); // calls MoveToDevice(newBuffer=null,disposeDetachedBufferHint=false)

            if (calledFromTensorDispose)
            {
                lock (m_AllocatedTensors)
                {
                    m_AllocatedTensors.Add(tensor);
                    tensor.name = "";
                }
            }

            if (!m_BusyTensors.ContainsKey(tensor))
            {
                if (detachedBuffer == null)
                {
                    return;
                }

                foreach (var entry in m_AllocatedBuffers)
                {
                    if (entry.tensorData == detachedBuffer && entry.free)
                    {
                        return;
                    }
                }

                // some operations can create new Tensor and reassign ITensorData to it
                foreach (var busyEntry in m_BusyTensors)
                {
                    if (busyEntry.Value == detachedBuffer)
                    {
                        return; // we have original ITensorData in m_BusyTensors, nothing to realease
                    }
                }
            }

            Assert.IsTrue(m_BusyTensors.ContainsKey(tensor));
            m_BusyTensors.Remove(tensor);


            Profiler.EndSample();
        }
Пример #2
0
        public virtual void Release(Tensor tensor, bool calledFromTensorDispose)
        {
            Profiler.BeginSample("Barracuda.SizeAllocator.Release");
            Assert.AreEqual(tensor.allocator, this);

            var unpinned = tensor.Invalidate(); // calls Repin(newBuffer=null)

            if (!m_BusyTensors.ContainsKey(tensor))
            {
                if (unpinned == null)
                {
                    return;
                }

                foreach (var entry in m_AllocatedBuffers)
                {
                    if (entry.buffer == unpinned && entry.free)
                    {
                        return;
                    }
                }

                // some operations can create new Tensor and reassign ITensorData to it
                foreach (var busyEntry in m_BusyTensors)
                {
                    if (busyEntry.Value == unpinned)
                    {
                        return; // we have original ITensorData in m_BusyTensors, nothing to realease
                    }
                }
            }

            Assert.IsTrue(m_BusyTensors.ContainsKey(tensor));
            m_BusyTensors.Remove(tensor);

            Profiler.EndSample();
        }
        public virtual void Release(Tensor tensor, bool calledFromTensorDispose)
        {
            Profiler.BeginSample("Barracuda.ShapeAllocator.Release");
            Assert.AreEqual(tensor.allocator, this);

            var detachedBuffer = tensor.Invalidate(); // calls MoveToDevice(newBuffer=null)

            if (!m_BusyTensors.ContainsKey(tensor))
            {
                if (detachedBuffer == null)
                {
                    return;
                }

                foreach (var freeEntry in m_FreeBuffers)
                {
                    if (freeEntry.buffer == detachedBuffer)
                    {
                        return;
                    }
                }

                // some operations can create new Tensor and reassign ITensorData to it
                foreach (var busyEntry in m_BusyTensors)
                {
                    if (busyEntry.Value == detachedBuffer)
                    {
                        return; // we have at least another instance ITensorData in m_BusyTensors, nothing to realease
                    }
                }
            }

            Assert.IsTrue(m_BusyTensors.ContainsKey(tensor));
            m_BusyTensors.Remove(tensor);
            Profiler.EndSample();
        }