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

2
3
4
5
6
7
8
9
// def rocmtestnode(variant, name, body, args, pre) {
def rocmtestnode(Map conf) {
    def variant = conf.get("variant")
    def name = conf.get("node")
    def body = conf.get("body")
    def docker_args = conf.get("docker_args", "")
    def docker_build_args = conf.get("docker_build_args", "")
    def pre = conf.get("pre", {})
Paul's avatar
Paul committed
10
    def image = 'migraphxlib'
Paul's avatar
Paul committed
11
12
    def cmake_build = { compiler, flags ->
        def cmd = """
Paul's avatar
Paul committed
13
            env
Paul's avatar
Paul committed
14
            ulimit -c unlimited
Paul's avatar
Paul committed
15
16
17
            rm -rf build
            mkdir build
            cd build
Paul's avatar
Paul committed
18
            CXX=${compiler} CXXFLAGS='-Werror -Wno-fallback' cmake ${flags} .. 
Paul's avatar
Paul committed
19
            CTEST_PARALLEL_LEVEL=32 make -j\$(nproc) generate all doc package check
Paul's avatar
Paul committed
20
21
22
        """
        echo cmd
        sh cmd
Paul's avatar
Paul committed
23
        if (compiler == "hcc") {
Paul's avatar
Paul committed
24
25
26
27
            // 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
28
        }
Paul's avatar
Paul committed
29
30
    }
    node(name) {
Paul's avatar
Paul committed
31
32
33
34
        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
35
            pre()
Paul's avatar
Paul committed
36
37
            stage("image ${variant}") {
                try {
38
                    docker.build("${image}", "${docker_build_args} .")
Paul's avatar
Paul committed
39
                } catch(Exception ex) {
40
                    docker.build("${image}", "${docker_build_args} --no-cache .")
Paul's avatar
Paul committed
41

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

64
def rocmnodename(name) {
Paul's avatar
Paul committed
65
66
67
68
69
70
71
72
    def node_name = 'rocmtest || rocm'
    if(name == 'fiji') {
        node_name = 'rocmtest && fiji';
    } else if(name == 'vega') {
        node_name = 'rocmtest && vega';
    } else {
        node_name = name
    }
73
    return node_name
Paul's avatar
Paul committed
74
75
}

Paul Fultz II's avatar
Paul Fultz II committed
76
def rocmnode(name, body) {
77
78
79
    return { label ->
        rocmtestnode(variant: label, node: rocmnodename(name), body: body)
    }
Paul Fultz II's avatar
Paul Fultz II committed
80
81
}

82
83
84
85
def rocmhipclangnode(name, body) {
    return { label ->
        rocmtestnode(variant: label, node: rocmnodename(name), docker_build_args: '-f hip-clang.docker', body: body)
    }
Paul's avatar
Paul committed
86
87
88
}

// Static checks
Paul's avatar
Paul committed
89
rocmtest tidy: rocmnode('rocmtest') { cmake_build ->
Paul's avatar
Paul committed
90
91
92
93
94
    stage('Clang Tidy') {
        sh '''
            rm -rf build
            mkdir build
            cd build
Paul's avatar
Paul committed
95
            CXX=hcc cmake .. 
Paul's avatar
Paul committed
96
            make -j$(nproc) -k analyze
Paul's avatar
Paul committed
97
98
        '''
    }
Paul's avatar
Paul committed
99
}, format: rocmnode('rocmtest') { cmake_build ->
kahmed10's avatar
kahmed10 committed
100
    stage('Format') {
Paul's avatar
Paul committed
101
102
103
104
105
106
107
108
109
110
        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
111
112
113
            find . -iname \'*.py\' \
            | grep -v 'build/'  \
            | xargs -n 1 -P 1 -I{} -t sh -c \'yapf {} | diff - {}\'
Paul's avatar
Paul committed
114
115
        '''
    }
Paul's avatar
Paul committed
116
}, clang_debug: rocmnode('vega') { cmake_build ->
Paul's avatar
Paul committed
117
    stage('Clang Debug') {
Paul's avatar
Paul committed
118
        // TODO: Enable integer
Paul's avatar
Paul committed
119
        def sanitizers = "undefined"
120
        def debug_flags = "-O2 -fsanitize=${sanitizers} -fno-sanitize-recover=${sanitizers}"
121
        cmake_build("hcc", "-DCMAKE_BUILD_TYPE=debug -DMIGRAPHX_ENABLE_PYTHON=Off -DCMAKE_CXX_FLAGS_DEBUG='${debug_flags}'")
Paul's avatar
Paul committed
122
    }
Paul's avatar
Paul committed
123
}, clang_release: rocmnode('vega') { cmake_build ->
Paul's avatar
Paul committed
124
    stage('Clang Release') {
Paul's avatar
Paul committed
125
        cmake_build("hcc", "-DCMAKE_BUILD_TYPE=release")
Paul Fultz II's avatar
Paul Fultz II committed
126
        stash includes: 'build/*.deb', name: 'migraphx-package'
Paul's avatar
Paul committed
127
    }
Paul's avatar
Paul committed
128
}, clang_release_py3: rocmnode('vega') { cmake_build ->
Paul's avatar
Paul committed
129
130
131
    stage('Clang Release Python 3') {
        cmake_build("hcc", "-DCMAKE_BUILD_TYPE=release -DPYTHON_EXECUTABLE=/usr/local/bin/python3")
    }
132
133
134
135
136
137
138
}, hip_clang_release: rocmhipclangnode('vega') { cmake_build ->
    stage('Hip Clang Release') {
        cmake_build("/opt/rocm/llvm/bin/clang++", "-DCMAKE_BUILD_TYPE=release")
        // stash includes: 'build/*.deb', name: 'migraphx-package'
    }
}, hip_clang_tidy: rocmhipclangnode('rocmtest') { cmake_build ->
    stage('Hip Clang Tidy') {
Paul's avatar
Paul committed
139
140
141
142
143
144
145
146
147
148
149
        try {
            sh '''
                rm -rf build
                mkdir build
                cd build
                CXX=/opt/rocm/llvm/bin/clang++ cmake .. 
                make -j$(nproc) -k analyze
            '''
        } finally {
            recordIssues aggregatingResults: true, enabledForFailure: true, tools: [cmake(), clangTidy(), cppCheck(), clang(), gcc(), sphinxBuild()]
        }
150
    }
Paul's avatar
Paul committed
151
152
}, gcc5: rocmnode('rocmtest') { cmake_build ->
    stage('GCC 5 Debug') {
Paul's avatar
Paul committed
153
        cmake_build("g++-5", "-DCMAKE_BUILD_TYPE=debug")
Paul's avatar
Paul committed
154
    }
Paul's avatar
Paul committed
155
    stage('GCC 5 Release') {
Paul's avatar
Paul committed
156
        cmake_build("g++-5", "-DCMAKE_BUILD_TYPE=release")
Paul's avatar
Paul committed
157
    }
Paul's avatar
Paul committed
158
159
}, gcc7: rocmnode('rocmtest') { cmake_build ->
    stage('GCC 7 Debug') {
Paul's avatar
Paul committed
160
        def linker_flags = '-fuse-ld=gold'
Paul's avatar
Paul committed
161
        def cmake_linker_flags = "-DCMAKE_EXE_LINKER_FLAGS='${linker_flags}' -DCMAKE_SHARED_LINKER_FLAGS='${linker_flags}'"
Paul's avatar
Paul committed
162
163
        // TODO: Add bounds-strict
        def sanitizers = "undefined,address"
Paul's avatar
Paul committed
164
        def debug_flags = "-g -fprofile-arcs -ftest-coverage -fno-omit-frame-pointer -fsanitize-address-use-after-scope -fsanitize=${sanitizers} -fno-sanitize-recover=${sanitizers}"
165
        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
166
167
168
169
170
171

    }
    stage('Codecov') {
        env.CODECOV_TOKEN="8545af1c-f90b-4345-92a5-0d075503ca56"
        sh '''
            cd build
Paul Fultz II's avatar
Paul Fultz II committed
172
173
174
            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
175
            curl -s https://codecov.io/bash | bash
Paul's avatar
Paul committed
176
            echo "Uploaded"
Paul's avatar
Paul committed
177
        '''
Paul's avatar
Paul committed
178
    }
Paul's avatar
Paul committed
179
}
Paul Fultz II's avatar
Paul Fultz II committed
180

181
182
183
184
185
186
187
188
189
190
def onnxnode(name, body) {
    return { label ->
        rocmtestnode(variant: label, node: rocmnodename(name), docker_args: '-u root', body: body, pre: {
            sh 'rm -rf ./build/*.deb'
            unstash 'migraphx-package' 
        })
    }
}

rocmtest onnx: onnxnode('rocmtest') { cmake_build ->
Paul Fultz II's avatar
Paul Fultz II committed
191
192
193
194
195
196
197
198
    stage("Onnx runtime") {
        sh '''
            ls -lR
            dpkg -i --force-depends ./build/*.deb
            cd /onnxruntime && ./build_and_test_onnxrt.sh
        '''
    }
}