Пример #1
0
        /// <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();
        }