bones-compiler 1.3.1 → 1.6.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.
- data/CHANGELOG +62 -0
- data/README.rdoc +14 -3
- data/Rakefile +13 -12
- data/VERSION +1 -1
- data/examples/applications/ffos.c +24 -8
- data/examples/benchmarks/PolyBench/2mm.c +0 -0
- data/examples/benchmarks/PolyBench/3mm.c +0 -0
- data/examples/benchmarks/PolyBench/adi.c +0 -0
- data/examples/benchmarks/PolyBench/atax.c +0 -0
- data/examples/benchmarks/PolyBench/bicg.c +0 -0
- data/examples/benchmarks/PolyBench/cholesky.c +0 -0
- data/examples/benchmarks/PolyBench/common.h +0 -0
- data/examples/benchmarks/PolyBench/correlation.c +0 -0
- data/examples/benchmarks/PolyBench/covariance.c +0 -0
- data/examples/benchmarks/PolyBench/doitgen.c +0 -0
- data/examples/benchmarks/PolyBench/durbin.c +0 -0
- data/examples/benchmarks/PolyBench/dynprog.c +0 -0
- data/examples/benchmarks/PolyBench/fdtd-2d-apml.c +0 -0
- data/examples/benchmarks/PolyBench/fdtd-2d.c +0 -0
- data/examples/benchmarks/PolyBench/floyd-warshall.c +0 -0
- data/examples/benchmarks/PolyBench/gemm.c +0 -0
- data/examples/benchmarks/PolyBench/gemver.c +0 -0
- data/examples/benchmarks/PolyBench/gesummv.c +0 -0
- data/examples/benchmarks/PolyBench/gramschmidt.c +0 -0
- data/examples/benchmarks/PolyBench/jacobi-1d-imper.c +4 -2
- data/examples/benchmarks/PolyBench/jacobi-2d-imper.c +1 -1
- data/examples/benchmarks/PolyBench/lu.c +0 -0
- data/examples/benchmarks/PolyBench/ludcmp.c +0 -0
- data/examples/benchmarks/PolyBench/mvt.c +0 -0
- data/examples/benchmarks/PolyBench/reg_detect.c +0 -0
- data/examples/benchmarks/PolyBench/seidel-2d.c +0 -0
- data/examples/benchmarks/PolyBench/symm.c +0 -0
- data/examples/benchmarks/PolyBench/syr2k.c +0 -0
- data/examples/benchmarks/PolyBench/syrk.c +0 -0
- data/examples/benchmarks/PolyBench/trisolv.c +0 -0
- data/examples/benchmarks/PolyBench/trmm.c +0 -0
- data/examples/benchmarks/Rodinia/bfs.c +143 -0
- data/examples/benchmarks/Rodinia/common.h +78 -0
- data/examples/benchmarks/Rodinia/hotspot.c +106 -126
- data/examples/benchmarks/Rodinia/kmeans.c +157 -164
- data/examples/benchmarks/Rodinia/nw.c +151 -0
- data/examples/benchmarks/Rodinia/pathfinder.c +88 -0
- data/examples/benchmarks/Rodinia/srad.c +50 -59
- data/examples/benchmarks/other/common.h +0 -0
- data/examples/benchmarks/other/dct.c +0 -0
- data/examples/benchmarks/other/mm.c +0 -0
- data/examples/benchmarks/other/saxpy.c +0 -0
- data/examples/chunk/example01.c +6 -4
- data/examples/chunk/example02.c +6 -4
- data/examples/chunk/example03.c +6 -4
- data/examples/chunk/example04.c +8 -5
- data/examples/chunk/example05.c +6 -4
- data/examples/chunk/example06.c +3 -1
- data/examples/chunk/example07.c +5 -2
- data/examples/dependences/example01.c +3 -1
- data/examples/dependences/example02.c +3 -1
- data/examples/dependences/example03.c +3 -1
- data/examples/dependences/example04.c +3 -1
- data/examples/dependences/example05.c +3 -1
- data/examples/element/example01.c +6 -4
- data/examples/element/example02.c +6 -4
- data/examples/element/example03.c +10 -8
- data/examples/element/example04.c +6 -4
- data/examples/element/example05.c +8 -5
- data/examples/element/example06.c +6 -4
- data/examples/element/example07.c +6 -4
- data/examples/element/example08.c +6 -4
- data/examples/element/example09.c +6 -4
- data/examples/element/example10.c +4 -2
- data/examples/element/example11.c +4 -2
- data/examples/element/example12.c +4 -2
- data/examples/element/example13.c +3 -1
- data/examples/fusion/example01.c +3 -12
- data/examples/fusion/example02.c +3 -16
- data/examples/fusion/example03.c +3 -1
- data/examples/fusion/example04.c +5 -3
- data/examples/fusion/example05.c +3 -1
- data/examples/neighbourhood/example01.c +6 -4
- data/examples/neighbourhood/example02.c +6 -4
- data/examples/neighbourhood/example03.c +6 -4
- data/examples/neighbourhood/example04.c +5 -3
- data/examples/neighbourhood/example05.c +3 -1
- data/examples/shared/example01.c +6 -4
- data/examples/shared/example02.c +6 -4
- data/examples/shared/example03.c +6 -4
- data/examples/shared/example04.c +6 -4
- data/examples/shared/example05.c +6 -4
- data/lib/adarwin/engine.rb +16 -5
- data/lib/adarwin/memorycopies.rb +21 -9
- data/lib/adarwin/nest.rb +18 -1
- data/lib/adarwin/preprocessor.rb +5 -2
- data/lib/adarwin/reference.rb +71 -6
- data/lib/bones/algorithm.rb +20 -5
- data/lib/bones/copy.rb +3 -2
- data/lib/bones/engine.rb +12 -9
- data/lib/bones/preprocessor.rb +170 -120
- data/lib/bones/variablelist.rb +1 -1
- data/lib/cast.rb +11 -0
- data/lib/castaddon.rb +23 -6
- data/lib/castaddon/node_adarwin.rb +17 -0
- data/lib/castaddon/node_common.rb +6 -0
- data/lib/castaddon/transformations.rb +13 -9
- data/skeletons/CPU-C/common/epilogue.c +0 -0
- data/skeletons/CPU-C/common/globals.c +0 -0
- data/skeletons/CPU-C/common/globals_kernel.c +0 -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_global.c +0 -0
- data/skeletons/CPU-C/common/mem_prologue.c +0 -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 +0 -0
- data/skeletons/CPU-C/common/timer_2_stop.c +0 -0
- data/skeletons/CPU-C/common/timer_globals.c +5 -0
- data/skeletons/CPU-C/kernel/default.host.c +0 -0
- data/skeletons/CPU-C/kernel/default.kernel.c +0 -0
- data/skeletons/CPU-C/skeletons.txt +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/epilogue.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/globals.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/globals_kernel.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/header.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/mem_copy_D2H.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/mem_copy_H2D.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/mem_epilogue.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/mem_prologue.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/prologue.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/timer_1_start.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/timer_1_stop.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/timer_2_start.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/common/timer_2_stop.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/kernel/D-element-to-1-shared.host.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/kernel/D-element-to-1-shared.kernel.cl +0 -0
- data/skeletons/CPU-OPENCL-AMD/kernel/default.host.c +0 -0
- data/skeletons/CPU-OPENCL-AMD/kernel/default.kernel.cl +0 -0
- data/skeletons/CPU-OPENCL-AMD/skeletons.txt +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/epilogue.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/globals.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/globals_kernel.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/header.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/mem_copy_D2H.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/mem_copy_H2D.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/mem_epilogue.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/mem_global.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/mem_prologue.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/prologue.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/timer_1_start.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/timer_1_stop.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/timer_2_start.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/timer_2_stop.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/common/timer_globals.c +5 -0
- data/skeletons/CPU-OPENCL-INTEL/kernel/D-element-to-1-shared.host.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/kernel/D-element-to-1-shared.kernel.cl +0 -0
- data/skeletons/CPU-OPENCL-INTEL/kernel/default.host.c +0 -0
- data/skeletons/CPU-OPENCL-INTEL/kernel/default.kernel.cl +0 -0
- data/skeletons/CPU-OPENCL-INTEL/skeletons.txt +0 -0
- data/skeletons/CPU-OPENMP/common/epilogue.c +0 -0
- data/skeletons/CPU-OPENMP/common/globals.c +0 -0
- data/skeletons/CPU-OPENMP/common/globals_kernel.c +0 -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_global.c +0 -0
- data/skeletons/CPU-OPENMP/common/mem_prologue.c +0 -0
- data/skeletons/CPU-OPENMP/common/prologue.c +0 -0
- data/skeletons/CPU-OPENMP/common/timer_1_start.c +0 -0
- data/skeletons/CPU-OPENMP/common/timer_1_stop.c +0 -0
- data/skeletons/CPU-OPENMP/common/timer_2_start.c +0 -0
- data/skeletons/CPU-OPENMP/common/timer_2_stop.c +0 -0
- data/skeletons/CPU-OPENMP/common/timer_globals.c +2 -0
- data/skeletons/CPU-OPENMP/kernel/D-element-to-1-shared.host.c +0 -0
- data/skeletons/CPU-OPENMP/kernel/D-element-to-1-shared.kernel.c +3 -3
- data/skeletons/CPU-OPENMP/kernel/default.host.c +0 -0
- data/skeletons/CPU-OPENMP/kernel/default.kernel.c +0 -0
- data/skeletons/CPU-OPENMP/skeletons.txt +0 -0
- data/skeletons/GPU-CUDA/common/epilogue.c +0 -0
- data/skeletons/GPU-CUDA/common/globals.c +0 -0
- data/skeletons/GPU-CUDA/common/globals_kernel.c +0 -0
- data/skeletons/GPU-CUDA/common/header.c +0 -0
- data/skeletons/GPU-CUDA/common/mem_async_alloc.c +0 -0
- data/skeletons/GPU-CUDA/common/mem_async_copyin.c +0 -0
- data/skeletons/GPU-CUDA/common/mem_async_copyout.c +0 -0
- data/skeletons/GPU-CUDA/common/mem_async_free.c +0 -0
- data/skeletons/GPU-CUDA/common/mem_copy_D2H.c +0 -0
- data/skeletons/GPU-CUDA/common/mem_copy_H2D.c +0 -0
- data/skeletons/GPU-CUDA/common/mem_epilogue.c +0 -0
- data/skeletons/GPU-CUDA/common/mem_global.c +0 -0
- data/skeletons/GPU-CUDA/common/mem_prologue.c +0 -0
- data/skeletons/GPU-CUDA/common/prologue.c +0 -0
- data/skeletons/GPU-CUDA/common/scheduler.c +2 -2
- data/skeletons/GPU-CUDA/common/timer_1_start.c +0 -0
- data/skeletons/GPU-CUDA/common/timer_1_stop.c +0 -0
- data/skeletons/GPU-CUDA/common/timer_2_start.c +0 -0
- data/skeletons/GPU-CUDA/common/timer_2_stop.c +0 -0
- data/skeletons/GPU-CUDA/common/timer_globals.c +0 -0
- data/skeletons/GPU-CUDA/kernel/2xN-N-chunk-1-N-to-D-element.host.c +0 -0
- data/skeletons/GPU-CUDA/kernel/2xN-N-chunk-1-N-to-D-element.kernel.cu +0 -0
- data/skeletons/GPU-CUDA/kernel/D-element-to-1-shared.host.c +0 -0
- data/skeletons/GPU-CUDA/kernel/D-element-to-1-shared.kernel.cu +0 -0
- data/skeletons/GPU-CUDA/kernel/D-element-to-N-shared.host.c +0 -0
- data/skeletons/GPU-CUDA/kernel/D-element-to-N-shared.kernel.cu +0 -0
- data/skeletons/GPU-CUDA/kernel/N-N-chunk-1-N-to-D-element.host.c +0 -0
- data/skeletons/GPU-CUDA/kernel/N-N-chunk-1-N-to-D-element.kernel.cu +0 -0
- data/skeletons/GPU-CUDA/kernel/N-neighbourhood-N-to-N-element.host.c +0 -0
- data/skeletons/GPU-CUDA/kernel/N-neighbourhood-N-to-N-element.kernel.cu +0 -0
- data/skeletons/GPU-CUDA/kernel/default.host.c +0 -0
- data/skeletons/GPU-CUDA/kernel/default.kernel.cu +0 -0
- data/skeletons/GPU-CUDA/skeletons.txt +4 -2
- data/skeletons/GPU-OPENCL-AMD/common/epilogue.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/globals.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/globals_kernel.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/header.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/mem_copy_D2H.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/mem_copy_H2D.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/mem_epilogue.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/mem_prologue.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/prologue.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/timer_1_start.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/timer_1_stop.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/timer_2_start.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/common/timer_2_stop.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/kernel/D-element-to-1-shared.host.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/kernel/D-element-to-1-shared.kernel.cl +0 -0
- data/skeletons/GPU-OPENCL-AMD/kernel/default.host.c +0 -0
- data/skeletons/GPU-OPENCL-AMD/kernel/default.kernel.cl +0 -0
- data/skeletons/GPU-OPENCL-AMD/skeletons.txt +0 -0
- data/skeletons/verification/header.c +0 -0
- data/skeletons/verification/timer_start.c +0 -0
- data/skeletons/verification/timer_stop.c +0 -0
- data/skeletons/verification/verify_results.c +0 -0
- data/test/bones/test_algorithm.rb +0 -0
- data/test/bones/test_common.rb +0 -0
- data/test/bones/test_preprocessor.rb +0 -0
- data/test/bones/test_species.rb +0 -0
- data/test/bones/test_variable.rb +0 -0
- data/test/examples/benchmarks/PolyBench/2mm_species.c +1 -1
- data/test/examples/benchmarks/PolyBench/3mm_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/adi_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/atax_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/bicg_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/cholesky_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/correlation_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/covariance_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/doitgen_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/durbin_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/dynprog_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/fdtd-2d-apml_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/fdtd-2d_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/floyd-warshall_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/gemm_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/gemver_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/gesummv_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/gramschmidt_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/jacobi-1d-imper_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/jacobi-2d-imper_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/lu_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/ludcmp_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/mvt_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/reg_detect_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/seidel-2d_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/symm_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/syr2k_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/syrk_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/trisolv_species.c +0 -0
- data/test/examples/benchmarks/PolyBench/trmm_species.c +0 -0
- data/test/examples/chunk/example01_species.c +3 -3
- data/test/examples/chunk/example02_species.c +3 -3
- data/test/examples/chunk/example03_species.c +3 -3
- data/test/examples/chunk/example04_species.c +3 -3
- data/test/examples/chunk/example05_species.c +3 -3
- data/test/examples/chunk/example06_species.c +1 -1
- data/test/examples/chunk/example07_species.c +3 -2
- data/test/examples/dependences/example01_species.c +1 -1
- data/test/examples/dependences/example02_species.c +1 -1
- data/test/examples/dependences/example03_species.c +1 -1
- data/test/examples/dependences/example04_species.c +1 -1
- data/test/examples/dependences/example05_species.c +1 -1
- data/test/examples/element/example01_species.c +3 -3
- data/test/examples/element/example02_species.c +3 -3
- data/test/examples/element/example03_species.c +7 -7
- data/test/examples/element/example04_species.c +3 -3
- data/test/examples/element/example05_species.c +3 -3
- data/test/examples/element/example06_species.c +3 -3
- data/test/examples/element/example07_species.c +3 -3
- data/test/examples/element/example08_species.c +3 -3
- data/test/examples/element/example09_species.c +3 -3
- data/test/examples/element/example10_species.c +1 -1
- data/test/examples/element/example11_species.c +1 -1
- data/test/examples/element/example12_species.c +1 -1
- data/test/examples/element/example13_species.c +1 -1
- data/test/examples/neighbourhood/example01_species.c +3 -3
- data/test/examples/neighbourhood/example02_species.c +3 -3
- data/test/examples/neighbourhood/example03_species.c +3 -3
- data/test/examples/neighbourhood/example04_species.c +3 -3
- data/test/examples/neighbourhood/example05_species.c +1 -1
- data/test/examples/shared/example01_species.c +3 -3
- data/test/examples/shared/example02_species.c +3 -3
- data/test/examples/shared/example03_species.c +3 -3
- data/test/examples/shared/example04_species.c +3 -3
- data/test/examples/shared/example05_species.c +3 -3
- data/test/test_helper.rb +2 -2
- metadata +266 -252
- checksums.yaml +0 -15
- data/examples/benchmarks/Rodinia/cfd.c +0 -180
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
|
|
2
|
+
//########################################################################
|
|
3
|
+
//### Includes
|
|
4
|
+
//########################################################################
|
|
5
|
+
|
|
6
|
+
#include <stdio.h>
|
|
7
|
+
#include <stdlib.h>
|
|
8
|
+
#include <math.h>
|
|
9
|
+
#include <float.h>
|
|
10
|
+
|
|
11
|
+
//########################################################################
|
|
12
|
+
//### Hotspot
|
|
13
|
+
//########################################################################
|
|
14
|
+
|
|
15
|
+
// Parameters
|
|
16
|
+
#define GRID_ROWS 512 // Number of rows in the grid (positive integer)
|
|
17
|
+
#define GRID_COLS 512 // Number of columns in the grid (positive integer)
|
|
18
|
+
#define SIM_TIME 10 // Number of iterations
|
|
19
|
+
#define TEMPERATURE_FILE "data/hotspot_temperature_512.txt" // Name of the file containing the initial temperature values of each cell
|
|
20
|
+
#define POWER_FILE "data/hotspot_power_512.txt" // Name of the file containing the dissipated power values of each cell
|
|
21
|
+
|
|
22
|
+
// Defines
|
|
23
|
+
#define STRING_SIZE 256 // Length of the strings in the temperature and power files
|
|
24
|
+
#define MAX_PD (3.0e6) // Maximum power density possible (say 300W for a 10mm x 10mm chip)
|
|
25
|
+
#define PRECISION 0.001 // Required precision in degrees
|
|
26
|
+
#define SPEC_HEAT_SI 1.75e6 //
|
|
27
|
+
#define K_SI 100 //
|
|
28
|
+
#define FACTOR_CHIP 0.5 // Capacitance fitting factor
|
|
29
|
+
#define T_CHIP 0.0005 // Chip temperature
|
|
30
|
+
#define CHIP_HEIGHT 0.016 // Chip height
|
|
31
|
+
#define CHIP_WIDTH 0.016 // Chip width
|
|
32
|
+
#define AMB_TEMP 80.0 // Ambient temperature, assuming no package at all
|
|
33
|
+
|
|
34
|
+
//########################################################################
|
|
35
|
+
//### Srad
|
|
36
|
+
//########################################################################
|
|
37
|
+
|
|
38
|
+
// Defines
|
|
39
|
+
#define ROWS 256 // Number of ROWS in the domain
|
|
40
|
+
#define COLS 256 // Number of COLS in the domain
|
|
41
|
+
#define R1 0 // y1 position of the speckle
|
|
42
|
+
#define R2 31 // y2 position of the speckle
|
|
43
|
+
#define C1 0 // x1 position of the speckle
|
|
44
|
+
#define C2 31 // x2 position of the speckle
|
|
45
|
+
#define LAMBDA 0.5 // Lambda value
|
|
46
|
+
#define NITER 4 // Number of iterations
|
|
47
|
+
|
|
48
|
+
//########################################################################
|
|
49
|
+
//### Pathfinder
|
|
50
|
+
//########################################################################
|
|
51
|
+
|
|
52
|
+
// Configuration
|
|
53
|
+
#define PATHCOLS 100000
|
|
54
|
+
#define PATHROWS 100
|
|
55
|
+
|
|
56
|
+
// Seed
|
|
57
|
+
#define M_SEED 9
|
|
58
|
+
|
|
59
|
+
//########################################################################
|
|
60
|
+
//### Kmeans
|
|
61
|
+
//########################################################################
|
|
62
|
+
|
|
63
|
+
#define SIZE (494020)
|
|
64
|
+
#define NUM_CLUSTERS 20
|
|
65
|
+
#define DIMENSIONS 2
|
|
66
|
+
#define THRESHOLD 0.001
|
|
67
|
+
|
|
68
|
+
//########################################################################
|
|
69
|
+
//### BFS
|
|
70
|
+
//########################################################################
|
|
71
|
+
|
|
72
|
+
// Settings
|
|
73
|
+
#define MAX_NODES 1000000
|
|
74
|
+
|
|
75
|
+
// Config
|
|
76
|
+
#define FILENAME "/home/cnugteren/software/rodinia_2.4/data/bfs/graph1MW_6.txt"
|
|
77
|
+
|
|
78
|
+
//########################################################################
|
|
@@ -15,47 +15,12 @@
|
|
|
15
15
|
// == File information
|
|
16
16
|
// Filename...........applications/hotspot.c
|
|
17
17
|
// Authors............Cedric Nugteren
|
|
18
|
-
// Last modified on...
|
|
18
|
+
// Last modified on...06-Jun-2014
|
|
19
19
|
//
|
|
20
|
-
|
|
21
|
-
//########################################################################
|
|
22
|
-
//### Includes
|
|
23
|
-
//########################################################################
|
|
24
|
-
|
|
25
|
-
#include <stdio.h>
|
|
26
|
-
#include <stdlib.h>
|
|
27
|
-
#include <math.h>
|
|
28
|
-
|
|
29
|
-
//########################################################################
|
|
30
|
-
//### Input parameters
|
|
31
|
-
//########################################################################
|
|
32
|
-
|
|
33
|
-
#define GRID_ROWS 64 // Number of rows in the grid (positive integer)
|
|
34
|
-
#define GRID_COLS 64 // Number of columns in the grid (positive integer)
|
|
35
|
-
#define SIM_TIME 2 // Number of iterations
|
|
36
|
-
#define TEMPERATURE_FILE "data/hotspot_temperature_64.txt" // Name of the file containing the initial temperature values of each cell
|
|
37
|
-
#define POWER_FILE "data/hotspot_power_64.txt" // Name of the file containing the dissipated power values of each cell
|
|
38
|
-
|
|
39
|
-
//########################################################################
|
|
40
|
-
//### Defines
|
|
41
20
|
//########################################################################
|
|
42
21
|
|
|
43
|
-
|
|
44
|
-
#
|
|
45
|
-
#define PRECISION 0.001 // Required precision in degrees
|
|
46
|
-
#define SPEC_HEAT_SI 1.75e6 //
|
|
47
|
-
#define K_SI 100 //
|
|
48
|
-
#define FACTOR_CHIP 0.5 // Capacitance fitting factor
|
|
49
|
-
#define T_CHIP 0.0005 // Chip temperature
|
|
50
|
-
#define CHIP_HEIGHT 0.016 // Chip height
|
|
51
|
-
#define CHIP_WIDTH 0.016 // Chip width
|
|
52
|
-
#define AMB_TEMP 80.0 // Ambient temperature, assuming no package at all
|
|
53
|
-
|
|
54
|
-
//########################################################################
|
|
55
|
-
//### Forward declarations
|
|
56
|
-
//########################################################################
|
|
57
|
-
|
|
58
|
-
void read_input(double* array, const char* filename);
|
|
22
|
+
// Includes
|
|
23
|
+
#include "common.h"
|
|
59
24
|
|
|
60
25
|
//########################################################################
|
|
61
26
|
//### Start of the main function
|
|
@@ -64,15 +29,13 @@ void read_input(double* array, const char* filename);
|
|
|
64
29
|
int main(void) {
|
|
65
30
|
|
|
66
31
|
// Declare the loop iterators
|
|
67
|
-
int r,c
|
|
32
|
+
int r,c;
|
|
33
|
+
int iter = 0;
|
|
68
34
|
|
|
69
35
|
// Declare other/helper variables
|
|
70
|
-
int index;
|
|
71
36
|
double delta;
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
double grid_height = CHIP_HEIGHT/row;
|
|
75
|
-
double grid_width = CHIP_WIDTH/col;
|
|
37
|
+
double grid_height = CHIP_HEIGHT/GRID_ROWS;
|
|
38
|
+
double grid_width = CHIP_WIDTH/GRID_COLS;
|
|
76
39
|
|
|
77
40
|
// Set domain variables
|
|
78
41
|
double cap = FACTOR_CHIP*SPEC_HEAT_SI*T_CHIP*grid_width*grid_height;
|
|
@@ -84,14 +47,38 @@ int main(void) {
|
|
|
84
47
|
|
|
85
48
|
// Initialising memory
|
|
86
49
|
printf("\n[hotspot] Initialising memory"); fflush(stdout);
|
|
87
|
-
double
|
|
88
|
-
double
|
|
89
|
-
double
|
|
50
|
+
double temperature[GRID_ROWS][GRID_COLS];
|
|
51
|
+
double power[GRID_ROWS][GRID_COLS];
|
|
52
|
+
double result[GRID_ROWS][GRID_COLS];
|
|
90
53
|
|
|
91
|
-
// Read initial temperature
|
|
54
|
+
// Read initial temperature array
|
|
92
55
|
printf("\n[hotspot] Populating memory"); fflush(stdout);
|
|
93
|
-
|
|
94
|
-
|
|
56
|
+
char string[STRING_SIZE];
|
|
57
|
+
double value;
|
|
58
|
+
FILE* file_pointer1 = fopen(TEMPERATURE_FILE, "r");
|
|
59
|
+
if (!file_pointer1) { printf("\n[hotspot] Error: file '%s' could not be opened for reading\n\n", TEMPERATURE_FILE); fflush(stdout); exit(1); }
|
|
60
|
+
for (r=0; r<GRID_ROWS; r++) {
|
|
61
|
+
for (c=0; c<GRID_COLS; c++) {
|
|
62
|
+
fgets(string, STRING_SIZE, file_pointer1);
|
|
63
|
+
if (feof(file_pointer1)) { printf("\n[hotspot] Error: not enough lines in file '%s'\n\n", TEMPERATURE_FILE); fflush(stdout); exit(1); }
|
|
64
|
+
if ((sscanf(string, "%lf", &value) != 1) ) { printf("\n[hotspot] Error: invalid file format for '%s'\n\n", TEMPERATURE_FILE); fflush(stdout); exit(1); }
|
|
65
|
+
temperature[r][c] = value;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
fclose(file_pointer1);
|
|
69
|
+
|
|
70
|
+
// Read initial power array
|
|
71
|
+
FILE* file_pointer2 = fopen(POWER_FILE, "r");
|
|
72
|
+
if (!file_pointer2) { printf("\n[hotspot] Error: file '%s' could not be opened for reading\n\n", POWER_FILE); fflush(stdout); exit(1); }
|
|
73
|
+
for (r=0; r<GRID_ROWS; r++) {
|
|
74
|
+
for (c=0; c<GRID_COLS; c++) {
|
|
75
|
+
fgets(string, STRING_SIZE, file_pointer2);
|
|
76
|
+
if (feof(file_pointer2)) { printf("\n[hotspot] Error: not enough lines in file '%s'\n\n", POWER_FILE); fflush(stdout); exit(1); }
|
|
77
|
+
if ((sscanf(string, "%lf", &value) != 1) ) { printf("\n[hotspot] Error: invalid file format for '%s'\n\n", POWER_FILE); fflush(stdout); exit(1); }
|
|
78
|
+
power[r][c] = value;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
fclose(file_pointer2);
|
|
95
82
|
|
|
96
83
|
// Perform the computation a given number of times
|
|
97
84
|
printf("\n[hotspot] Performing the computation %d times",SIM_TIME); fflush(stdout);
|
|
@@ -100,100 +87,112 @@ int main(void) {
|
|
|
100
87
|
|
|
101
88
|
// Transient solver driver routine: convert the heat transfer differential equations to difference equations
|
|
102
89
|
// and solve the difference equations by iterating
|
|
103
|
-
for (r=0; r<
|
|
104
|
-
for (c=0; c<
|
|
90
|
+
for (r=0; r<GRID_ROWS; r++) {
|
|
91
|
+
for (c=0; c<GRID_COLS; c++) {
|
|
92
|
+
|
|
93
|
+
// Load the temperatures from memory
|
|
94
|
+
double temp_r_c = temperature[r][c];
|
|
95
|
+
double temp_rp1_c = 0;
|
|
96
|
+
if (r < GRID_ROWS-1) { temp_rp1_c = temperature[r+1][c]; }
|
|
97
|
+
double temp_rm1_c = 0;
|
|
98
|
+
if (r > 0) { temp_rm1_c = temperature[r-1][c]; }
|
|
99
|
+
double temp_r_cp1 = 0;
|
|
100
|
+
if (c < GRID_COLS-1) { temp_r_cp1 = temperature[r][c+1]; }
|
|
101
|
+
double temp_r_cm1 = 0;
|
|
102
|
+
if (c > 0) { temp_r_cm1 = temperature[r][c-1]; }
|
|
103
|
+
|
|
104
|
+
// Load the power
|
|
105
|
+
double power_r_c = power[r][c];
|
|
105
106
|
|
|
106
107
|
// Corner 1
|
|
107
108
|
if ( (r == 0) && (c == 0) ) {
|
|
108
|
-
delta = (step / cap) * (
|
|
109
|
-
(
|
|
110
|
-
(
|
|
111
|
-
(AMB_TEMP
|
|
109
|
+
delta = (step / cap) * (power_r_c +
|
|
110
|
+
(temp_r_cp1 - temp_r_c) / Rx +
|
|
111
|
+
(temp_rp1_c - temp_r_c) / Ry +
|
|
112
|
+
(AMB_TEMP - temp_r_c) / Rz);
|
|
112
113
|
}
|
|
113
114
|
// Corner 2
|
|
114
|
-
else if ((r == 0) && (c ==
|
|
115
|
-
delta = (step / cap) * (
|
|
116
|
-
(
|
|
117
|
-
(
|
|
118
|
-
(AMB_TEMP
|
|
115
|
+
else if ((r == 0) && (c == GRID_COLS-1)) {
|
|
116
|
+
delta = (step / cap) * (power_r_c +
|
|
117
|
+
(temp_r_cm1 - temp_r_c) / Rx +
|
|
118
|
+
(temp_rp1_c - temp_r_c) / Ry +
|
|
119
|
+
(AMB_TEMP - temp_r_c) / Rz);
|
|
119
120
|
}
|
|
120
121
|
// Corner 3
|
|
121
|
-
else if ((r ==
|
|
122
|
-
delta = (step / cap) * (
|
|
123
|
-
(
|
|
124
|
-
(
|
|
125
|
-
(AMB_TEMP
|
|
122
|
+
else if ((r == GRID_ROWS-1) && (c == GRID_COLS-1)) {
|
|
123
|
+
delta = (step / cap) * (power_r_c +
|
|
124
|
+
(temp_r_cm1 - temp_r_c) / Rx +
|
|
125
|
+
(temp_rm1_c - temp_r_c) / Ry +
|
|
126
|
+
(AMB_TEMP - temp_r_c) / Rz);
|
|
126
127
|
}
|
|
127
128
|
// Corner 4
|
|
128
|
-
else if ((r ==
|
|
129
|
-
delta = (step / cap) * (
|
|
130
|
-
(
|
|
131
|
-
(
|
|
132
|
-
(AMB_TEMP
|
|
129
|
+
else if ((r == GRID_ROWS-1) && (c == 0)) {
|
|
130
|
+
delta = (step / cap) * (power_r_c +
|
|
131
|
+
(temp_r_cp1 - temp_r_c) / Rx +
|
|
132
|
+
(temp_rm1_c - temp_r_c) / Ry +
|
|
133
|
+
(AMB_TEMP - temp_r_c) / Rz);
|
|
133
134
|
}
|
|
134
135
|
// Edge 1
|
|
135
136
|
else if (r == 0) {
|
|
136
|
-
delta = (step / cap) * (
|
|
137
|
-
(
|
|
138
|
-
(
|
|
139
|
-
(AMB_TEMP
|
|
137
|
+
delta = (step / cap) * (power_r_c +
|
|
138
|
+
(temp_r_cp1 + temp_r_cm1 - 2.0*temp_r_c) / Rx +
|
|
139
|
+
(temp_rp1_c - temp_r_c) / Ry +
|
|
140
|
+
(AMB_TEMP - temp_r_c) / Rz);
|
|
140
141
|
}
|
|
141
142
|
// Edge 2
|
|
142
|
-
else if (c ==
|
|
143
|
-
delta = (step / cap) * (
|
|
144
|
-
(
|
|
145
|
-
(
|
|
146
|
-
(AMB_TEMP
|
|
143
|
+
else if (c == GRID_COLS-1) {
|
|
144
|
+
delta = (step / cap) * (power_r_c +
|
|
145
|
+
(temp_rp1_c + temp_rm1_c - 2.0*temp_r_c) / Ry +
|
|
146
|
+
(temp_r_cm1 - temp_r_c) / Rx +
|
|
147
|
+
(AMB_TEMP - temp_r_c) / Rz);
|
|
147
148
|
}
|
|
148
149
|
// Edge 3
|
|
149
|
-
else if (r ==
|
|
150
|
-
delta = (step / cap) * (
|
|
151
|
-
(
|
|
152
|
-
(
|
|
153
|
-
(AMB_TEMP
|
|
150
|
+
else if (r == GRID_ROWS-1) {
|
|
151
|
+
delta = (step / cap) * (power_r_c +
|
|
152
|
+
(temp_r_cp1 + temp_r_cm1 - 2.0*temp_r_c) / Rx +
|
|
153
|
+
(temp_rm1_c - temp_r_c) / Ry +
|
|
154
|
+
(AMB_TEMP - temp_r_c) / Rz);
|
|
154
155
|
}
|
|
155
156
|
// Edge 4
|
|
156
157
|
else if (c == 0) {
|
|
157
|
-
delta = (step / cap) * (
|
|
158
|
-
(
|
|
159
|
-
(
|
|
160
|
-
(AMB_TEMP
|
|
158
|
+
delta = (step / cap) * (power_r_c +
|
|
159
|
+
(temp_rp1_c + temp_rm1_c - 2.0*temp_r_c) / Ry +
|
|
160
|
+
(temp_r_cp1 - temp_r_c) / Rx +
|
|
161
|
+
(AMB_TEMP - temp_r_c) / Rz);
|
|
161
162
|
}
|
|
162
163
|
// Inside the chip
|
|
163
164
|
else {
|
|
164
|
-
delta = (step / cap) * (
|
|
165
|
-
(
|
|
166
|
-
(
|
|
167
|
-
(AMB_TEMP
|
|
165
|
+
delta = (step / cap) * (power_r_c +
|
|
166
|
+
(temp_rp1_c + temp_rm1_c - 2.0*temp_r_c) / Ry +
|
|
167
|
+
(temp_r_cp1 + temp_r_cm1 - 2.0*temp_r_c) / Rx +
|
|
168
|
+
(AMB_TEMP - temp_r_c) / Rz);
|
|
168
169
|
}
|
|
169
170
|
|
|
170
171
|
// Update the temperatures
|
|
171
|
-
result[r
|
|
172
|
+
result[r][c] = temperature[r][c] + delta;
|
|
172
173
|
}
|
|
173
174
|
}
|
|
174
175
|
|
|
175
176
|
// Copy the result as the new temperatures
|
|
176
|
-
for (r=0; r<
|
|
177
|
-
for (c=0; c<
|
|
178
|
-
temperature[r
|
|
177
|
+
for (r=0; r<GRID_ROWS; r++) {
|
|
178
|
+
for (c=0; c<GRID_COLS; c++) {
|
|
179
|
+
temperature[r][c] = result[r][c];
|
|
179
180
|
}
|
|
180
181
|
}
|
|
181
182
|
}
|
|
182
183
|
#pragma endscop
|
|
183
184
|
|
|
184
185
|
// Print the values matrix
|
|
185
|
-
printf("\n[hotspot] Printing the final temperatures:\n\n"); fflush(stdout);
|
|
186
|
-
for (r=0; r<
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
}
|
|
186
|
+
//printf("\n[hotspot] Printing the final temperatures:\n\n"); fflush(stdout);
|
|
187
|
+
//for (r=0; r<GRID_ROWS; r++) {
|
|
188
|
+
// for (c=0; c<GRID_COLS; c++) {
|
|
189
|
+
// printf("%6d: %.3lf ", r*GRID_COLS+c, temperature[r][c]);
|
|
190
|
+
// }
|
|
191
|
+
// printf("\n");
|
|
192
|
+
//}
|
|
193
193
|
|
|
194
194
|
// Clean-up and exit
|
|
195
195
|
printf("\n[hotspot] Completed\n\n"); fflush(stdout);
|
|
196
|
-
free(temperature); free(power); free(result);
|
|
197
196
|
fflush(stdout);
|
|
198
197
|
return 0;
|
|
199
198
|
}
|
|
@@ -202,27 +201,8 @@ int main(void) {
|
|
|
202
201
|
//### Function to read an input file (power or temperature values)
|
|
203
202
|
//########################################################################
|
|
204
203
|
|
|
205
|
-
void read_input(double
|
|
206
|
-
int r, c;
|
|
207
|
-
char string[STRING_SIZE];
|
|
208
|
-
double value;
|
|
204
|
+
void read_input(double array[GRID_ROWS][GRID_COLS], const char* filename) {
|
|
209
205
|
|
|
210
|
-
// Open the file
|
|
211
|
-
FILE* file_pointer = fopen(filename, "r");
|
|
212
|
-
if (!file_pointer) { printf("\n[hotspot] Error: file '%s' could not be opened for reading\n\n", filename); fflush(stdout); exit(1); }
|
|
213
|
-
|
|
214
|
-
// Process the file
|
|
215
|
-
for (r=0; r<GRID_ROWS; r++) {
|
|
216
|
-
for (c=0; c<GRID_COLS; c++) {
|
|
217
|
-
fgets(string, STRING_SIZE, file_pointer);
|
|
218
|
-
if (feof(file_pointer)) { printf("\n[hotspot] Error: not enough lines in file '%s'\n\n", filename); fflush(stdout); exit(1); }
|
|
219
|
-
if ((sscanf(string, "%lf", &value) != 1) ) { printf("\n[hotspot] Error: invalid file format for '%s'\n\n", filename); fflush(stdout); exit(1); }
|
|
220
|
-
array[r*GRID_COLS+c] = value;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
// Clean-up and return
|
|
225
|
-
fclose(file_pointer);
|
|
226
206
|
}
|
|
227
207
|
|
|
228
208
|
//########################################################################
|
|
@@ -1,164 +1,157 @@
|
|
|
1
|
-
//
|
|
2
|
-
// This file is part of the Bones source-to-source compiler examples. This C-code
|
|
3
|
-
// demonstrates the use of Bones for an example application: 'K-means clustering',
|
|
4
|
-
// as also available in the Rodinia benchmark suite. For more information on the
|
|
5
|
-
// application or on Bones please use the contact information below.
|
|
6
|
-
//
|
|
7
|
-
// == This implementation of K-means clustering is inspired by:
|
|
8
|
-
// Author.............Roger Zhang
|
|
9
|
-
// Web address........http://cs.smu.ca/~r_zhang/code/kmeans.c
|
|
10
|
-
//
|
|
11
|
-
// == More information on Bones
|
|
12
|
-
// Contact............Cedric Nugteren <c.nugteren@tue.nl>
|
|
13
|
-
// Web address........http://parse.ele.tue.nl/bones/
|
|
14
|
-
//
|
|
15
|
-
// == File information
|
|
16
|
-
// Filename...........applications/kmeans.c
|
|
17
|
-
// Authors............Cedric Nugteren
|
|
18
|
-
// Last modified on...
|
|
19
|
-
//
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
//
|
|
57
|
-
printf("\n[k-means]
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
//
|
|
65
|
-
printf("\n[k-means]
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
//
|
|
146
|
-
printf("
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
// Clean-up and exit the function
|
|
159
|
-
printf("\n[k-means] Completed\n\n"); fflush(stdout);
|
|
160
|
-
fflush(stdout);
|
|
161
|
-
return 0;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
//########################################################################
|
|
1
|
+
//
|
|
2
|
+
// This file is part of the Bones source-to-source compiler examples. This C-code
|
|
3
|
+
// demonstrates the use of Bones for an example application: 'K-means clustering',
|
|
4
|
+
// as also available in the Rodinia benchmark suite. For more information on the
|
|
5
|
+
// application or on Bones please use the contact information below.
|
|
6
|
+
//
|
|
7
|
+
// == This implementation of K-means clustering is inspired by:
|
|
8
|
+
// Author.............Roger Zhang
|
|
9
|
+
// Web address........http://cs.smu.ca/~r_zhang/code/kmeans.c
|
|
10
|
+
//
|
|
11
|
+
// == More information on Bones
|
|
12
|
+
// Contact............Cedric Nugteren <c.nugteren@tue.nl>
|
|
13
|
+
// Web address........http://parse.ele.tue.nl/bones/
|
|
14
|
+
//
|
|
15
|
+
// == File information
|
|
16
|
+
// Filename...........applications/kmeans.c
|
|
17
|
+
// Authors............Cedric Nugteren
|
|
18
|
+
// Last modified on...06-Jun-2014
|
|
19
|
+
//
|
|
20
|
+
//########################################################################
|
|
21
|
+
|
|
22
|
+
// Includes
|
|
23
|
+
#include "common.h"
|
|
24
|
+
|
|
25
|
+
//########################################################################
|
|
26
|
+
//### Start of the main function
|
|
27
|
+
//########################################################################
|
|
28
|
+
int main(void) {
|
|
29
|
+
|
|
30
|
+
// Declare the loop iterators
|
|
31
|
+
int i,j,k;
|
|
32
|
+
|
|
33
|
+
// Declare the error variables
|
|
34
|
+
float error[1] = { 100000.0 };
|
|
35
|
+
float old_error;
|
|
36
|
+
int iterations = 0;
|
|
37
|
+
|
|
38
|
+
// Declare the distance variables and arrays
|
|
39
|
+
float distances[SIZE];
|
|
40
|
+
|
|
41
|
+
// Initialising memory
|
|
42
|
+
printf("\n[k-means] Initialising memory"); fflush(stdout);
|
|
43
|
+
float input[SIZE][DIMENSIONS];
|
|
44
|
+
float centroids[NUM_CLUSTERS][DIMENSIONS];
|
|
45
|
+
float centroids_temp[NUM_CLUSTERS][DIMENSIONS];
|
|
46
|
+
int output[SIZE];
|
|
47
|
+
int counts[NUM_CLUSTERS];
|
|
48
|
+
|
|
49
|
+
// Set the input data
|
|
50
|
+
printf("\n[k-means] Populating memory"); fflush(stdout);
|
|
51
|
+
for (i=0; i<SIZE; i++) {
|
|
52
|
+
input[i][0] = (i/16);
|
|
53
|
+
input[i][1] = i%4;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Pick k initial centroids
|
|
57
|
+
printf("\n[k-means] Setting 'k' initial centroids"); fflush(stdout);
|
|
58
|
+
for (k=0; k<NUM_CLUSTERS; k++) {
|
|
59
|
+
for (j=0; j<DIMENSIONS; j++) {
|
|
60
|
+
centroids[k][j] = input[(SIZE/NUM_CLUSTERS)*k][j];
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Perform the k-means clustering algorithm, end when the error is not becoming smaller
|
|
65
|
+
printf("\n[k-means] Perform the clustering algorithm"); fflush(stdout);
|
|
66
|
+
do {
|
|
67
|
+
//for (int iters=0; iters<10; iters++) {
|
|
68
|
+
|
|
69
|
+
// Start of the scop
|
|
70
|
+
#pragma scop
|
|
71
|
+
|
|
72
|
+
// Save the error from the last step
|
|
73
|
+
old_error = error[0];
|
|
74
|
+
error[0] = 0;
|
|
75
|
+
|
|
76
|
+
// Clear old counts and temporary centroids
|
|
77
|
+
for (k=0; k<NUM_CLUSTERS; k++) {
|
|
78
|
+
counts[k] = 0;
|
|
79
|
+
}
|
|
80
|
+
for (k=0; k<NUM_CLUSTERS; k++) {
|
|
81
|
+
for (j=0; j<DIMENSIONS; j++) {
|
|
82
|
+
centroids_temp[k][j] = 0;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
// Iterate over all data points
|
|
86
|
+
for (i=0; i<SIZE; i++) {
|
|
87
|
+
|
|
88
|
+
// Find the closest cluster
|
|
89
|
+
float min_distance = 100000.0;
|
|
90
|
+
for (k=0; k<NUM_CLUSTERS; k++) {
|
|
91
|
+
float distance = 0;
|
|
92
|
+
for (j=0; j<DIMENSIONS; j++) {
|
|
93
|
+
float val = (input[i][j]-centroids[k][j]);
|
|
94
|
+
distance += val * val;
|
|
95
|
+
}
|
|
96
|
+
if (distance < min_distance) {
|
|
97
|
+
output[i] = k;
|
|
98
|
+
min_distance = distance;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
// Update the size and temporary centroid of the destination cluster
|
|
103
|
+
int cluster_index = output[i];
|
|
104
|
+
for (j=0; j<DIMENSIONS; j++) {
|
|
105
|
+
centroids_temp[cluster_index][j] += input[i][j];
|
|
106
|
+
}
|
|
107
|
+
counts[cluster_index] += 1;
|
|
108
|
+
|
|
109
|
+
// Store the resulting distance
|
|
110
|
+
distances[i] = min_distance;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
// Update the standard error
|
|
114
|
+
for (i=0; i<SIZE; i++) {
|
|
115
|
+
error[0] += distances[i];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
// Update all centroids
|
|
119
|
+
for (k=0; k<NUM_CLUSTERS; k++) {
|
|
120
|
+
for (j=0; j<DIMENSIONS; j++) {
|
|
121
|
+
int count = counts[k];
|
|
122
|
+
float val;
|
|
123
|
+
if (count > 0) {
|
|
124
|
+
val = centroids_temp[k][j] / count;
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
val = centroids_temp[k][j];
|
|
128
|
+
}
|
|
129
|
+
centroids[k][j] = val;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Go to the next iteration
|
|
134
|
+
iterations += 1;
|
|
135
|
+
#pragma endscop
|
|
136
|
+
//}
|
|
137
|
+
} while (fabs(error[0]-old_error) > THRESHOLD);
|
|
138
|
+
|
|
139
|
+
// Print the results
|
|
140
|
+
printf("\n[k-means] Algorithm finished in %d iterations with an error of %.3lf", iterations, error[0]); fflush(stdout);
|
|
141
|
+
//printf("\n[k-means] Printing the results: \n\n"); fflush(stdout);
|
|
142
|
+
//for (k=0; k<NUM_CLUSTERS; k++) {
|
|
143
|
+
// printf("Cluster %2i: ", k);
|
|
144
|
+
// for (i=0; i<SIZE; i++) {
|
|
145
|
+
// if (output[i] == k) {
|
|
146
|
+
// printf("%3i ", i);
|
|
147
|
+
// }
|
|
148
|
+
// }
|
|
149
|
+
// printf("\n");
|
|
150
|
+
//}
|
|
151
|
+
|
|
152
|
+
// Clean-up and exit the function
|
|
153
|
+
printf("\n[k-means] Completed\n\n"); fflush(stdout);
|
|
154
|
+
fflush(stdout);
|
|
155
|
+
return 0;
|
|
156
|
+
}
|
|
157
|
+
//########################################################################
|