public CudaModuleLoadException(CudaResult result, string logText, string errorText) : base(result) { this.logText = logText; this.Data.Add("Message Log", logText); this.errorText = errorText; this.Data.Add("Error Log", errorText); }
public static void CudaCall(CudaResult result) { if (result != CudaResult.Success) { var str = Marshal.PtrToStringAnsi(cudaGetErrorString(result)); throw new ApplicationException(str); } }
private void Load(byte[] image) { CudaResult result = CudaResult.Unknown; IntPtr logBuffer = Marshal.AllocHGlobal(LogBufferSize + 1); //leave room for a null terminator IntPtr errorBuffer = Marshal.AllocHGlobal(ErrorBufferSize + 1); //leave room for a null terminator try{ int outLogLen = 0; int outErrorLen = 0; unsafe { uint * options = stackalloc uint[4]; void **values = stackalloc void *[4]; options[0] = (uint)JitOptions.InfoLogBuffer; values[0] = (void *)logBuffer; options[1] = (uint)JitOptions.InfoLogBufferSizeBytes; values[1] = (void *)LogBufferSize; options[2] = (uint)JitOptions.ErrorLogBuffer; values[2] = (void *)errorBuffer; options[3] = (uint)JitOptions.ErrorLogBufferSizeBytes; values[3] = (void *)ErrorBufferSize; fixed(byte *pImage = image) { result = cuModuleLoadDataEx(out handle, (void *)pImage, 4, options, values); } outLogLen = (int)values[1]; outErrorLen = (int)values[3]; ((byte *)logBuffer)[LogBufferSize] = 0; //make certain the ANSI strings are properly null terminated ((byte *)errorBuffer)[ErrorBufferSize] = 0; } log = Marshal.PtrToStringAnsi(logBuffer); errors = Marshal.PtrToStringAnsi(errorBuffer); } finally { Marshal.FreeHGlobal(logBuffer); Marshal.FreeHGlobal(errorBuffer); } if (result != CudaResult.Success) { throw new CudaModuleLoadException(result, log, errors); } }
public StreamQueryResult Query() { CudaResult result = cuStreamQuery(handle); switch (result) { case CudaResult.NotReady: return(StreamQueryResult.Unfinished); case CudaResult.Success: return(StreamQueryResult.Finished); default: throw new CudaException(result); } }
public void Synchronize() { CudaResult result = cuEventSynchronize(handle); switch (result) { case CudaResult.Success: return; case CudaResult.InvalidValue: return; default: throw new CudaException(result); } }
/// <summary> /// Computes the elapsed time in seconds between two events /// </summary> /// <param name="start">The starting event</param> /// <param name="stop">The stoping event</param> /// <returns>The number of seconds between the two events, or NaN if either event has not been recored.</returns> public static float ElapsedTime(Event start, Event stop) { float time_ms; CudaResult result = cuEventElapsedTime(out time_ms, start.handle, stop.handle); switch (result) { case CudaResult.Success: return(time_ms / 1000.0f); case CudaResult.InvalidValue: return(float.NaN); default: throw new CudaException(result); } }
public EventQueryResult Query() { CudaResult result = cuEventQuery(handle); switch (result) { case CudaResult.NotReady: return(EventQueryResult.Unfinished); case CudaResult.Success: return(EventQueryResult.Finished); case CudaResult.InvalidValue: return(EventQueryResult.NotStarted); default: throw new CudaException(result); } }
public static extern IntPtr cudaGetErrorString(CudaResult c);
public CudaException(string message) : base(message) { this.result = CudaResult.Unknown; }
public CudaException(CudaResult result) : base("Cuda Error: " + Enum.GetName(typeof(CudaResult), (object)result)) { this.result = result; }
/// <summary> /// Initializes a new instance of the <see cref="CudaException"/> class. /// </summary> /// <param name="result"></param> public CudaException(CudaResult result) { Result = result; }