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,52 @@
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 species kernel B[0:size-1]|neighbourhood(-1:1) ^ A[0:size-1]|element -> C[0:size-1]|element
37
+ for(i=0;i<size;i++) {
38
+ factor = A[i]/100.0;
39
+ if ((i >= 1) && (i < size-1)) {
40
+ C[i] = factor*(B[i-1]+B[i]+B[i+1]);
41
+ }
42
+ else {
43
+ C[i] = B[i];
44
+ }
45
+ }
46
+ #pragma species endkernel example4
47
+
48
+ // Clean-up and exit the function
49
+ fflush(stdout);
50
+ return 0;
51
+ }
52
+
@@ -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...........shared/example1.c
12
+ // Author.............Cedric Nugteren
13
+ // Last modified on...16-April-2012
14
+ //
15
+
16
+ #include <stdio.h>
17
+ #include <stdlib.h>
18
+ #define SIZE 512*1024
19
+
20
+ // This is 'example1', a basic associative and commutative reduction to scalar
21
+ int main(void) {
22
+ int i;
23
+
24
+ // Declare input/output arrays
25
+ int *A = (int *)malloc(SIZE*sizeof(int));
26
+ int B[1];
27
+
28
+ // Set the input data
29
+ for(i=0;i<SIZE;i++) {
30
+ A[i] = 1;
31
+ }
32
+
33
+ // Perform the computation
34
+ B[0] = 0;
35
+ #pragma species kernel 0:SIZE-1|element -> 0:0|shared
36
+ for(i=0;i<SIZE;i++) {
37
+ B[0] = B[0] + A[i];
38
+ }
39
+ #pragma species endkernel example1
40
+
41
+ // Clean-up and exit the function
42
+ fflush(stdout);
43
+ return 0;
44
+ }
45
+
@@ -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...........shared/example2.c
12
+ // Author.............Cedric Nugteren
13
+ // Last modified on...09-May-2012
14
+ //
15
+
16
+ #include <stdio.h>
17
+
18
+ // This is 'example2', demonstrating a 3D input reduction to scalar
19
+ int main(void) {
20
+ int a,b,c;
21
+
22
+ // Declare input/output arrays
23
+ float in[8][16][32];
24
+ float out[1];
25
+
26
+ // Set the input data
27
+ for(a=0;a<8;a++) {
28
+ for(b=0;b<16;b++) {
29
+ for(c=0;c<32;c++) {
30
+ in[a][b][c] = 1;
31
+ }
32
+ }
33
+ }
34
+
35
+ // Perform the computation
36
+ out[0] = 0;
37
+ #pragma species kernel 0:7,0:15,0:31|element -> 0:0|shared
38
+ for(a=0;a<8;a++) {
39
+ for(b=0;b<16;b++) {
40
+ for(c=0;c<32;c++) {
41
+ out[0] = out[0] + in[a][b][c];
42
+ }
43
+ }
44
+ }
45
+ #pragma species endkernel example2
46
+
47
+ // Clean-up and exit the function
48
+ fflush(stdout);
49
+ return 0;
50
+ }
51
+
@@ -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...........shared/example3.c
12
+ // Author.............Cedric Nugteren
13
+ // Last modified on...16-April-2012
14
+ //
15
+
16
+ #include <stdio.h>
17
+ #include <stdlib.h>
18
+ #define SIZE 1024
19
+
20
+ // This is 'example3', demonstrating a reduction to a 2D array
21
+ int main(void) {
22
+ int i,p,q;
23
+ int index1,index2;
24
+
25
+ // Declare input/output arrays
26
+ int *in = (int *)malloc(SIZE*sizeof(int));
27
+ int B[20][10];
28
+
29
+ // Set the input data
30
+ for(i=0;i<SIZE;i++) {
31
+ in[i] = (SIZE-i);
32
+ }
33
+
34
+ // Set the output to zero before starting
35
+ for(p=0;p<20;p++) {
36
+ for(q=0;q<10;q++) {
37
+ B[p][q] = 0;
38
+ }
39
+ }
40
+
41
+ // Perform the computation
42
+ #pragma species kernel 0:SIZE-1|element -> 0:19,0:9|shared
43
+ for(i=0;i<SIZE;i++) {
44
+ index1 = in[i]%20;
45
+ index2 = in[i]%10;
46
+ B[index1][index2] = B[index1][index2] + 1;
47
+ }
48
+ #pragma species endkernel example3
49
+
50
+ // Clean-up and exit the function
51
+ free(in);
52
+ fflush(stdout);
53
+ return 0;
54
+ }
55
+
@@ -0,0 +1,52 @@
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...........shared/example4.c
12
+ // Author.............Cedric Nugteren
13
+ // Last modified on...16-April-2012
14
+ //
15
+
16
+ #include <stdio.h>
17
+ #include <stdlib.h>
18
+ #define SIZE 1024*1024
19
+
20
+ // This is 'example4', demonstrating a basic 256-bin histogram computation
21
+ int main(void) {
22
+ int i;
23
+ unsigned char index;
24
+
25
+ // Declare input/output arrays
26
+ unsigned char *A = (unsigned char *)malloc(SIZE*sizeof(unsigned char));
27
+ int B[256];
28
+
29
+ // Set the input data
30
+ for(i=0;i<SIZE;i++) {
31
+ A[i] = i%256;
32
+ }
33
+
34
+ // Set the output to zero before starting
35
+ for (i=0;i<256;i++) {
36
+ B[i] = 0;
37
+ }
38
+
39
+ // Perform the computation
40
+ #pragma species kernel 0:SIZE-1|element -> 0:255|shared
41
+ for(i=0;i<SIZE;i++) {
42
+ index = A[i];
43
+ B[index]++;
44
+ }
45
+ #pragma species endkernel example4
46
+
47
+ // Clean-up and exit the function
48
+ free(A);
49
+ fflush(stdout);
50
+ return 0;
51
+ }
52
+
@@ -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...........shared/example5.c
12
+ // Author.............Cedric Nugteren
13
+ // Last modified on...07-May-2012
14
+ //
15
+
16
+ #include <stdio.h>
17
+
18
+ // This is 'example5', demonstrating an inner-loop only classification of a reduction to scalar
19
+ int main(void) {
20
+ int a,b,c;
21
+
22
+ // Declare input/output arrays
23
+ float in[16][16];
24
+ float out[1];
25
+
26
+ // Set the input data
27
+ out[0] = -1;
28
+ for(a=0;a<16;a++) {
29
+ for(b=0;b<16;b++) {
30
+ in[a][b] = 1.001;
31
+ }
32
+ }
33
+
34
+ // Perform the computation
35
+ for(a=0;a<16;a++) {
36
+ #pragma species kernel a:a,0:a|element -> 0:0|shared
37
+ for(b=0;b<=a;b++) {
38
+ out[0] = out[0] - in[a][b]*in[a][b];
39
+ }
40
+ #pragma species endkernel example5
41
+ out[0] = 1.002;
42
+ }
43
+
44
+ // Clean-up and exit the function
45
+ fflush(stdout);
46
+ return 0;
47
+ }
48
+
data/lib/bones.rb ADDED
@@ -0,0 +1,266 @@
1
+
2
+ # Bones requires 'fileutils' from the Ruby standard library.
3
+ require 'fileutils'
4
+
5
+ # Bones uses the 'trollop' gem to parse command line options.
6
+ require 'rubygems'
7
+ require 'trollop'
8
+
9
+ # We define a custom error class for code generation related
10
+ # errors (any error raised by Bones).
11
+ class CodeGenError < StandardError #:nodoc:
12
+ end
13
+ def raise_error(message) #:nodoc:
14
+ puts Bones::ERROR+message
15
+ raise CodeGenError, 'Error encountered, stopping execution of Bones'
16
+ end
17
+
18
+ # Extending the Ruby standard string class to support some
19
+ # addition methods. They include a hack of the gsub! command,
20
+ # and two methods related to comma removal.
21
+ class String #:nodoc:
22
+
23
+ # Extend the Ruby string class to be able to chain 'gsub!'
24
+ #-commands. This code is taken from the web.
25
+ meth = 'gsub!'
26
+ orig_meth = "orig_#{meth}"
27
+ alias_method orig_meth, meth
28
+ define_method(meth) do |*args|
29
+ self.send(orig_meth, *args)
30
+ self
31
+ end
32
+
33
+ # Replace double comma's in a string with a single comma.
34
+ # This method is useful for function-argument lists.
35
+ def remove_double_commas
36
+ return self.gsub!(/(,\s*){2,}/,',')
37
+ end
38
+
39
+ # Remove a comma before a closing bracket in a string, for
40
+ # example: ',)'. This method is useful for function-argument
41
+ # lists.
42
+ def remove_extra_commas
43
+ return self.gsub!(/,\s*\)/,')')
44
+ end
45
+
46
+ # This function repeatedly applies the remove double commas
47
+ # and remove extra commas functions
48
+ def remove_extras
49
+ return self.remove_double_commas.remove_extra_commas.remove_double_commas.remove_extra_commas
50
+ end
51
+
52
+ end
53
+
54
+ # The Bones module keeps all the Bones classes and constants
55
+ # together. It contains the classes:
56
+ # * Engine The main component of the Bones tool, providing the high-level tool flow.
57
+ # * Preprocessor A C-preprocessor, extracting class information from source code.
58
+ # * Algorithm An individual algorithm, containing an algorithm classification, code and more.
59
+ # * Species A class representing an algorithm class (or: species).
60
+ # * Variable A class for individual variables (not related to CAST).
61
+ # * Structure A class inheriting from the String class, representing parts of the algorithm classification.
62
+ #
63
+ # The module also contains a list of inter-class constants.
64
+ module Bones
65
+
66
+ # Set the newline character
67
+ NL = "\n"
68
+ # Set the tab size (currently: 2 spaces)
69
+ INDENT = ' '
70
+
71
+ # A string given as a start of an informative message. See also ERROR and WARNING.
72
+ MESSAGE = '[Bones] ### Info : '
73
+ # A string given as a start of an warning message. See also ERROR and MESSAGE.
74
+ WARNING = '[Bones] ### Warning: '
75
+ # A string given as a start of an error message. See also MESSAGE and WARNING.
76
+ ERROR = '[Bones] ### Error : '
77
+
78
+ # Gives a string representing an read-only variable. See also OUTPUT, INOUT and DIRECTIONS.
79
+ INPUT = 'in'
80
+ # Gives a string representing an write-only variable. See also INPUT, INOUT and DIRECTIONS.
81
+ OUTPUT = 'out'
82
+ # Gives a string representing an read/write variable. See also INPUT, OUTPUT and DIRECTIONS.
83
+ INOUT = 'inout'
84
+ # Gives a list of all directions considered. Makes use of the INPUT and OUTPUT constants.
85
+ DIRECTIONS = [INPUT,OUTPUT]
86
+
87
+ # A string representing the combination character ('^') of a species. See also ARROW and PIPE.
88
+ WEDGE = '^'
89
+ # A string representing the production character ('->') of a species. See also WEDGE and PIPE.
90
+ ARROW = '->'
91
+ # A string representing the pipe character ('|') of a species. See also WEDGE and ARROW.
92
+ PIPE = '|'
93
+ # A string representing the colon character (':') to separate ranges in dimensions.
94
+ RANGE_SEP = ':'
95
+ # A string representing the comma character (',') to separate different ranges.
96
+ DIM_SEP = ','
97
+
98
+ # Sets the prefix used by variables in the skeleton library. This is used in LOCAL_MEMORY, GLOBAL_ID, LOCAL_ID, GLOBAL_SIZE and LOCAL_SIZE.
99
+ VARIABLE_PREFIX = 'bones_'
100
+ # Sets the variable name for the local memory variable in the skeleton library.
101
+ LOCAL_MEMORY = VARIABLE_PREFIX+'local_memory'
102
+ # Sets the variable name for the thread private (i.e. register) memory variable in the skeleton library.
103
+ PRIVATE_MEMORY = VARIABLE_PREFIX+'private_memory'
104
+ # Sets the variable name for the global memory thread index in the skeleton library.
105
+ GLOBAL_ID = VARIABLE_PREFIX+'global_id'
106
+ # Sets the variable name for the local memory thread index in the skeleton library.
107
+ LOCAL_ID = VARIABLE_PREFIX+'local_id'
108
+ # Sets the variable name for the global memory size as used in the skeleton library.
109
+ GLOBAL_SIZE = VARIABLE_PREFIX+'global_size'
110
+ # Sets the variable name for the local memory size as used in the skeleton library.
111
+ LOCAL_SIZE = VARIABLE_PREFIX+'local_size'
112
+ # Provide a function definition for the initialization C-code (if present). See als INITIALIZATION_CODE.
113
+ INITIALIZATION_DEFINITION = 'void '+VARIABLE_PREFIX+'initialize_target(void);'
114
+ # Provide a function call to the initialization C-code (if present). See als INITIALIZATION_DEFINITION.
115
+ INITIALIZATION_CODE = VARIABLE_PREFIX+'initialize_target();'
116
+ # Sets the name for the 'golden' output, required for verification purposes.
117
+ GOLDEN = VARIABLE_PREFIX+'golden'
118
+ # Sets the loop variable name for the 'golden' output, required for verification purposes.
119
+ LOOP = VARIABLE_PREFIX+'loop'
120
+ # Constant to set the device variable name
121
+ DEVICE = 'device_'
122
+
123
+ # Provides the starting marker for a search-and-replace variable. See also SAR_MARKER2.
124
+ SAR_MARKER1 = '<'
125
+ # Provides the ending marker for a search-and-replace variable. See also SAR_MARKER1.
126
+ SAR_MARKER2 = '>'
127
+
128
+ # Set the start of a function definition, used in the skeleton library files. See also END_DEFINITION.
129
+ START_DEFINITION = '\/\* STARTDEF'
130
+ # Set the end of a function definition, used in the skeleton library files. See also START_DEFINITION.
131
+ END_DEFINITION = 'ENDDEF \*\/'
132
+
133
+ # This class is created to be a parent class of the Bones
134
+ # engine, the Bones species and the Bones algorithm class.
135
+ class Common
136
+
137
+ # Helper to obtain the 'from' part from a range. For example,
138
+ # the method will yield '1' if applied to '1:N-1'.
139
+ def from(range)
140
+ return '('+simplify(range.split(RANGE_SEP)[0])+')'
141
+ end
142
+
143
+
144
+ # Helper to obtain the 'to' part from a range. For example,
145
+ # the method will yield 'N-1' if applied to '1:N-1'.
146
+ def to(range)
147
+ return '('+simplify(range.split(RANGE_SEP)[1])+')'
148
+ end
149
+
150
+ # Helper to obtain the sum of a range. For example, the method
151
+ # will yield 'N-2' if applied to '1:N-1'. There is a check to
152
+ # ensure that the range is correct.
153
+ def sum(range)
154
+ raise_error('Incorrect range given: "'+range+'"') if range.split(RANGE_SEP).length != 2
155
+ return '('+simplify("(#{to(range)}-#{from(range)}+1)")+')'
156
+ end
157
+
158
+
159
+ # Helper to obtain the sum and 'from' part of a range. For
160
+ # example, the method will yield '((N-2)+1)' if applied to '1:N-1'.
161
+ def sum_and_from(range)
162
+ return '('+simplify(sum(range)+'+'+from(range))+')'
163
+ end
164
+
165
+ # This method flattens a multidimensional hash into a one
166
+ # dimensional hash. This method is called recursively.
167
+ def flatten_hash(hash,flat_hash={},prefix='')
168
+ hash.each do |key,value|
169
+ if value.is_a?(Hash)
170
+ flatten_hash(value,flat_hash,prefix+key.to_s+'_')
171
+ else
172
+ flat_hash[(prefix+key.to_s).to_sym] = value
173
+ end
174
+ end
175
+ return flat_hash
176
+ end
177
+
178
+ # This method performs a search-and-replace. It searches
179
+ # for the <index> of the input hash and replaces it with
180
+ # the corresponding key. It searches for to-be-replaced
181
+ # variables of the form '<name>'. If such patterns still
182
+ # occur after searching and replacing, the method raises
183
+ # an error.
184
+ def search_and_replace!(hash,code)
185
+ flat_hash = flatten_hash(hash)
186
+ 2.times do
187
+ flat_hash.each { |search,replace| code.gsub!(SAR_MARKER1+search.to_s+SAR_MARKER2,replace) }
188
+ end
189
+ raise_error('Unrecognized replace variable "'+($~).to_s+'" in the skeleton library') if code =~ /<[a-zA-Z]+\w*>/
190
+ end
191
+
192
+ # This method calls search_and_replace! to replaces markers
193
+ # in code with a hash of search-and-replace values. Before,
194
+ # it clones the existing code so that the original copy is
195
+ # maintained.
196
+ def search_and_replace(hash,code)
197
+ new_code = code.clone
198
+ search_and_replace!(hash,new_code)
199
+ return new_code
200
+ end
201
+
202
+ # Method to process the defines in a piece of code. The code
203
+ # must be formatted as a string. It returns a copy of the code
204
+ # with all defines replaced.
205
+ def replace_defines(original_code,defines)
206
+ code = original_code.clone
207
+ list = defines.sort_by { |key,value| key.to_s.length }
208
+ list.reverse.each do |pair|
209
+ search = pair[0].to_s
210
+ replace = pair[1]
211
+ code.gsub!(search,replace)
212
+ end
213
+ return code
214
+ end
215
+
216
+ # Helper method to evaluate mathematical expressions, possibly containing
217
+ # symbols. This method is only used for readability, without it the code
218
+ # is functionally correct, but expressions might be larger than needed.
219
+ # This method is only tested on integers.
220
+ def simplify(expr)
221
+ raise_error('Invalid expression to simplify') if !expr
222
+ done = false
223
+ while !done do
224
+ old_expr = expr
225
+ case expr
226
+ when /^\(([^\(\)]*)\)$/ then expr = $1 # Remove outer brackets
227
+ when /(.*)\((-?\w*)\)(.*)/ then expr = $1+$2+$3 # Remove brackets with one constant or variable inside
228
+ when /(.*)\(\(([^\(\)]*)\)\)(.*)/ then expr = $1+'('+$2+')'+$3 # Substitute double brackets into single brackets
229
+ when /(.*)(\-\d+)\*(\d+)\b(.*)/ then expr = $1+'+'+(($2.to_i)*($3.to_i)).to_s+$4 # Perform multiplications on constants (starting with a '-')
230
+ when /(.*)(\-\d+)\+(\d+)\b(.*)/ then expr = $1+'+'+(($2.to_i)+($3.to_i)).to_s+$4 # Perform additions on constants (starting with a '-')
231
+ when /(.*)(\-\d+)\-(\d+)\b(.*)/ then expr = $1+'+'+(($2.to_i)-($3.to_i)).to_s+$4 # Perform subtractions on constants (starting with a '-')
232
+ when /(.*)\b(\d+)\*(\d+)\b(.*)/ then expr = $1+(($2.to_i)*($3.to_i)).to_s+$4 # Perform multiplications on constants
233
+ when /(.*)\b(\d+)\+(\d+)\b(.*)/ then expr = $1+(($2.to_i)+($3.to_i)).to_s+$4 # Perform additions on constants
234
+ when /(.*)\b(\d+)\-(\d+)\b(.*)/ then expr = $1+(($2.to_i)-($3.to_i)).to_s+$4 # Perform subtractions on constants
235
+ when /(.*)\b(\w+)\-(\2)\b(.*)/ then expr = $1+'0'+$4 # Perform subtractions of variables to zero (e.g. 'a-a=0')
236
+ when /(.*)\/1\b(.*)/ then expr = $1+$2 # Remove divisions by 1
237
+ when /(.*)(\+0\b|\b0\+)(.*)/ then expr = $1+$3 # Remove additions with 0
238
+ when /(.*[\+\(])\(([^\(\)\*\/\%]+)\)([\+\-\)].*)/ then expr = $1+$2+$3 # Remove brackets that are not needed (e.g. '(a+b)+c')
239
+ end
240
+ expr.gsub!(/\s/,'') # Remove whitespaces
241
+ expr.gsub!(/\-\-/,'+') # Substitute double minusses for a plus
242
+ expr.gsub!(/\+\-/,'-') # Substitute plus-minus for a minus
243
+ expr.gsub!(/(^|\()\+/,'') # Remove plus signs at the start of a line or after an opening bracket
244
+ if expr =~ /(.*)\b(\d+)\/(\d+)\b(.*)/ # Perform divisions on constants...
245
+ division = ($2.to_i)/($3.to_i) # ...but first check whether the result will be correct (integer division)
246
+ expr = $1+division.to_s+$4 if division*$3.to_i == $2.to_i
247
+ end
248
+ done = true if old_expr == expr
249
+ end
250
+ return expr
251
+ end
252
+
253
+ end
254
+
255
+ end
256
+
257
+ # This list of require's makes sure all Bones classes are
258
+ # included. The order is not important here.
259
+ require 'bones/structure.rb'
260
+ require 'bones/species.rb'
261
+ require 'bones/algorithm.rb'
262
+ require 'bones/variablelist.rb'
263
+ require 'bones/variable.rb'
264
+ require 'bones/preprocessor.rb'
265
+ require 'bones/engine.rb'
266
+