Jenkinsfile 8.21 KB
Newer Older
1
#!groovy
2 3 4 5 6
// -*- mode: groovy -*-
// Jenkins pipeline
// See documents at https://jenkins.io/doc/book/pipeline/jenkinsfile/

// tvm libraries
7 8 9 10 11
tvm_runtime = "lib/libtvm_runtime.so, config.mk"
tvm_lib = "lib/libtvm.so, " + tvm_runtime
// LLVM upstream lib
tvm_multilib = "lib/libtvm_llvm40.so, lib/libtvm_llvm50.so, lib/libtvm_llvm60.so, " + tvm_runtime

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
// command to start a docker container
docker_run = 'tests/ci_build/ci_build.sh'
// timeout in minutes
max_time = 60

// initialize source codes
def init_git() {
  checkout scm
  retry(5) {
    timeout(time: 2, unit: 'MINUTES') {
      sh 'git submodule update --init'
    }
  }
}

def init_git_win() {
    checkout scm
    retry(5) {
        timeout(time: 2, unit: 'MINUTES') {
            bat 'git submodule update --init'
        }
    }
}

stage("Sanity Check") {
  timeout(time: max_time, unit: 'MINUTES') {
    node('linux') {
      ws('workspace/tvm/sanity') {
        init_git()
        sh "${docker_run} lint  ./tests/scripts/task_lint.sh"
      }
    }
  }
}

// Run make. First try to do an incremental make from a previous workspace in hope to
// accelerate the compilation. If something wrong, clean the workspace and then
// build from scratch.
def make(docker_type, make_flag) {
  timeout(time: max_time, unit: 'MINUTES') {
    try {
      sh "${docker_run} ${docker_type} make ${make_flag}"
    } catch (exc) {
      echo 'Incremental compilation failed. Fall back to build from scratch'
      sh "${docker_run} ${docker_type} make clean"
      sh "${docker_run} ${docker_type} make ${make_flag}"
    }
  }
}

// pack libraries for later use
63
def pack_lib(name, libs) {
64 65 66 67 68 69 70 71 72
  sh """
     echo "Packing ${libs} into ${name}"
     echo ${libs} | sed -e 's/,/ /g' | xargs md5sum
     """
  stash includes: libs, name: name
}


// unpack libraries saved before
73
def unpack_lib(name, libs) {
74 75 76 77 78 79 80 81 82 83 84 85 86 87
  unstash name
  sh """
     echo "Unpacked ${libs} from ${name}"
     echo ${libs} | sed -e 's/,/ /g' | xargs md5sum
     """
}

stage('Build') {
  parallel 'GPU': {
    node('GPU' && 'linux') {
      ws('workspace/tvm/build-gpu') {
        init_git()
        sh """
           cp make/config.mk .
88
           echo USE_CUDNN=1 >> config.mk
89 90
           echo USE_CUDA=1 >> config.mk
           echo USE_OPENCL=1 >> config.mk
91
           echo LLVM_CONFIG=llvm-config-4.0 >> config.mk
92
           echo USE_RPC=1 >> config.mk
93
           echo USE_GRAPH_RUNTIME=1 >> config.mk
94
           echo USE_BLAS=openblas >> config.mk
95
           rm -f lib/libtvm_runtime.so lib/libtvm.so
96
           """
97 98 99 100 101 102 103 104 105
        make('gpu', '-j2')
        sh "mv lib/libtvm.so lib/libtvm_llvm40.so"
        sh "echo LLVM_CONFIG=llvm-config-5.0 >> config.mk"
        make('gpu', '-j2')
        sh "mv lib/libtvm.so lib/libtvm_llvm50.so"
        sh "echo LLVM_CONFIG=llvm-config-6.0 >> config.mk"
        make('gpu', '-j2')
        sh "mv lib/libtvm.so lib/libtvm_llvm60.so"
        pack_lib('gpu', tvm_multilib)
106 107 108 109 110
        sh """
           echo USE_ROCM=1 >> config.mk
           echo ROCM_PATH=/opt/rocm >> config.mk
           """
        make('gpu', '-j2')
111 112 113 114 115 116 117 118 119 120 121 122
      }
    }
  },
  'CPU': {
    node('CPU' && 'linux') {
      ws('workspace/tvm/build-cpu') {
        init_git()
        sh """
           cp make/config.mk .
           echo USE_CUDA=0 >> config.mk
           echo USE_OPENCL=0 >> config.mk
           echo USE_RPC=0 >> config.mk
123
           echo LLVM_CONFIG=llvm-config-4.0 >> config.mk
124
           """
125 126
        make('cpu', '-j2')
        pack_lib('cpu', tvm_lib)
127 128
      }
    }
129 130 131 132 133 134 135 136 137 138 139 140
  },
  'i386': {
    node('CPU' && 'linux') {
      ws('workspace/tvm/build-i386') {
        init_git()
        sh """
           cp make/config.mk .
           echo USE_CUDA=0 >> config.mk
           echo USE_OPENCL=0 >> config.mk
           echo LLVM_CONFIG=llvm-config-4.0 >> config.mk
           echo USE_RPC=1 >> config.mk
           """
141 142 143 144 145 146 147 148 149
        make('i386', '-j2')
        sh "mv lib/libtvm.so lib/libtvm_llvm40.so"
        sh "echo LLVM_CONFIG=llvm-config-5.0 >> config.mk"
        make('i386', '-j2')
        sh "mv lib/libtvm.so lib/libtvm_llvm50.so"
        sh "echo LLVM_CONFIG=llvm-config-6.0 >> config.mk"
        make('i386', '-j2')
        sh "mv lib/libtvm.so lib/libtvm_llvm60.so"
        pack_lib('i386', tvm_multilib)
150 151
      }
    }
152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
  },
  'web': {
    node('emcc') {
      ws('workspace/tvm/build-weblib') {
        init_git()
        sh """
           cp make/config.mk .
           echo USE_CUDA=0 >> config.mk
           echo USE_OPENCL=0 >> config.mk
           echo LLVM_CONFIG=llvm-config >> config.mk
           echo USE_RPC=0 >> config.mk
           """
        sh "${docker_run} emscripten echo testing javascript..."
        timeout(time: max_time, unit: 'MINUTES') {
          try {
            sh "${docker_run} emscripten ./tests/scripts/task_web_build.sh"
          } catch (exc) {
            echo 'Incremental compilation failed. Fall back to build from scratch'
            sh "${docker_run} emscripten make clean"
            sh "${docker_run} emscripten ./tests/scripts/task_web_build.sh"
         }
        }
174
        pack_lib('weblib', tvm_lib)
175 176
      }
    }
177 178 179 180 181 182 183 184
  }
}

stage('Unit Test') {
  parallel 'python2/3: GPU': {
    node('GPU' && 'linux') {
      ws('workspace/tvm/ut-python-gpu') {
        init_git()
185 186 187 188 189 190 191
        unpack_lib('gpu', tvm_multilib)
        sh "cp lib/libtvm_llvm40.so lib/libtvm.so"
        timeout(time: max_time, unit: 'MINUTES') {
          sh "${docker_run} gpu ./tests/scripts/task_python_unittest.sh"
        }
        // Test on the lastest mainline.
        sh "cp lib/libtvm_llvm60.so lib/libtvm.so"
192 193 194 195 196 197
        timeout(time: max_time, unit: 'MINUTES') {
          sh "${docker_run} gpu ./tests/scripts/task_python_unittest.sh"
        }
      }
    }
  },
198 199 200 201
  'python2/3: i386': {
    node('CPU' && 'linux') {
      ws('workspace/tvm/ut-python-i386') {
        init_git()
202 203
        unpack_lib('i386', tvm_multilib)
        sh "cp lib/libtvm_llvm40.so lib/libtvm.so"
204 205 206 207
        timeout(time: max_time, unit: 'MINUTES') {
          sh "${docker_run} i386 ./tests/scripts/task_python_unittest.sh"
          sh "${docker_run} i386 ./tests/scripts/task_python_integration.sh"
        }
208 209 210 211 212
        // Test on llvm 5.0
        sh "cp lib/libtvm_llvm50.so lib/libtvm.so"
        timeout(time: max_time, unit: 'MINUTES') {
          sh "${docker_run} i386 ./tests/scripts/task_python_integration.sh"
        }
213 214 215
      }
    }
  },
216 217 218 219 220 221 222 223 224 225
  'cpp': {
    node('linux') {
      ws('workspace/tvm/ut-cpp') {
        init_git()
        unpack_lib('cpu', tvm_lib)
        timeout(time: max_time, unit: 'MINUTES') {
          sh "${docker_run} cpu ./tests/scripts/task_cpp_unittest.sh"
        }
      }
    }
226 227 228 229 230
  },
  'java': {
    node('GPU' && 'linux') {
      ws('workspace/tvm/ut-java') {
        init_git()
231 232
        unpack_lib('gpu', tvm_multilib)
        sh "cp lib/libtvm_llvm40.so lib/libtvm.so"
233 234 235 236 237
        timeout(time: max_time, unit: 'MINUTES') {
          sh "${docker_run} gpu ./tests/scripts/task_java_unittest.sh"
        }
      }
    }
238 239 240 241 242 243 244 245
  }
}

stage('Integration Test') {
  parallel 'python': {
    node('GPU' && 'linux') {
      ws('workspace/tvm/it-python-gpu') {
        init_git()
246 247
        unpack_lib('gpu', tvm_multilib)
        sh "cp lib/libtvm_llvm40.so lib/libtvm.so"
248 249
        timeout(time: max_time, unit: 'MINUTES') {
          sh "${docker_run} gpu ./tests/scripts/task_python_integration.sh"
250
          sh "${docker_run} gpu ./tests/scripts/task_python_topi.sh"
251 252 253 254
        }
      }
    }
  },
255 256 257 258
  'web': {
    node('emcc') {
      ws('workspace/tvm/it-weblib') {
        init_git()
259
        unpack_lib('weblib', tvm_lib)
260 261 262 263 264 265 266
        sh "${docker_run} emscripten echo testing javascript..."
        timeout(time: max_time, unit: 'MINUTES') {
          sh "${docker_run} emscripten ./tests/scripts/task_web_test.sh"
        }
      }
    }
  },
267 268 269 270
  'docs': {
    node('GPU' && 'linux') {
      ws('workspace/tvm/docs-python-gpu') {
        init_git()
271 272
        unpack_lib('gpu', tvm_multilib)
        sh "cp lib/libtvm_llvm40.so lib/libtvm.so"
273 274 275
        timeout(time: max_time, unit: 'MINUTES') {
          sh "${docker_run} gpu ./tests/scripts/task_python_docs.sh"
        }
276
        pack_lib('mydocs', 'docs.tgz')
277 278 279 280
      }
    }
  }
}
281 282 283 284 285 286 287 288 289 290 291

stage('Deploy') {
    node('docker' && 'doc') {
      ws('workspace/tvm/deploy-docs') {
        if (env.BRANCH_NAME == "master") {
           unpack_lib('mydocs', 'docs.tgz')
           sh "tar xf docs.tgz -C /var/docs"
        }
      }
    }
}