Library/ManagedCuda/CudaKernel.cs
/// <summary>
/// Set the constant variable <c>name</c> to value <c>value</c><para>The constant variable must be defined in the CUDA module.</para>
/// </summary>
/// <param name="name">constant variable name</param>
/// <param name="value">value</param>
Set the constant variable namevalueThe constant variable must be defined in the CUDA module.
Set the constant variable namevalueThe constant variable must be defined in the CUDA module .
public void SetConstantVariable<T>(string name, T value) where T : struct
		{
			CUdeviceptr dVarPtr = new CUdeviceptr();
			SizeT varSize = 0;
			res = DriverAPINativeMethods.ModuleManagement.cuModuleGetGlobal_v2(ref dVarPtr, ref varSize, _module, name);
			Debug.WriteLine(String.Format("{0:G}, {1}: {2}, Kernel: {3}", DateTime.Now, "cuModuleGetGlobal", res, _kernelName));
			if (res != CUResult.Success) throw new CudaException(res);
			GCHandle handle = GCHandle.Alloc(value, GCHandleType.Pinned);
			try
			{
				IntPtr ptr = handle.AddrOfPinnedObject();
				res = DriverAPINativeMethods.SynchronousMemcpy_v2.cuMemcpyHtoD_v2(dVarPtr, ptr, varSize);
				Debug.WriteLine(String.Format("{0:G}, {1}: {2}, Kernel: {3}", DateTime.Now, "cuMemcpyHtoD", res, _kernelName));
			}
			finally
			{
				handle.Free();
			}
			if (res != CUResult.Success) throw new CudaException(res);
		}
public void SetConstantVariable < T > ( string name , T value ) where T : struct { CUdeviceptr dVarPtr = new CUdeviceptr ( ) ; SizeT varSize = 0 ; res = DriverAPINativeMethods . ModuleManagement . cuModuleGetGlobal_v2 ( ref dVarPtr , ref varSize , _module , name ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res , _kernelName ) ) ; if ( res != CUResult . Success ) throw new CudaException ( res ) ; GCHandle handle = GCHandle . Alloc ( value , GCHandleType . Pinned ) ; try { IntPtr ptr = handle . AddrOfPinnedObject ( ) ; res = DriverAPINativeMethods . SynchronousMemcpy_v2 . cuMemcpyHtoD_v2 ( dVarPtr , ptr , varSize ) ; Debug . WriteLine ( String . Format ( " " , DateTime . Now , " " , res , _kernelName ) ) ; } finally { handle . Free ( ) ; } if ( res != CUResult . Success ) throw new CudaException ( res ) ; }
Set the constant variable namevalueThe constant variable must be defined in the CUDA module.
Set the constant variable namevalueThe constant variable must be defined in the CUDA module .
name
string
constant variable name
constant variable name
value
T
None