/// <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); }
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); }