1

In the article "How to set up Xcode to run OpenCL code, and how to verify the kernels before building" NeXTCoder referred to some code as the "Short Answer", i.e. https://developer.apple.com/library/mac/#documentation/Performance/Conceptual/OpenCL_MacProgGuide/XCodeHelloWorld/XCodeHelloWorld.html.

In that code the author says "Wrap your kernel code into a kernel block:" without explaining what is a "kernel block". (The OpenCL Programmer Guide for Mac OS X by Apple makes no mention of kernel block.)

The host program calls "square_kernel" but the sample kernel is called "square" and the sample kernel block is labelled "kernelName" (in italics). Can you please tell me how to put the 3 pieces together:kernel, kernel block & host program to run in Xcode 5.1? I only have one kernel. Thanks.

user1118321
  • 25,567
  • 4
  • 55
  • 86
rsacker
  • 9
  • 4
  • When talking about the "article", you seem to refer to the answer to http://stackoverflow.com/questions/13046035/how-to-set-up-xcode-to-run-opencl-code-and-how-to-verify-the-kernels-before-bui – Marco13 Aug 24 '14 at 10:23

2 Answers2

1

It's not really jargon. It's closure-like entity.

OpenCL C 2.0 adds support for the clang block syntax. You use the ^ operator to declare a Block variable and to indicate the beginning of a Block literal. The body of the Block itself is contained within {}, as shown in the example (as usual with C, ; indicates the end of the statement).The Block is able to make use of variables from the same scope in which it was defined.

Example:

int multiplier = 7;
int (^myBlock)(int) = ^(int num) {
    return num * multiplier;
};
printf(ā€œ%d\nā€, myBlock(3));
// prints 21

Source: https://www.khronos.org/registry/cl/sdk/2.1/docs/man/xhtml/blocks.html

Vinoth Krishnan
  • 2,925
  • 6
  • 29
  • 34
Kos
  • 1,547
  • 14
  • 23
-1

The term "kernel block" only seems to be a jargon to refer to the "part of the code that is the kernel". Particularly, the kernel block in this case is simply the function that is declared to be a kernel, by adding kernel before its declaration. Or, even simpler, and from the way how the term is used on this website, I would say that "kernel block" is the same as "kernel".

The kernelName (in italics) is a placeholder. The code there shows the general pattern of how to define any kernel:

  • It is prefixed with kernel
  • It returns void
  • It has a name ... the kernelName, which may for example be square
  • It has several input- and output parameters

The reason why the kernel is called square, but invoked with square_kernel seems to be some magic that is done by XCode: It seems to read the .cl file, and creates a .h file that contains additional declarations that are derived from the .cl file (as can be seen in this question, where a kernel called rebound is defined, and GCL generated a rebound_kernel declaration).

Community
  • 1
  • 1
Marco13
  • 53,703
  • 9
  • 80
  • 159
  • Marco 13's answer to racker's question was very helpful. Can someone recommend a good source for learning how to put an OpenCL program together on Xcode 5.1 using C++11 that contains more "how to" and less "you can". – rsacker Aug 26 '14 at 22:09