File: test_block.cl

package info (click to toggle)
pocl 0.13-8
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 18,452 kB
  • ctags: 13,529
  • sloc: lisp: 113,221; cpp: 57,376; ansic: 25,021; sh: 6,150; makefile: 2,067; python: 699; pascal: 98; 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);
}