Repository navigation
Expand file tree
/
Copy pathJenkinsfile
More file actions
381 lines (347 loc) · 12.4 KB
/
Copy pathJenkinsfile
File metadata and controls
381 lines (347 loc) · 12.4 KB
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
// This file relates to internal XMOS infrastructure and should be ignored by external users
@Library('xmos_jenkins_shared_library@v0.56.0') _
if (env.job_type != 'beta_release' && env.job_type != 'official_release') {
getApproval()
}
def setupRepo() {
println "Stage running on: ${env.NODE_NAME}"
checkout scm
sh 'git submodule update --init --recursive --jobs 8'
}
def doVersionCheck() {
createVenv()
withVenv {
sh 'python -m pip install pytest'
sh 'python -m pytest -q integration_tests/test_version_check.py'
}
}
def createDeviceZip() {
// build device runtime (vx4), (xs3), and install lib (xs3 is used)
// Native build is a host-side compile check, not part of the device archive.
dir('third_party/lib_tflite_micro') {
withTools(params.TOOLS_VX4_VERSION) {sh 'make build_vx4'}
withTools(params.TOOLS_VERSION) {sh 'make build_xs3'}
withTools(params.TOOLS_VERSION) {sh 'make build_install'}
sh 'make build'
stash name: 'release_archive', includes: 'build_xs3/release_archive.zip'
}
}
def buildXinterpreterAndHostLib() {
dir('python/xmos_ai_tools/xinterpreters') {
sh 'cmake -B build'
sh 'cmake --build build --target install --parallel 8 --config Release'
}
}
def extractDeviceZipAndHeaders() {
dir('python/xmos_ai_tools/runtime') {
unstash 'release_archive'
sh 'unzip -o build_xs3/release_archive.zip'
}
}
def installWheel(String wheelStash) {
dir('python') {
unstash wheelStash
sh 'pip install --force-reinstall dist/*'
}
}
def runTestsHost(Map options) {
setupRepo()
createVenv(reqFile: 'integration_tests/requirements.txt')
withVenv {
installWheel(options.wheelStash)
sh 'pytest integration_tests/test_runner.py -k daily_host -n auto --junitxml=integration_tests/integration_host_junit.xml'
junit '**/*_junit.xml'
}
}
def runTestsDevice(Map options) {
setupRepo()
createVenv(reqFile: 'integration_tests/requirements.txt')
withVenv {
installWheel(options.wheelStash)
sh 'pip install git+https://github0.xmos.com/xmos-int/xtagctl.git'
withTools(params.TOOLS_VERSION) {
sh 'pytest integration_tests/test_runner.py -k daily_device --device -n 1 --junitxml=integration_tests/integration_device_junit.xml'
}
junit '**/*_junit.xml'
}
}
def runTestsDeviceXsim(Map options) {
def test_path = 'integration_tests/device_test_sim/test_device_sim.py'
def junit_options = '-o junit_logging=all -o junit_log_passing_tests=true'
setupRepo()
createVenv(reqFile: 'integration_tests/requirements.txt')
withVenv {
installWheel(options.wheelStash)
try {
withTools(params.TOOLS_VERSION) {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE', catchInterruptions: false) {
runPytest("${test_path} --hw-target REF-XS3 --junit-prefix=REF-XS3 ${junit_options}")
}
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE', catchInterruptions: false) {
runPytest("${test_path} --hw-target XK-EVK-XU316 --junit-prefix=xsim_xs3a ${junit_options}")
}
}
withTools(params.TOOLS_VX4_VERSION) {
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE', catchInterruptions: false) {
runPytest("${test_path} --hw-target REF-VX4 --junit-prefix=REF-VX4 ${junit_options}")
}
catchError(buildResult: 'FAILURE', stageResult: 'FAILURE', catchInterruptions: false) {
runPytest("${test_path} --hw-target XK-EVK-XU416 --junit-prefix=xsim_vx4 ${junit_options}")
}
}
}
finally {
archiveArtifacts artifacts: 'integration_tests/device_test_sim/model_errors_*.csv', allowEmptyArchive: true
}
}
}
def buildExamples() {
setupRepo()
createVenv(reqFile: 'requirements.txt')
withVenv {
installWheel('linux_wheel')
dir('examples') {
xcoreBuild()
}
}
}
def buildXformer(Map options) {
def bazelBin = options.bazelBin
def bazelConfig = options.bazelConfig
def buildArgs = options.buildArgs ? " ${options.buildArgs}" : ''
def commonArgs = "--config=${bazelConfig} --define SETUPTOOLS_SCM_VERSION=${env.SETUPTOOLS_SCM_PRETEND_VERSION}"
dir('xformer') {
sh "curl -fL ${env.BAZELISK_RELEASE_URL}/${bazelBin} -o ${bazelBin}"
if (options.executable) {sh "chmod +x ${bazelBin}"}
sh "./${bazelBin} build //:xcore-opt ${commonArgs} ${buildArgs}"
if (options.runTests != false) {
sh "./${bazelBin} test //Test:all ${commonArgs} ${buildArgs}"
}
}
}
def buildPyWheel(String platform) {
def extra = (platform == 'mac') ? '--plat macosx_10_15_universal2' : ''
dir('python') {
sh "python setup.py bdist_wheel ${extra}"
if (platform == 'linux') {
sh 'auditwheel repair --plat manylinux_2_31_x86_64 dist/*.whl'
sh 'rm dist/*.whl && mv wheelhouse/*.whl dist/'
}
stash name: "${platform}_wheel", includes: 'dist/*'
archiveArtifacts artifacts: 'dist/*.whl', fingerprint: true
}
}
def cleanXformer(String bazelBin) {
dir('xformer') {
sh "./${bazelBin} clean --expunge"
sh "./${bazelBin} shutdown"
}
}
pipeline {
agent none
environment {
REPO = 'ai_tools'
BAZELISK_RELEASE_URL = 'https://github.com/bazelbuild/bazelisk/releases/download/v1.19.0'
SETUPTOOLS_SCM_PRETEND_VERSION = "1.4.5"
}
parameters {
string(
name: 'TOOLS_VERSION',
defaultValue: '15.3.1',
description: 'The tools version to build with (check /projects/tools/ReleasesTools/)'
)
string(
name: 'TOOLS_VX4_VERSION',
defaultValue: 'slipgate@develop',
description: 'The XTC Slipgate tools version'
)
}
options {
timestamps()
skipDefaultCheckout()
buildDiscarder(xmosDiscardBuildSettings())
}
stages { stage('On PR') {
when { anyOf { branch pattern: 'PR-.*', comparator: 'REGEXP'; expression { env.job_type == 'beta_release' || env.job_type == 'official_release' } } }
agent { label 'linux && x86_64 && !noAVX2' }
stages {
stage('Build device runtime') {
steps {
setupRepo()
doVersionCheck()
createVenv(reqFile: 'requirements.txt')
withVenv { createDeviceZip() }
}
post {
unsuccessful { xcoreCleanSandbox() }
}
} // stage('Build device runtime')
stage('Build host wheels') {
parallel {
stage('Build linux runtime') {
steps {
extractDeviceZipAndHeaders()
buildXinterpreterAndHostLib()
createVenv(reqFile: 'python/requirements_build.txt')
withVenv {
script {
buildXformer(
bazelBin: 'bazelisk-linux-amd64',
bazelConfig: 'ci_linux',
executable: true
)
buildPyWheel('linux')
} // script
} // withVenv
} // steps
post {
cleanup {
cleanXformer('bazelisk-linux-amd64')
xcoreCleanSandbox()
}
}
} // stage('Build linux runtime')
stage('Build Windows runtime') {
agent { label 'windows10 && ai' }
steps {
withVS() {
setupRepo()
extractDeviceZipAndHeaders()
buildXinterpreterAndHostLib()
createVenv(reqFile: 'python/requirements_build.txt')
withVenv {
buildXformer(
bazelBin: 'bazelisk-windows-amd64.exe',
bazelConfig: 'ci_windows',
runTests: false
)
buildPyWheel('windows')
}
}
}
post {
cleanup {
cleanXformer('bazelisk-windows-amd64.exe')
xcoreCleanSandbox()
}
}
} // stage('Build Windows runtime')
stage('Build Mac runtime') {
agent { label 'sw-uni-mac0'}
steps {
setupRepo()
extractDeviceZipAndHeaders()
buildXinterpreterAndHostLib()
createVenv(reqFile: 'python/requirements_build.txt')
withVenv {
script {
buildXformer(
bazelBin: 'bazelisk-darwin-arm64',
bazelConfig: 'ci_macos',
executable: true,
buildArgs: '--cpu=darwin_arm64'
)
dir('xformer') {
sh 'mv bazel-bin/xcore-opt xcore-opt-arm64'
}
buildXformer(
bazelBin: 'bazelisk-darwin-arm64',
bazelConfig: 'ci_macos',
buildArgs: '--cpu=darwin_x86_64'
)
dir('xformer') {
sh 'mv bazel-bin/xcore-opt xcore-opt-x86_64'
sh 'lipo -create xcore-opt-arm64 xcore-opt-x86_64 -output bazel-bin/xcore-opt'
}
buildPyWheel('mac')
} // script
} // withVenv
} // steps
post {
cleanup {
cleanXformer('bazelisk-darwin-arm64')
xcoreCleanSandbox()
} // cleanup
} // post
} // stage('Build Mac runtime')
} // Parallel
} // Build host wheels
stage('Build examples') {
when {
expression { env.job_type != 'beta_release' && env.job_type != 'official_release' }
}
steps {
script { buildExamples() }
}
post { unsuccessful { xcoreCleanSandbox() } }
} // stage('Build examples')
stage('Test') {
when {
expression { env.job_type != 'beta_release' && env.job_type != 'official_release' }
}
parallel {
stage('Linux Test') {
steps { script {
runTestsHost(wheelStash: 'linux_wheel')
withVenv {
sh 'pip install pytest nbmake'
sh 'pytest --nbmake ./docs/notebooks/*.ipynb'
}}}
} // stage('Linux Test')
stage('Mac arm64 Test') {
agent { label 'sw-uni-mac0' }
steps { script {runTestsHost(wheelStash: 'mac_wheel')}}
post { cleanup { xcoreCleanSandbox() } }
} // stage('Mac arm64 Test')
stage('Windows Test') {
agent { label 'ai && windows10' }
steps { script {runTestsHost(wheelStash: 'windows_wheel')}}
post { cleanup { xcoreCleanSandbox() } }
} // stage('Windows Test')
stage('Device Test') {
agent {label 'xcore.ai-explorer && lpddr && !macos'}
steps {script {dir('sandbox/ai_tools') {
runTestsDeviceXsim(wheelStash: 'linux_wheel')
runTestsDevice(wheelStash: 'linux_wheel')
}}}
post {
always {
archiveArtifacts artifacts: 'sandbox/ai_tools/examples/app_mobilenetv2/arena_sizes.csv', allowEmptyArchive: true
}
cleanup {
xcoreCleanSandbox()
}
}
} // stage('Device Test')
}
} // stage('Test')
stage('Publish') {
when {
expression { env.job_type == 'beta_release' || env.job_type == 'official_release' }
}
steps {
script {
dir('python') {
unstash 'linux_wheel'
unstash 'mac_wheel'
unstash 'windows_wheel'
archiveArtifacts artifacts: 'dist/*', allowEmptyArchive: true
createVenv()
withVenv {
withCredentials([usernamePassword(
credentialsId: 'PYPI_AITOOLS_TOKEN',
usernameVariable: 'TWINE_USERNAME',
passwordVariable: 'TWINE_PASSWORD')])
{
sh 'pip install twine'
sh 'twine upload --verbose dist/*'
}
}
}
}
}
} // stage('Publish')
}
post { cleanup { xcoreCleanSandbox() } }
} }
}