Brook+ GPU
Brook+ is a C stream programming model for numerical computations on the AMD/ATI Radeon graphics processing units (GPU).
A simplified translation of the following example parallel-for loop is given below.
Grid1 *g = new Grid1(0, n+1);
Grid1IteratorSub it(1, n, g);
DistArray x(g), y(g);
...
float e = 0;
ForEach(int i, it,
x(i) += ( y(i+1) + y(i-1) )*.5;
e += sqr( y(i) ); )
...
|
kernel code:
kernel void sub1(float x[], float y[],
out float xout<>, out float eout<>)
{
float i = 1 + indexof(xout).x;
xout = x[i] + (y[i+1] + y[i-1])*.5f;
eout = y[i] * y[i];
}
reduce void sub2(float y<>, reduce float e<>)
{
e += y;
}
|
main code:
unsigned int n = 8190;
unsigned int n2 = n + 2;
float *x = (float*)malloc(sizeof(float) * n2);
float *y = (float*)malloc(sizeof(float) * n2);
float e;
...
{
float xStream<n>;
float xoutStream<n>;
float yStream<n2>;
float einStream<n2>;
float eStream<1>;
streamRead(xStream, x+1);
streamRead(yStream, y);
sub1(xStream, yStream, xoutStream, einStream);
streamWrite(xoutStream, x+1);
sub2(einStream, eStream);
streamWrite(eStream, &e);
}
...
free(y);
free(x);
|
Arrays larger than the maximum of 8192 in one dimension require some code modifications. Note the limited programming features for the kernel code.