libdrm_amdgpu_sys/amdgpu/
chip_class.rs

1/*
2************************************************************************************************************************
3*
4*  Copyright (C) 2017-2022 Advanced Micro Devices, Inc.  All rights reserved.
5*
6* Permission is hereby granted, free of charge, to any person obtaining a
7* copy of this software and associated documentation files (the "Software"),
8* to deal in the Software without restriction, including without limitation
9* the rights to use, copy, modify, merge, publish, distribute, sublicense,
10* and/or sell copies of the Software, and to permit persons to whom the
11* Software is furnished to do so, subject to the following conditions:
12*
13* The above copyright notice and this permission notice shall be included in
14* all copies or substantial portions of the Software.
15*
16* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
20* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22* OTHER DEALINGS IN THE SOFTWARE
23*
24***********************************************************************************************************************/
25
26/*
27    https://gitlab.freedesktop.org/mesa/mesa/-/blob/main/src/amd/common/amd_family.h
28    Commit: dda718d2bfe9309145d8e521c59c617e7674045a
29*/
30
31use crate::AMDGPU::ASIC_NAME;
32
33/// List of AMDGPU chip class (generation)
34#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd)]
35#[repr(u32)]
36pub enum CHIP_CLASS {
37    CLASS_UNKNOWN = 0,
38    R300,
39    R400,
40    R500,
41    R600,
42    R700,
43    EVERGREEN,
44    CAYMAN,
45    GFX6,
46    GFX7,
47    GFX8,
48    GFX9,
49    GFX10,
50    GFX10_3,
51    GFX11,
52    GFX11_5,
53    GFX12,
54}
55
56impl From<ASIC_NAME> for CHIP_CLASS {
57    fn from(asic_name: ASIC_NAME) -> Self {
58        if asic_name >= ASIC_NAME::CHIP_GFX1200 {
59            Self::GFX12
60        } else if asic_name >= ASIC_NAME::CHIP_GFX1150 {
61            Self::GFX11_5
62        } else if asic_name >= ASIC_NAME::CHIP_GFX1100 {
63            Self::GFX11
64        } else if asic_name >= ASIC_NAME::CHIP_NAVI21 {
65            Self::GFX10_3
66        } else if asic_name >= ASIC_NAME::CHIP_NAVI10 {
67            Self::GFX10
68        } else if asic_name >= ASIC_NAME::CHIP_VEGA10 {
69            Self::GFX9
70        } else if asic_name >= ASIC_NAME::CHIP_TONGA {
71            Self::GFX8
72        } else if asic_name >= ASIC_NAME::CHIP_BONAIRE {
73            Self::GFX7
74        } else if asic_name >= ASIC_NAME::CHIP_TAHITI {
75            Self::GFX6
76        } else {
77            Self::CLASS_UNKNOWN
78        }
79    }
80}
81
82impl CHIP_CLASS {
83    pub fn has_packed_math_16bit(&self) -> bool {
84        *self >= Self::GFX9
85    }
86
87    pub fn cu_group(&self) -> u8 {
88        if *self >= Self::GFX10 {
89            2
90        } else {
91            1
92        }
93    }
94}
95
96#[test]
97fn test_amdgpu_chip_class() {
98    assert_eq!(ASIC_NAME::CHIP_GFX1200.chip_class(), CHIP_CLASS::GFX12);
99    assert_eq!(ASIC_NAME::CHIP_GFX1150.chip_class(), CHIP_CLASS::GFX11_5);
100    assert_eq!(ASIC_NAME::CHIP_GFX1103_R2X.chip_class(), CHIP_CLASS::GFX11);
101    assert_eq!(ASIC_NAME::CHIP_GFX1100.chip_class(), CHIP_CLASS::GFX11);
102    assert_eq!(ASIC_NAME::CHIP_GFX1036.chip_class(), CHIP_CLASS::GFX10_3);
103    assert_eq!(ASIC_NAME::CHIP_GFX1013.chip_class(), CHIP_CLASS::GFX10);
104    assert_eq!(ASIC_NAME::CHIP_GFX940.chip_class(), CHIP_CLASS::GFX9);
105    assert_eq!(ASIC_NAME::CHIP_POLARIS11.chip_class(), CHIP_CLASS::GFX8);
106}
107
108use std::fmt;
109impl fmt::Display for CHIP_CLASS {
110    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
111        match self {
112            Self::CLASS_UNKNOWN => write!(f, "Unknown"),
113            Self::R300 => write!(f, "R300"),
114            Self::R400 => write!(f, "R400"),
115            Self::R500 => write!(f, "R500"),
116            Self::R600 => write!(f, "R600"),
117            Self::R700 => write!(f, "R700"),
118            Self::EVERGREEN => write!(f, "Evergreen"),
119            Self::CAYMAN => write!(f, "Cayman"),
120            Self::GFX6 => write!(f, "GFX6"),
121            Self::GFX7 => write!(f, "GFX7"),
122            Self::GFX8 => write!(f, "GFX8"),
123            Self::GFX9 => write!(f, "GFX9"),
124            Self::GFX10 => write!(f, "GFX10"),
125            Self::GFX10_3 => write!(f, "GFX10_3"),
126            Self::GFX11 => write!(f, "GFX11"),
127            Self::GFX11_5 => write!(f, "GFX11_5"),
128            Self::GFX12 => write!(f, "GFX12"),
129        }
130    }
131}