forked from ROCm/Tensile
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Jenkinsfile
426 lines (369 loc) · 14.1 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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
#!/usr/bin/env groovy
////////////////////////////////////////////////////////////////////////
// Mostly generated from snippet generator 'properties; set job properties'
// Time-based triggers added to execute nightly tests, eg '30 2 * * *' means 2:30 AM
properties([
pipelineTriggers([cron('0 3 * * *'), [$class: 'PeriodicFolderTrigger', interval: '5m']]),
buildDiscarder(logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '',
daysToKeepStr: '',
numToKeepStr: '10')),
disableConcurrentBuilds(),
// parameters([booleanParam( name: 'push_image_to_docker_hub', defaultValue: false, description: 'Push tensile image to rocm docker-hub' )]),
[$class: 'CopyArtifactPermissionProperty', projectNames: '*']
])
////////////////////////////////////////////////////////////////////////
// -- AUXILLARY HELPER FUNCTIONS
// import hudson.FilePath;
import java.nio.file.Path;
// check if the job was started by a timer
@NonCPS
def isJobStartedByTimer() {
def startedByTimer = false
try {
def buildCauses = currentBuild.rawBuild.getCauses()
for ( buildCause in buildCauses ) {
if (buildCause != null) {
def causeDescription = buildCause.getShortDescription()
echo "shortDescription: ${causeDescription}"
if (causeDescription.contains("Started by timer")) {
startedByTimer = true
}
}
}
} catch(theError) {
echo "Error getting build cause"
}
return startedByTimer
}
////////////////////////////////////////////////////////////////////////
// Return build number of upstream job
@NonCPS
int get_upstream_build_num( )
{
def upstream_cause = currentBuild.rawBuild.getCause( hudson.model.Cause$UpstreamCause )
if( upstream_cause == null)
return 0
return upstream_cause.getUpstreamBuild()
}
////////////////////////////////////////////////////////////////////////
// Return project name of upstream job
@NonCPS
String get_upstream_build_project( )
{
def upstream_cause = currentBuild.rawBuild.getCause( hudson.model.Cause$UpstreamCause )
if( upstream_cause == null)
return null
return upstream_cause.getUpstreamProject()
}
////////////////////////////////////////////////////////////////////////
// Calculate the relative path between two sub-directories from a common root
@NonCPS
String g_relativize( String root_string, String rel_source, String rel_build )
{
Path root_path = new File( root_string ).toPath( )
Path path_src = root_path.resolve( rel_source )
Path path_build = root_path.resolve( rel_build )
String rel_path = path_build.relativize( path_src ).toString( )
// If rel_path is empty,
if( rel_path?.trim( ) )
return rel_path
else
return "."
}
////////////////////////////////////////////////////////////////////////
// Construct the relative path of the build directory
void build_directory_rel( project_paths paths, compiler_data hcc_args )
{
// if( hcc_args.build_config.equalsIgnoreCase( 'release' ) )
// {
// paths.project_build_prefix = paths.build_prefix + '/' + paths.project_name + '/release';
// }
// else
// {
// paths.project_build_prefix = paths.build_prefix + '/' + paths.project_name + '/debug';
// }
// Currently, for this python based project, the build directory has to match the source directory
paths.project_build_prefix = paths.project_src_prefix;
}
////////////////////////////////////////////////////////////////////////
// Lots of images are created above; no apparent way to delete images:tags with docker global variable
def docker_clean_images( String org, String image_name )
{
// Check if any images exist first grepping for image names
int docker_images = sh( script: "docker images | grep \"${org}/${image_name}\"", returnStatus: true )
// The script returns a 0 for success (images were found )
if( docker_images == 0 )
{
// run bash script to clean images:tags after successful pushing
sh "docker images | grep \"${org}/${image_name}\" | awk '{print \$1 \":\" \$2}' | xargs docker rmi"
}
}
////////////////////////////////////////////////////////////////////////
// -- BUILD RELATED FUNCTIONS
////////////////////////////////////////////////////////////////////////
// Checkout source code, source dependencies and update version number numbers
// Returns a relative path to the directory where the source exists in the workspace
void checkout_and_version( project_paths paths )
{
paths.project_src_prefix = paths.src_prefix + '/' + paths.project_name
dir( paths.project_src_prefix )
{
sh """#!/usr/bin/env bash
set -x
ls -la
"""
// checkout tensile
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions + [[$class: 'CleanCheckout']],
userRemoteConfigs: scm.userRemoteConfigs
])
sh """#!/usr/bin/env bash
set -x
ls -la
"""
}
}
////////////////////////////////////////////////////////////////////////
// This creates the docker image that we use to build the project in
// The docker images contains all dependencies, including OS platform, to build
def docker_build_image( docker_data docker_args, project_paths paths )
{
String build_image_name = "build-tensile-hip-artifactory"
def build_image = null
dir( paths.project_src_prefix )
{
def user_uid = sh( script: 'id -u', returnStdout: true ).trim()
// Docker 17.05 introduced the ability to use ARG values in FROM statements
// Docker inspect failing on FROM statements with ARG https://issues.jenkins-ci.org/browse/JENKINS-44836
// build_image = docker.build( "${paths.project_name}/${build_image_name}:latest", "--pull -f docker/${build_docker_file} --build-arg user_uid=${user_uid} --build-arg base_image=${from_image} ." )
// JENKINS-44836 workaround by using a bash script instead of docker.build()
sh "docker build -t ${paths.project_name}/${build_image_name}:latest -f docker/${docker_args.build_docker_file} ${docker_args.docker_build_args} --build-arg user_uid=${user_uid} --build-arg base_image=${docker_args.from_image} ."
build_image = docker.image( "${paths.project_name}/${build_image_name}:latest" )
}
return build_image
}
////////////////////////////////////////////////////////////////////////
// This encapsulates the cmake configure, build and package commands
// Leverages docker containers to encapsulate the build in a fixed environment
def docker_build_inside_image( def build_image, compiler_data compiler_args, docker_data docker_args, project_paths paths )
{
// Construct a relative path from build directory to src directory; used to invoke cmake
String rel_path_to_src = g_relativize( pwd( ), paths.project_src_prefix, paths.project_build_prefix )
build_image.inside( docker_args.docker_run_args )
{
def tox_file = isJobStartedByTimer() ? "Tensile/Tests/nightly" : "Tensile/Tests/pre_checkin";
stage( "Test ${compiler_args.compiler_name} ${compiler_args.build_config}" )
{
timeout(time: 3, unit: 'HOURS') {
sh """#!/usr/bin/env bash
set -x
cd ${paths.project_src_prefix}
tox --version
tox -vv --workdir /tmp/.tensile-tox ${tox_file} -e lint
tox -vv --workdir /tmp/.tensile-tox ${tox_file} -e py27
"""
}
}
}
return void
}
// Docker related variables gathered together to reduce parameter bloat on function calls
class docker_data implements Serializable
{
String from_image
String build_docker_file
String install_docker_file
String docker_run_args
String docker_build_args
}
// Docker related variables gathered together to reduce parameter bloat on function calls
class compiler_data implements Serializable
{
String compiler_name
String build_config
String compiler_path
}
// Paths variables bundled together to reduce parameter bloat on function calls
class project_paths implements Serializable
{
String project_name
String src_prefix
String project_src_prefix
String build_prefix
String project_build_prefix
}
////////////////////////////////////////////////////////////////////////
// -- MAIN
// Following this line is the start of MAIN of this Jenkinsfile
// Integration testing is a special path which implies testing of an upsteam build of hcc,
// but does not need testing across older builds of hcc or cuda.
// params.hip_integration_test is set in HIP build
// NOTE: hip does not currently set this bit; this is non-functioning at this time
// if( params.hip_integration_test )
// {
// println "Enabling tensile integration testing pass"
// node('docker && rocm')
// {
// hip_integration_testing( '--device=/dev/kfd', 'hip-ctu', 'Release' )
// }
// return
// }
// This defines a common build pipeline used by most targets
def build_pipeline( compiler_data compiler_args, docker_data docker_args, project_paths tensile_paths, def docker_inside_closure )
{
ansiColor( 'vga' )
{
stage( "Build ${compiler_args.compiler_name} ${compiler_args.build_config}" )
{
// Checkout source code, dependencies and version files
checkout_and_version( tensile_paths )
// Conctruct a binary directory path based on build config
build_directory_rel( tensile_paths, compiler_args );
// Create/reuse a docker image that represents the tensile build environment
def tensile_build_image = docker_build_image( docker_args, tensile_paths )
// Print system information for the log
tensile_build_image.inside( docker_args.docker_run_args, docker_inside_closure )
// Build tensile inside of the build environment
docker_build_inside_image( tensile_build_image, compiler_args, docker_args, tensile_paths )
}
}
}
// The following launches 3 builds in parallel: hcc-ctu, hcc-rocm and cuda
//parallel hcc_ctu:
//{
// try
// {
// node( 'docker && rocm && gfx900' )
// {
// def docker_args = new docker_data(
// from_image:'compute-artifactory:5001/rocm-developer-tools/hip/master/hip-hcc-ctu-ubuntu-16.04:latest',
// build_docker_file:'dockerfile-build-hip-hcc-ctu-ubuntu-16.04',
// install_docker_file:'dockerfile-tensile-hip-hcc-ctu-ubuntu-16.04',
// docker_run_args:'--device=/dev/kfd --device=/dev/dri --group-add=video',
// docker_build_args:' --pull' )
//
// def compiler_args = new compiler_data(
// compiler_name:'hcc-ctu',
// build_config:'Release',
// compiler_path:'/opt/rocm/bin/hcc' )
//
// def tensile_paths = new project_paths(
// project_name:'tensile',
// src_prefix:'src',
// build_prefix:'src' )
//
// def print_version_closure = {
// sh """
// set -x
// /opt/rocm/bin/rocm_agent_enumerator -t ALL
// /opt/rocm/bin/hcc --version
// """
// }
//
// build_pipeline( compiler_args, docker_args, tensile_paths, print_version_closure )
// }
// }
// catch( err )
// {
// currentBuild.result = 'UNSTABLE'
// }
//},
parallel rocm22_ubuntu_gfx900:
{
node( 'docker && rocm22 && gfx900')
{
def hcc_docker_args = new docker_data(
from_image:'rocm/dev-ubuntu-16.04:2.2',
build_docker_file:'dockerfile-build-rocm-terminal',
install_docker_file:'dockerfile-install-ubuntu',
docker_run_args:'--device=/dev/kfd --device=/dev/dri --group-add=video',
docker_build_args:' --pull' )
def hcc_compiler_args = new compiler_data(
compiler_name:'hcc-rocm22-ubuntu',
build_config:'Release',
compiler_path:'/opt/rocm/bin/hcc' )
def tensile_paths = new project_paths(
project_name:'tensile',
src_prefix:'src',
build_prefix:'src' )
def print_version_closure = {
sh """
set -x
/opt/rocm/bin/rocm_agent_enumerator -t ALL
/opt/rocm/bin/hcc --version
"""
}
build_pipeline( hcc_compiler_args, hcc_docker_args, tensile_paths, print_version_closure )
}
},
rocm22_ubuntu_gfx906:
{
try
{
node( 'docker && rocm22 && gfx906')
{
def hcc_docker_args = new docker_data(
from_image:'rocm/dev-ubuntu-16.04:2.2',
build_docker_file:'dockerfile-build-rocm-terminal',
install_docker_file:'dockerfile-install-ubuntu',
docker_run_args:'--device=/dev/kfd --device=/dev/dri --group-add=video',
docker_build_args:' --pull' )
def hcc_compiler_args = new compiler_data(
compiler_name:'hcc-rocm22-ubuntu',
build_config:'Release',
compiler_path:'/opt/rocm/bin/hcc' )
def tensile_paths = new project_paths(
project_name:'tensile',
src_prefix:'src',
build_prefix:'src' )
def print_version_closure = {
sh """
set -x
/opt/rocm/bin/rocm_agent_enumerator -t ALL
/opt/rocm/bin/hcc --version
"""
}
build_pipeline( hcc_compiler_args, hcc_docker_args, tensile_paths, print_version_closure )
}
}
catch( err )
{
currentBuild.result = 'UNSTABLE'
}
}
"""
,
nvcc:
{
node( 'docker && cuda' )
{
def hcc_docker_args = new docker_data(
from_image:'nvidia/cuda:8.0-devel',
build_docker_file:'dockerfile-build-nvidia-cuda-8',
install_docker_file:'dockerfile-install-nvidia-cuda-8',
docker_run_args:'--device=/dev/nvidiactl --device=/dev/nvidia0 --device=/dev/nvidia-uvm --device=/dev/nvidia-uvm-tools --volume-driver=nvidia-docker --volume=nvidia_driver_375.74:/usr/local/nvidia:ro',
docker_build_args:' --pull' )
def hcc_compiler_args = new compiler_data(
compiler_name:'nvcc-8.0',
build_config:'Release',
compiler_path:'g++' )
def tensile_paths = new project_paths(
project_name:'tensile',
src_prefix:'src',
build_prefix:'src' )
def print_version_closure = {
sh """
// set -x
// nvidia-smi
// nvcc --version
"""
}
build_pipeline( hcc_compiler_args, hcc_docker_args, tensile_paths, print_version_closure )
}
}
"""