Hi all
I am new to BROOK+.Can anyone please send me references and relevant materials which supports for learn and study brook+ language.can anyone help to solve the following problem,pls,,
task to read an image 4x4 array ,
example
0 1 2 3
4 5 6 7
8 9 10 11
12 13 14 15
In this array I divided into 4 regions,, R1 (0,1,4,5) R2(2,3,,6,7) R3(8,9,12,13) R4(10,11,14,15),
The problem is how to write the parallel comparison brook+ program to get the minimum,maximum and average value of the regions,,
R1 R2
0 10
1 11
4 14
5 15
These comparison R1(0) with other 4 elements in R2 region and so on,,It should be paralleled comparison, because GPU can do it parallel y. Could you please send sample codings for BROOK+ program and supported links for solve this problem,,
Thanking You,
Anushka .
Hi Anushka,
You can take a look at stream computing user guide under Brook+ doc directory. You can first start with Appendix A and then chapter 2 of it.
Brook+ supports parallel reduction, so writing a reduction kernel to find max, min or sum of your input array will solve your problem. Section A.4.1.2 and A.4.1.3 talks about reduction and contains some examples.
You can also take a look at different samples coming with Brook+ SDK.
Thank you very much,,
Hi gaurav
I am working with this problem,but I am stuck with parallel comparison with 2 regions(array) and getting max,min and avg of that results. the sample c program as follow,,
for (i = 0; i < region_1.no_pixels; i++) {
for (j = 0; j < region_2.no_pixels; j++) {
pixel_1 = region_1.pixel_array.value;
pixel_2 = region_2.pixel_array
pixel_diff = abs(pixel_1 - pixel_2);
if (pixel_diff < min_val) min_val = pixel_diff;
if (pixel_diff > max_val) max_val = pixel_diff;
avg_val = avg_val + pixel_diff;
count++;
}
}
region_stats->max_diff = max_val;
region_stats->min_diff = min_val;
region_stats->avg_diff = (avg_val/count);
since this uses for loop for comparison,how do we use reduction without for loop in brook+,
please help,,
thank you,
Reduction in Brook+ can be aplied only on binary commutative and associative operator. e.g. You can find min, max or avg. of a single stream.But, you can't operate simultaneously on multiple input streams.
Hi ,
Before get the max,min,avg,, I want to get the absolute difference values of the two regions and these comparison should be done in parallel. Then the out put valus can be considred as input stream of what i need. so could u tell me how to approach this using Brook+,,
Thank you.
You can calculate the absolute difference in one kernel and then the ouput stream of this kernel can be sent to another reduction kernel.
could you suggest related examples and clues from the SDK examples and Steam computing user giuds.I have gone through these stuff but (swizzle,scatter,index),,
Thank you.
Look at the sample under $(BROOKROOT)\samples\CPP\apps\SparseMatrixVector, it does some operations on input stream first in a seperate kernel and then use reduce kernel on previous output streams.
Hi
Thank you,Could u suggest how to get the difference within two regions parallelly.
Hi ;
This is my Brook program and I could get the differences of the 2 regions, but I have no idea to get the max,min and avg using reduction, The reduction part of Strem computing user guides does not contain much information. Because I need to get the max,min,avg values of the output streams. Please help,,
thank you.
# include <stdio.h>
kernel void sub(float a<>,float b<>,out float c<>
{
c=abs(a-b);
}
int main(int argc,char **argv)
{
int i,j;
int pixel_value=0;
float input_a[4];
float input_b[4];
float temp_c_array[4];
float *output_ptr;
float outputs[4][4];
float array1< 4 >;
float array2< 4 >;
float out_array<4>;
float Image[4][4];
for (i=0; i<4;i++)
{
for(j=0;j<4;j++)
{
Image
pixel_value++;
}
}
//To form the Region 1 of the Image
input_a[0]=Image[0][0];
input_a[1]=Image[0][1];
input_a[2]=Image[1][0];
input_a[3]=Image[1][1];
//To form the Region 2 of the Image
input_b[0]=Image[2][2];
input_b[1]=Image[2][3];
input_b[2]=Image[3][2];
input_b[3]=Image[3][3];
printf("array 1 values \n");
for (i=0; i<4;i++){
printf("%5.0f",input_a
printf("\n");
}
printf("array 2 values \n");
for (i=0; i<4;i++) {
printf("%5.0f",input_b);
printf("\n");
}
streamRead(array2,input_b);
//Find the Diff between each of the Element in Region 1 with the Elements in R2
for (i = 0; i < 4; i++) { //Outer Loop
temp_c_array[0] = input_a;
temp_c_array[1] = input_a;
temp_c_array[2] = input_a;
temp_c_array[3] = input_a;
streamRead(array1,temp_c_array);
sub(array1,array2,out_array);
output_ptr = outputs;
streamWrite(out_array, output_ptr);
}
printf("output arrat after subtracting array1 and array2\n");
for (i = 0; i < 4; i++){
for (j = 0; j < 4; j++){
printf("%5.0f",outputs
}
printf("\n");
}
return 0;
}
////////////////////////////////////////output///////////////////////////////////////
anushka@anushka-desktop:~/Brook/project/progs/ans$ ./subtractnew
array 1 values
0
1
4
5
array 2 values
10
11
14
15
output arrat after subtracting array1 and array2
10 11 14 15
9 10 13 14
6 7 10 11
5 6 9 10