Exemplo n.º 1
0
        /// <summary>
        /// Create a OpenCLManager, configure it, and then create a context using all devices in platform 0,
        /// Once the context is up and running we compile our source file "OpenCLFunctions.cl"
        /// The Helper automatically compiles and creates kernels.
        /// We can then extract named kernels using the GetKernel method.
        ///
        /// For more advanced scenarios, one might use the functions in the Platform class
        /// to query devices, create contexts etc. Platforms can be enumerated using
        /// for( int i=0; i<OpenCL.NumberofPlatforms; i++ )
        ///     Platform p = OpenCL.GetPlatform(i);
        /// </summary>
        private void InitializeOpenCL()
        {
            if (OpenCL.NumberOfPlatforms == 0)
            {
                MessageBox.Show("OpenCL not available");
                Application.Exit();
            }

            OCLMan = new OpenCLManager();
            // Attempt to save binaries after compilation, as well as load precompiled binaries
            // to avoid compilation. Usually you'll want this to be true.
            OCLMan.AttemptUseBinaries = true;
            // Attempt to compile sources. This should probably be true for almost all projects.
            // Setting it to false means that when you attempt to compile "mysource.cl", it will
            // only scan the precompiled binary directory for a binary corresponding to a source
            // with that name. There's a further restriction that the compiled binary also has to
            // use the same Defines and BuildOptions
            OCLMan.AttemptUseSource = true;
            // Binary and source paths
            // This is where we store our sources and where compiled binaries are placed
            OCLMan.BinaryPath = @"OpenCL\bin";
            OCLMan.SourcePath = @"OpenCL\src";
            // If true, RequireImageSupport will filter out any devices without image support
            // In this project we don't need image support though, so we set it to false
            OCLMan.RequireImageSupport = false;
            // The Defines string gets prepended to any and all sources that are compiled
            // and serve as a convenient way to pass configuration information to the compilation process
            OCLMan.Defines = "#define MyCompany_MyProject_Define 1";
            // The BuildOptions string is passed directly to clBuild and can be used to do debug builds etc
            OCLMan.BuildOptions = "";

            OCLMan.CreateDefaultContext(0, DeviceType.ALL);

            OCLProgram = OCLMan.CompileFile("OpenCLFunctions.cl");

            for (int i = 0; i < OCLMan.Context.Devices.Length; i++)
            {
                comboBoxDeviceSelector.Items.Add(OCLMan.Context.Devices[i].Vendor + ":" + OCLMan.Context.Devices[i].Name);
            }
            comboBoxDeviceSelector.SelectedIndex = 0;

            CrossFadeKernel = OCLProgram.CreateKernel("CrossFade");
        }
Exemplo n.º 2
0
 public void BuildOCLSource(string source)
 {
     oclProgram = oclContext.CreateProgramWithSource(source);
     oclProgram.Build();
     FilterKernel = oclProgram.CreateKernel("FilterImage");
 }