Luis B
Luis B

Reputation: 1722

What is the difference between kernel and program object?

I've been through several resources: the OpenCL Khronos book, GATech tutorial, NYU tutorial, and I could go through more. But I still don't understand fully. What is the difference between a kernel and a program object?

So far the best explanation is this for me, but this is not enough for me to fully understand: PROGRAM OBJECT: A program object encapsulates some source code (with potentially several kernel functions) and its last successful build. KERNEL: A kernel object encapsulates the values of the kernel’s arguments used when the kernel is executed.

Maybe a program object is the code? And the kernel is the compiled executable? Is that it? Because I could understand something like that.

Thanks in advance!

Upvotes: 5

Views: 1824

Answers (2)

Pubudu Premathilaka
Pubudu Premathilaka

Reputation: 11

For an OpenCL context, we can create multiple Program objects. First, I will describe the uses of program objects in the OpenCL application.

  • To facilitate the compilation of the kernels for the devices to which the program is attached
  • To provide facilities for determining build errors and querying the program for information

An OpenCL application uses kernel objects to execute a function parallelly on the device. Kernel objects are created from program objects. A program object can have multiple kernel objects.

  • As we know, to execute kernel we need to pass arguments to it. The primary purpose of kernel objects are this.

To get more clear about it here is an analogy which is given in the book "OpenCL Programming Guide" by Aaftab Munshi et al

An analogy that may be helpful in understanding the distinction between kernel objects and program objects is that the program object is like a dynamic library in that it holds a collection of kernel functions. The kernel object is like a handle to a function within the dynamic library. The program object is created from either source code (OpenCL C) or a compiled program binary (more on this later). The program gets built for any of the devices to which the program object is attached. The kernel object is then used to access properties of the compiled kernel function, enqueue calls to it, and set its arguments.

Upvotes: 0

Robert Ioffe
Robert Ioffe

Reputation: 232

A program is a collection of one or more kernels plus optionally supporting functions. A program could be created from source or from several types of binaries (e.g. SPIR, SPIR-V, native). Some program objects (created from source or from intermediate binaries) need to be built for one or more devices (with clBuildProgram or clCompileProgram and clLinkProgram) prior to selecting kernels from them. The easiest way to think about programs is that they are like DLLs and export kernels for use by the programmer.

Kernel is an executable entity (not necessarily compiled, since you can have built-in kernels that represent piece of hardware (e.g. Video Motion Estimation kernels on Intel hardware)), you can bind its arguments and submit them to various queues for execution.

Upvotes: 8

Related Questions