/// <summary>
        /// Pin `Tensor` to Burst backend device
        /// </summary>
        /// <param name="X">`Tensor`</param>
        /// <returns>`BurstTensorData`</returns>
        new public static BurstTensorData Pin(Tensor X)
        {
            X.FlushCache();

            var onDevice = X.tensorOnDevice as BurstTensorData;

            if (onDevice == null)
            {
                // try to adopt CPU arrays
                var asUnsafeArray = X.tensorOnDevice as UnsafeArrayTensorData;
                var asSharedArray = X.tensorOnDevice as SharedArrayTensorData;
                var asArray       = X.tensorOnDevice as ArrayTensorData;
                if (asUnsafeArray != null)
                {
                    X.AttachToDevice(new BurstTensorData(asUnsafeArray));
                }
                else if (asSharedArray != null)
                {
                    X.AttachToDevice(new BurstTensorData(asSharedArray));
                }
                else if (asArray != null)
                {
                    X.AttachToDevice(new BurstTensorData(asArray));
                }
                else
                {
                    X.UploadToDevice(new BurstTensorData(X.shape)); // device is not compatible, create new array and upload
                }
            }

            return(X.tensorOnDevice as BurstTensorData);
        }
Пример #2
0
        public TextureTensorData Pin(Tensor X, bool uploadCache = true)
        {
            X.FlushCache(uploadCache);

            var onDevice = X.tensorOnDevice as TextureTensorData;

            if (onDevice == null)
            {
                var asTexture = X.tensorOnDevice as TextureAsTensorData;
                if (asTexture != null)
                {
                    X.AttachToDevice(TextureToTensorData(asTexture, X.name));
                }
                else
                {
                    if (uploadCache)
                    {
                        X.UploadToDevice(new TextureTensorData(X.shape, X.name)); // device is not compatible, create new array and upload
                    }
                    else
                    {
                        X.AllocateOnDevice(new TextureTensorData(X.shape, X.name)); // device is not compatible, create new array but do not upload nor 0-fill
                    }
                }
            }

            Assert.IsNotNull(X.tensorOnDevice as TextureTensorData);
            Assert.IsNotNull((X.tensorOnDevice as TextureTensorData).bufferAsTexture);

            return(X.tensorOnDevice as TextureTensorData);
        }
        /// <summary>
        /// Create a copy of the current Tensor.
        /// </summary>
        public Tensor DeepCopy()
        {
            // @TODO: use Tensor allocator
            var copy = new Tensor(shape, $"clone of {name}");

            if (m_TensorOnDevice is ICloneable)
            {
                UploadIfDirty();
                var copyOfTensorData = (m_TensorOnDevice as ICloneable).Clone() as ITensorData;
                copy.AttachToDevice(copyOfTensorData);
            }
            else
            {
                PrepareCacheForAccess();
                copy.PrepareCacheForAccess();
                Array.Copy(m_Cache, 0, copy.m_Cache, 0, length);
            }

            return(copy);
        }
Пример #4
0
 public static void CastOnDevice(this Tensor self, ITensorData onDevice)
 {
     self.AttachToDevice(onDevice);
 }
Пример #5
0
 public static void PinToDeviceAndDownloadFromIt(this Tensor self, ITensorData onDevice)
 {
     self.AttachToDevice(onDevice);
 }