/// <summary cref="MemoryBuffer{T, TIndex}.CopyFromView(AcceleratorStream, ArrayView{T}, Index)"/> protected internal unsafe override void CopyFromView( AcceleratorStream stream, ArrayView <T> source, Index targetOffset) { var binding = stream.BindScoped(); var targetAddress = ComputeEffectiveAddress(targetOffset); switch (source.AcceleratorType) { case AcceleratorType.CPU: Unsafe.CopyBlock( targetAddress, source.LoadEffectiveAddress(), (uint)source.LengthInBytes); break; case AcceleratorType.Cuda: CudaException.ThrowIfFailed(CudaAPI.Current.MemcpyDeviceToHost( new IntPtr(targetAddress), new IntPtr(source.LoadEffectiveAddress()), new IntPtr(source.LengthInBytes), stream)); break; default: throw new NotSupportedException(RuntimeErrorMessages.NotSupportedTargetAccelerator); } binding.Recover(); }
/// <summary cref="MemoryBuffer{T, TIndex}.CopyFromView(AcceleratorStream, ArrayView{T}, Index)"/> protected internal unsafe override void CopyFromView( AcceleratorStream stream, ArrayView <T> source, Index targetOffset) { var clStream = (CLStream)stream; switch (source.AcceleratorType) { case AcceleratorType.CPU: CLException.ThrowIfFailed( CLAPI.WriteBuffer( clStream.CommandQueue, NativePtr, false, new IntPtr(targetOffset * ElementSize), new IntPtr(source.LengthInBytes), new IntPtr(source.LoadEffectiveAddress()))); break; case AcceleratorType.OpenCL: CLException.ThrowIfFailed( CLAPI.CopyBuffer( clStream.CommandQueue, source.Source.NativePtr, NativePtr, new IntPtr(source.Index * ElementSize), new IntPtr(targetOffset * ElementSize), new IntPtr(source.LengthInBytes))); break; default: throw new NotSupportedException(RuntimeErrorMessages.NotSupportedTargetAccelerator); } }
/// <summary cref="MemoryBuffer{T, TIndex}.CopyToView(AcceleratorStream, ArrayView{T}, Index)"/> protected internal unsafe override void CopyToView( AcceleratorStream stream, ArrayView <T> target, Index sourceOffset) { var binding = Accelerator.BindScoped(); var targetBuffer = target.Source; var sourceAddress = new IntPtr(ComputeEffectiveAddress(sourceOffset)); var targetAddress = new IntPtr(target.LoadEffectiveAddress()); switch (targetBuffer.AcceleratorType) { case AcceleratorType.CPU: CudaException.ThrowIfFailed(CudaAPI.Current.MemcpyDeviceToHost( targetAddress, sourceAddress, new IntPtr(target.LengthInBytes), stream)); break; case AcceleratorType.Cuda: CudaException.ThrowIfFailed(CudaAPI.Current.MemcpyDeviceToDevice( targetAddress, sourceAddress, new IntPtr(target.LengthInBytes), stream)); break; default: throw new NotSupportedException(RuntimeErrorMessages.NotSupportedTargetAccelerator); } binding.Recover(); }
/// <summary cref="MemoryBuffer{T, TIndex}.CopyFromView( /// AcceleratorStream, ArrayView{T}, LongIndex1)"/> protected internal unsafe override void CopyFromView( AcceleratorStream stream, ArrayView <T> source, LongIndex1 targetOffset) { var binding = Accelerator.BindScoped(); var sourceAddress = new IntPtr(source.LoadEffectiveAddress()); var targetAddress = new IntPtr(ComputeEffectiveAddress(targetOffset)); var lengthInBytes = new IntPtr(source.LengthInBytes); switch (source.AcceleratorType) { case AcceleratorType.CPU: case AcceleratorType.Cuda: CudaException.ThrowIfFailed( CurrentAPI.MemcpyAsync( targetAddress, sourceAddress, lengthInBytes, stream)); break; default: throw new NotSupportedException( RuntimeErrorMessages.NotSupportedTargetAccelerator); } binding.Recover(); }
public ViewImplementation(ArrayView <T> source) : this( source.IsValid ? source.LoadEffectiveAddress() : null, source.Length) { }
public ViewImplementation(ArrayView <T> source) : this( source.IsValid ? Unsafe.AsPointer(ref source.LoadEffectiveAddress()) : null, source.Length) { }
/// <summary cref="MemoryBuffer{T, TIndex}.CopyToView( /// AcceleratorStream, ArrayView{T}, LongIndex1)"/> protected internal unsafe override void CopyToView( AcceleratorStream stream, ArrayView <T> target, LongIndex1 sourceOffset) { var binding = Accelerator.BindScoped(); var clStream = (CLStream)stream; switch (target.AcceleratorType) { case AcceleratorType.CPU: CLException.ThrowIfFailed( CurrentAPI.ReadBuffer( clStream.CommandQueue, NativePtr, false, new IntPtr(sourceOffset * ElementSize), new IntPtr(target.LengthInBytes), new IntPtr(target.LoadEffectiveAddress()))); break; case AcceleratorType.OpenCL: CLException.ThrowIfFailed( CurrentAPI.CopyBuffer( clStream.CommandQueue, NativePtr, target.Source.NativePtr, new IntPtr(sourceOffset * ElementSize), new IntPtr(target.Index * ElementSize), new IntPtr(target.LengthInBytes))); break; default: throw new NotSupportedException( RuntimeErrorMessages.NotSupportedTargetAccelerator); } binding.Recover(); }
/// <summary cref="MemoryBuffer{T, TIndex}.CopyFromView( /// AcceleratorStream, ArrayView{T}, LongIndex1)"/> protected internal unsafe override void CopyFromView( AcceleratorStream stream, ArrayView <T> source, LongIndex1 targetOffset) { var binding = Accelerator.BindScoped(); switch (source.AcceleratorType) { case AcceleratorType.CPU: CLException.ThrowIfFailed( CurrentAPI.WriteBuffer( stream, NativePtr, false, new IntPtr(targetOffset * ElementSize), new IntPtr(source.LengthInBytes), new IntPtr(source.LoadEffectiveAddress()))); break; case AcceleratorType.OpenCL: CLException.ThrowIfFailed( CurrentAPI.CopyBuffer( stream, source.Source.NativePtr, NativePtr, new IntPtr(source.Index * ElementSize), new IntPtr(targetOffset * ElementSize), new IntPtr(source.LengthInBytes))); break; default: throw new NotSupportedException( RuntimeErrorMessages.NotSupportedTargetAccelerator); } binding.Recover(); }
public static ref byte LoadEffectiveAddress <T>(this ArrayView <T> view) where T : unmanaged => ref view.LoadEffectiveAddress();