_node_handler.py 1.4 KB
Newer Older
1
2
3
4
5
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

"""SuperBench CLI node subgroup command handler."""

6
7
8
from pathlib import Path
import json

9
10
from knack.util import CLIError

11
from superbench.tools import SystemInfo
12
from superbench.common.utils import create_sb_output_dir
13
14
15
16
from superbench.common.utils.gpu_topology import (
    get_gpu_numa_affinity,
    get_gpu_numa_map,
)
17
18


19
def info_command_handler(output_dir=None):
20
21
    """Get node hardware info.

22
23
24
    Args:
        output_dir (str): Output directory.

25
26
27
28
29
    Returns:
        dict: node info.
    """
    try:
        info = SystemInfo().get_all()
30
31
32
33
        output_dir = create_sb_output_dir(output_dir)
        output_dir_path = Path(output_dir)
        with open(output_dir_path / 'sys_info.json', 'w') as f:
            json.dump(info, f)
34
35
36
    except Exception as ex:
        raise RuntimeError('Failed to get node info.') from ex
    return info
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54


def topo_command_handler(get=None, gpu_id=None):
    """Get node topology information.

    Args:
        get (str): Topology field to get.
        gpu_id (int): GPU id.
    """
    if get == 'gpu-numa-map':
        print(json.dumps(get_gpu_numa_map()))
        return
    if get != 'gpu-numa-affinity':
        raise CLIError('Unsupported topology field: {}.'.format(get))
    if gpu_id is None:
        raise CLIError('--gpu-id is required for {}.'.format(get))

    print(get_gpu_numa_affinity(gpu_id))