Class Program

All Implemented Interfaces:
OpenCLObject
Direct Known Subclasses:
LwjglProgram

public abstract class Program extends AbstractOpenCLObject
A wrapper for an OpenCL program. A program is created from kernel source code, manages the build process and creates the kernels.

Warning: Creating the same kernel more than one leads to undefined behaviour, this is especially important for createAllKernels()

See Also:
  • Constructor Details

  • Method Details

    • register

      public Program register()
      Description copied from interface: OpenCLObject
      Registers this object for automatic releasing on garbage collection. By default, OpenCLObjects are not registered in the OpenCLObjectManager, you have to release it manually by calling OpenCLObject.release(). Without registering or releasing, a memory leak might occur.
      Returns this to allow calls like Buffer buffer = clContext.createBuffer(1024).register();.
      Specified by:
      register in interface OpenCLObject
      Overrides:
      register in class AbstractOpenCLObject
      Returns:
      this
    • build

      public abstract void build(String args, Device... devices) throws KernelCompilationException
      Builds this program with the specified argument string on the specified devices. Please see the official OpenCL specification for a definition of all supported arguments. The list of devices specify on which device the compiled program can then be executed. It must be a subset of Context.getDevices(). If null is passed, the program is built on all available devices.
      Parameters:
      args - the compilation arguments
      devices - a list of devices on which the program is build.
      Throws:
      KernelCompilationException - if the compilation fails
      See Also:
    • build

      public void build() throws KernelCompilationException
      Builds this program without additional arguments
      Throws:
      KernelCompilationException - if the compilation fails
    • createKernel

      public abstract Kernel createKernel(String name)
      Creates the kernel with the specified name.
      Parameters:
      name - the name of the kernel as defined in the source code
      Returns:
      the kernel object
      Throws:
      OpenCLException - if the kernel was not found or some other error occurred
    • createAllKernels

      public abstract Kernel[] createAllKernels()
      Creates all available kernels in this program. The names of the kernels can then be queried by Kernel.getName().
      Returns:
      an array of all kernels
    • getBinary

      public abstract ByteBuffer getBinary(Device device)
      Queries a compiled binary representation of this program for a particular device. This binary can then be used e.g. in the next application launch to create the program from the binaries and not from the sources. This saves time.
      Parameters:
      device - the device from which the binaries are taken
      Returns:
      the binaries
      See Also: