This repository has been archived by the owner on Mar 3, 2021. It is now read-only.
forked from Xilinx/SDAccel_Examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Jenkinsfile
363 lines (290 loc) · 8 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#!/usr/bin/env groovy
properties([
disableConcurrentBuilds()
])
// Days between clean builds
days = 10
devices = []
devices += ['xilinx_vcu1525_dynamic_5_1']
devices += ['xilinx_kcu1500_dynamic_5_0']
version = '2018.2'
precheck_status = 'FAILURE'
sw_status = 'FAILURE'
hw_status = 'FAILURE'
def setupExample(dir, workdir) {
return { ->
sh """#!/bin/bash -e
cd ${workdir}
. /tools/local/bin/modinit.sh > /dev/null 2>&1
module use.own /proj/picasso/modulefiles
module add sdaccel/${version}_daily
module add opencv/sdaccel
cd ${dir}
echo
echo "-----------------------------------------------"
echo "PWD: \$(pwd)"
echo "-----------------------------------------------"
echo
rsync -rL \$XILINX_SDX/lnx64/tools/opencv/ lib/
make clean exe
"""
}
}
def buildExample(target, dir, device, workdir) {
return { ->
if ( target == "sw_emu" ) {
cores = 1
mem = 4000
queue = "medium"
mins = 5
} else {
cores = 8
mem = 32000
queue = "long"
mins = 12*60
}
retry(3) {
sh """#!/bin/bash -e
cd ${workdir}
. /tools/local/bin/modinit.sh > /dev/null 2>&1
module use.own /proj/picasso/modulefiles
module add vivado/${version}_daily
module add sdaccel/${version}_daily
module add opencv/sdaccel
module add lsf
cd ${dir}
echo
echo "-----------------------------------------------"
echo "PWD: \$(pwd)"
echo "-----------------------------------------------"
echo
# Check if a rebuild is necessary
set -x
set +e
make -q TARGETS=${target} DEVICES=\"${device}\" all
rc=\$?
set -e
export TMPDIR=\$(mktemp -d -p \$(pwd))
# if rebuild required then use LSF
if [[ \$rc != 0 ]]; then
bsub -W ${mins} -I -q ${queue} -R "osdistro=rhel && osver==ws6" -n ${cores} -R "rusage[mem=${mem}] span[ptile=${cores}]" -J "\$(basename ${dir})-${target}" <<EOF
#!/bin/bash -ex
export TMPDIR=\$TMPDIR
make -j TARGETS=${target} DEVICES=\"${device}\" all
rm -rf \$TMPDIR
EOF
fi
set +x
"""
}
}
}
def dirsafe(device) {
return device.replaceAll(":", "_").replaceAll("\\.", "_")
}
def runExample(target, dir, device, workdir) {
return { ->
if ( target == "sw_emu" ) {
cores = 4
mem = 32000
queue = "medium"
mins = 15
} else {
cores = 1
mem = 4000
queue = "long"
mins = 8*60
}
devdir = dirsafe(device)
retry(3) {
// lock("${dir}") {
sh """#!/bin/bash -e
cd ${workdir}
. /tools/local/bin/modinit.sh > /dev/null 2>&1
module use.own /proj/picasso/modulefiles
module add vivado/${version}_daily
module add sdaccel/${version}_daily
module add opencv/sdaccel
module add proxy
module add lftp
module add lsf
cd ${dir}
echo
echo "-----------------------------------------------"
echo "PWD: \$(pwd)"
echo "-----------------------------------------------"
echo
export PYTHONUNBUFFERED=true
export TMPDIR=\$(mktemp -d -p \$(pwd))
rm -rf \"out/${target}_${devdir}\" && mkdir -p out
bsub -W ${mins} -I -q ${queue} -R "osdistro=rhel && osver==ws6" -n ${cores} -R "rusage[mem=${mem}] span[ptile=${cores}]" -J "\$(basename ${dir})-${target}-run" <<EOF
#!/bin/bash -ex
export TMPDIR=\$TMPDIR
make TARGETS=${target} DEVICES=\"${device}\" NIMBIXFLAGS=\"--out out/${target}_${devdir} --queue_timeout=${mins}\" check
rm -rf \$TMPDIR
EOF
"""
// }
}
}
}
def buildStatus(context, message, state) {
step([$class: 'GitHubCommitStatusSetter',
contextSource: [$class: 'ManuallyEnteredCommitContextSource', context: context],
statusResultSource: [$class: 'ConditionalStatusResultSource',
results: [[$class: 'AnyBuildResult', message: message,
state: state
]]
]
])
return state
}
timestamps {
// Always build on the same host so that the workspace is reused
node('rhel6 && xsjrdevl && xsjrdevl110') {
try {
stage("checkout") {
checkout scm
}
precheck_status = buildStatus('ci-precheck', 'pre-build checks pending', 'PENDING')
sw_emu_status = buildStatus('ci-sw_emu', 'sw_emu checks pending', 'PENDING')
hw_status = buildStatus('ci-hw', 'hw checks pending', 'PENDING')
stage("clean") {
try {
lastclean = readFile('lastclean.dat')
} catch (e) {
lastclean = "01/01/1970"
} finally {
lastcleanDate = new Date(lastclean)
echo "Last Clean Build on ${lastcleanDate}"
}
def date = new Date()
echo "Current Build Date is ${date}"
if(date > lastcleanDate + days) {
echo "Build too old reseting build area"
sh 'git clean -xfd'
// After clean write new lastclean Date to lastclean.dat
writeFile(file: 'lastclean.dat', text: "${date}")
}
}
stage('pre-check') {
sh """
. /tools/local/bin/modinit.sh > /dev/null 2>&1
module use.own /proj/picasso/modulefiles
module add vivado/${version}_daily
module add sdaccel/${version}_daily
module add opencv/sdaccel
module add proxy
./utility/check_license.sh LICENSE.txt
./utility/check_readme.sh
"""
}
precheck_status = buildStatus('ci-precheck', 'pre-build checks passed', 'SUCCESS')
workdir = pwd()
def examples = []
stage('configure') {
sh 'utility/build_what.sh'
examplesFile = readFile 'examples.dat'
examples = examplesFile.split('\\n')
def exSteps = [:]
for(int i = 0; i < examples.size(); i++) {
name = "${examples[i]}-setup"
exSteps[name] = setupExample(examples[i], workdir)
}
parallel exSteps
}
def swBatches = devices.size() * 2
def swEmuSteps = []
def swEmuRunSteps = []
for(int i = 0; i < swBatches; i++) {
swEmuSteps[i] = [:]
swEmuRunSteps[i] = [:]
}
for(int i = 0; i < examples.size(); i++) {
for(int j = 0; j < devices.size(); j++) {
batch = (j * examples.size() + i) % swBatches
name = "${examples[i]}-${devices[j]}-sw_emu"
swEmuSteps[batch]["${name}-build"] = buildExample('sw_emu', examples[i], devices[j], workdir)
swEmuRunSteps[batch]["${name}-run"] = runExample( 'sw_emu', examples[i], devices[j], workdir)
}
}
stage('sw_emu build') {
for(int i = 0; i < swBatches; i++) {
parallel swEmuSteps[i]
}
}
/* Disabled sw_emu while fixing a semaphore issue
stage('sw_emu run') {
lock("only_one_run_stage_at_a_time") {
for(int i = 0; i < swBatches; i++) {
parallel swEmuRunSteps[i]
}
}
}
*/
sw_emu_status = buildStatus('ci-sw_emu', 'sw_emu checks passed', 'SUCCESS')
def hwBatches = devices.size() * 2
def hwSteps = []
def hwRunSteps = []
for(int i = 0; i < hwBatches; i++) {
hwSteps[i] = [:]
hwRunSteps[i] = [:]
}
for(int i = 0; i < examples.size(); i++) {
for(int j = 0; j < devices.size(); j++) {
batch = (j * examples.size() + i) % hwBatches
name = "${examples[i]}-${devices[j]}-hw"
hwSteps[batch]["${name}-build"] = buildExample('hw', examples[i], devices[j], workdir)
hwRunSteps[batch]["${name}-run"] = runExample( 'nimbix', examples[i], devices[j], workdir)
}
}
stage('hw build') {
for(int i = 0; i < hwBatches; i++) {
try {
parallel hwSteps[i]
} catch(e) {
hw_status = buildStatus('ci-hw', 'hw checks failed', 'FAILURE')
}
}
}
if(hw_status == "FAILURE") {
throw RuntimeException("Failed to Build all Hardware Binaries");
}
stage('hw run') {
lock("only_one_run_stage_at_a_time") {
for(int i = 0; i < hwBatches; i++) {
try {
parallel hwRunSteps[i]
} catch(e) {
hw_status = buildStatus('ci-hw', 'hw checks failed', 'FAILURE')
}
}
}
}
if(hw_status == "FAILURE") {
throw RuntimeException("Failed to all examples in hw");
}
hw_status = buildStatus('ci-hw', 'hw checks passed', 'SUCCESS')
} catch (e) {
if ( precheck_status == 'PENDING' ) {
precheck_status = buildStatus('ci-precheck', 'prechecks failed', 'FAILURE')
}
if ( sw_emu_status == 'PENDING' ) {
sw_emu_status = buildStatus('ci-sw_emu', 'sw_emu checks failed', 'FAILURE')
}
if ( hw_status == 'PENDING' ) {
hw_status = buildStatus('ci-hw', 'hw checks failed', 'FAILURE')
}
currentBuild.result = "FAILED"
throw e
} finally {
stage('post-check') {
step([$class: 'Mailer', notifyEveryUnstableBuild: true, recipients: 'sdausr@xilinx.com', sendToIndividuals: false])
}
stage('cleanup') {
// Cleanup .Xil Files after run
sh 'find . -name .Xil | xargs rm -rf'
}
} // try
} // node
} // timestamps