private void Multiply(Image multiplicators, uint elements, uint batch) { if (ElementsComplex != elements * batch || multiplicators.ElementsComplex != elements || //IsFT != multiplicators.IsFT || multiplicators.IsComplex) { throw new DimensionMismatchException(); } if (!IsComplex) { if (IsHalf && multiplicators.IsHalf) { GPU.MultiplySlicesHalf(GetDevice(Intent.Read), multiplicators.GetDevice(Intent.Read), GetDevice(Intent.Write), elements, batch); } else if (!IsHalf && !multiplicators.IsHalf) { GPU.MultiplySlices(GetDevice(Intent.Read), multiplicators.GetDevice(Intent.Read), GetDevice(Intent.Write), elements, batch); } else { Image ThisSingle = AsSingle(); Image MultiplicatorsSingle = multiplicators.AsSingle(); GPU.MultiplySlices(ThisSingle.GetDevice(Intent.Read), MultiplicatorsSingle.GetDevice(Intent.Read), ThisSingle.GetDevice(Intent.Write), elements, batch); if (IsHalf) { GPU.HalfToSingle(ThisSingle.GetDevice(Intent.Read), GetDevice(Intent.Write), elements * batch); } else { GPU.CopyDeviceToDevice(ThisSingle.GetDevice(Intent.Read), GetDevice(Intent.Write), elements * batch); } ThisSingle.Dispose(); MultiplicatorsSingle.Dispose(); } } else { if (IsHalf) { throw new Exception("Complex multiplication not supported for fp16."); } GPU.MultiplyComplexSlicesByScalar(GetDevice(Intent.Read), multiplicators.GetDevice(Intent.Read), GetDevice(Intent.Write), elements, batch); } }
public void SetVolumeFrom(Image data) { if (Volume == null || Volume.Dims != data.Dims) { Volume?.Dispose(); FreeOnDevice(); Volume = data.GetCopyGPU(); } else { GPU.CopyDeviceToDevice(data.GetDevice(Intent.Read), Volume.GetDevice(Intent.Write), data.ElementsReal); } }
private void Divide(Image divisors, uint elements, uint batch) { if (ElementsComplex != elements * batch || divisors.ElementsComplex != elements || //IsFT != divisors.IsFT || divisors.IsComplex) { throw new DimensionMismatchException(); } if (!IsComplex) { if (!IsHalf && !divisors.IsHalf) { GPU.DivideSlices(GetDevice(Intent.Read), divisors.GetDevice(Intent.Read), GetDevice(Intent.Write), elements, batch); } else { Image ThisSingle = AsSingle(); Image DivisorsSingle = divisors.AsSingle(); GPU.DivideSlices(ThisSingle.GetDevice(Intent.Read), DivisorsSingle.GetDevice(Intent.Read), ThisSingle.GetDevice(Intent.Write), elements, batch); if (IsHalf) { GPU.HalfToSingle(ThisSingle.GetDevice(Intent.Read), GetDevice(Intent.Write), elements * batch); } else { GPU.CopyDeviceToDevice(ThisSingle.GetDevice(Intent.Read), GetDevice(Intent.Write), elements * batch); } ThisSingle.Dispose(); DivisorsSingle.Dispose(); } } else { if (IsHalf) { throw new Exception("Complex division not supported for fp16."); } GPU.DivideComplexSlicesByScalar(GetDevice(Intent.Read), divisors.GetDevice(Intent.Read), GetDevice(Intent.Write), elements, batch); } }
public void SetVolumeFrom(Image data) { if (Volume == null || Volume.Dims != data.Dims) { Volume?.Dispose(); Volume = data.GetCopyGPU(); SliderPositionX.MaxValue = data.Dims.X - 1; SliderPositionY.MaxValue = data.Dims.Y - 1; SliderPositionZ.MaxValue = data.Dims.Z - 1; PositionX = data.Dims.X / 2; PositionY = data.Dims.Y / 2; PositionZ = data.Dims.Z / 2; } else { GPU.CopyDeviceToDevice(data.GetDevice(Intent.Read), Volume.GetDevice(Intent.Write), data.ElementsReal); } }
private void Add(Image summands, uint elements, uint batch) { if (ElementsReal != elements * batch || summands.ElementsReal != elements || //IsFT != summands.IsFT || IsComplex != summands.IsComplex) { throw new DimensionMismatchException(); } if (IsHalf && summands.IsHalf) { GPU.AddToSlicesHalf(GetDevice(Intent.Read), summands.GetDevice(Intent.Read), GetDevice(Intent.Write), elements, batch); } else if (!IsHalf && !summands.IsHalf) { GPU.AddToSlices(GetDevice(Intent.Read), summands.GetDevice(Intent.Read), GetDevice(Intent.Write), elements, batch); } else { Image ThisSingle = AsSingle(); Image SummandsSingle = summands.AsSingle(); GPU.AddToSlices(ThisSingle.GetDevice(Intent.Read), SummandsSingle.GetDevice(Intent.Read), ThisSingle.GetDevice(Intent.Write), elements, batch); if (IsHalf) { GPU.HalfToSingle(ThisSingle.GetDevice(Intent.Read), GetDevice(Intent.Write), elements * batch); } else { GPU.CopyDeviceToDevice(ThisSingle.GetDevice(Intent.Read), GetDevice(Intent.Write), elements * batch); } ThisSingle.Dispose(); SummandsSingle.Dispose(); } }
public Image(IntPtr deviceData, int3 dims, bool isft = false, bool iscomplex = false, bool ishalf = false) { Dims = dims; IsFT = isft; IsComplex = iscomplex; IsHalf = ishalf; _DeviceData = !IsHalf?GPU.MallocDevice(ElementsReal) : GPU.MallocDeviceHalf(ElementsReal); GPU.OnMemoryChanged(); if (deviceData != IntPtr.Zero) { if (!IsHalf) { GPU.CopyDeviceToDevice(deviceData, _DeviceData, ElementsReal); } else { GPU.CopyDeviceHalfToDeviceHalf(deviceData, _DeviceData, ElementsReal); } } IsDeviceDirty = true; }