Backends/SiaNet.Backend.TensorSharp/Cuda/KernelOps/CopyOps.cs
/// <summary>
/// Copies the cpu to gpu.
/// </summary>
/// <param name="result">The result.</param>
/// <param name="src">The source.</param>
/// <param name="totalElements">The total elements.</param>
Copies the cpu to gpu.
Copies the cpu to gpu .
public void CopyCpuToGpu(NDArray result, NDArray src, long totalElements)
        {
            var context = CudaHelpers.TSContextForTensor(result);
            var resultContext = context.CudaContextForTensor(result);
            using (var srcContig = AsTypeCpu(src, result.ElementType, true))
            using (var resultContig = Ops.AsContiguous(result))
            {
                var resultContigPtr = ((CudaStorage)resultContig.Storage).DevicePtrAtElement(resultContig.StorageOffset);
                var srcContigPtr = ((Cpu.CpuStorage)srcContig.Storage).PtrAtElement(srcContig.StorageOffset);
                resultContext.CopyToDevice(resultContigPtr, srcContigPtr, totalElements * srcContig.ElementType.Size());
                if (result.Storage != resultContig.Storage)
                {
                    CopyGpuDirect(result, resultContig, resultContext);
                }
            }
        }
public void CopyCpuToGpu ( NDArray result , NDArray src , long totalElements ) { var context = CudaHelpers . TSContextForTensor ( result ) ; var resultContext = context . CudaContextForTensor ( result ) ; using ( var srcContig = AsTypeCpu ( src , result . ElementType , true ) ) using ( var resultContig = Ops . AsContiguous ( result ) ) { var resultContigPtr = ( ( CudaStorage ) resultContig . Storage ) . DevicePtrAtElement ( resultContig . StorageOffset ) ; var srcContigPtr = ( ( Cpu . CpuStorage ) srcContig . Storage ) . PtrAtElement ( srcContig . StorageOffset ) ; resultContext . CopyToDevice ( resultContigPtr , srcContigPtr , totalElements * srcContig . ElementType . Size ( ) ) ; if ( result . Storage != resultContig . Storage ) { CopyGpuDirect ( result , resultContig , resultContext ) ; } } }
Copies the cpu to gpu.
Copies the cpu to gpu .
// If types of src and result are different, convert on the CPU first.
result
NDArray
None
src
NDArray
None
totalElements
long
The total elements.
The total elements .