public void FreeDevice() { lock (Sync) { if (_DeviceData != IntPtr.Zero) { if (IsDeviceDirty) { for (int z = 0; z < Dims.Z; z++) { if (!IsHalf) { GPU.CopyDeviceToHost(new IntPtr((long)DeviceData + ElementsSliceReal * z * sizeof(float)), HostData[z], ElementsSliceReal); } else { GPU.CopyDeviceHalfToHost(new IntPtr((long)DeviceData + ElementsSliceReal * z * sizeof(short)), HostData[z], ElementsSliceReal); } } } GPU.FreeDevice(DeviceData); GPU.OnMemoryChanged(); _DeviceData = IntPtr.Zero; IsDeviceDirty = false; } IsHostDirty = true; } }
public float[][] GetHost(Intent intent) { lock (Sync) { if ((intent & Intent.Read) > 0 && IsDeviceDirty) { for (int z = 0; z < Dims.Z; z++) { if (!IsHalf) { GPU.CopyDeviceToHost(new IntPtr((long)DeviceData + ElementsSliceReal * z * sizeof(float)), HostData[z], ElementsSliceReal); } else { GPU.CopyDeviceHalfToHost(new IntPtr((long)DeviceData + ElementsSliceReal * z * sizeof(short)), HostData[z], ElementsSliceReal); } } IsDeviceDirty = false; } if ((intent & Intent.Write) > 0) { IsHostDirty = true; IsDeviceDirty = false; } return(HostData); } }