File: test_block.cl

package info (click to toggle)
pocl 6.0-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,320 kB
  • sloc: lisp: 149,513; ansic: 103,778; cpp: 54,947; python: 1,513; sh: 949; ruby: 255; pascal: 226; tcl: 180; makefile: 175; java: 72; xml: 49
file content (22 lines) | stat: -rw-r--r-- 493 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
void output(float (^op)(float))
{
  printf("op(1)=%f\n", op(1.0f));
}

kernel void test_block()
{
  // Two simple tests
  float (^add1)(float) = ^(float x) { return x + 1.0f; };
  float (^mul2)(float) = ^(float x) { return x * 2.0f; };
  output(add1);
  output(mul2);
  
  // Capture a pointer to a local variable
  float counter = 0.0f;
  float* counterp = &counter;
  float (^stepcounter)(float) = ^(float x) {
    return *counterp += x;
  };
  output(stepcounter);
  output(stepcounter);
}