/// <summary>
/// Creates a runtime compiler instance.
/// </summary>
/// <param name="src">CUDA program source.</param>
/// <param name="name">CUDA program name.<para/>
/// name can be NULL; "default_program" is used when name is NULL.</param>
/// <param name="includeNames">Sources of the headers.</param>
/// <param name="headers">Name of each header by which they can be included in the CUDA program source.</param>
public CudaRuntimeCompiler(string src, string name, string[] headers, string[] includeNames)
{
int headerCount = 0;
IntPtr[] headersPtr = null;
IntPtr[] includeNamesPtr = null;
try
{
if (headers != null && includeNames != null)
{
if (headers.Length != includeNames.Length)
{
throw new ArgumentException("headers and includeNames must have same length.");
}
if (headers == null)
{
throw new ArgumentNullException("headers can't be NULL if includeNames is not NULL");
}
if (includeNames == null)
{
throw new ArgumentNullException("includeNames can't be NULL if headers is not NULL");
}
headerCount = headers.Length;
headersPtr = new IntPtr[headerCount];
includeNamesPtr = new IntPtr[headerCount];
for (int i = 0; i < headerCount; i++)
{
headersPtr[i] = Marshal.StringToHGlobalAnsi(headers[i]);
includeNamesPtr[i] = Marshal.StringToHGlobalAnsi(includeNames[i]);
}
}
_program = new nvrtcProgram();
res = NVRTCNativeMethods.nvrtcCreateProgram(ref _program, src, name, headerCount, headersPtr, includeNamesPtr);
Debug.Write(""); //Line(String.Format("{0:G}, {1}: {2}", DateTime.Now, "nvrtcCreateProgram", res));
}
finally
{
if (headersPtr != null)
{
for (int i = 0; i < headersPtr.Length; i++)
{
Marshal.FreeHGlobal(headersPtr[i]);
}
}
if (includeNamesPtr != null)
{
for (int i = 0; i < includeNamesPtr.Length; i++)
{
Marshal.FreeHGlobal(includeNamesPtr[i]);
}
}
}
if (res != nvrtcResult.Success)
{
throw new NVRTCException(res);
}
}