/// <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 targetBuffer = target.Source; var sourceAddress = new IntPtr(ComputeEffectiveAddress(sourceOffset)); var targetAddress = new IntPtr(target.LoadEffectiveAddress()); var lengthInBytes = new IntPtr(target.LengthInBytes); switch (targetBuffer.AcceleratorType) { case AcceleratorType.CPU: CudaException.ThrowIfFailed( CurrentAPI.MemcpyDeviceToHost( targetAddress, sourceAddress, lengthInBytes, stream)); break; case AcceleratorType.Cuda: CudaException.ThrowIfFailed( CurrentAPI.MemcpyDeviceToDevice( targetAddress, sourceAddress, 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 = stream.BindScoped(); var sourceAddress = source.LoadEffectiveAddress(); var targetAddress = ComputeEffectiveAddress(targetOffset); switch (source.AcceleratorType) { case AcceleratorType.CPU: Buffer.MemoryCopy( sourceAddress, targetAddress, LengthInBytes, source.LengthInBytes); break; case AcceleratorType.Cuda: CudaException.ThrowIfFailed( CurrentAPI.MemcpyDeviceToHost( new IntPtr(targetAddress), new IntPtr(sourceAddress), new IntPtr(source.LengthInBytes), stream)); break; default: throw new NotSupportedException( RuntimeErrorMessages.NotSupportedTargetAccelerator); } binding.Recover(); }