Library/ManagedCuda/CudaKernel.cs
/// <summary>
/// Executes the kernel on the device asynchronously
/// </summary>
/// <param name="stream">Stream</param>
/// <param name="parameters">Parameters as given by the kernel</param>
Executes the kernel on the device asynchronously
Executes the kernel on the device asynchronously
public virtual void RunAsync(CUstream stream, params object[] parameters)
		{
			int paramCount = parameters.Length;
			IntPtr[] paramsList = new IntPtr[paramCount];
			GCHandle[] GCHandleList = new GCHandle[paramCount];
			for (int i = 0; i < paramCount; i++)
			{
				GCHandleList[i] = GCHandle.Alloc(parameters[i], GCHandleType.Pinned);
				paramsList[i] = GCHandleList[i].AddrOfPinnedObject();
			}
			res = DriverAPINativeMethods.Launch.cuLaunchKernel(_function, _gridDim.x, _gridDim.y, _gridDim.z, _blockDim.x, _blockDim.y, _blockDim.z, _sharedMemSize, stream, paramsList, null);
			for (int i = 0; i < paramCount; i++)
			{
				GCHandleList[i].Free();
			}
			if (res != CUResult.Success) throw new CudaException(res);
		}
public virtual void RunAsync ( CUstream stream , params object [ ] parameters ) { int paramCount = parameters . Length ; IntPtr [ ] paramsList = new IntPtr [ paramCount ] ; GCHandle [ ] GCHandleList = new GCHandle [ paramCount ] ; for ( int i = 0 ; i < paramCount ; i ++ ) { GCHandleList [ i ] = GCHandle . Alloc ( parameters [ i ] , GCHandleType . Pinned ) ; paramsList [ i ] = GCHandleList [ i ] . AddrOfPinnedObject ( ) ; } res = DriverAPINativeMethods . Launch . cuLaunchKernel ( _function , _gridDim . x , _gridDim . y , _gridDim . z , _blockDim . x , _blockDim . y , _blockDim . z , _sharedMemSize , stream , paramsList , null ) ; for ( int i = 0 ; i < paramCount ; i ++ ) { GCHandleList [ i ] . Free ( ) ; } if ( res != CUResult . Success ) throw new CudaException ( res ) ; }
Executes the kernel on the device asynchronously
Executes the kernel on the device asynchronously
//Get pointers to kernel parameters //Launch the kernel //Free pinned managed parameters //First free resources then throw potential exception!
stream
CUstream
None
parameters
Parameters as given by the kernel
Parameters as given by the kernel