stringify_ocl_krnls.sh 2.95 KB
Newer Older
1
2
3
4
5
6
7
8
#!/bin/bash

# kernel-header files
HEADER_DIR="./common"
IN_HEADER1=$HEADER_DIR/"defines.h"
IN_HEADER2=$HEADER_DIR/"calcenergy_basic.h"

echo " "
9
echo "Stringified input header files: "
10
11
12
echo $IN_HEADER1
echo $IN_HEADER2

13
# device source-code folder
14
KERNEL_DIR="./device"
15
16
17
18
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

# non-kernel function files
## AUXI:   auxiliary
## ENER:   energy
## GRAD:   gradient
## ENEGRA: merged energy & gradient
IN_FUNCTION_AUXI=$KERNEL_DIR/"auxiliary_genetic.cl"
IN_FUNCTION_ENER=$KERNEL_DIR/"calcenergy.cl"
IN_FUNCTION_GRAD=$KERNEL_DIR/"calcgradient.cl"
IN_FUNCTION_MERGED_EG=$KERNEL_DIR/"calcMergedEneGra.cl"

# kernel files
## INIT: energy calculation of initial population
## EVAL: evaluation count 
## GS_ORIG_GA: Global Search Original Genetic Algorithm
## LS_ORIG_SW: Local Search Original Solis-Wets
## LS_GRAD_{SD | FI | AD}: Local Search Gradient-based {Steepest-Descent | Fire | Ada-Delta}
IN_KERNEL_INIT=$KERNEL_DIR/"kernel1.cl"
IN_KERNEL_EVAL=$KERNEL_DIR/"kernel2.cl"
IN_KERNEL_GS_ORIG_GA=$KERNEL_DIR/"kernel4.cl"
IN_KERNEL_LS_ORIG_SW=$KERNEL_DIR/"kernel3.cl"
IN_KERNEL_LS_GRAD_SD=$KERNEL_DIR/"kernel_sd.cl"
IN_KERNEL_LS_GRAD_FI=$KERNEL_DIR/"kernel_fire.cl"
IN_KERNEL_LS_GRAD_AD=$KERNEL_DIR/"kernel_ad.cl"

echo " "
echo "Stringified input non-kernel files: "
echo $IN_FUNCTION_AUXI
echo $IN_FUNCTION_ENER
echo $IN_FUNCTION_GRAD
echo $IN_FUNCTION_MERGED_EG
46
47
48

echo " "
echo "Stringified input kernel-files: "
49
50
51
52
53
54
55
echo $IN_KERNEL_INIT
echo $IN_KERNEL_EVAL
echo $IN_KERNEL_GS_ORIG_GA
echo $IN_KERNEL_LS_ORIG_SW
echo $IN_KERNEL_LS_GRAD_SD
echo $IN_KERNEL_LS_GRAD_FI
echo $IN_KERNEL_LS_GRAD_AD
56
57
58
59
60
61
62
63
64
65
66
67

# output file
OUT=host/inc/stringify.h

echo " "
echo "Stringified output file: "
echo $OUT
echo " "

# temporal file
TMP=$KERNEL_DIR/stringify_tmp

68
echo "// OCLADock: AUTOMATICALLY GENERATED FILE, DO NOT EDIT." >$TMP
69
70
71
72
echo "#ifndef STRINGIFY_H" >>$TMP
echo "#define STRINGIFY_H" >>$TMP

echo "const char *calcenergy_ocl =" >>$TMP
73
74
75
76
77
78
79
80
81
82
83
84
85
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_HEADER1            >> $TMP
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_HEADER2            >> $TMP
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_FUNCTION_AUXI      >> $TMP
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_FUNCTION_ENER      >> $TMP
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_FUNCTION_GRAD      >> $TMP
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_FUNCTION_MERGED_EG >> $TMP
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_KERNEL_INIT        >> $TMP
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_KERNEL_EVAL        >> $TMP
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_KERNEL_GS_ORIG_GA  >> $TMP
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_KERNEL_LS_ORIG_SW  >> $TMP
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_KERNEL_LS_GRAD_SD  >> $TMP
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_KERNEL_LS_GRAD_FI  >> $TMP
sed 's/\\/\\\\/g;s/"/\\"/g;s/^/"/;s/$/\\n"/' $IN_KERNEL_LS_GRAD_AD  >> $TMP
86
87
88
89
90
91
echo ";" >>$TMP

echo "#endif // End of STRINGIFY_H" >>$TMP

# remove "#include" lines
grep -v '#include' $TMP > $OUT