bones-compiler 1.1.0

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.
Files changed (203) hide show
  1. data/CHANGELOG +117 -0
  2. data/LICENSE +9 -0
  3. data/README.rdoc +126 -0
  4. data/Rakefile +107 -0
  5. data/VERSION +1 -0
  6. data/bin/bones +20 -0
  7. data/examples/applications/ffos.c +552 -0
  8. data/examples/benchmarks/2mm.c +70 -0
  9. data/examples/benchmarks/3mm.c +81 -0
  10. data/examples/benchmarks/adi.c +81 -0
  11. data/examples/benchmarks/atax.c +65 -0
  12. data/examples/benchmarks/bicg.c +67 -0
  13. data/examples/benchmarks/cholesky.c +64 -0
  14. data/examples/benchmarks/common.h +168 -0
  15. data/examples/benchmarks/correlation.c +97 -0
  16. data/examples/benchmarks/covariance.c +77 -0
  17. data/examples/benchmarks/doitgen.c +63 -0
  18. data/examples/benchmarks/durbin.c +76 -0
  19. data/examples/benchmarks/dynprog.c +67 -0
  20. data/examples/benchmarks/fdtd-2d-apml.c +114 -0
  21. data/examples/benchmarks/fdtd-2d.c +74 -0
  22. data/examples/benchmarks/floyd-warshall.c +50 -0
  23. data/examples/benchmarks/gemm.c +69 -0
  24. data/examples/benchmarks/gemver.c +89 -0
  25. data/examples/benchmarks/gesummv.c +64 -0
  26. data/examples/benchmarks/gramschmidt.c +84 -0
  27. data/examples/benchmarks/jacobi-1d-imper.c +55 -0
  28. data/examples/benchmarks/jacobi-2d-imper.c +61 -0
  29. data/examples/benchmarks/lu.c +57 -0
  30. data/examples/benchmarks/ludcmp.c +91 -0
  31. data/examples/benchmarks/mvt.c +65 -0
  32. data/examples/benchmarks/overview.txt +38 -0
  33. data/examples/benchmarks/reg_detect.c +82 -0
  34. data/examples/benchmarks/saxpy.c +45 -0
  35. data/examples/benchmarks/seidel-2d.c +51 -0
  36. data/examples/benchmarks/symm.c +74 -0
  37. data/examples/benchmarks/syr2k.c +65 -0
  38. data/examples/benchmarks/syrk.c +62 -0
  39. data/examples/benchmarks/trisolv.c +57 -0
  40. data/examples/benchmarks/trmm.c +57 -0
  41. data/examples/chunk/example1.c +54 -0
  42. data/examples/chunk/example2.c +44 -0
  43. data/examples/chunk/example3.c +59 -0
  44. data/examples/chunk/example4.c +55 -0
  45. data/examples/chunk/example5.c +52 -0
  46. data/examples/element/example1.c +46 -0
  47. data/examples/element/example10.c +50 -0
  48. data/examples/element/example11.c +47 -0
  49. data/examples/element/example12.c +56 -0
  50. data/examples/element/example2.c +46 -0
  51. data/examples/element/example3.c +58 -0
  52. data/examples/element/example4.c +49 -0
  53. data/examples/element/example5.c +56 -0
  54. data/examples/element/example6.c +46 -0
  55. data/examples/element/example7.c +54 -0
  56. data/examples/element/example8.c +45 -0
  57. data/examples/element/example9.c +48 -0
  58. data/examples/neighbourhood/example1.c +54 -0
  59. data/examples/neighbourhood/example2.c +55 -0
  60. data/examples/neighbourhood/example3.c +82 -0
  61. data/examples/neighbourhood/example4.c +52 -0
  62. data/examples/shared/example1.c +45 -0
  63. data/examples/shared/example2.c +51 -0
  64. data/examples/shared/example3.c +55 -0
  65. data/examples/shared/example4.c +52 -0
  66. data/examples/shared/example5.c +48 -0
  67. data/lib/bones.rb +266 -0
  68. data/lib/bones/algorithm.rb +541 -0
  69. data/lib/bones/engine.rb +386 -0
  70. data/lib/bones/preprocessor.rb +161 -0
  71. data/lib/bones/species.rb +196 -0
  72. data/lib/bones/structure.rb +94 -0
  73. data/lib/bones/variable.rb +169 -0
  74. data/lib/bones/variablelist.rb +72 -0
  75. data/lib/castaddon.rb +27 -0
  76. data/lib/castaddon/index.rb +40 -0
  77. data/lib/castaddon/node.rb +753 -0
  78. data/lib/castaddon/type.rb +37 -0
  79. data/skeletons/CPU-C/common/epilogue.c +0 -0
  80. data/skeletons/CPU-C/common/globals.c +17 -0
  81. data/skeletons/CPU-C/common/globals_kernel.c +1 -0
  82. data/skeletons/CPU-C/common/header.c +0 -0
  83. data/skeletons/CPU-C/common/mem_copy_D2H.c +0 -0
  84. data/skeletons/CPU-C/common/mem_copy_H2D.c +0 -0
  85. data/skeletons/CPU-C/common/mem_epilogue.c +0 -0
  86. data/skeletons/CPU-C/common/mem_prologue.c +3 -0
  87. data/skeletons/CPU-C/common/prologue.c +0 -0
  88. data/skeletons/CPU-C/common/timer_1_start.c +0 -0
  89. data/skeletons/CPU-C/common/timer_1_stop.c +0 -0
  90. data/skeletons/CPU-C/common/timer_2_start.c +20 -0
  91. data/skeletons/CPU-C/common/timer_2_stop.c +8 -0
  92. data/skeletons/CPU-C/kernel/default.host.c +3 -0
  93. data/skeletons/CPU-C/kernel/default.kernel.c +15 -0
  94. data/skeletons/CPU-C/skeletons.txt +24 -0
  95. data/skeletons/CPU-OPENCL-AMD/common/epilogue.c +6 -0
  96. data/skeletons/CPU-OPENCL-AMD/common/globals.c +155 -0
  97. data/skeletons/CPU-OPENCL-AMD/common/globals_kernel.c +4 -0
  98. data/skeletons/CPU-OPENCL-AMD/common/header.c +0 -0
  99. data/skeletons/CPU-OPENCL-AMD/common/mem_copy_D2H.c +8 -0
  100. data/skeletons/CPU-OPENCL-AMD/common/mem_copy_H2D.c +4 -0
  101. data/skeletons/CPU-OPENCL-AMD/common/mem_epilogue.c +3 -0
  102. data/skeletons/CPU-OPENCL-AMD/common/mem_prologue.c +6 -0
  103. data/skeletons/CPU-OPENCL-AMD/common/prologue.c +24 -0
  104. data/skeletons/CPU-OPENCL-AMD/common/timer_1_start.c +5 -0
  105. data/skeletons/CPU-OPENCL-AMD/common/timer_1_stop.c +9 -0
  106. data/skeletons/CPU-OPENCL-AMD/common/timer_2_start.c +16 -0
  107. data/skeletons/CPU-OPENCL-AMD/common/timer_2_stop.c +11 -0
  108. data/skeletons/CPU-OPENCL-AMD/kernel/D-element-to-1-shared.host.c +67 -0
  109. data/skeletons/CPU-OPENCL-AMD/kernel/D-element-to-1-shared.kernel.cl +72 -0
  110. data/skeletons/CPU-OPENCL-AMD/kernel/default.host.c +14 -0
  111. data/skeletons/CPU-OPENCL-AMD/kernel/default.kernel.cl +13 -0
  112. data/skeletons/CPU-OPENCL-AMD/skeletons.txt +26 -0
  113. data/skeletons/CPU-OPENCL-INTEL/common/epilogue.c +3 -0
  114. data/skeletons/CPU-OPENCL-INTEL/common/globals.c +154 -0
  115. data/skeletons/CPU-OPENCL-INTEL/common/globals_kernel.c +4 -0
  116. data/skeletons/CPU-OPENCL-INTEL/common/header.c +31 -0
  117. data/skeletons/CPU-OPENCL-INTEL/common/mem_copy_D2H.c +5 -0
  118. data/skeletons/CPU-OPENCL-INTEL/common/mem_copy_H2D.c +3 -0
  119. data/skeletons/CPU-OPENCL-INTEL/common/mem_epilogue.c +3 -0
  120. data/skeletons/CPU-OPENCL-INTEL/common/mem_prologue.c +4 -0
  121. data/skeletons/CPU-OPENCL-INTEL/common/prologue.c +24 -0
  122. data/skeletons/CPU-OPENCL-INTEL/common/timer_1_start.c +5 -0
  123. data/skeletons/CPU-OPENCL-INTEL/common/timer_1_stop.c +9 -0
  124. data/skeletons/CPU-OPENCL-INTEL/common/timer_2_start.c +16 -0
  125. data/skeletons/CPU-OPENCL-INTEL/common/timer_2_stop.c +11 -0
  126. data/skeletons/CPU-OPENCL-INTEL/kernel/D-element-to-1-shared.host.c +67 -0
  127. data/skeletons/CPU-OPENCL-INTEL/kernel/D-element-to-1-shared.kernel.cl +72 -0
  128. data/skeletons/CPU-OPENCL-INTEL/kernel/default.host.c +14 -0
  129. data/skeletons/CPU-OPENCL-INTEL/kernel/default.kernel.cl +13 -0
  130. data/skeletons/CPU-OPENCL-INTEL/skeletons.txt +26 -0
  131. data/skeletons/CPU-OPENMP/common/epilogue.c +0 -0
  132. data/skeletons/CPU-OPENMP/common/globals.c +37 -0
  133. data/skeletons/CPU-OPENMP/common/globals_kernel.c +6 -0
  134. data/skeletons/CPU-OPENMP/common/header.c +0 -0
  135. data/skeletons/CPU-OPENMP/common/mem_copy_D2H.c +0 -0
  136. data/skeletons/CPU-OPENMP/common/mem_copy_H2D.c +0 -0
  137. data/skeletons/CPU-OPENMP/common/mem_epilogue.c +0 -0
  138. data/skeletons/CPU-OPENMP/common/mem_prologue.c +3 -0
  139. data/skeletons/CPU-OPENMP/common/prologue.c +0 -0
  140. data/skeletons/CPU-OPENMP/common/timer_1_start.c +12 -0
  141. data/skeletons/CPU-OPENMP/common/timer_1_stop.c +0 -0
  142. data/skeletons/CPU-OPENMP/common/timer_2_start.c +18 -0
  143. data/skeletons/CPU-OPENMP/common/timer_2_stop.c +8 -0
  144. data/skeletons/CPU-OPENMP/kernel/D-element-to-1-shared.host.c +27 -0
  145. data/skeletons/CPU-OPENMP/kernel/D-element-to-1-shared.kernel.c +46 -0
  146. data/skeletons/CPU-OPENMP/kernel/default.host.c +11 -0
  147. data/skeletons/CPU-OPENMP/kernel/default.kernel.c +18 -0
  148. data/skeletons/CPU-OPENMP/skeletons.txt +26 -0
  149. data/skeletons/GPU-CUDA/common/epilogue.c +0 -0
  150. data/skeletons/GPU-CUDA/common/globals.c +31 -0
  151. data/skeletons/GPU-CUDA/common/globals_kernel.c +4 -0
  152. data/skeletons/GPU-CUDA/common/header.c +0 -0
  153. data/skeletons/GPU-CUDA/common/mem_copy_D2H.c +3 -0
  154. data/skeletons/GPU-CUDA/common/mem_copy_H2D.c +3 -0
  155. data/skeletons/GPU-CUDA/common/mem_epilogue.c +3 -0
  156. data/skeletons/GPU-CUDA/common/mem_prologue.c +5 -0
  157. data/skeletons/GPU-CUDA/common/prologue.c +6 -0
  158. data/skeletons/GPU-CUDA/common/timer_1_start.c +6 -0
  159. data/skeletons/GPU-CUDA/common/timer_1_stop.c +10 -0
  160. data/skeletons/GPU-CUDA/common/timer_2_start.c +6 -0
  161. data/skeletons/GPU-CUDA/common/timer_2_stop.c +10 -0
  162. data/skeletons/GPU-CUDA/kernel/2xN-N-chunk-1-N-to-D-element.host.c +3 -0
  163. data/skeletons/GPU-CUDA/kernel/2xN-N-chunk-1-N-to-D-element.kernel.cu +105 -0
  164. data/skeletons/GPU-CUDA/kernel/D-element-to-1-shared.host.c +3 -0
  165. data/skeletons/GPU-CUDA/kernel/D-element-to-1-shared.kernel.cu +119 -0
  166. data/skeletons/GPU-CUDA/kernel/D-element-to-N-shared.host.c +3 -0
  167. data/skeletons/GPU-CUDA/kernel/D-element-to-N-shared.kernel.cu +166 -0
  168. data/skeletons/GPU-CUDA/kernel/N-N-chunk-1-N-to-D-element.host.c +3 -0
  169. data/skeletons/GPU-CUDA/kernel/N-N-chunk-1-N-to-D-element.kernel.cu +69 -0
  170. data/skeletons/GPU-CUDA/kernel/N-neighbourhood-N-to-N-element.host.c +3 -0
  171. data/skeletons/GPU-CUDA/kernel/N-neighbourhood-N-to-N-element.kernel.cu +42 -0
  172. data/skeletons/GPU-CUDA/kernel/default.host.c +3 -0
  173. data/skeletons/GPU-CUDA/kernel/default.kernel.cu +28 -0
  174. data/skeletons/GPU-CUDA/skeletons.txt +30 -0
  175. data/skeletons/GPU-OPENCL-AMD/common/epilogue.c +3 -0
  176. data/skeletons/GPU-OPENCL-AMD/common/globals.c +155 -0
  177. data/skeletons/GPU-OPENCL-AMD/common/globals_kernel.c +4 -0
  178. data/skeletons/GPU-OPENCL-AMD/common/header.c +0 -0
  179. data/skeletons/GPU-OPENCL-AMD/common/mem_copy_D2H.c +4 -0
  180. data/skeletons/GPU-OPENCL-AMD/common/mem_copy_H2D.c +4 -0
  181. data/skeletons/GPU-OPENCL-AMD/common/mem_epilogue.c +3 -0
  182. data/skeletons/GPU-OPENCL-AMD/common/mem_prologue.c +3 -0
  183. data/skeletons/GPU-OPENCL-AMD/common/prologue.c +24 -0
  184. data/skeletons/GPU-OPENCL-AMD/common/timer_1_start.c +5 -0
  185. data/skeletons/GPU-OPENCL-AMD/common/timer_1_stop.c +9 -0
  186. data/skeletons/GPU-OPENCL-AMD/common/timer_2_start.c +4 -0
  187. data/skeletons/GPU-OPENCL-AMD/common/timer_2_stop.c +11 -0
  188. data/skeletons/GPU-OPENCL-AMD/kernel/D-element-to-1-shared.host.c +67 -0
  189. data/skeletons/GPU-OPENCL-AMD/kernel/D-element-to-1-shared.kernel.cl +72 -0
  190. data/skeletons/GPU-OPENCL-AMD/kernel/default.host.c +14 -0
  191. data/skeletons/GPU-OPENCL-AMD/kernel/default.kernel.cl +13 -0
  192. data/skeletons/GPU-OPENCL-AMD/skeletons.txt +26 -0
  193. data/skeletons/verification/header.c +2 -0
  194. data/skeletons/verification/timer_start.c +4 -0
  195. data/skeletons/verification/timer_stop.c +6 -0
  196. data/skeletons/verification/verify_results.c +23 -0
  197. data/test/bones/test_algorithm.rb +40 -0
  198. data/test/bones/test_common.rb +54 -0
  199. data/test/bones/test_preprocessor.rb +46 -0
  200. data/test/bones/test_species.rb +21 -0
  201. data/test/bones/test_variable.rb +84 -0
  202. data/test/test_helper.rb +106 -0
  203. 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
+