summaryrefslogtreecommitdiff
path: root/opendc-experiments/opendc-experiments-base/src/test/kotlin/org/opendc/experiments/base/GpuTest.kt
blob: a645f4e645e05caa1c490af6a6ab065fb803e623 (plain)
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
/*
 * Copyright (c) 2020 AtLarge Research
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

package org.opendc.experiments.base

import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertAll
import org.opendc.compute.simulator.service.ServiceTask
import org.opendc.compute.topology.specs.ClusterSpec
import org.opendc.simulator.compute.workload.trace.TraceFragment
import java.util.ArrayList

/**
 * Testing suite containing tests that specifically test the FlowDistributor
 */
class GpuTest {
    /**
     * Test the creation of a GPU host with a single GPU, in minimal configuration
     */
    @Test
    fun testGpuHostCreationSingleMinimal() {
        val topology = createTopology("Gpus/single_gpu_no_vendor_no_memory.json")
        assertGpuConfiguration(
            topology,
            coreCount = 1,
            coreSpeed = 2000.0,
            memorySize = -1L,
            memoryBandwidth = -1.0,
            vendor = "unknown",
            modelName = "unknown",
            architecture = "unknown",
            gpuCount = 1,
        )
    }

    /**
     * Test the creation of a GPU host with a single GPU with memory but no vendor
     */
    @Test
    fun testGpuHostCreationSingleWithMemoryNoVendor() {
        val topology = createTopology("Gpus/single_gpu_no_vendor.json")
        assertGpuConfiguration(
            topology,
            coreCount = 1,
            coreSpeed = 2000.0,
            memorySize = 4096L,
            memoryBandwidth = 500.0,
            vendor = "unknown",
            modelName = "unknown",
            architecture = "unknown",
            gpuCount = 1,
        )
    }

    /**
     * Test the creation of a GPU host with a single GPU with no memory but with vendor
     */
    @Test
    fun testGpuHostCreationSingleNoMemoryWithVendor() {
        val topology = createTopology("Gpus/single_gpu_no_memory.json")
        assertGpuConfiguration(
            topology,
            coreCount = 1,
            coreSpeed = 2000.0,
            memorySize = -1L,
            memoryBandwidth = -1.0,
            vendor = "NVIDIA",
            modelName = "Tesla V100",
            architecture = "Volta",
            gpuCount = 1,
        )
    }

    /**
     * Test the creation of a GPU host with a single GPU, in full configuration
     */
    @Test
    fun testGpuHostCreationSingleWithMemoryWithVendor() {
        val topology = createTopology("Gpus/single_gpu_full.json")
        assertGpuConfiguration(
            topology,
            // cuda cores
            coreCount = 5120,
//            coreCount = 640, // tensor cores
            // fictional value
            coreSpeed = 5000.0,
            memorySize = 30517578125,
            memoryBandwidth = 7031250000.0,
            vendor = "NVIDIA",
            modelName = "Tesla V100",
            architecture = "Volta",
            gpuCount = 1,
        )
    }

    /**
     * Test the creation of a GPU host with multiple GPU, in minimal configuration
     */
    @Test
    fun testGpuHostCreationMultiMinimal() {
        val topology = createTopology("Gpus/multi_gpu_no_vendor_no_memory.json")
        assertGpuConfiguration(
            topology,
            coreCount = 1,
            coreSpeed = 2000.0,
            memorySize = -1L,
            memoryBandwidth = -1.0,
            vendor = "unknown",
            modelName = "unknown",
            architecture = "unknown",
            gpuCount = 3,
        )
    }

    /**
     * Test the creation of a GPU host with multiple GPU with memory but no vendor
     */
    @Test
    fun testGpuHostCreationMultiWithMemoryNoVendor() {
        val topology = createTopology("Gpus/multi_gpu_no_vendor.json")

        assertGpuConfiguration(
            topology,
            coreCount = 1,
            coreSpeed = 2000.0,
            memorySize = 4096L,
            memoryBandwidth = 500.0,
            vendor = "unknown",
            modelName = "unknown",
            architecture = "unknown",
            gpuCount = 100,
        )
    }

    /**
     * Test the creation of a GPU host with multiple GPU with no memory but with vendor
     */
    @Test
    fun testGpuHostCreationMultiNoMemoryWithVendor() {
        val topology = createTopology("Gpus/multi_gpu_no_memory.json")
        assertGpuConfiguration(
            topology,
            coreCount = 1,
            coreSpeed = 2000.0,
            memorySize = -1L,
            memoryBandwidth = -1.0,
            vendor = "NVIDIA",
            modelName = "Tesla V100",
            architecture = "Volta",
            gpuCount = 2,
        )
    }

    /**
     * Test the creation of a GPU host with multiple GPU, in full configuration
     */
    @Test
    fun testGpuHostCreationMultiWithMemoryWithVendor() {
        val topology = createTopology("Gpus/multi_gpu_full.json")
        // temporary implementation, to account for GPU concatenation
        assertGpuConfiguration(
            topology,
            // cuda cores
            coreCount = 5120,
            // fictional value
            coreSpeed = 5000.0,
            memorySize = 30517578125,
            memoryBandwidth = 7031250000.0,
            vendor = "NVIDIA",
            modelName = "Tesla V100",
            architecture = "Volta",
            gpuCount = 5,
        )
    }

    /**
     * This test checks if the FlowDistributor can handle a workload that requires multiple GPUs.
     * This test assumes that multiple GPUs are concatenated into on single larger GPU.
     */
    @Test
    fun testMultiGpuConcation() {
        val workload: ArrayList<ServiceTask> =
            arrayListOf(
                createTestTask(
                    id = 0,
                    fragments =
                        arrayListOf(
                            TraceFragment(10 * 60 * 1000, 1000.0, 2000.0),
                        ),
                    cpuCoreCount = 1,
                    gpuCoreCount = 1,
                ),
                createTestTask(
                    id = 1,
                    fragments =
                        arrayListOf(
                            TraceFragment(10 * 60 * 1000, 1000.0, 2000.0),
                        ),
                    cpuCoreCount = 1,
                    gpuCoreCount = 1,
                ),
            )
        val topology = createTopology("Gpus/multi_gpu_host.json")

        val monitor = runTest(topology, workload)

        assertAll(
            { assertEquals(10 * 60 * 1000, monitor.maxTimestamp) { "The expected runtime is exceeded" } },
            // CPU
            // task 0
            { assertEquals(1000.0, monitor.taskCpuDemands[0]?.get(1)) { "The cpu demanded by task 0 is incorrect" } },
            { assertEquals(1000.0, monitor.taskCpuDemands[0]?.get(8)) { "The cpu demanded by task 0 is incorrect" } },
            { assertEquals(1000.0, monitor.taskCpuSupplied[0]?.get(1)) { "The cpu used by task 0 is incorrect" } },
            { assertEquals(1000.0, monitor.taskCpuSupplied[0]?.get(8)) { "The cpu used by task 0 is incorrect" } },
            // task 1
            { assertEquals(1000.0, monitor.taskCpuDemands[1]?.get(1)) { "The cpu demanded by task 1 is incorrect" } },
            { assertEquals(1000.0, monitor.taskCpuDemands[1]?.get(8)) { "The cpu demanded by task 1 is incorrect" } },
            { assertEquals(1000.0, monitor.taskCpuSupplied[1]?.get(1)) { "The cpu used by task 1 is incorrect" } },
            { assertEquals(1000.0, monitor.taskCpuSupplied[1]?.get(8)) { "The cpu used by task 1 is incorrect" } },
            // host
            { assertEquals(2000.0, monitor.hostCpuDemands["DualGpuHost"]?.get(1)) { "The cpu demanded by the host is incorrect" } },
            { assertEquals(2000.0, monitor.hostCpuDemands["DualGpuHost"]?.get(9)) { "The cpu demanded by the host is incorrect" } },
            { assertEquals(2000.0, monitor.hostCpuSupplied["DualGpuHost"]?.get(1)) { "The cpu used by the host is incorrect" } },
            { assertEquals(2000.0, monitor.hostCpuSupplied["DualGpuHost"]?.get(9)) { "The cpu used by the host is incorrect" } },
            // GPU
            // task 0
            { assertEquals(2000.0, monitor.taskGpuDemands[0]?.get(1)) { "The gpu demanded by task 0 is incorrect" } },
            { assertEquals(2000.0, monitor.taskGpuDemands[0]?.get(8)) { "The gpu demanded by task 0 is incorrect" } },
            { assertEquals(2000.0, monitor.taskGpuSupplied[0]?.get(1)) { "The gpu used by task 0 is incorrect" } },
            { assertEquals(2000.0, monitor.taskGpuSupplied[0]?.get(8)) { "The gpu used by task 0 is incorrect" } },
            // task 1
            { assertEquals(2000.0, monitor.taskGpuDemands[1]?.get(1)) { "The gpu demanded by task 1 is incorrect" } },
            { assertEquals(2000.0, monitor.taskGpuDemands[1]?.get(8)) { "The gpu demanded by task 1 is incorrect" } },
            { assertEquals(2000.0, monitor.taskGpuSupplied[1]?.get(1)) { "The gpu used by task 1 is incorrect" } },
            { assertEquals(2000.0, monitor.taskGpuSupplied[1]?.get(8)) { "The gpu used by task 1 is incorrect" } },
            // host
            // GPU 0
            { assertEquals(2000.0, monitor.hostGpuDemands["DualGpuHost"]?.get(1)?.get(0)) { "The gpu demanded by the host is incorrect" } },
            { assertEquals(2000.0, monitor.hostGpuDemands["DualGpuHost"]?.get(9)?.get(0)) { "The gpu demanded by the host is incorrect" } },
            { assertEquals(2000.0, monitor.hostGpuSupplied["DualGpuHost"]?.get(1)?.get(0)) { "The gpu used by the host is incorrect" } },
            { assertEquals(2000.0, monitor.hostGpuSupplied["DualGpuHost"]?.get(9)?.get(0)) { "The gpu used by the host is incorrect" } },
            // GPU 1
            { assertEquals(2000.0, monitor.hostGpuDemands["DualGpuHost"]?.get(1)?.get(1)) { "The gpu demanded by the host is incorrect" } },
            { assertEquals(2000.0, monitor.hostGpuDemands["DualGpuHost"]?.get(9)?.get(1)) { "The gpu demanded by the host is incorrect" } },
            { assertEquals(2000.0, monitor.hostGpuSupplied["DualGpuHost"]?.get(1)?.get(1)) { "The gpu used by the host is incorrect" } },
            { assertEquals(2000.0, monitor.hostGpuSupplied["DualGpuHost"]?.get(9)?.get(1)) { "The gpu used by the host is incorrect" } },
        )
    }

    private fun assertGpuConfiguration(
        topology: List<ClusterSpec>,
        coreCount: Int,
        coreSpeed: Double,
        memorySize: Long,
        memoryBandwidth: Double,
        vendor: String,
        modelName: String,
        architecture: String,
        gpuCount: Int,
    ) {
        for (cluster in topology) {
            for (host in cluster.hostSpecs) {
                assert(host.model.gpuModels.size == gpuCount) { "GPU count should be $gpuCount, but is ${host.model.gpuModels.size}" }

                for (gpuModel in host.model.gpuModels) {
                    assert(gpuModel.coreCount == coreCount) { "GPU Core count should be $coreCount, but is ${gpuModel.coreCount}" }
                    assert(gpuModel.coreSpeed == coreSpeed) { "GPU core speed should be $coreSpeed, but is ${gpuModel.coreSpeed}" }
                    assert(gpuModel.memorySize == memorySize) { "GPU memory size should be $memorySize, but is ${gpuModel.memorySize}" }
                    assert(gpuModel.memoryBandwidth == memoryBandwidth) {
                        "GPU memory bandwidth should be $memoryBandwidth, but is ${gpuModel.memoryBandwidth}"
                    }
                    assert(gpuModel.vendor.contentEquals(vendor)) { "GPU vendor should be $vendor, but is ${gpuModel.vendor}" }
                    assert(
                        gpuModel.modelName.contentEquals(modelName),
                    ) { "GPU model name should be $modelName, but is ${gpuModel.modelName}" }
                    assert(
                        gpuModel.architecture.contentEquals(architecture),
                    ) { "GPU architecture should be $architecture, but is ${gpuModel.architecture}" }
                }
            }
        }
    }
}