|
| 1 | +############################################################################### |
| 2 | +# |
| 3 | +# MIT License |
| 4 | +# |
| 5 | +# Copyright (c) 2025 Advanced Micro Devices, Inc. |
| 6 | +# |
| 7 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 8 | +# of this software and associated documentation files (the "Software"), to deal |
| 9 | +# in the Software without restriction, including without limitation the rights |
| 10 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 11 | +# copies of the Software, and to permit persons to whom the Software is |
| 12 | +# furnished to do so, subject to the following conditions: |
| 13 | +# |
| 14 | +# The above copyright notice and this permission notice shall be included in all |
| 15 | +# copies or substantial portions of the Software. |
| 16 | +# |
| 17 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 20 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 22 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 23 | +# SOFTWARE. |
| 24 | +# |
| 25 | +############################################################################### |
| 26 | +from typing import Dict, Optional, Union |
| 27 | + |
| 28 | +from nodescraper.models import AnalyzerArgs |
| 29 | + |
| 30 | + |
| 31 | +class PcieAnalyzerArgs(AnalyzerArgs): |
| 32 | + """Arguments for PCIe analyzer |
| 33 | +
|
| 34 | + Attributes: |
| 35 | + exp_speed: Expected PCIe speed (generation 1-5) |
| 36 | + exp_width: Expected PCIe width (1-16 lanes) |
| 37 | + exp_sriov_count: Expected SR-IOV VF count |
| 38 | + exp_gpu_count_override: Override expected GPU count |
| 39 | + exp_max_payload_size: Expected max payload size (int for all devices, dict for specific device IDs) |
| 40 | + exp_max_rd_req_size: Expected max read request size (int for all devices, dict for specific device IDs) |
| 41 | + exp_ten_bit_tag_req_en: Expected 10-bit tag request enable (int for all devices, dict for specific device IDs) |
| 42 | + """ |
| 43 | + |
| 44 | + exp_speed: int = 5 |
| 45 | + exp_width: int = 16 |
| 46 | + exp_sriov_count: int = 0 |
| 47 | + exp_gpu_count_override: Optional[int] = None |
| 48 | + exp_max_payload_size: Optional[Union[Dict[int, int], int]] = None |
| 49 | + exp_max_rd_req_size: Optional[Union[Dict[int, int], int]] = None |
| 50 | + exp_ten_bit_tag_req_en: Optional[Union[Dict[int, int], int]] = None |
| 51 | + |
| 52 | + |
| 53 | +def normalize_to_dict( |
| 54 | + value: Optional[Union[Dict[int, int], int]], vendorid_ep: int |
| 55 | +) -> Dict[int, int]: |
| 56 | + """Normalize int or dict values to dict format using vendorid_ep as key for int values""" |
| 57 | + if value is None: |
| 58 | + return {} |
| 59 | + if isinstance(value, int): |
| 60 | + return {vendorid_ep: value} |
| 61 | + if isinstance(value, dict): |
| 62 | + return value |
| 63 | + return {} |
0 commit comments