forked from ROCm/rocFFT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
447 lines (381 loc) · 16 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
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
#!/usr/bin/env groovy
// Generated from snippet generator 'properties; set job properties'
properties([buildDiscarder(logRotator(
artifactDaysToKeepStr: '',
artifactNumToKeepStr: '',
daysToKeepStr: '',
numToKeepStr: '10')),
disableConcurrentBuilds(),
// parameters([booleanParam( name: 'push_image_to_docker_hub', defaultValue: false, description: 'Push rocfft image to rocm docker-hub' )]),
[$class: 'CopyArtifactPermissionProperty', projectNames: '*']
])
////////////////////////////////////////////////////////////////////////
// -- AUXILLARY HELPER FUNCTIONS
// import hudson.FilePath;
import java.nio.file.Path;
////////////////////////////////////////////////////////////////////////
// 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 )
return path_build.relativize( path_src ).toString( )
}
////////////////////////////////////////////////////////////////////////
// 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';
// }
paths.project_build_prefix = paths.build_prefix + '/' + paths.project_name;
}
////////////////////////////////////////////////////////////////////////
// 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 )
{
// checkout rocfft
checkout([
$class: 'GitSCM',
branches: scm.branches,
doGenerateSubmoduleConfigurations: scm.doGenerateSubmoduleConfigurations,
extensions: scm.extensions + [[$class: 'CleanCheckout']],
userRemoteConfigs: scm.userRemoteConfigs
])
if( fileExists( 'CMakeLists.txt' ) )
{
def cmake_version_file = readFile( 'CMakeLists.txt' ).trim()
//echo "cmake_version_file:\n${cmake_version_file}"
cmake_version_file = cmake_version_file.replaceAll(/(\d+\.)(\d+\.)(\d+\.)\d+/, "\$1\$2\$3${env.BUILD_ID}")
//echo "cmake_version_file:\n${cmake_version_file}"
writeFile( file: 'CMakeLists.txt', text: cmake_version_file )
}
}
}
////////////////////////////////////////////////////////////////////////
// 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"
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
Boolean 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 )
String build_type_postfix = null
if( compiler_args.build_config.equalsIgnoreCase( 'release' ) )
{
build_type_postfix = ""
}
else
{
build_type_postfix = "-d"
}
// For the nvidia path, we somewhat arbitrarily choose to use the hcc-ctu rocblas package
String rocblas_archive_path=compiler_args.compiler_name;
if( rocblas_archive_path.toLowerCase( ).startsWith( 'nvcc-' ) )
{
rocblas_archive_path='hcc-ctu'
}
build_image.inside( docker_args.docker_run_args )
{
withEnv(["CXX=${compiler_args.compiler_path}", 'CLICOLOR_FORCE=1'])
{
// Build library & clients
sh """#!/usr/bin/env bash
set -x
cd ${paths.project_build_prefix}
${paths.build_command}
"""
}
stage( "Test ${compiler_args.compiler_name} ${compiler_args.build_config}" )
{
// Cap the maximum amount of testing to be a few hours; assume failure if the time limit is hit
timeout(time: 1, unit: 'HOURS')
{
sh """#!/usr/bin/env bash
set -x
cd ${paths.project_build_prefix}/build/release/clients/staging
./rocfft-test${build_type_postfix} --gtest_output=xml --gtest_color=yes
"""
junit "${paths.project_build_prefix}/build/release/clients/staging/*.xml"
}
String docker_context = "${compiler_args.build_config}/${compiler_args.compiler_name}"
if( compiler_args.compiler_name.toLowerCase( ).startsWith( 'hcc-' ) )
{
sh """#!/usr/bin/env bash
set -x
cd ${paths.project_build_prefix}/build/release
make package
"""
sh """#!/usr/bin/env bash
set -x
rm -rf ${docker_context} && mkdir -p ${docker_context}
mv ${paths.project_build_prefix}/build/release/*.deb ${docker_context}
# mv ${paths.project_build_prefix}/build/release/*.rpm ${docker_context}
dpkg -c ${docker_context}/*.deb
"""
archiveArtifacts artifacts: "${docker_context}/*.deb", fingerprint: true
// archiveArtifacts artifacts: "${docker_context}/*.rpm", fingerprint: true
}
}
}
return true
}
////////////////////////////////////////////////////////////////////////
// This builds a fresh docker image FROM a clean base image, with no build dependencies included
// Uploads the new docker image to internal artifactory
// String docker_test_install( String hcc_ver, String artifactory_org, String from_image, String rocfft_src_rel, String build_dir_rel )
String docker_test_install( compiler_data compiler_args, docker_data docker_args, project_paths rocfft_paths, String job_name )
{
def rocfft_install_image = null
String image_name = "rocfft-hip-${compiler_args.compiler_name}-ubuntu-16.04"
String docker_context = "${compiler_args.build_config}/${compiler_args.compiler_name}"
stage( "Artifactory ${compiler_args.compiler_name} ${compiler_args.build_config}" )
{
// We copy the docker files into the bin directory where the .deb lives so that it's a clean build everytime
sh """#!/usr/bin/env bash
set -x
mkdir -p ${docker_context}
cp -r ${rocfft_paths.project_src_prefix}/docker/* ${docker_context}
"""
// 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
// rocfft_install_image = docker.build( "${job_name}/${image_name}:${env.BUILD_NUMBER}", "--pull -f ${build_dir_rel}/dockerfile-rocfft-ubuntu-16.04 --build-arg base_image=${from_image} ${build_dir_rel}" )
// JENKINS-44836 workaround by using a bash script instead of docker.build()
sh """docker build -t ${job_name}/${image_name} --pull -f ${docker_context}/${docker_args.install_docker_file} \
--build-arg base_image=${docker_args.from_image} ${docker_context}"""
rocfft_install_image = docker.image( "${job_name}/${image_name}" )
}
return image_name
}
// 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
String build_command
}
////////////////////////////////////////////////////////////////////////
// -- MAIN
// Following this line is the start of MAIN of this Jenkinsfile
// sh """
// set -x
// # printf '\033[31mHello World\033[0m'
// # echo "TERM=${env.TERM}"
// # echo "LANG=${env.LANG}"
// # echo "SHELL=${env.SHELL}"
// """
// 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 rocfft integration testing pass"
// node('docker && rocm')
// {
// rocfft_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 rocfft_paths, def docker_inside_closure )
{
ansiColor( 'vga' )
{
// NOTE: build_succeeded does not appear to be local to each function invokation. I couldn't use it where each
// node had a different success value.
def build_succeeded = false;
stage( "Build ${compiler_args.compiler_name} ${compiler_args.build_config}" )
{
// Checkout source code, dependencies and version files
checkout_and_version( rocfft_paths )
// Conctruct a binary directory path based on build config
build_directory_rel( rocfft_paths, compiler_args );
// Create/reuse a docker image that represents the rocfft build environment
def rocfft_build_image = docker_build_image( docker_args, rocfft_paths )
// Print system information for the log
rocfft_build_image.inside( docker_args.docker_run_args, docker_inside_closure )
// Build rocfft inside of the build environment
build_succeeded = docker_build_inside_image( rocfft_build_image, compiler_args, docker_args, rocfft_paths )
}
// After a successful build, test the installer
// Only do this for rocm based builds
if( compiler_args.compiler_name.toLowerCase( ).startsWith( 'hcc-' ) )
{
String job_name = env.JOB_NAME.toLowerCase( )
String rocfft_image_name = docker_test_install( compiler_args, docker_args, rocfft_paths, job_name )
docker_clean_images( job_name, rocfft_image_name )
}
}
}
// The following launches 3 builds in parallel: hcc-ctu, hcc-1.6 and cuda
parallel hcc_ctu:
{
node( 'docker && rocm && dkms' )
{
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-ubuntu-16.04',
install_docker_file:'dockerfile-rocfft-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 rocfft_paths = new project_paths(
project_name:'rocfft-hcc-ctu',
src_prefix:'src',
build_prefix:'src',
build_command: './install.sh -cd' )
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, rocfft_paths, print_version_closure )
}
},
hcc_rocm:
{
node( 'docker && rocm && dkms' )
{
def hcc_docker_args = new docker_data(
from_image:'rocm/dev-ubuntu-16.04:1.7.1',
build_docker_file:'dockerfile-build-ubuntu-16.04',
install_docker_file:'dockerfile-rocfft-ubuntu-16.04',
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-rocm',
build_config:'Release',
compiler_path:'/opt/rocm/bin/hcc' )
def rocfft_paths = new project_paths(
project_name:'rocfft-hcc-rocm',
src_prefix:'src',
build_prefix:'src',
build_command: './install.sh -cd' )
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, rocfft_paths, print_version_closure )
}
} //,
// nvcc:
// {
// node( 'docker && cuda' )
// {
// def hcc_docker_args = new docker_data(
// from_image:'nvidia/cuda:9.1-devel-ubuntu16.04',
// build_docker_file:'dockerfile-build-nvidia-cuda',
// install_docker_file:'dockerfile-rocfft-ubuntu-cuda',
// docker_run_args:'--runtime=nvidia',
// docker_build_args:' --pull' )
// def hcc_compiler_args = new compiler_data(
// compiler_name:'nvcc-9.1',
// build_config:'Release',
// compiler_path:'g++' )
// def rocfft_paths = new project_paths(
// project_name:'rocfft-nvcc',
// src_prefix:'src',
// build_prefix:'src',
// build_command: './install.sh -cd --cuda' )
// def print_version_closure = {
// sh """
// set -x
// nvidia-smi
// nvcc --version
// """
// }
// build_pipeline( hcc_compiler_args, hcc_docker_args, rocfft_paths, print_version_closure )
// }
// }