test_gpcnet_performance.py 4.54 KB
Newer Older
1
2
3
4
5
6
7
8
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""Tests for GPCNet benchmark."""

import numbers
import unittest

9
10
from tests.helper import decorator
from tests.helper.testcase import BenchmarkTestCase
11
12
13
from superbench.benchmarks import BenchmarkRegistry, Platform, BenchmarkType


14
class GPCNetBenchmarkTest(BenchmarkTestCase, unittest.TestCase):
15
    """Tests for GPCNetBenchmark benchmark."""
16
17
18
19
20
21
22
23
24
25
    @classmethod
    def setUpClass(cls):
        """Hook method for setting up class fixture before running tests in the class."""
        super().setUpClass()
        cls.createMockEnvs(cls)
        cls.createMockFiles(cls, ['bin/network_test', 'bin/network_load_test'])

    @decorator.load_data('tests/data/gpcnet_network_test.log')
    @decorator.load_data('tests/data/gpcnet_network_test_error.log')
    def test_gpcnet_network_test(self, raw_output, raw_output_no_execution):
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
        """Test gpcnet-network-test benchmark."""
        # Check registry.
        benchmark_name = 'gpcnet-network-test'
        (benchmark_class,
         predefine_params) = BenchmarkRegistry._BenchmarkRegistry__select_benchmark(benchmark_name, Platform.CPU)
        assert (benchmark_class)

        # Check preprocess
        benchmark = benchmark_class(benchmark_name)
        ret = benchmark._preprocess()
        assert (ret)

        expect_command = 'network_test'
        command = benchmark._bin_name + benchmark._commands[0].split(benchmark._bin_name)[1]
        assert (command == expect_command)

        assert (benchmark._process_raw_result(0, raw_output_no_execution))
43
        assert (len(benchmark.result) == benchmark.default_metric_count)
44
45
46
47
48

        # Check function process_raw_data.
        # Positive case - valid raw output.
        assert (benchmark._process_raw_result(0, raw_output))
        metric_list = [
49
50
51
52
53
54
55
56
            'rr_two-sided_lat',
            'rr_get_lat',
            'rr_two-sided_bw',
            'rr_put_bw',
            'rr_two-sided+sync_bw',
            'nat_two-sided_bw',
            'multiple_allreduce_time',
            'multiple_alltoall_bw',
57
58
        ]
        for metric_medium in metric_list:
59
60
            for suffix in ['avg', '99%']:
                metric = metric_medium + '_' + suffix
61
62
63
64
65
66
67
68
69
70
71
72
                assert (metric in benchmark.result)
                assert (len(benchmark.result[metric]) == 1)
                assert (isinstance(benchmark.result[metric][0], numbers.Number))

        # Negative case - Add invalid raw output.
        assert (benchmark._process_raw_result(0, 'ERROR') is False)

        # Check basic information.
        assert (benchmark.name == 'gpcnet-network-test')
        assert (benchmark.type == BenchmarkType.MICRO)
        assert (benchmark._bin_name == 'network_test')

73
74
75
    @decorator.load_data('tests/data/gpcnet_network_load.log')
    @decorator.load_data('tests/data/gpcnet_network_load_error.log')
    def test_gpcnet_network_load(self, raw_output, raw_output_no_execution):
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
        """Test gpcnet-network-load-test benchmark."""
        # Check registry.
        benchmark_name = 'gpcnet-network-load-test'
        (benchmark_class,
         predefine_params) = BenchmarkRegistry._BenchmarkRegistry__select_benchmark(benchmark_name, Platform.CPU)
        assert (benchmark_class)

        # Check preprocess
        benchmark = benchmark_class(benchmark_name)
        ret = benchmark._preprocess()
        assert (ret)

        expect_command = 'network_load_test'
        command = benchmark._bin_name + benchmark._commands[0].split(benchmark._bin_name)[1]
        assert (command == expect_command)

        # Check function process_raw_data.
        assert (benchmark._process_raw_result(0, raw_output_no_execution))
94
        assert (len(benchmark.result) == benchmark.default_metric_count)
95
96
        # Positive case - valid raw output.
        assert (benchmark._process_raw_result(0, raw_output))
97
        metric_list = ['rr_two-sided_lat_x', 'rr_two-sided+sync_bw_x', 'multiple_allreduce_x']
98
        for metric_medium in metric_list:
99
100
            for suffix in ['avg', '99%']:
                metric = metric_medium + '_' + suffix
101
102
103
104
105
106
107
108
109
110
111
                assert (metric in benchmark.result)
                assert (len(benchmark.result[metric]) == 1)
                assert (isinstance(benchmark.result[metric][0], numbers.Number))

        # Negative case - Add invalid raw output.
        assert (benchmark._process_raw_result(0, 'ERROR') is False)

        # Check basic information.
        assert (benchmark.name == 'gpcnet-network-load-test')
        assert (benchmark.type == BenchmarkType.MICRO)
        assert (benchmark._bin_name == 'network_load_test')