示例#1
0
        public static Program Create(String[] sources, Context context, Devices devices, String buildOptions)
        {
            CLError error = CLError.None;

            CLProgram openclProgram = OpenCLDriver.clCreateProgramWithSource(context.CLContext, sources.Length, sources, GetLengths(sources), ref error);

            OpenCLError.Validate(error);

            OpenCLBuildError.ValidateBuild(openclProgram, devices[0], OpenCLDriver.clBuildProgram(openclProgram, devices.Count, devices.OpenCLDeviceArray, buildOptions, null, IntPtr.Zero));

            return(new Program(openclProgram, sources, context, devices, buildOptions));
        }
示例#2
0
        public static void CreateAsync <T>(CreateCallback <T> createCallback, T userData, String[] sources, Devices devices, Context context, String buildOptions)
        {
            CLError error = CLError.None;

            CLProgram openclProgram = OpenCLDriver.clCreateProgramWithSource(context.CLContext, sources.Length, sources, GetLengths(sources), ref error);

            OpenCLError.Validate(error);

            Program program = new Program(openclProgram, sources, context, devices, buildOptions);

            program.AsyncHelperObject = new AsyncHelper <T>(program, createCallback, userData);

            OpenCLError.Validate(OpenCLDriver.clBuildProgram(openclProgram, devices.Count, devices.OpenCLDeviceArray, buildOptions, program.AsyncCallback, IntPtr.Zero));
        }
示例#3
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());
            }
        }