Пример #1
0
        /// <summary>
        /// Copy data from this array to host
        /// </summary>
        /// <typeparam name="T">Host array base type</typeparam>
        /// <param name="aHostDest">Destination</param>
        public void CopyFromThisToHost <T>(T[] aHostDest)
        {
            GCHandle handle = GCHandle.Alloc(aHostDest, GCHandleType.Pinned);

            try
            {
                CUDAMemCpy3D copyParams = new CUDAMemCpy3D();
                copyParams.dstHost       = handle.AddrOfPinnedObject();
                copyParams.dstMemoryType = CUMemoryType.Host;
                copyParams.srcArray      = _cuArray;
                copyParams.srcMemoryType = CUMemoryType.Array;
                copyParams.Depth         = _array3DDescriptor.Depth;
                copyParams.Height        = _array3DDescriptor.Height;
                copyParams.WidthInBytes  = _array3DDescriptor.Width * Marshal.SizeOf(typeof(T));

                res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpy3D_v2(ref copyParams);
                Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpy3D", res));
            }
            finally
            {
                handle.Free();
            }
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }
Пример #2
0
 /// <summary>
 /// A raw data copy method
 /// </summary>
 /// <param name="aCopyParameters">3D copy paramters</param>
 public void CopyData(CUDAMemCpy3D aCopyParameters)
 {
     res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpy3D_v2(ref aCopyParameters);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpy3D", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
 }
Пример #3
0
 /// <summary>
 /// Sets the parameters for a memcpy node in the given graphExec.<para/>
 /// Updates the work represented by \p hNode in \p hGraphExec as though \p hNode had
 /// contained \p copyParams at instantiation.  hNode must remain in the graph which was
 /// used to instantiate \p hGraphExec.  Changed edges to and from hNode are ignored.<para/>
 /// The source and destination memory in \p copyParams must be allocated from the same
 /// contexts as the original source and destination memory.  Both the instantiation-time
 /// memory operands and the memory operands in \p copyParams must be 1-dimensional.
 /// Zero-length operations are not supported.<para/>
 /// The modifications only affect future launches of \p hGraphExec.  Already enqueued
 /// or running launches of \p hGraphExec are not affected by this call.  hNode is also
 /// not modified by this call.<para/>
 /// Returns CUDA_ERROR_INVALID_VALUE if the memory operands' mappings changed or
 /// either the original or new memory operands are multidimensional.
 /// </summary>
 public void SetParams(CUgraphNode hNode, ref CUDAMemCpy3D copyParams, CUcontext ctx)
 {
     res = DriverAPINativeMethods.GraphManagment.cuGraphExecMemcpyNodeSetParams(_graph, hNode, ref copyParams, ctx);
     Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphExecMemcpyNodeSetParams", res));
     if (res != CUResult.Success)
     {
         throw new CudaException(res);
     }
 }
        /// <summary>
        /// Gets the parameters of memcpy node.
        /// </summary>
        /// <param name="nodeParams"></param>
        public void GetParameters(ref CUDAMemCpy3D nodeParams)
        {
            CUResult res = DriverAPINativeMethods.GraphManagment.cuGraphMemcpyNodeGetParams(this, ref nodeParams);

            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphMemcpyNodeGetParams", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }
Пример #5
0
        /// <summary>
        /// Copy array to array
        /// </summary>
        /// <param name="aDestArray"></param>
        public void CopyFromThisToArray(CudaArray3D aDestArray)
        {
            CUDAMemCpy3D copyParams = new CUDAMemCpy3D();

            copyParams.srcArray      = _cuArray;
            copyParams.srcMemoryType = CUMemoryType.Array;
            copyParams.dstArray      = aDestArray.CUArray;
            copyParams.dstMemoryType = CUMemoryType.Array;
            copyParams.Depth         = aDestArray._array3DDescriptor.Depth;
            copyParams.Height        = aDestArray.Array3DDescriptor.Height;
            copyParams.WidthInBytes  = aDestArray.Array3DDescriptor.Width * CudaHelperMethods.GetChannelSize(aDestArray.Array3DDescriptor.Format) * aDestArray.Array3DDescriptor.NumChannels;

            res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpy3D_v2(ref copyParams);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpy3D", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }
Пример #6
0
        /// <summary>
        /// Copy data from this array to host
        /// </summary>
        /// <param name="aHostDest">IntPtr to destination in host memory</param>
        /// <param name="aElementSizeInBytes"></param>
        public void CopyFromThisToHost(IntPtr aHostDest, SizeT aElementSizeInBytes)
        {
            CUDAMemCpy3D copyParams = new CUDAMemCpy3D();

            copyParams.dstHost       = aHostDest;
            copyParams.dstMemoryType = CUMemoryType.Host;
            copyParams.srcArray      = _cuArray;
            copyParams.srcMemoryType = CUMemoryType.Array;
            copyParams.Depth         = _array3DDescriptor.Depth;
            copyParams.Height        = _array3DDescriptor.Height;
            copyParams.WidthInBytes  = _array3DDescriptor.Width * aElementSizeInBytes;

            res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpy3D_v2(ref copyParams);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpy3D", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }
Пример #7
0
        /// <summary>
        /// Creates a memcpy node and adds it to a graph<para/>
        /// Creates a new memcpy node and adds it to graph with
        /// dependencies specified via dependencies.<para/>
        /// It is possible for dependencies to be null, in which case the node will be placed
        /// at the root of the graph. Dependencies may not have any duplicate entries.
        /// A handle to the new node will be returned.<para/>
        /// When the graph is launched, the node will perform the memcpy described by copyParams.
        /// See ::cuMemcpy3D() for a description of the structure and its restrictions.<para/>
        /// Memcpy nodes have some additional restrictions with regards to managed memory, if the
        /// system contains at least one device which has a zero value for the device attribute
        /// ::CU_DEVICE_ATTRIBUTE_CONCURRENT_MANAGED_ACCESS. If one or more of the operands refer
        /// to managed memory, then using the memory type ::CU_MEMORYTYPE_UNIFIED is disallowed
        /// for those operand(s). The managed memory will be treated as residing on either the
        /// host or the device, depending on which memory type is specified.
        /// </summary>
        /// <param name="dependencies">can be null</param>
        /// <param name="copyParams">Parameters for the memory copy</param>
        /// <param name="ctx">Cuda context used for the operation</param>
        /// <returns>A handle to the new node will be returned.</returns>
        public CUgraphNode AddMemcpyNode(CUgraphNode[] dependencies, CUDAMemCpy3D copyParams, CudaContext ctx)
        {
            CUgraphNode node            = new CUgraphNode();
            SizeT       numDependencies = 0;

            if (dependencies != null)
            {
                numDependencies = dependencies.Length;
            }

            res = DriverAPINativeMethods.GraphManagment.cuGraphAddMemcpyNode(ref node, _graph, dependencies, numDependencies, ref copyParams, ctx.Context);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuGraphAddMemcpyNode", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }

            return(node);
        }
Пример #8
0
        /// <summary>
        /// Copy from a pitched device variable to this array
        /// </summary>
        /// <param name="aDeviceVariable">Source</param>
        /// <param name="aElementSizeInBytes"></param>
        /// <param name="pitch">Pitch in bytes</param>
        public void CopyFromDeviceToThis(CUdeviceptr aDeviceVariable, SizeT aElementSizeInBytes, SizeT pitch)
        {
            CUDAMemCpy3D copyParams = new CUDAMemCpy3D();

            copyParams.srcDevice     = aDeviceVariable;
            copyParams.srcMemoryType = CUMemoryType.Device;
            copyParams.srcPitch      = pitch;
            copyParams.dstArray      = _cuArray;
            copyParams.dstMemoryType = CUMemoryType.Array;
            copyParams.Depth         = _array3DDescriptor.Depth;
            copyParams.Height        = _array3DDescriptor.Height;
            copyParams.WidthInBytes  = _array3DDescriptor.Width * aElementSizeInBytes;

            res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpy3D_v2(ref copyParams);
            Debug.WriteLine(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpy3D", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }
Пример #9
0
        /// <summary>
        /// Asynchron copy 3D Array to host
        /// </summary>
        /// <param name="deviceArray"></param>
        /// <param name="stream"></param>
        public void AsyncCopyFromArray3D(CUarray deviceArray, CUstream stream)
        {
            if (disposed)
            {
                throw new ObjectDisposedException(this.ToString());
            }
            CUDAMemCpy3D cpyProps = new CUDAMemCpy3D();

            cpyProps.srcArray      = deviceArray;
            cpyProps.srcMemoryType = CUMemoryType.Array;
            cpyProps.dstHost       = _intPtr;
            cpyProps.dstMemoryType = CUMemoryType.Host;
            cpyProps.dstPitch      = _pitchInBytes;
            cpyProps.WidthInBytes  = _width * _typeSize;
            cpyProps.Height        = _height;
            cpyProps.Depth         = _depth;

            res = DriverAPINativeMethods.AsynchronousMemcpy_v2.cuMemcpy3DAsync_v2(ref cpyProps, stream);
            Debug.Write("");//Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "cuMemcpy3DAsync", res));
            if (res != CUResult.Success)
            {
                throw new CudaException(res);
            }
        }