Jenkinsfile 5.41 KB
Newer Older
Paul's avatar
Paul committed
1

Paul Fultz II's avatar
Paul Fultz II committed
2
def rocmtestnode(variant, name, body, args, pre) {
Paul's avatar
Paul committed
3
    def image = 'migraphxlib'
Paul's avatar
Paul committed
4
5
    def cmake_build = { compiler, flags ->
        def cmd = """
Paul's avatar
Paul committed
6
            env
Paul's avatar
Paul committed
7
            ulimit -c unlimited
Paul's avatar
Paul committed
8
9
10
            rm -rf build
            mkdir build
            cd build
Paul's avatar
Paul committed
11
            CXX=${compiler} CXXFLAGS='-Werror -Wno-fallback' cmake ${flags} .. 
Paul's avatar
Paul committed
12
            CTEST_PARALLEL_LEVEL=32 make -j\$(nproc) generate all doc package check
Paul's avatar
Paul committed
13
14
15
        """
        echo cmd
        sh cmd
Paul's avatar
Paul committed
16
        if (compiler == "hcc") {
Paul's avatar
Paul committed
17
18
19
20
            // Only archive from master or develop
            if (env.BRANCH_NAME == "develop" || env.BRANCH_NAME == "master") {
                archiveArtifacts artifacts: "build/*.deb", allowEmptyArchive: true, fingerprint: true
            }
Paul's avatar
Paul committed
21
        }
Paul's avatar
Paul committed
22
23
    }
    node(name) {
Paul's avatar
Paul committed
24
25
26
27
        withEnv(['HSA_ENABLE_SDMA=0', 'MIOPEN_DEBUG_GCN_ASM_KERNELS=0']) {
            stage("checkout ${variant}") {
                checkout scm
            }
Paul Fultz II's avatar
Paul Fultz II committed
28
            pre()
Paul's avatar
Paul committed
29
30
31
32
33
            stage("image ${variant}") {
                try {
                    docker.build("${image}", '.')
                } catch(Exception ex) {
                    docker.build("${image}", '--no-cache .')
Paul's avatar
Paul committed
34

Paul's avatar
Paul committed
35
                }
Paul's avatar
Paul committed
36
            }
Paul Fultz II's avatar
Paul Fultz II committed
37
            withDockerContainer(image: image, args: "--device=/dev/kfd --device=/dev/dri --group-add video --cap-add SYS_PTRACE ${args}") {
Paul's avatar
Paul committed
38
39
40
                timeout(time: 1, unit: 'HOURS') {
                    body(cmake_build)
                }
Paul's avatar
Paul committed
41
42
43
44
            }
        }
    }
}
Paul Fultz II's avatar
Paul Fultz II committed
45
// @NonCPS
Paul's avatar
Paul committed
46
47
def rocmtest(m) {
    def builders = [:]
Paul Fultz II's avatar
Paul Fultz II committed
48
    m.each { e ->
Paul's avatar
Paul committed
49
50
51
52
53
54
55
56
57
        def label = e.key;
        def action = e.value;
        builders[label] = {
            action(label)
        }
    }
    parallel builders
}

Paul Fultz II's avatar
Paul Fultz II committed
58
59
// @NonCPS
def rocmnode(name, args, pre, body) {
Paul's avatar
Paul committed
60
61
62
63
64
65
66
67
68
    def node_name = 'rocmtest || rocm'
    if(name == 'fiji') {
        node_name = 'rocmtest && fiji';
    } else if(name == 'vega') {
        node_name = 'rocmtest && vega';
    } else {
        node_name = name
    }
    return { label ->
Paul Fultz II's avatar
Paul Fultz II committed
69
        rocmtestnode(label, node_name, body, args, pre)
Paul's avatar
Paul committed
70
71
72
    }
}

Paul Fultz II's avatar
Paul Fultz II committed
73
74
75
76
77
def rocmnode(name, body) {
    rocmnode(name, '', {}, body)
}

// @NonCPS
Paul's avatar
Paul committed
78
def rocmnode(body) {
Paul Fultz II's avatar
Paul Fultz II committed
79
    rocmnode('rocmtest', '', {}, body)
Paul's avatar
Paul committed
80
81
82
}

// Static checks
Paul's avatar
Paul committed
83
rocmtest tidy: rocmnode('rocmtest') { cmake_build ->
Paul's avatar
Paul committed
84
85
86
87
88
    stage('Clang Tidy') {
        sh '''
            rm -rf build
            mkdir build
            cd build
Paul's avatar
Paul committed
89
            CXX=hcc cmake .. 
Paul's avatar
Paul committed
90
            make -j$(nproc) -k analyze
Paul's avatar
Paul committed
91
92
        '''
    }
Paul's avatar
Paul committed
93
}, format: rocmnode('rocmtest') { cmake_build ->
kahmed10's avatar
kahmed10 committed
94
    stage('Format') {
Paul's avatar
Paul committed
95
96
97
98
99
100
101
102
103
104
        sh '''
            find . -iname \'*.h\' \
                -o -iname \'*.hpp\' \
                -o -iname \'*.cpp\' \
                -o -iname \'*.h.in\' \
                -o -iname \'*.hpp.in\' \
                -o -iname \'*.cpp.in\' \
                -o -iname \'*.cl\' \
            | grep -v 'build/' \
            | xargs -n 1 -P 1 -I{} -t sh -c \'clang-format-5.0 -style=file {} | diff - {}\'
kahmed10's avatar
kahmed10 committed
105
106
107
            find . -iname \'*.py\' \
            | grep -v 'build/'  \
            | xargs -n 1 -P 1 -I{} -t sh -c \'yapf {} | diff - {}\'
Paul's avatar
Paul committed
108
109
        '''
    }
Paul's avatar
Paul committed
110
}, clang_debug: rocmnode('vega') { cmake_build ->
Paul's avatar
Paul committed
111
    stage('Clang Debug') {
Paul's avatar
Paul committed
112
        // TODO: Enable integer
Paul's avatar
Paul committed
113
        def sanitizers = "undefined"
114
        def debug_flags = "-O2 -fsanitize=${sanitizers} -fno-sanitize-recover=${sanitizers}"
115
        cmake_build("hcc", "-DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_PYTHON=Off -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}'")
Paul's avatar
Paul committed
116
    }
Paul's avatar
Paul committed
117
}, clang_release: rocmnode('vega') { cmake_build ->
Paul's avatar
Paul committed
118
    stage('Clang Release') {
Paul's avatar
Paul committed
119
        cmake_build("hcc", "-DCMAKE_BUILD_TYPE=release")
Paul Fultz II's avatar
Paul Fultz II committed
120
        stash includes: 'build/*.deb', name: 'migraphx-package'
Paul's avatar
Paul committed
121
    }
Paul's avatar
Paul committed
122
}, clang_release_py3: rocmnode('vega') { cmake_build ->
Paul's avatar
Paul committed
123
124
125
    stage('Clang Release Python 3') {
        cmake_build("hcc", "-DCMAKE_BUILD_TYPE=release -DPYTHON_EXECUTABLE=/usr/local/bin/python3")
    }
Paul's avatar
Paul committed
126
127
}, gcc5: rocmnode('rocmtest') { cmake_build ->
    stage('GCC 5 Debug') {
Paul's avatar
Paul committed
128
        cmake_build("g++-5", "-DCMAKE_BUILD_TYPE=debug")
Paul's avatar
Paul committed
129
    }
Paul's avatar
Paul committed
130
    stage('GCC 5 Release') {
Paul's avatar
Paul committed
131
        cmake_build("g++-5", "-DCMAKE_BUILD_TYPE=release")
Paul's avatar
Paul committed
132
    }
Paul's avatar
Paul committed
133
134
}, gcc7: rocmnode('rocmtest') { cmake_build ->
    stage('GCC 7 Debug') {
Paul's avatar
Paul committed
135
        def linker_flags = '-fuse-ld=gold'
Paul's avatar
Paul committed
136
        def cmake_linker_flags = "-DCMAKE_EXE_LINKER_FLAGS='${linker_flags}' -DCMAKE_SHARED_LINKER_FLAGS='${linker_flags}'"
Paul's avatar
Paul committed
137
138
        // TODO: Add bounds-strict
        def sanitizers = "undefined,address"
Paul's avatar
Paul committed
139
        def debug_flags = "-g -fprofile-arcs -ftest-coverage -fno-omit-frame-pointer -fsanitize-address-use-after-scope -fsanitize=${sanitizers} -fno-sanitize-recover=${sanitizers}"
140
        cmake_build("g++-7", "-DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_PYTHON=Off ${cmake_linker_flags} -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}'")
Paul's avatar
Paul committed
141
142
143
144
145
146

    }
    stage('Codecov') {
        env.CODECOV_TOKEN="8545af1c-f90b-4345-92a5-0d075503ca56"
        sh '''
            cd build
Paul Fultz II's avatar
Paul Fultz II committed
147
148
149
            lcov --directory . --capture --output-file $(pwd)/coverage.info
            lcov --remove $(pwd)/coverage.info '/usr/*' --output-file $(pwd)/coverage.info
            lcov --list $(pwd)/coverage.info
Paul's avatar
Paul committed
150
            curl -s https://codecov.io/bash | bash
Paul's avatar
Paul committed
151
            echo "Uploaded"
Paul's avatar
Paul committed
152
        '''
Paul's avatar
Paul committed
153
    }
Paul's avatar
Paul committed
154
}
Paul Fultz II's avatar
Paul Fultz II committed
155
156
157
158
159
160
161
162
163
164
165
166
167

rocmtest onnx: rocmnode('rocmtest', '-u root', { 
    sh 'rm -rf ./build/*.deb'
    unstash 'migraphx-package' 
}) { cmake_build ->
    stage("Onnx runtime") {
        sh '''
            ls -lR
            dpkg -i --force-depends ./build/*.deb
            cd /onnxruntime && ./build_and_test_onnxrt.sh
        '''
    }
}