private extern static ErrorCode clBuildProgram( IntPtr program, UInt32 num_devices, [MarshalAs(UnmanagedType.LPArray)] IntPtr[] device_list, String options, BuildProgramNotifyFunction pfn_notify, IntPtr user_data);
/// <summary> /// Builds the source code and creates the specified <see cref="Kernel"/>. /// </summary> /// <param name="source">The source code of the OpenCL program.</param> /// <param name="functionName">The name of the Kernel to create.</param> /// <param name="buildOptions">The build options to be used for building the program executable.</param> /// <param name="notifyFunction">The callback method which will be called when the program executable has been built (successfully or unsuccessfully).</param> /// <param name="userData">User data passed to the callback.</param> /// <returns>The <see cref="Kernel"/> associated to the function name.</returns> public Kernel BuildKernel(string source, string functionName, string buildOptions = "", BuildProgramNotifyFunction notifyFunction = null, IntPtr userData = default) { IntPtr programHandle = clCreateProgramWithSource(Handle, 1, new string[] { source }, null, out error); if (error != ErrorCode.Success) { return(null); } IntPtr[] deviceHandles = new IntPtr[Devices.Count]; for (int i = 0; i < Devices.Count; i++) { deviceHandles[i] = Devices[i].Handle; } error = clBuildProgram(programHandle, (uint)Devices.Count, deviceHandles, buildOptions, notifyFunction, userData); if (error != ErrorCode.Success) { return(null); } IntPtr kernelHandle = clCreateKernel(programHandle, functionName, out error); if (error != ErrorCode.Success) { return(null); } error = clReleaseProgram(programHandle); if (error != ErrorCode.Success) { return(null); } return(new Kernel(kernelHandle, this)); }
/// <summary> /// Builds the source code and creates all <see cref="Kernel"/>s. /// </summary> /// <param name="source">The source code of the OpenCL program.</param> /// <param name="buildOptions">The build options to be used for building the program executable.</param> /// <param name="notifyFunction">The callback method which will be called when the program executable has been built (successfully or unsuccessfully).</param> /// <param name="userData">User data passed to the callback.</param> /// <returns>A dictionary of <see cref="Kernel"/>s. The key is the kernel name.</returns> public Dictionary <string, Kernel> BuildAllKernels(string source, string buildOptions = "", BuildProgramNotifyFunction notifyFunction = null, IntPtr userData = default) { IntPtr programHandle = clCreateProgramWithSource(Handle, 1, new string[] { source }, null, out error); if (error != ErrorCode.Success) { return(null); } IntPtr[] deviceHandles = new IntPtr[Devices.Count]; for (int i = 0; i < Devices.Count; i++) { deviceHandles[i] = Devices[i].Handle; } error = clBuildProgram(programHandle, (uint)Devices.Count, deviceHandles, buildOptions, notifyFunction, userData); if (error != ErrorCode.Success) { return(null); } error = clCreateKernelsInProgram(programHandle, 0, null, out uint kernelsCount); if (error != ErrorCode.Success) { return(null); } IntPtr[] kernelHandles = new IntPtr[kernelsCount]; error = clCreateKernelsInProgram(programHandle, kernelsCount, kernelHandles, out _); if (error != ErrorCode.Success) { return(null); } error = clReleaseProgram(programHandle); if (error != ErrorCode.Success) { return(null); } var kernels = new Dictionary <string, Kernel>(); for (int i = 0; i < kernelsCount; i++) { Kernel kernel = new Kernel(kernelHandles[i], this); kernels.Add(kernel.Name, kernel); } return(kernels); }