public static Kernel Create(String name, CommandQueue commandQueue, Program sources, params Argument[] arguments) { CLError error = CLError.None; CLKernel openclKernel = OpenCLDriver.clCreateKernel(sources.CLProgram, name, ref error); Kernel result = new Kernel(openclKernel, sources, commandQueue, name.Length + 1); result.InitializeArguments(arguments); return(result); }
/// <summary> /// Setup OpenCL /// </summary> internal static void Setup() { try { // ADD YOUR CODE HERE CLError err; uint num_entries = 0;// get platform CLPlatformID[] platforms = new CLPlatformID[5]; err = OpenCLDriver.clGetPlatformIDs(5, platforms, ref num_entries); if (num_entries == 0) { throw new Exception("No Platform Entries found!"); } //get device ID CLDeviceID[] devices = new CLDeviceID[1]; err = OpenCLDriver.clGetDeviceIDs(platforms[0], CLDeviceType.GPU, 1, devices, ref num_entries); // create context ctx = OpenCLDriver.clCreateContext(null, 1, devices, null, IntPtr.Zero, ref err); if (err != CLError.Success) { throw new Exception(err.ToString()); } // create command queue comQ = OpenCLDriver.clCreateCommandQueue(ctx, devices[0], 0, ref err); if (err != CLError.Success) { throw new Exception(err.ToString()); } // Compile Program string[] progString = new string[1]; progString[0] = File.ReadAllText("..\\..\\prog.cl"); program = OpenCLDriver.clCreateProgramWithSource(ctx, 1, progString, null, ref err); err = OpenCLDriver.clBuildProgram(program, 1, devices, "", null, IntPtr.Zero); //create kernel kernel_mult = OpenCLDriver.clCreateKernel(program, "multiply", ref err); } catch (Exception exc) { MessageBox.Show(exc.ToString()); } }