public OpenCLBuildException(CLProgram program, ErrorCode result) : base("Build failed with error code " + result, result) { foreach (Device d in program.Devices) { BuildLogs.Add(program.GetBuildLog(d)); } }
public void ReleaseDeviceResources() { oclFullyInitialized = false; if (OCLSampler != null) { OCLSampler.Dispose(); OCLSampler = null; } if (OCLInputImage != null) { OCLInputImage.Dispose(); OCLInputImage = null; } if (OCLOutputImage != null) { OCLOutputImage.Dispose(); OCLOutputImage = null; } if (FilterKernel != null) { FilterKernel.Dispose(); FilterKernel = null; } if (oclProgram != null) { oclProgram.Dispose(); oclProgram = null; } if (oclCQ != null) { oclCQ.Dispose(); oclCQ = null; } if (oclContext != null) { oclContext.Dispose(); oclContext = null; } }
protected virtual void Initialize(DeviceType deviceType, string source) { Devices = Platform.QueryDevices(deviceType); if (Devices.Length == 0) { throw new OpenCLException("No devices of type " + deviceType + " present"); } Context = Platform.CreateContext(null, Devices, null, IntPtr.Zero); CQs = new CommandQueue[Devices.Length]; for (int i = 0; i < CQs.Length; i++) { CQs[i] = Context.CreateCommandQueue(Devices[i], CommandQueueProperties.PROFILING_ENABLE); } CQ = CQs[0]; Program = Context.CreateProgramWithSource(source); Program.Build(); Kernels = Program.CreateKernelDictionary(); }
/// <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"); }
public void BuildOCLSource(string source) { oclProgram = oclContext.CreateProgramWithSource(source); oclProgram.Build(); FilterKernel = oclProgram.CreateKernel("FilterImage"); }
internal Kernel(Context context, CLProgram program, IntPtr kernelID) { Context = context; Program = program; KernelID = kernelID; }
public BuildInfo(CLProgram p, Device d) { Program = p; Device = d; }