/// <summary> /// Copy this SyncedMemory. /// </summary> /// <returns>A new SynedMemory that is a copy of this one, is returned.</returns> public SyncedMemory <T> Clone() { SyncedMemory <T> dst = new SyncedMemory <T>(m_cuda, m_log, m_lCapacity); if (m_lCount > 0) { dst.Copy(this); } return(dst); }
/// <summary> /// Copy another SyncedMemory into this one. /// </summary> /// <param name="src">Specifies the SyncedMemory to copy.</param> /// <param name="hDstHostBuffer">Optionally, specifies a host buffer used to copy between kernels (default = 0, not used).</param> /// <returns>When used the dst host buffer handle is returned.</returns> public long Copy(SyncedMemory <T> src, long hDstHostBuffer = 0) { if (src == null) { m_lCount = 0; return(hDstHostBuffer); } if (m_lCapacity < src.m_lCount) { Allocate(src.m_lCount); } m_lCount = src.m_lCount; if (m_lCount > 0) { if (m_cuda.KernelHandle == src.m_cuda.KernelHandle) { check_device(); m_cuda.copy((int)m_lCount, src.m_hGpuData, m_hGpuData); } else { if (hDstHostBuffer == 0) { hDstHostBuffer = m_cuda.AllocHostBuffer(m_lCount); } else { long lCount = m_cuda.GetHostBufferCapacity(hDstHostBuffer); if (lCount < m_lCount) { m_cuda.FreeHostBuffer(hDstHostBuffer); hDstHostBuffer = m_cuda.AllocHostBuffer(m_lCount); } } src.m_cuda.KernelCopy((int)m_lCount, src.m_hGpuData, 0, m_cuda.KernelHandle, m_hGpuData, 0, hDstHostBuffer, m_cuda.KernelHandle); } } return(hDstHostBuffer); }
/// <summary> /// Copy another SyncedMemory into this one. /// </summary> /// <param name="src">Specifies the SyncedMemory to copy.</param> public void Copy(SyncedMemory <T> src) { if (src == null) { m_lCount = 0; return; } if (m_lCapacity < src.m_lCount) { Allocate(src.m_lCount); } m_lCount = src.m_lCount; if (m_lCount > 0) { check_device(); m_cuda.copy((int)m_lCount, src.m_hGpuData, m_hGpuData); } }