bones-compiler 1.1.0 → 1.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +15 -0
- data/CHANGELOG +37 -0
- data/LICENSE +1 -1
- data/README.rdoc +95 -70
- data/Rakefile +78 -3
- data/VERSION +1 -1
- data/bin/adarwin +17 -0
- data/examples/benchmarks/PolyBench/2mm.c +104 -0
- data/examples/benchmarks/{3mm.c → PolyBench/3mm.c} +5 -2
- data/examples/benchmarks/{adi.c → PolyBench/adi.c} +6 -3
- data/examples/benchmarks/{atax.c → PolyBench/atax.c} +5 -2
- data/examples/benchmarks/{bicg.c → PolyBench/bicg.c} +5 -2
- data/examples/benchmarks/{cholesky.c → PolyBench/cholesky.c} +3 -0
- data/examples/benchmarks/{common.h → PolyBench/common.h} +2 -2
- data/examples/benchmarks/{correlation.c → PolyBench/correlation.c} +16 -7
- data/examples/benchmarks/{covariance.c → PolyBench/covariance.c} +7 -2
- data/examples/benchmarks/{doitgen.c → PolyBench/doitgen.c} +5 -2
- data/examples/benchmarks/{durbin.c → PolyBench/durbin.c} +3 -0
- data/examples/benchmarks/{dynprog.c → PolyBench/dynprog.c} +3 -0
- data/examples/benchmarks/{fdtd-2d-apml.c → PolyBench/fdtd-2d-apml.c} +3 -0
- data/examples/benchmarks/{fdtd-2d.c → PolyBench/fdtd-2d.c} +5 -2
- data/examples/benchmarks/{floyd-warshall.c → PolyBench/floyd-warshall.c} +3 -0
- data/examples/benchmarks/{gemm.c → PolyBench/gemm.c} +5 -2
- data/examples/benchmarks/{gemver.c → PolyBench/gemver.c} +5 -2
- data/examples/benchmarks/{gesummv.c → PolyBench/gesummv.c} +5 -2
- data/examples/benchmarks/{gramschmidt.c → PolyBench/gramschmidt.c} +3 -0
- data/examples/benchmarks/{jacobi-1d-imper.c → PolyBench/jacobi-1d-imper.c} +10 -2
- data/examples/benchmarks/{jacobi-2d-imper.c → PolyBench/jacobi-2d-imper.c} +8 -3
- data/examples/benchmarks/{lu.c → PolyBench/lu.c} +3 -0
- data/examples/benchmarks/{ludcmp.c → PolyBench/ludcmp.c} +3 -0
- data/examples/benchmarks/{mvt.c → PolyBench/mvt.c} +6 -2
- data/examples/benchmarks/{reg_detect.c → PolyBench/reg_detect.c} +3 -0
- data/examples/benchmarks/{seidel-2d.c → PolyBench/seidel-2d.c} +3 -0
- data/examples/benchmarks/{symm.c → PolyBench/symm.c} +3 -0
- data/examples/benchmarks/{syr2k.c → PolyBench/syr2k.c} +5 -2
- data/examples/benchmarks/{syrk.c → PolyBench/syrk.c} +7 -4
- data/examples/benchmarks/{trisolv.c → PolyBench/trisolv.c} +3 -0
- data/examples/benchmarks/{trmm.c → PolyBench/trmm.c} +3 -0
- data/examples/benchmarks/Rodinia/cfd.c +180 -0
- data/examples/benchmarks/Rodinia/hotspot.c +228 -0
- data/examples/benchmarks/Rodinia/kmeans.c +164 -0
- data/examples/benchmarks/Rodinia/srad.c +188 -0
- data/examples/benchmarks/other/common.h +0 -0
- data/examples/benchmarks/other/dct.c +58 -0
- data/examples/benchmarks/other/mm.c +50 -0
- data/examples/benchmarks/{saxpy.c → other/saxpy.c} +11 -7
- data/examples/chunk/{example1.c → example01.c} +0 -0
- data/examples/chunk/{example2.c → example02.c} +0 -0
- data/examples/chunk/{example3.c → example03.c} +0 -0
- data/examples/chunk/{example4.c → example04.c} +0 -0
- data/examples/chunk/{example5.c → example05.c} +0 -0
- data/examples/chunk/example06.c +45 -0
- data/examples/chunk/example07.c +49 -0
- data/examples/dependences/example01.c +42 -0
- data/examples/dependences/example02.c +40 -0
- data/examples/dependences/example03.c +43 -0
- data/examples/dependences/example04.c +44 -0
- data/examples/dependences/example05.c +42 -0
- data/examples/element/{example1.c → example01.c} +0 -0
- data/examples/element/{example2.c → example02.c} +2 -2
- data/examples/element/{example3.c → example03.c} +0 -0
- data/examples/element/{example4.c → example04.c} +0 -0
- data/examples/element/{example5.c → example05.c} +0 -0
- data/examples/element/{example6.c → example06.c} +0 -0
- data/examples/element/{example7.c → example07.c} +0 -0
- data/examples/element/{example8.c → example08.c} +0 -0
- data/examples/element/{example9.c → example09.c} +0 -0
- data/examples/element/example13.c +73 -0
- data/examples/fusion/example01.c +68 -0
- data/examples/fusion/example02.c +73 -0
- data/examples/fusion/example03.c +72 -0
- data/examples/fusion/example04.c +61 -0
- data/examples/fusion/example05.c +55 -0
- data/examples/neighbourhood/{example1.c → example01.c} +0 -0
- data/examples/neighbourhood/{example2.c → example02.c} +0 -0
- data/examples/neighbourhood/{example3.c → example03.c} +0 -0
- data/examples/neighbourhood/{example4.c → example04.c} +0 -0
- data/examples/neighbourhood/example05.c +44 -0
- data/examples/shared/{example1.c → example01.c} +0 -0
- data/examples/shared/{example2.c → example02.c} +0 -0
- data/examples/shared/{example3.c → example03.c} +0 -0
- data/examples/shared/{example4.c → example04.c} +0 -0
- data/examples/shared/{example5.c → example05.c} +0 -0
- data/lib/adarwin.rb +62 -0
- data/lib/adarwin/dependences.rb +268 -0
- data/lib/adarwin/engine.rb +277 -0
- data/lib/adarwin/fusion.rb +174 -0
- data/lib/adarwin/interval.rb +57 -0
- data/lib/adarwin/memorycopies.rb +153 -0
- data/lib/adarwin/nest.rb +225 -0
- data/lib/adarwin/preprocessor.rb +76 -0
- data/lib/adarwin/reference.rb +261 -0
- data/lib/bones.rb +4 -55
- data/lib/bones/algorithm.rb +77 -40
- data/lib/bones/copy.rb +26 -0
- data/lib/bones/engine.rb +147 -31
- data/lib/bones/preprocessor.rb +92 -12
- data/lib/bones/species.rb +4 -3
- data/lib/bones/structure.rb +14 -4
- data/lib/castaddon.rb +11 -6
- data/lib/castaddon/node_adarwin.rb +245 -0
- data/lib/castaddon/node_bones.rb +316 -0
- data/lib/castaddon/node_common.rb +289 -0
- data/lib/castaddon/transformations.rb +236 -0
- data/lib/common.rb +216 -0
- data/skeletons/CPU-C/common/header.c +3 -0
- data/skeletons/CPU-C/common/mem_global.c +0 -0
- data/skeletons/CPU-C/common/timer_2_start.c +11 -13
- data/skeletons/CPU-C/common/timer_2_stop.c +1 -1
- data/skeletons/CPU-C/common/timer_globals.c +29 -0
- data/skeletons/CPU-OPENCL-INTEL/common/globals.c +1 -1
- data/skeletons/CPU-OPENCL-INTEL/common/header.c +3 -0
- data/skeletons/CPU-OPENCL-INTEL/common/mem_copy_D2H.c +7 -2
- data/skeletons/CPU-OPENCL-INTEL/common/mem_copy_H2D.c +4 -2
- data/skeletons/CPU-OPENCL-INTEL/common/mem_global.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/mem_prologue.c +6 -3
- data/skeletons/CPU-OPENCL-INTEL/common/timer_2_stop.c +1 -1
- data/skeletons/CPU-OPENCL-INTEL/common/timer_globals.c +24 -0
- data/skeletons/CPU-OPENMP/common/globals.c +1 -0
- data/skeletons/CPU-OPENMP/common/header.c +3 -0
- data/skeletons/CPU-OPENMP/common/mem_global.c +0 -0
- data/skeletons/CPU-OPENMP/common/timer_1_start.c +0 -12
- data/skeletons/CPU-OPENMP/common/timer_2_stop.c +1 -1
- data/skeletons/CPU-OPENMP/common/timer_globals.c +33 -0
- data/skeletons/GPU-CUDA/common/globals.c +27 -3
- data/skeletons/GPU-CUDA/common/header.c +2 -0
- data/skeletons/GPU-CUDA/common/mem_async_alloc.c +6 -0
- data/skeletons/GPU-CUDA/common/mem_async_copyin.c +6 -0
- data/skeletons/GPU-CUDA/common/mem_async_copyout.c +6 -0
- data/skeletons/GPU-CUDA/common/mem_async_free.c +6 -0
- data/skeletons/GPU-CUDA/common/mem_copy_D2H.c +2 -1
- data/skeletons/GPU-CUDA/common/mem_copy_H2D.c +2 -1
- data/skeletons/GPU-CUDA/common/mem_global.c +1 -0
- data/skeletons/GPU-CUDA/common/mem_prologue.c +1 -2
- data/skeletons/GPU-CUDA/common/scheduler.c +86 -0
- data/skeletons/GPU-CUDA/common/timer_2_start.c +2 -4
- data/skeletons/GPU-CUDA/common/timer_2_stop.c +3 -5
- data/skeletons/GPU-CUDA/common/timer_globals.c +26 -0
- data/skeletons/GPU-CUDA/kernel/2xN-N-chunk-1-N-to-D-element.kernel.cu +5 -7
- data/skeletons/GPU-CUDA/kernel/N-N-chunk-1-N-to-D-element.kernel.cu +4 -6
- data/skeletons/GPU-CUDA/kernel/default.host.c +1 -1
- data/skeletons/GPU-CUDA/kernel/default.kernel.cu +6 -8
- data/skeletons/GPU-CUDA/skeletons.txt +6 -5
- data/{examples/benchmarks/2mm.c → test/examples/benchmarks/PolyBench/2mm_species.c} +19 -15
- data/test/examples/benchmarks/PolyBench/3mm_species.c +82 -0
- data/test/examples/benchmarks/PolyBench/adi_species.c +89 -0
- data/test/examples/benchmarks/PolyBench/atax_species.c +69 -0
- data/test/examples/benchmarks/PolyBench/bicg_species.c +71 -0
- data/test/examples/benchmarks/PolyBench/cholesky_species.c +68 -0
- data/test/examples/benchmarks/PolyBench/correlation_species.c +97 -0
- data/test/examples/benchmarks/PolyBench/covariance_species.c +78 -0
- data/test/examples/benchmarks/PolyBench/doitgen_species.c +67 -0
- data/test/examples/benchmarks/PolyBench/durbin_species.c +80 -0
- data/test/examples/benchmarks/PolyBench/dynprog_species.c +71 -0
- data/test/examples/benchmarks/PolyBench/fdtd-2d-apml_species.c +112 -0
- data/test/examples/benchmarks/PolyBench/fdtd-2d_species.c +78 -0
- data/test/examples/benchmarks/PolyBench/floyd-warshall_species.c +54 -0
- data/test/examples/benchmarks/PolyBench/gemm_species.c +73 -0
- data/test/examples/benchmarks/PolyBench/gemver_species.c +93 -0
- data/test/examples/benchmarks/PolyBench/gesummv_species.c +68 -0
- data/test/examples/benchmarks/PolyBench/gramschmidt_species.c +78 -0
- data/test/examples/benchmarks/PolyBench/jacobi-1d-imper_species.c +59 -0
- data/test/examples/benchmarks/PolyBench/jacobi-2d-imper_species.c +65 -0
- data/test/examples/benchmarks/PolyBench/lu_species.c +57 -0
- data/test/examples/benchmarks/PolyBench/ludcmp_species.c +89 -0
- data/test/examples/benchmarks/PolyBench/mvt_species.c +69 -0
- data/test/examples/benchmarks/PolyBench/reg_detect_species.c +86 -0
- data/test/examples/benchmarks/PolyBench/seidel-2d_species.c +53 -0
- data/test/examples/benchmarks/PolyBench/symm_species.c +74 -0
- data/test/examples/benchmarks/PolyBench/syr2k_species.c +69 -0
- data/test/examples/benchmarks/PolyBench/syrk_species.c +66 -0
- data/test/examples/benchmarks/PolyBench/trisolv_species.c +61 -0
- data/test/examples/benchmarks/PolyBench/trmm_species.c +61 -0
- data/test/examples/chunk/example01_species.c +58 -0
- data/test/examples/chunk/example02_species.c +48 -0
- data/test/examples/chunk/example03_species.c +63 -0
- data/test/examples/chunk/example04_species.c +58 -0
- data/test/examples/chunk/example05_species.c +56 -0
- data/test/examples/chunk/example06_species.c +49 -0
- data/test/examples/chunk/example07_species.c +53 -0
- data/test/examples/dependences/example01_species.c +46 -0
- data/test/examples/dependences/example02_species.c +44 -0
- data/test/examples/dependences/example03_species.c +47 -0
- data/test/examples/dependences/example04_species.c +48 -0
- data/test/examples/dependences/example05_species.c +46 -0
- data/test/examples/element/example01_species.c +50 -0
- data/test/examples/element/example02_species.c +50 -0
- data/test/examples/element/example03_species.c +62 -0
- data/test/examples/element/example04_species.c +53 -0
- data/test/examples/element/example05_species.c +59 -0
- data/test/examples/element/example06_species.c +50 -0
- data/test/examples/element/example07_species.c +58 -0
- data/test/examples/element/example08_species.c +49 -0
- data/test/examples/element/example09_species.c +52 -0
- data/test/examples/element/example10_species.c +54 -0
- data/test/examples/element/example11_species.c +51 -0
- data/test/examples/element/example12_species.c +60 -0
- data/test/examples/element/example13_species.c +77 -0
- data/test/examples/neighbourhood/example01_species.c +57 -0
- data/test/examples/neighbourhood/example02_species.c +56 -0
- data/test/examples/neighbourhood/example03_species.c +83 -0
- data/test/examples/neighbourhood/example04_species.c +55 -0
- data/test/examples/neighbourhood/example05_species.c +48 -0
- data/test/examples/shared/example01_species.c +49 -0
- data/test/examples/shared/example02_species.c +55 -0
- data/test/examples/shared/example03_species.c +59 -0
- data/test/examples/shared/example04_species.c +56 -0
- data/test/examples/shared/example05_species.c +52 -0
- metadata +193 -73
- data/examples/benchmarks/overview.txt +0 -38
- data/lib/castaddon/node.rb +0 -753
|
@@ -0,0 +1,51 @@
|
|
|
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/example11.c
|
|
12
|
+
// Author.............Cedric Nugteren
|
|
13
|
+
// Last modified on...16-April-2012
|
|
14
|
+
//
|
|
15
|
+
|
|
16
|
+
#include <stdio.h>
|
|
17
|
+
|
|
18
|
+
// This is 'example11', demonstrating an inner-loop which is dependent on an outer-loop variable and a classification of the inner-loop only
|
|
19
|
+
int main(void) {
|
|
20
|
+
int i,j;
|
|
21
|
+
|
|
22
|
+
// Declare input/output arrays
|
|
23
|
+
int A[128][128];
|
|
24
|
+
int B[128][128];
|
|
25
|
+
|
|
26
|
+
// Set the input data
|
|
27
|
+
for(i=0;i<128;i++) {
|
|
28
|
+
for(j=0;j<128;j++) {
|
|
29
|
+
A[i][j] = i+j;
|
|
30
|
+
B[i][j] = 999;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Perform the computation
|
|
35
|
+
#pragma scop
|
|
36
|
+
{
|
|
37
|
+
#pragma species kernel A[0:127,0:127]|element -> B[0:127,0:127]|element
|
|
38
|
+
for (i = 0; i < 128; i++) {
|
|
39
|
+
for (j = i; j < 128; j++) {
|
|
40
|
+
B[i][j] = 2 * A[i][j];
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
#pragma species endkernel example11_k1
|
|
44
|
+
}
|
|
45
|
+
#pragma endscop
|
|
46
|
+
|
|
47
|
+
// Clean-up and exit the function
|
|
48
|
+
fflush(stdout);
|
|
49
|
+
return 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
@@ -0,0 +1,60 @@
|
|
|
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/example12.c
|
|
12
|
+
// Author.............Cedric Nugteren
|
|
13
|
+
// Last modified on...06-Aug-2012
|
|
14
|
+
//
|
|
15
|
+
|
|
16
|
+
#include <stdio.h>
|
|
17
|
+
#include <stdlib.h>
|
|
18
|
+
|
|
19
|
+
void computation(int* A, int* B, int constant);
|
|
20
|
+
|
|
21
|
+
// This is 'example12', demonstrating a classification in another function
|
|
22
|
+
int main(void) {
|
|
23
|
+
int i;
|
|
24
|
+
|
|
25
|
+
// Declare input/output arrays
|
|
26
|
+
int* A = (int*)malloc(128*sizeof(int));
|
|
27
|
+
int* B = (int*)malloc(128*sizeof(int));
|
|
28
|
+
|
|
29
|
+
// Set the input data
|
|
30
|
+
for(i=0;i<128;i++) {
|
|
31
|
+
A[i] = i+3;
|
|
32
|
+
B[i] = 999;
|
|
33
|
+
}
|
|
34
|
+
int constant = 3;
|
|
35
|
+
|
|
36
|
+
// Call the computation function
|
|
37
|
+
computation(A,B,constant);
|
|
38
|
+
|
|
39
|
+
// Clean-up and exit the function
|
|
40
|
+
free(A);
|
|
41
|
+
free(B);
|
|
42
|
+
fflush(stdout);
|
|
43
|
+
return 0;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Function implementing the computation for 'example12'
|
|
47
|
+
void computation(int* A, int* B, int constant) {
|
|
48
|
+
int i;
|
|
49
|
+
|
|
50
|
+
// Perform the computation
|
|
51
|
+
#pragma scop
|
|
52
|
+
{
|
|
53
|
+
#pragma species kernel A[0:127]|element -> B[0:127]|element
|
|
54
|
+
for (i = 0; i < 128; i++) {
|
|
55
|
+
B[i] = 2 * A[i] + constant;
|
|
56
|
+
}
|
|
57
|
+
#pragma species endkernel example12_k1
|
|
58
|
+
}
|
|
59
|
+
#pragma endscop
|
|
60
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
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/example13.c
|
|
12
|
+
// Author.............Cedric Nugteren
|
|
13
|
+
// Last modified on...07-May-2013
|
|
14
|
+
//
|
|
15
|
+
|
|
16
|
+
#include <stdio.h>
|
|
17
|
+
|
|
18
|
+
// This is 'example13', an example with multiple loop nests and various if-statements
|
|
19
|
+
int main(void) {
|
|
20
|
+
int i,j;
|
|
21
|
+
int N = 256;
|
|
22
|
+
|
|
23
|
+
// Declare input/output arrays
|
|
24
|
+
int A[N];
|
|
25
|
+
int B[N];
|
|
26
|
+
int C[N];
|
|
27
|
+
int D[N][N];
|
|
28
|
+
int E[N][N];
|
|
29
|
+
|
|
30
|
+
// Set the input data
|
|
31
|
+
for(i=0;i<N;i++) {
|
|
32
|
+
A[i] = i;
|
|
33
|
+
B[i] = i+5;
|
|
34
|
+
C[i] = i+9;
|
|
35
|
+
for(j=0;j<N;j++) {
|
|
36
|
+
D[i][j] = i*j+3;
|
|
37
|
+
E[i][j] = i*j+9;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
// Perform the computation
|
|
42
|
+
#pragma scop
|
|
43
|
+
{
|
|
44
|
+
#pragma species kernel C[0:N-1]|element -> B[11:N-1]|element ^ A[0:5]|element
|
|
45
|
+
for (i = 0; i < N; i++) {
|
|
46
|
+
if (i > 10) {
|
|
47
|
+
B[i] = C[i];
|
|
48
|
+
}
|
|
49
|
+
if (i < 6) {
|
|
50
|
+
A[i] = C[i];
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
#pragma species endkernel example13_k1
|
|
54
|
+
#pragma species kernel A[50:N-1]|element -> B[50:N-1]|element
|
|
55
|
+
for (i = 0; i < N - 9; i++) {
|
|
56
|
+
if (i + 10 > 50) {
|
|
57
|
+
B[i + 9] = A[i + 9];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
#pragma species endkernel example13_k2
|
|
61
|
+
#pragma species kernel E[5:N-1,0:N-1]|element -> D[5:N-1,0:N-1]|element
|
|
62
|
+
for (i = 0; i < N; i++) {
|
|
63
|
+
for (j = 0; j < N; j++) {
|
|
64
|
+
if (i > 4) {
|
|
65
|
+
D[i][j] = E[i][j];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
#pragma species endkernel example13_k3
|
|
70
|
+
}
|
|
71
|
+
#pragma endscop
|
|
72
|
+
|
|
73
|
+
// Clean-up and exit the function
|
|
74
|
+
fflush(stdout);
|
|
75
|
+
return 0;
|
|
76
|
+
}
|
|
77
|
+
|
|
@@ -0,0 +1,57 @@
|
|
|
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 scop
|
|
36
|
+
{
|
|
37
|
+
#pragma species kernel A[0:SIZE-1]|neighbourhood(-NB:NB) ^ A[0:SIZE-1]|element -> B[0:SIZE-1]|element
|
|
38
|
+
for (i = 0; i < SIZE; i++) {
|
|
39
|
+
if (i >= NB && i < SIZE - NB) {
|
|
40
|
+
result = 0;
|
|
41
|
+
for (n = -NB; n <= NB; n++) {
|
|
42
|
+
result = result + A[i + n];
|
|
43
|
+
}
|
|
44
|
+
B[i] = result / (NB * 2 + 1);
|
|
45
|
+
} else {
|
|
46
|
+
B[i] = A[i];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
#pragma species endkernel example01_k1
|
|
50
|
+
}
|
|
51
|
+
#pragma endscop
|
|
52
|
+
|
|
53
|
+
// Clean-up and exit the function
|
|
54
|
+
fflush(stdout);
|
|
55
|
+
return 0;
|
|
56
|
+
}
|
|
57
|
+
|
|
@@ -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...........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 scop
|
|
37
|
+
{
|
|
38
|
+
#pragma species kernel in[0:A-1,0:B-1]|neighbourhood(-1:1,-1:1) -> out[0:A-1,0:B-1]|element
|
|
39
|
+
for (i = 0; i < A; i++) {
|
|
40
|
+
for (j = 0; j < B; j++) {
|
|
41
|
+
if (i >= 1 && j >= 1 && i < A - 1 && j < B - 1) {
|
|
42
|
+
out[i][j] = (in[i + 1][j + 1] + in[i + 1][j] + in[i + 1][j - 1] + in[i][j + 1] + in[i][j] + in[i][j - 1] + in[i - 1][j + 1] + in[i - 1][j] + in[i - 1][j - 1]) / 9.0;
|
|
43
|
+
} else {
|
|
44
|
+
out[i][j] = in[i][j];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
#pragma species endkernel example02_k1
|
|
49
|
+
}
|
|
50
|
+
#pragma endscop
|
|
51
|
+
|
|
52
|
+
// Clean-up and exit the function
|
|
53
|
+
fflush(stdout);
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
|
|
@@ -0,0 +1,83 @@
|
|
|
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 scop
|
|
45
|
+
{
|
|
46
|
+
#pragma species kernel in[0:sizea-1,0:sizeb-1]|neighbourhood(-1:1,-1:1) -> out[0:sizea-1,0:sizeb-1]|element
|
|
47
|
+
for (i = 0; i < sizea; i++) {
|
|
48
|
+
for (j = 0; j < sizeb; j++) {
|
|
49
|
+
if (i >= 1 && j >= 1 && i < sizea - 1 && j < sizeb - 1) {
|
|
50
|
+
out[i][j] = in[i + 1][j] + in[i][j + 1] + in[i][j] + in[i][j - 1] + in[i - 1][j];
|
|
51
|
+
} else {
|
|
52
|
+
out[i][j] = sqrt(in[i][j]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
#pragma species endkernel example03_k1
|
|
57
|
+
}
|
|
58
|
+
#pragma endscop
|
|
59
|
+
|
|
60
|
+
// Clean-up and exit the function
|
|
61
|
+
free_2D(in);
|
|
62
|
+
free_2D(out);
|
|
63
|
+
fflush(stdout);
|
|
64
|
+
return 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Helper function to allocate a 2D-array
|
|
68
|
+
float ** alloc_2D(int size1, int size2) {
|
|
69
|
+
int a;
|
|
70
|
+
float ** array_2D = (float **)malloc(size1*sizeof(float*));
|
|
71
|
+
float * array_1D = (float *)malloc(size1*size2*sizeof(float));
|
|
72
|
+
for (a=0; a<size1; a++) {
|
|
73
|
+
array_2D[a] = &array_1D[a*size2];
|
|
74
|
+
}
|
|
75
|
+
return array_2D;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Helper function to free a 2D-array
|
|
79
|
+
void free_2D(float ** array_2D) {
|
|
80
|
+
free(array_2D[0]);
|
|
81
|
+
free(array_2D);
|
|
82
|
+
}
|
|
83
|
+
|
|
@@ -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/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 naming (optional) in the classification to distingish the two input arrays
|
|
19
|
+
int main(void) {
|
|
20
|
+
int i;
|
|
21
|
+
float factor;
|
|
22
|
+
int size = 512;
|
|
23
|
+
|
|
24
|
+
// Declare input/output arrays
|
|
25
|
+
float A[size];
|
|
26
|
+
float B[size];
|
|
27
|
+
float C[size];
|
|
28
|
+
|
|
29
|
+
// Set the input data
|
|
30
|
+
for(i=0;i<size;i++) {
|
|
31
|
+
A[i] = i*2.3;
|
|
32
|
+
B[i] = i+6.0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
// Perform the computation
|
|
36
|
+
#pragma scop
|
|
37
|
+
{
|
|
38
|
+
#pragma species kernel A[0:size-1]|element ^ B[0:size-1]|neighbourhood(-1:1) -> C[0:size-1]|element
|
|
39
|
+
for (i = 0; i < size; i++) {
|
|
40
|
+
factor = A[i] / 100.0;
|
|
41
|
+
if (i >= 1 && i < size - 1) {
|
|
42
|
+
C[i] = factor * (B[i - 1] + B[i] + B[i + 1]);
|
|
43
|
+
} else {
|
|
44
|
+
C[i] = B[i];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
#pragma species endkernel example04_k1
|
|
48
|
+
}
|
|
49
|
+
#pragma endscop
|
|
50
|
+
|
|
51
|
+
// Clean-up and exit the function
|
|
52
|
+
fflush(stdout);
|
|
53
|
+
return 0;
|
|
54
|
+
}
|
|
55
|
+
|