diff --git a/projects/clr/hipamd/Jenkinsfile b/projects/clr/hipamd/Jenkinsfile index 392c018259..12d76803b8 100644 --- a/projects/clr/hipamd/Jenkinsfile +++ b/projects/clr/hipamd/Jenkinsfile @@ -7,50 +7,36 @@ properties([buildDiscarder(logRotator( daysToKeepStr: '', numToKeepStr: '10')), disableConcurrentBuilds(), + // parameters([string(name: 'sample_string', defaultValue: '', description: 'description of a sample string')]), [$class: 'CopyArtifactPermissionProperty', projectNames: '*'] ]) //////////////////////////////////////////////////////////////////////// -// -- Test & Bootstrapping code - -node('docker && rocm') -{ - String hcc_ver = 'hcc-1.6' - String from_image = 'compute-artifactory:5001/radeonopencompute/hcc/roc-1.6.x/hcc-lc-ubuntu-16.04:latest' - String inside_args = '--device=/dev/kfd' - - stage( 'parameters' ) - { - cleanWs( ) - - println "upstream_hcc: ${params.upstream_hcc}" - if( params.upstream_hcc ) - { - step([$class: 'CopyArtifact', filter: 'archive/**/*.deb, docker/dockerfile-*', - fingerprintArtifacts: true, projectName: "${params.upstream_hcc}", flatten: true, - selector: [$class: 'TriggeredBuildSelector', allowUpstreamDependencies: false, fallbackToLastSuccessful: false, upstreamFilterStrategy: 'UseGlobalSetting'], - target: 'integration-testing' ]) - - // // The following that copies from workspace apparently copies from the PREVIOUS COMPLETED build, so not as handy - // step( [$class: 'CopyArtifact', filter: '**', fingerprintArtifacts: true, flatten: true, - // projectName: "${params.upstream_hcc}", selector: [$class: 'WorkspaceSelector'], target: 'integration-testing'] ) - } - else - { - println "upstream_hcc: tested false" - } - - sh """#!/usr/bin/env bash - set -x - ls -Rlah - """ - } -} - -return +// -- AUXILLARY HELPER FUNCTIONS //////////////////////////////////////////////////////////////////////// -// -- AUXILLARY HELPER FUNCTIONS +// 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() +} //////////////////////////////////////////////////////////////////////// // Construct the relative path of the build directory @@ -99,12 +85,10 @@ String checkout_and_version( String platform ) //////////////////////////////////////////////////////////////////////// // 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( String platform, String source_hip_rel, String from_image ) +def docker_build_image( String platform, String org, String optional_build_parm, String source_hip_rel, String from_image ) { - String project = "hip" - String build_type_name = "build-ubuntu-16.04" - String dockerfile_name = "dockerfile-${build_type_name}" - String build_image_name = "${build_type_name}" + String build_image_name = "build-ubuntu-16.04" + String dockerfile_name = "dockerfile-build-ubuntu-16.04" def build_image = null stage("${platform} build image") @@ -115,11 +99,11 @@ def docker_build_image( String platform, String source_hip_rel, String from_imag // 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( "${project}/${build_image_name}:latest", "--pull -f docker/${dockerfile_name} --build-arg user_uid=${user_uid} --build-arg base_image=${from_image} ." ) + // build_image = docker.build( "${org}/${build_image_name}:latest", "--pull -f docker/${dockerfile_name} --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 ${project}/${build_image_name}:latest --pull -f docker/${dockerfile_name} --build-arg user_uid=${user_uid} --build-arg base_image=${from_image} ." - build_image = docker.image( "${project}/${build_image_name}:latest" ) + sh "docker build -t ${org}/${build_image_name}:latest -f docker/${dockerfile_name} ${optional_build_parm} --build-arg user_uid=${user_uid} --build-arg base_image=${from_image} ." + build_image = docker.image( "${org}/${build_image_name}:latest" ) } } @@ -275,24 +259,99 @@ def docker_upload_dockerhub( String artifactory_org, String image_name ) } // Lots of images with tags are created above; no apparent way to delete images:tags with docker global variable -def docker_clean_images( String artifactory_org, String image_name ) +def docker_clean_images( String org, String image_name ) { // Check if any images exist first, the script returns a 0 for success, indicating grep found images - def docker_images = sh( script: "docker images | grep \"${artifactory_org}/${image_name}\"", returnStatus: true ) + def docker_images = sh( script: "docker images | grep \"${org}/${image_name}\"", returnStatus: true ) if( docker_images == 0 ) { // run bash script to clean images:tags after successful pushing - sh "docker images | grep \"${artifactory_org}/${image_name}\" | awk '{print \$1 \":\" \$2}' | xargs docker rmi" + sh "docker images | grep \"${org}/${image_name}\" | awk '{print \$1 \":\" \$2}' | xargs docker rmi" } } +//////////////////////////////////////////////////////////////////////// +// hcc_integration_testing +// This function is sets up compilation and testing of HiP on a compiler downloaded from an upstream build +// Integration testing is centered around docker and constructing clean test environments every time + +// NOTES: I have implemeneted integration testing 3 different ways, and I've come to the conclusion nothing is perfect +// 1. I've tried having HCC push the test compiler to artifactory, and having HiP download the test docker image from artifactory +// a. The act of uploading and downloading images from artifactory takes minutes +// b. There is no good way of deleting images from a repository. You have to use an arcane CURL command and I don't know how +// to keep the password secret. These test integration images are meant to be ephemeral. +// 2. I tried 'docker save' to export a docker image into a tarball, and transfering the image through 'copy artifacts plugin' +// a. The HCC docker image uncompressed is over 1GB +// b. Compressing the docker image takes even longer than uploading the image to artifactory +// 3. Download the HCC .deb and dockerfile through 'copy artifacts plugin'. Create a new HCC image on the fly +// a. There is inefficency in building a new ubuntu image and installing HCC twice (once in HCC build, once here) +// b. This solution doesn't scale when we start testing downstream libraries + +// I've implemented solution #3 above, probably transitioning to #2 down the line (probably without compression) +String hcc_integration_testing( String inside_args, String job, String build_config ) +{ + // Attempt to make unique docker image names for each build, to support concurrent builds + // Mangle docker org name with upstream build info + String testing_org_name = 'hcc-test-' + get_upstream_build_project( ).replaceAll('/','-') + '-' + get_upstream_build_num( ) + + // Tag image name with this build number + String hcc_test_image_name = "hcc:${env.BUILD_NUMBER}" + + def hip_integration_image = null + + dir( 'integration-testing' ) + { + deleteDir( ) + + // This invokes 'copy artifact plugin' to copy archived files from upstream build + step([$class: 'CopyArtifact', filter: 'archive/**/*.deb, docker/dockerfile-*', + fingerprintArtifacts: true, projectName: get_upstream_build_project( ), flatten: true, + selector: [$class: 'TriggeredBuildSelector', allowUpstreamDependencies: false, fallbackToLastSuccessful: false, upstreamFilterStrategy: 'UseGlobalSetting'], + target: '.' ]) +// // The following 'copy artifact' is supposed to copy direct from workspace, but it doesn't seem to work across machines +// step( [$class: 'CopyArtifact', filter: '**', fingerprintArtifacts: true, flatten: true, +// projectName: "${params.upstream_hcc}", selector: [$class: 'WorkspaceSelector'], target: 'integration-testing'] ) + + docker.build( "${testing_org_name}/${hcc_test_image_name}", "-f dockerfile-hcc-lc-ubuntu-16.04 ." ) + } + + // Checkout source code, dependencies and version files + String source_hip_rel = checkout_and_version( job ) + + // Conctruct a binary directory path based on build config + String build_hip_rel = build_directory_rel( build_config ); + + // Build hip inside of the build environment + hip_integration_image = docker_build_image( job, testing_org_name, '', source_hip_rel, "${testing_org_name}/${hcc_test_image_name}" ) + + docker_build_inside_image( hip_integration_image, inside_args, job, '', build_config, source_hip_rel, build_hip_rel ) + + docker_clean_images( testing_org_name, '*' ) +} + //////////////////////////////////////////////////////////////////////// // -- MAIN // Following this line is the start of MAIN of this Jenkinsfile String build_config = 'Release' String job_name = env.JOB_NAME.toLowerCase( ) +// 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. This is more of a compiler +// hcc unit test +if( params.hcc_integration_test ) +{ + println "HCC integration testing" + + node('docker && rocm') + { + hcc_integration_testing( '--device=/dev/kfd', 'hcc-ctu', build_config ) + } + + return +} + +// The following launches 3 builds in parallel: hcc-ctu, hcc-1.6 and cuda parallel hcc_ctu: { node('docker && rocm && gfx803') @@ -305,7 +364,7 @@ parallel hcc_ctu: String source_hip_rel = checkout_and_version( hcc_ver ) // Create/reuse a docker image that represents the hip build environment - def hip_build_image = docker_build_image( hcc_ver, source_hip_rel, from_image ) + def hip_build_image = docker_build_image( hcc_ver, 'hip', ' --pull', source_hip_rel, from_image ) // Print system information for the log hip_build_image.inside( inside_args ) @@ -342,7 +401,7 @@ hcc_1_6: String source_hip_rel = checkout_and_version( hcc_ver ) // Create/reuse a docker image that represents the hip build environment - def hip_build_image = docker_build_image( hcc_ver, source_hip_rel, from_image ) + def hip_build_image = docker_build_image( hcc_ver, 'hip', ' --pull', source_hip_rel, from_image ) // Print system information for the log hip_build_image.inside( inside_args ) @@ -383,7 +442,7 @@ nvcc: String source_hip_rel = checkout_and_version( nvcc_ver ) // We pull public nvidia images - def hip_build_image = docker_build_image( nvcc_ver, source_hip_rel, from_image ) + def hip_build_image = docker_build_image( nvcc_ver, 'hip', ' --pull', source_hip_rel, from_image ) // Print system information for the log hip_build_image.inside( inside_args )