Beispiel #1
0
        public static CommandQueue Create(Context context, Device device, CommandQueueProperties commandQueueProperties)
        {
            CLError error = CLError.None;

            CLCommandQueue openclCommandQueue = OpenCLDriver.clCreateCommandQueue(context.CLContext, device.CLDeviceID, (ManOCL.Internal.OpenCL.CLCommandQueueProperties)commandQueueProperties, ref error);

            OpenCLError.Validate(error);

            return(new CommandQueue(openclCommandQueue, context, device, commandQueueProperties));
        }
Beispiel #2
0
        /// <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());
            }
        }