/// <summary> /// Create a copy of the current Tensor, actively syncing there data in a blocking way. /// </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.PinToDeviceAndDownloadFromIt(copyOfTensorData); } else { PrepareCacheForAccess(); copy.PrepareCacheForAccess(); Array.Copy(m_Cache, 0, copy.m_Cache, 0, length); } return(copy); }