bones-compiler 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +117 -0
- data/LICENSE +9 -0
- data/README.rdoc +126 -0
- data/Rakefile +107 -0
- data/VERSION +1 -0
- data/bin/bones +20 -0
- data/examples/applications/ffos.c +552 -0
- data/examples/benchmarks/2mm.c +70 -0
- data/examples/benchmarks/3mm.c +81 -0
- data/examples/benchmarks/adi.c +81 -0
- data/examples/benchmarks/atax.c +65 -0
- data/examples/benchmarks/bicg.c +67 -0
- data/examples/benchmarks/cholesky.c +64 -0
- data/examples/benchmarks/common.h +168 -0
- data/examples/benchmarks/correlation.c +97 -0
- data/examples/benchmarks/covariance.c +77 -0
- data/examples/benchmarks/doitgen.c +63 -0
- data/examples/benchmarks/durbin.c +76 -0
- data/examples/benchmarks/dynprog.c +67 -0
- data/examples/benchmarks/fdtd-2d-apml.c +114 -0
- data/examples/benchmarks/fdtd-2d.c +74 -0
- data/examples/benchmarks/floyd-warshall.c +50 -0
- data/examples/benchmarks/gemm.c +69 -0
- data/examples/benchmarks/gemver.c +89 -0
- data/examples/benchmarks/gesummv.c +64 -0
- data/examples/benchmarks/gramschmidt.c +84 -0
- data/examples/benchmarks/jacobi-1d-imper.c +55 -0
- data/examples/benchmarks/jacobi-2d-imper.c +61 -0
- data/examples/benchmarks/lu.c +57 -0
- data/examples/benchmarks/ludcmp.c +91 -0
- data/examples/benchmarks/mvt.c +65 -0
- data/examples/benchmarks/overview.txt +38 -0
- data/examples/benchmarks/reg_detect.c +82 -0
- data/examples/benchmarks/saxpy.c +45 -0
- data/examples/benchmarks/seidel-2d.c +51 -0
- data/examples/benchmarks/symm.c +74 -0
- data/examples/benchmarks/syr2k.c +65 -0
- data/examples/benchmarks/syrk.c +62 -0
- data/examples/benchmarks/trisolv.c +57 -0
- data/examples/benchmarks/trmm.c +57 -0
- data/examples/chunk/example1.c +54 -0
- data/examples/chunk/example2.c +44 -0
- data/examples/chunk/example3.c +59 -0
- data/examples/chunk/example4.c +55 -0
- data/examples/chunk/example5.c +52 -0
- data/examples/element/example1.c +46 -0
- data/examples/element/example10.c +50 -0
- data/examples/element/example11.c +47 -0
- data/examples/element/example12.c +56 -0
- data/examples/element/example2.c +46 -0
- data/examples/element/example3.c +58 -0
- data/examples/element/example4.c +49 -0
- data/examples/element/example5.c +56 -0
- data/examples/element/example6.c +46 -0
- data/examples/element/example7.c +54 -0
- data/examples/element/example8.c +45 -0
- data/examples/element/example9.c +48 -0
- data/examples/neighbourhood/example1.c +54 -0
- data/examples/neighbourhood/example2.c +55 -0
- data/examples/neighbourhood/example3.c +82 -0
- data/examples/neighbourhood/example4.c +52 -0
- data/examples/shared/example1.c +45 -0
- data/examples/shared/example2.c +51 -0
- data/examples/shared/example3.c +55 -0
- data/examples/shared/example4.c +52 -0
- data/examples/shared/example5.c +48 -0
- data/lib/bones.rb +266 -0
- data/lib/bones/algorithm.rb +541 -0
- data/lib/bones/engine.rb +386 -0
- data/lib/bones/preprocessor.rb +161 -0
- data/lib/bones/species.rb +196 -0
- data/lib/bones/structure.rb +94 -0
- data/lib/bones/variable.rb +169 -0
- data/lib/bones/variablelist.rb +72 -0
- data/lib/castaddon.rb +27 -0
- data/lib/castaddon/index.rb +40 -0
- data/lib/castaddon/node.rb +753 -0
- data/lib/castaddon/type.rb +37 -0
- data/skeletons/CPU-C/common/epilogue.c +0 -0
- data/skeletons/CPU-C/common/globals.c +17 -0
- data/skeletons/CPU-C/common/globals_kernel.c +1 -0
- data/skeletons/CPU-C/common/header.c +0 -0
- data/skeletons/CPU-C/common/mem_copy_D2H.c +0 -0
- data/skeletons/CPU-C/common/mem_copy_H2D.c +0 -0
- data/skeletons/CPU-C/common/mem_epilogue.c +0 -0
- data/skeletons/CPU-C/common/mem_prologue.c +3 -0
- data/skeletons/CPU-C/common/prologue.c +0 -0
- data/skeletons/CPU-C/common/timer_1_start.c +0 -0
- data/skeletons/CPU-C/common/timer_1_stop.c +0 -0
- data/skeletons/CPU-C/common/timer_2_start.c +20 -0
- data/skeletons/CPU-C/common/timer_2_stop.c +8 -0
- data/skeletons/CPU-C/kernel/default.host.c +3 -0
- data/skeletons/CPU-C/kernel/default.kernel.c +15 -0
- data/skeletons/CPU-C/skeletons.txt +24 -0
- data/skeletons/CPU-OPENCL-AMD/common/epilogue.c +6 -0
- data/skeletons/CPU-OPENCL-AMD/common/globals.c +155 -0
- data/skeletons/CPU-OPENCL-AMD/common/globals_kernel.c +4 -0
- data/skeletons/CPU-OPENCL-AMD/common/header.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/mem_copy_D2H.c +8 -0
- data/skeletons/CPU-OPENCL-AMD/common/mem_copy_H2D.c +4 -0
- data/skeletons/CPU-OPENCL-AMD/common/mem_epilogue.c +3 -0
- data/skeletons/CPU-OPENCL-AMD/common/mem_prologue.c +6 -0
- data/skeletons/CPU-OPENCL-AMD/common/prologue.c +24 -0
- data/skeletons/CPU-OPENCL-AMD/common/timer_1_start.c +5 -0
- data/skeletons/CPU-OPENCL-AMD/common/timer_1_stop.c +9 -0
- data/skeletons/CPU-OPENCL-AMD/common/timer_2_start.c +16 -0
- data/skeletons/CPU-OPENCL-AMD/common/timer_2_stop.c +11 -0
- data/skeletons/CPU-OPENCL-AMD/kernel/D-element-to-1-shared.host.c +67 -0
- data/skeletons/CPU-OPENCL-AMD/kernel/D-element-to-1-shared.kernel.cl +72 -0
- data/skeletons/CPU-OPENCL-AMD/kernel/default.host.c +14 -0
- data/skeletons/CPU-OPENCL-AMD/kernel/default.kernel.cl +13 -0
- data/skeletons/CPU-OPENCL-AMD/skeletons.txt +26 -0
- data/skeletons/CPU-OPENCL-INTEL/common/epilogue.c +3 -0
- data/skeletons/CPU-OPENCL-INTEL/common/globals.c +154 -0
- data/skeletons/CPU-OPENCL-INTEL/common/globals_kernel.c +4 -0
- data/skeletons/CPU-OPENCL-INTEL/common/header.c +31 -0
- data/skeletons/CPU-OPENCL-INTEL/common/mem_copy_D2H.c +5 -0
- data/skeletons/CPU-OPENCL-INTEL/common/mem_copy_H2D.c +3 -0
- data/skeletons/CPU-OPENCL-INTEL/common/mem_epilogue.c +3 -0
- data/skeletons/CPU-OPENCL-INTEL/common/mem_prologue.c +4 -0
- data/skeletons/CPU-OPENCL-INTEL/common/prologue.c +24 -0
- data/skeletons/CPU-OPENCL-INTEL/common/timer_1_start.c +5 -0
- data/skeletons/CPU-OPENCL-INTEL/common/timer_1_stop.c +9 -0
- data/skeletons/CPU-OPENCL-INTEL/common/timer_2_start.c +16 -0
- data/skeletons/CPU-OPENCL-INTEL/common/timer_2_stop.c +11 -0
- data/skeletons/CPU-OPENCL-INTEL/kernel/D-element-to-1-shared.host.c +67 -0
- data/skeletons/CPU-OPENCL-INTEL/kernel/D-element-to-1-shared.kernel.cl +72 -0
- data/skeletons/CPU-OPENCL-INTEL/kernel/default.host.c +14 -0
- data/skeletons/CPU-OPENCL-INTEL/kernel/default.kernel.cl +13 -0
- data/skeletons/CPU-OPENCL-INTEL/skeletons.txt +26 -0
- data/skeletons/CPU-OPENMP/common/epilogue.c +0 -0
- data/skeletons/CPU-OPENMP/common/globals.c +37 -0
- data/skeletons/CPU-OPENMP/common/globals_kernel.c +6 -0
- data/skeletons/CPU-OPENMP/common/header.c +0 -0
- data/skeletons/CPU-OPENMP/common/mem_copy_D2H.c +0 -0
- data/skeletons/CPU-OPENMP/common/mem_copy_H2D.c +0 -0
- data/skeletons/CPU-OPENMP/common/mem_epilogue.c +0 -0
- data/skeletons/CPU-OPENMP/common/mem_prologue.c +3 -0
- data/skeletons/CPU-OPENMP/common/prologue.c +0 -0
- data/skeletons/CPU-OPENMP/common/timer_1_start.c +12 -0
- data/skeletons/CPU-OPENMP/common/timer_1_stop.c +0 -0
- data/skeletons/CPU-OPENMP/common/timer_2_start.c +18 -0
- data/skeletons/CPU-OPENMP/common/timer_2_stop.c +8 -0
- data/skeletons/CPU-OPENMP/kernel/D-element-to-1-shared.host.c +27 -0
- data/skeletons/CPU-OPENMP/kernel/D-element-to-1-shared.kernel.c +46 -0
- data/skeletons/CPU-OPENMP/kernel/default.host.c +11 -0
- data/skeletons/CPU-OPENMP/kernel/default.kernel.c +18 -0
- data/skeletons/CPU-OPENMP/skeletons.txt +26 -0
- data/skeletons/GPU-CUDA/common/epilogue.c +0 -0
- data/skeletons/GPU-CUDA/common/globals.c +31 -0
- data/skeletons/GPU-CUDA/common/globals_kernel.c +4 -0
- data/skeletons/GPU-CUDA/common/header.c +0 -0
- data/skeletons/GPU-CUDA/common/mem_copy_D2H.c +3 -0
- data/skeletons/GPU-CUDA/common/mem_copy_H2D.c +3 -0
- data/skeletons/GPU-CUDA/common/mem_epilogue.c +3 -0
- data/skeletons/GPU-CUDA/common/mem_prologue.c +5 -0
- data/skeletons/GPU-CUDA/common/prologue.c +6 -0
- data/skeletons/GPU-CUDA/common/timer_1_start.c +6 -0
- data/skeletons/GPU-CUDA/common/timer_1_stop.c +10 -0
- data/skeletons/GPU-CUDA/common/timer_2_start.c +6 -0
- data/skeletons/GPU-CUDA/common/timer_2_stop.c +10 -0
- data/skeletons/GPU-CUDA/kernel/2xN-N-chunk-1-N-to-D-element.host.c +3 -0
- data/skeletons/GPU-CUDA/kernel/2xN-N-chunk-1-N-to-D-element.kernel.cu +105 -0
- data/skeletons/GPU-CUDA/kernel/D-element-to-1-shared.host.c +3 -0
- data/skeletons/GPU-CUDA/kernel/D-element-to-1-shared.kernel.cu +119 -0
- data/skeletons/GPU-CUDA/kernel/D-element-to-N-shared.host.c +3 -0
- data/skeletons/GPU-CUDA/kernel/D-element-to-N-shared.kernel.cu +166 -0
- data/skeletons/GPU-CUDA/kernel/N-N-chunk-1-N-to-D-element.host.c +3 -0
- data/skeletons/GPU-CUDA/kernel/N-N-chunk-1-N-to-D-element.kernel.cu +69 -0
- data/skeletons/GPU-CUDA/kernel/N-neighbourhood-N-to-N-element.host.c +3 -0
- data/skeletons/GPU-CUDA/kernel/N-neighbourhood-N-to-N-element.kernel.cu +42 -0
- data/skeletons/GPU-CUDA/kernel/default.host.c +3 -0
- data/skeletons/GPU-CUDA/kernel/default.kernel.cu +28 -0
- data/skeletons/GPU-CUDA/skeletons.txt +30 -0
- data/skeletons/GPU-OPENCL-AMD/common/epilogue.c +3 -0
- data/skeletons/GPU-OPENCL-AMD/common/globals.c +155 -0
- data/skeletons/GPU-OPENCL-AMD/common/globals_kernel.c +4 -0
- data/skeletons/GPU-OPENCL-AMD/common/header.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/mem_copy_D2H.c +4 -0
- data/skeletons/GPU-OPENCL-AMD/common/mem_copy_H2D.c +4 -0
- data/skeletons/GPU-OPENCL-AMD/common/mem_epilogue.c +3 -0
- data/skeletons/GPU-OPENCL-AMD/common/mem_prologue.c +3 -0
- data/skeletons/GPU-OPENCL-AMD/common/prologue.c +24 -0
- data/skeletons/GPU-OPENCL-AMD/common/timer_1_start.c +5 -0
- data/skeletons/GPU-OPENCL-AMD/common/timer_1_stop.c +9 -0
- data/skeletons/GPU-OPENCL-AMD/common/timer_2_start.c +4 -0
- data/skeletons/GPU-OPENCL-AMD/common/timer_2_stop.c +11 -0
- data/skeletons/GPU-OPENCL-AMD/kernel/D-element-to-1-shared.host.c +67 -0
- data/skeletons/GPU-OPENCL-AMD/kernel/D-element-to-1-shared.kernel.cl +72 -0
- data/skeletons/GPU-OPENCL-AMD/kernel/default.host.c +14 -0
- data/skeletons/GPU-OPENCL-AMD/kernel/default.kernel.cl +13 -0
- data/skeletons/GPU-OPENCL-AMD/skeletons.txt +26 -0
- data/skeletons/verification/header.c +2 -0
- data/skeletons/verification/timer_start.c +4 -0
- data/skeletons/verification/timer_stop.c +6 -0
- data/skeletons/verification/verify_results.c +23 -0
- data/test/bones/test_algorithm.rb +40 -0
- data/test/bones/test_common.rb +54 -0
- data/test/bones/test_preprocessor.rb +46 -0
- data/test/bones/test_species.rb +21 -0
- data/test/bones/test_variable.rb +84 -0
- data/test/test_helper.rb +106 -0
- metadata +303 -0
@@ -0,0 +1,49 @@
|
|
1
|
+
//
|
2
|
+
// This file is part of the Bones source-to-source compiler examples. This C-code
|
3
|
+
// example is meant to illustrate the use of Bones. For more information on Bones
|
4
|
+
// use the contact information below.
|
5
|
+
//
|
6
|
+
// == More information on Bones
|
7
|
+
// Contact............Cedric Nugteren <c.nugteren@tue.nl>
|
8
|
+
// Web address........http://parse.ele.tue.nl/bones/
|
9
|
+
//
|
10
|
+
// == File information
|
11
|
+
// Filename...........element/example4.c
|
12
|
+
// Author.............Cedric Nugteren
|
13
|
+
// Last modified on...16-April-2012
|
14
|
+
//
|
15
|
+
|
16
|
+
#include <stdio.h>
|
17
|
+
|
18
|
+
// This is 'example4', demonstrating two input arrays and an inner-loop as the computational body
|
19
|
+
int main(void) {
|
20
|
+
int i,l;
|
21
|
+
float factor = 0;
|
22
|
+
|
23
|
+
// Declare input/output arrays
|
24
|
+
float A[700];
|
25
|
+
float B[700];
|
26
|
+
float C[700];
|
27
|
+
|
28
|
+
// Set the input data
|
29
|
+
for(i=0;i<700;i++) {
|
30
|
+
A[i] = i*2.3;
|
31
|
+
B[i] = i+6.0;
|
32
|
+
}
|
33
|
+
|
34
|
+
// Perform the computation
|
35
|
+
#pragma species kernel 0:699|element ^ 0:699|element -> 0:699|element
|
36
|
+
for(i=0;i<700;i++) {
|
37
|
+
factor = 0.5;
|
38
|
+
for (l=0;l<3;l++) {
|
39
|
+
factor = factor + 0.2*factor;
|
40
|
+
}
|
41
|
+
C[i] = factor*A[i] + factor*B[i];
|
42
|
+
}
|
43
|
+
#pragma species endkernel example4
|
44
|
+
|
45
|
+
// Clean-up and exit the function
|
46
|
+
fflush(stdout);
|
47
|
+
return 0;
|
48
|
+
}
|
49
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
//
|
2
|
+
// This file is part of the Bones source-to-source compiler examples. This C-code
|
3
|
+
// example is meant to illustrate the use of Bones. For more information on Bones
|
4
|
+
// use the contact information below.
|
5
|
+
//
|
6
|
+
// == More information on Bones
|
7
|
+
// Contact............Cedric Nugteren <c.nugteren@tue.nl>
|
8
|
+
// Web address........http://parse.ele.tue.nl/bones/
|
9
|
+
//
|
10
|
+
// == File information
|
11
|
+
// Filename...........element/example5.c
|
12
|
+
// Author.............Cedric Nugteren
|
13
|
+
// Last modified on...16-April-2012
|
14
|
+
//
|
15
|
+
|
16
|
+
#include <stdio.h>
|
17
|
+
#define SIZE 2311
|
18
|
+
|
19
|
+
// This is 'example5', demonstrating multiple inputs and outputs of different types
|
20
|
+
int main(void) {
|
21
|
+
int i;
|
22
|
+
float result = 0;
|
23
|
+
|
24
|
+
// Declare input/output arrays
|
25
|
+
float in1[SIZE];
|
26
|
+
int in2[SIZE];
|
27
|
+
char in3[SIZE];
|
28
|
+
float out1[SIZE];
|
29
|
+
float out2[SIZE];
|
30
|
+
|
31
|
+
// Set the input data
|
32
|
+
for(i=0;i<SIZE;i++) {
|
33
|
+
in1[i] = -0.34*i;
|
34
|
+
in2[i] = i*3;
|
35
|
+
in3[i] = i%100;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Perform the computation
|
39
|
+
#pragma species kernel 0:SIZE-1|element ^ 0:SIZE-1|element ^ 0:SIZE-1|element -> 0:SIZE-1|element ^ 0:SIZE-1|element
|
40
|
+
for(i=0;i<SIZE;i++) {
|
41
|
+
if (in3[i] > 50) {
|
42
|
+
result = in2[i] / in1[i];
|
43
|
+
}
|
44
|
+
else {
|
45
|
+
result = in2[i] * in1[i];
|
46
|
+
}
|
47
|
+
out1[i] = result;
|
48
|
+
out2[i] = in3[i]/255.0;
|
49
|
+
}
|
50
|
+
#pragma species endkernel example5
|
51
|
+
|
52
|
+
// Clean-up and exit the function
|
53
|
+
fflush(stdout);
|
54
|
+
return 0;
|
55
|
+
}
|
56
|
+
|
@@ -0,0 +1,46 @@
|
|
1
|
+
//
|
2
|
+
// This file is part of the Bones source-to-source compiler examples. This C-code
|
3
|
+
// example is meant to illustrate the use of Bones. For more information on Bones
|
4
|
+
// use the contact information below.
|
5
|
+
//
|
6
|
+
// == More information on Bones
|
7
|
+
// Contact............Cedric Nugteren <c.nugteren@tue.nl>
|
8
|
+
// Web address........http://parse.ele.tue.nl/bones/
|
9
|
+
//
|
10
|
+
// == File information
|
11
|
+
// Filename...........element/example6.c
|
12
|
+
// Author.............Cedric Nugteren
|
13
|
+
// Last modified on...16-April-2012
|
14
|
+
//
|
15
|
+
|
16
|
+
#include <stdio.h>
|
17
|
+
#include <stdlib.h>
|
18
|
+
|
19
|
+
// This is 'example6', demonstrating dynamically sized arrays, a dynamically sized kernel, and a classification including variables
|
20
|
+
int main(void) {
|
21
|
+
int i;
|
22
|
+
int N = 2048*2048;
|
23
|
+
|
24
|
+
// Declare input/output arrays
|
25
|
+
int *A = (int *)malloc(N*sizeof(int));
|
26
|
+
int *B = (int *)malloc(N*sizeof(int));
|
27
|
+
|
28
|
+
// Set the input data
|
29
|
+
for(i=0;i<N;i++) {
|
30
|
+
A[i] = i;
|
31
|
+
}
|
32
|
+
|
33
|
+
// Perform the computation
|
34
|
+
#pragma species kernel 0:N-1|element -> 0:N-1|element
|
35
|
+
for(i=0;i<N;i++) {
|
36
|
+
B[i] = A[i] + 3;
|
37
|
+
}
|
38
|
+
#pragma species endkernel example6
|
39
|
+
|
40
|
+
// Clean-up and exit the function
|
41
|
+
free(A);
|
42
|
+
free(B);
|
43
|
+
fflush(stdout);
|
44
|
+
return 0;
|
45
|
+
}
|
46
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
//
|
2
|
+
// This file is part of the Bones source-to-source compiler examples. This C-code
|
3
|
+
// example is meant to illustrate the use of Bones. For more information on Bones
|
4
|
+
// use the contact information below.
|
5
|
+
//
|
6
|
+
// == More information on Bones
|
7
|
+
// Contact............Cedric Nugteren <c.nugteren@tue.nl>
|
8
|
+
// Web address........http://parse.ele.tue.nl/bones/
|
9
|
+
//
|
10
|
+
// == File information
|
11
|
+
// Filename...........element/example7.c
|
12
|
+
// Author.............Cedric Nugteren
|
13
|
+
// Last modified on...16-April-2012
|
14
|
+
|
15
|
+
#include <stdio.h>
|
16
|
+
#include <stdlib.h>
|
17
|
+
|
18
|
+
// This is 'example7', demonstrating variable length arrays (C99 VLAs)
|
19
|
+
int main(void) {
|
20
|
+
int a,b,c;
|
21
|
+
int dim_1A = 50;
|
22
|
+
int dim_1B = 40;
|
23
|
+
|
24
|
+
// Declare input/output arrays
|
25
|
+
int in1[dim_1A][dim_1B][30];
|
26
|
+
int in2[dim_1A][dim_1B][30];
|
27
|
+
int out[dim_1A][dim_1B][30];
|
28
|
+
|
29
|
+
// Set the input data
|
30
|
+
for(a=0;a<dim_1A;a++) {
|
31
|
+
for(b=0;b<dim_1B;b++) {
|
32
|
+
for(c=0;c<30;c++) {
|
33
|
+
in1[a][b][c] = a*b+c;
|
34
|
+
in2[a][b][c] = -(c/4)+6;
|
35
|
+
}
|
36
|
+
}
|
37
|
+
}
|
38
|
+
|
39
|
+
// Perform the computation
|
40
|
+
#pragma species kernel 0:dim_1A-1,0:dim_1B-1,0:29|element ^ 0:dim_1A-1,0:dim_1B-1,0:29|element -> 0:dim_1A-1,0:dim_1B-1,0:29|element
|
41
|
+
for(a=0;a<dim_1A;a++) {
|
42
|
+
for(b=0;b<dim_1B;b++) {
|
43
|
+
for(c=0;c<30;c++) {
|
44
|
+
out[a][b][c] = in1[a][b][c] + in2[a][b][c];
|
45
|
+
}
|
46
|
+
}
|
47
|
+
}
|
48
|
+
#pragma species endkernel example7
|
49
|
+
|
50
|
+
// Clean-up and exit the function
|
51
|
+
fflush(stdout);
|
52
|
+
return 0;
|
53
|
+
}
|
54
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
//
|
2
|
+
// This file is part of the Bones source-to-source compiler examples. This C-code
|
3
|
+
// example is meant to illustrate the use of Bones. For more information on Bones
|
4
|
+
// use the contact information below.
|
5
|
+
//
|
6
|
+
// == More information on Bones
|
7
|
+
// Contact............Cedric Nugteren <c.nugteren@tue.nl>
|
8
|
+
// Web address........http://parse.ele.tue.nl/bones/
|
9
|
+
//
|
10
|
+
// == File information
|
11
|
+
// Filename...........element/example8.c
|
12
|
+
// Author.............Cedric Nugteren
|
13
|
+
// Last modified on...16-April-2012
|
14
|
+
//
|
15
|
+
|
16
|
+
#include <stdio.h>
|
17
|
+
|
18
|
+
// This is 'example8', demonstrating a reading and writing from the same array
|
19
|
+
int main(void) {
|
20
|
+
int i,j;
|
21
|
+
|
22
|
+
// Declare input/output arrays
|
23
|
+
int A[100][16];
|
24
|
+
|
25
|
+
// Set the input data
|
26
|
+
for(i=0;i<100;i++) {
|
27
|
+
for(j=0;j<16;j++) {
|
28
|
+
A[i][j] = i+j;
|
29
|
+
}
|
30
|
+
}
|
31
|
+
|
32
|
+
// Perform the computation
|
33
|
+
#pragma species kernel 0:99,0:15|element -> 0:99,0:15|element
|
34
|
+
for(i=0;i<100;i++) {
|
35
|
+
for(j=0;j<16;j++) {
|
36
|
+
A[i][j] = 2*A[i][j];
|
37
|
+
}
|
38
|
+
}
|
39
|
+
#pragma species endkernel example8
|
40
|
+
|
41
|
+
// Clean-up and exit the function
|
42
|
+
fflush(stdout);
|
43
|
+
return 0;
|
44
|
+
}
|
45
|
+
|
@@ -0,0 +1,48 @@
|
|
1
|
+
//
|
2
|
+
// This file is part of the Bones source-to-source compiler examples. This C-code
|
3
|
+
// example is meant to illustrate the use of Bones. For more information on Bones
|
4
|
+
// use the contact information below.
|
5
|
+
//
|
6
|
+
// == More information on Bones
|
7
|
+
// Contact............Cedric Nugteren <c.nugteren@tue.nl>
|
8
|
+
// Web address........http://parse.ele.tue.nl/bones/
|
9
|
+
//
|
10
|
+
// == File information
|
11
|
+
// Filename...........element/example9.c
|
12
|
+
// Author.............Cedric Nugteren
|
13
|
+
// Last modified on...16-April-2012
|
14
|
+
//
|
15
|
+
|
16
|
+
#include <stdio.h>
|
17
|
+
#include <stdlib.h>
|
18
|
+
|
19
|
+
// This is 'example9', demonstrating a for-loop that does not start at zero
|
20
|
+
int main(void) {
|
21
|
+
int i;
|
22
|
+
int result;
|
23
|
+
int N = 2048*2048;
|
24
|
+
|
25
|
+
// Declare input/output arrays
|
26
|
+
int *A = (int *)malloc(N*sizeof(int));
|
27
|
+
int *B = (int *)malloc(N*sizeof(int));
|
28
|
+
|
29
|
+
// Set the input data
|
30
|
+
for(i=0;i<N;i++) {
|
31
|
+
A[i] = i;
|
32
|
+
}
|
33
|
+
|
34
|
+
// Perform the computation
|
35
|
+
#pragma species kernel 2:N-1|element -> 2:N-1|element
|
36
|
+
for(i=2;i<N;i++) {
|
37
|
+
result = A[i] + 3;
|
38
|
+
B[i] = result * 3;
|
39
|
+
}
|
40
|
+
#pragma species endkernel example9
|
41
|
+
|
42
|
+
// Clean-up and exit the function
|
43
|
+
free(A);
|
44
|
+
free(B);
|
45
|
+
fflush(stdout);
|
46
|
+
return 0;
|
47
|
+
}
|
48
|
+
|
@@ -0,0 +1,54 @@
|
|
1
|
+
//
|
2
|
+
// This file is part of the Bones source-to-source compiler examples. This C-code
|
3
|
+
// example is meant to illustrate the use of Bones. For more information on Bones
|
4
|
+
// use the contact information below.
|
5
|
+
//
|
6
|
+
// == More information on Bones
|
7
|
+
// Contact............Cedric Nugteren <c.nugteren@tue.nl>
|
8
|
+
// Web address........http://parse.ele.tue.nl/bones/
|
9
|
+
//
|
10
|
+
// == File information
|
11
|
+
// Filename...........neighbourhood/example1.c
|
12
|
+
// Author.............Cedric Nugteren
|
13
|
+
// Last modified on...16-April-2012
|
14
|
+
//
|
15
|
+
|
16
|
+
#include <stdio.h>
|
17
|
+
#define SIZE 60000
|
18
|
+
#define NB 2
|
19
|
+
|
20
|
+
// This is 'example1', demonstrating a basic 1D neighbourhood-based computation whose size is set by a define
|
21
|
+
int main(void) {
|
22
|
+
int i,n;
|
23
|
+
float result = 0;
|
24
|
+
|
25
|
+
// Declare input/output arrays
|
26
|
+
float A[SIZE];
|
27
|
+
float B[SIZE];
|
28
|
+
|
29
|
+
// Set the input data
|
30
|
+
for(i=0;i<SIZE;i++) {
|
31
|
+
A[i] = i/2.0;
|
32
|
+
}
|
33
|
+
|
34
|
+
// Perform the computation
|
35
|
+
#pragma species kernel 0:SIZE-1|neighbourhood(-NB:NB) -> 0:SIZE-1|element
|
36
|
+
for(i=0;i<SIZE;i++) {
|
37
|
+
if (i >= NB && i < SIZE-NB) {
|
38
|
+
result = 0;
|
39
|
+
for (n=-NB;n<=NB;n++) {
|
40
|
+
result = result + A[i+n];
|
41
|
+
}
|
42
|
+
B[i] = result / (NB*2+1);
|
43
|
+
}
|
44
|
+
else {
|
45
|
+
B[i] = A[i];
|
46
|
+
}
|
47
|
+
}
|
48
|
+
#pragma species endkernel example1
|
49
|
+
|
50
|
+
// Clean-up and exit the function
|
51
|
+
fflush(stdout);
|
52
|
+
return 0;
|
53
|
+
}
|
54
|
+
|
@@ -0,0 +1,55 @@
|
|
1
|
+
//
|
2
|
+
// This file is part of the Bones source-to-source compiler examples. This C-code
|
3
|
+
// example is meant to illustrate the use of Bones. For more information on Bones
|
4
|
+
// use the contact information below.
|
5
|
+
//
|
6
|
+
// == More information on Bones
|
7
|
+
// Contact............Cedric Nugteren <c.nugteren@tue.nl>
|
8
|
+
// Web address........http://parse.ele.tue.nl/bones/
|
9
|
+
//
|
10
|
+
// == File information
|
11
|
+
// Filename...........neighbourhood/example2.c
|
12
|
+
// Author.............Cedric Nugteren
|
13
|
+
// Last modified on...16-April-2012
|
14
|
+
//
|
15
|
+
|
16
|
+
#include <stdio.h>
|
17
|
+
#define A 256
|
18
|
+
#define B 512
|
19
|
+
|
20
|
+
// This is 'example2', demonstrating a 2D array, a 2D neighbourhood and a for-loop-less notation of the neighbourhood accesses
|
21
|
+
int main(void) {
|
22
|
+
int i,j;
|
23
|
+
|
24
|
+
// Declare input/output arrays
|
25
|
+
float in[A][B];
|
26
|
+
float out[A][B];
|
27
|
+
|
28
|
+
// Set the input data
|
29
|
+
for(i=0;i<A;i++) {
|
30
|
+
for(j=0;j<B;j++) {
|
31
|
+
in[i][j] = i+j;
|
32
|
+
}
|
33
|
+
}
|
34
|
+
|
35
|
+
// Perform the computation
|
36
|
+
#pragma species kernel 0:255,0:511|neighbourhood(-1:1,-1:1) -> 0:255,0:511|element
|
37
|
+
for(i=0;i<A;i++) {
|
38
|
+
for(j=0;j<B;j++) {
|
39
|
+
if (i >= 1 && j >= 1 && i < (A-1) && j < (B-1)) {
|
40
|
+
out[i][j] = (in[i+1][j+1] + in[i+1][ j ] + in[i+1][j-1] +
|
41
|
+
in[ i ][j+1] + in[ i ][ j ] + in[ i ][j-1] +
|
42
|
+
in[i-1][j+1] + in[i-1][ j ] + in[i-1][j-1])/9.0;
|
43
|
+
}
|
44
|
+
else {
|
45
|
+
out[i][j] = in[i][j];
|
46
|
+
}
|
47
|
+
}
|
48
|
+
}
|
49
|
+
#pragma species endkernel example2
|
50
|
+
|
51
|
+
// Clean-up and exit the function
|
52
|
+
fflush(stdout);
|
53
|
+
return 0;
|
54
|
+
}
|
55
|
+
|
@@ -0,0 +1,82 @@
|
|
1
|
+
//
|
2
|
+
// This file is part of the Bones source-to-source compiler examples. This C-code
|
3
|
+
// example is meant to illustrate the use of Bones. For more information on Bones
|
4
|
+
// use the contact information below.
|
5
|
+
//
|
6
|
+
// == More information on Bones
|
7
|
+
// Contact............Cedric Nugteren <c.nugteren@tue.nl>
|
8
|
+
// Web address........http://parse.ele.tue.nl/bones/
|
9
|
+
//
|
10
|
+
// == File information
|
11
|
+
// Filename...........neighbourhood/example3.c
|
12
|
+
// Author.............Cedric Nugteren
|
13
|
+
// Last modified on...16-April-2012
|
14
|
+
//
|
15
|
+
|
16
|
+
#include <stdio.h>
|
17
|
+
#include <stdlib.h>
|
18
|
+
#include <math.h>
|
19
|
+
#define A 1024
|
20
|
+
#define B 1536
|
21
|
+
|
22
|
+
// Forward declarations of helper functions for statically allocated 2D memory
|
23
|
+
float ** alloc_2D(int size1, int size2);
|
24
|
+
void free_2D(float ** array_2D);
|
25
|
+
|
26
|
+
// This is 'example3', demonstrating a neighbourhood with only some values used (a cross) and a math.h square root function call
|
27
|
+
int main(void) {
|
28
|
+
int i,j;
|
29
|
+
int sizea = A;
|
30
|
+
int sizeb = B;
|
31
|
+
|
32
|
+
// Declare input/output arrays
|
33
|
+
float **in = alloc_2D(sizea,sizeb);
|
34
|
+
float **out = alloc_2D(sizea,sizeb);
|
35
|
+
|
36
|
+
// Set the input data
|
37
|
+
for(i=0;i<sizea;i++) {
|
38
|
+
for(j=0;j<sizeb;j++) {
|
39
|
+
in[i][j] = i+j;
|
40
|
+
}
|
41
|
+
}
|
42
|
+
|
43
|
+
// Perform the computation
|
44
|
+
#pragma species kernel 0:sizea-1,0:sizeb-1|neighbourhood(-1:1,-1:1) -> 0:sizea-1,0:sizeb-1|element
|
45
|
+
for(i=0;i<sizea;i++) {
|
46
|
+
for(j=0;j<sizeb;j++) {
|
47
|
+
if (i >= 1 && j >= 1 && i < (sizea-1) && j < (sizeb-1)) {
|
48
|
+
out[i][j] = in[i+1][ j ] +
|
49
|
+
in[ i ][j+1] + in[ i ][ j ] + in[ i ][j-1] +
|
50
|
+
in[i-1][ j ] ;
|
51
|
+
}
|
52
|
+
else {
|
53
|
+
out[i][j] = sqrt(in[i][j]);
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
57
|
+
#pragma species endkernel example3
|
58
|
+
|
59
|
+
// Clean-up and exit the function
|
60
|
+
free_2D(in);
|
61
|
+
free_2D(out);
|
62
|
+
fflush(stdout);
|
63
|
+
return 0;
|
64
|
+
}
|
65
|
+
|
66
|
+
// Helper function to allocate a 2D-array
|
67
|
+
float ** alloc_2D(int size1, int size2) {
|
68
|
+
int a;
|
69
|
+
float ** array_2D = (float **)malloc(size1*sizeof(float*));
|
70
|
+
float * array_1D = (float *)malloc(size1*size2*sizeof(float));
|
71
|
+
for (a=0; a<size1; a++) {
|
72
|
+
array_2D[a] = &array_1D[a*size2];
|
73
|
+
}
|
74
|
+
return array_2D;
|
75
|
+
}
|
76
|
+
|
77
|
+
// Helper function to free a 2D-array
|
78
|
+
void free_2D(float ** array_2D) {
|
79
|
+
free(array_2D[0]);
|
80
|
+
free(array_2D);
|
81
|
+
}
|
82
|
+
|