Skip to content

Commit

Permalink
Add arch major/minor info
Browse files Browse the repository at this point in the history
  • Loading branch information
solidpixel committed Aug 16, 2024
1 parent 9ccc6ee commit 23b3713
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 4 deletions.
4 changes: 3 additions & 1 deletion source/arm_gpuinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

/*
* Copyright (c) 2023 ARM Limited.
* Copyright (c) 2023-2024 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -119,6 +119,8 @@ int main(int argc, char *argv[])
std::cout << "GPU configuration:\n";
std::cout << " Name: " << info.gpu_name << "\n";
std::cout << " Architecture: " << info.architecture_name << "\n";
std::cout << " Architecture version: " << info.architecture_major
<< "." << info.architecture_minor <<"\n";
std::cout << " Model number: 0x" << std::hex << info.gpu_id << std::dec << "\n";
std::cout << " Core count: " << info.num_shader_cores << "\n";
std::cout << " Core mask: 0x" << std::hex << info.shader_core_mask << std::dec << "\n";
Expand Down
41 changes: 40 additions & 1 deletion source/libgpuinfo.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2024 ARM Limited.
* Copyright (c) 2021-2024 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -766,6 +766,8 @@ struct get_gpuprops_t {
raw_l2_features = 29,
/** Raw core features. */
raw_core_features = 30,
/** Raw GPU id. */
raw_gpu_id = 55,
/** Raw thread max threads. */
raw_thread_max_threads = 56,
/** Raw thread max workgroup size. */
Expand Down Expand Up @@ -830,6 +832,7 @@ class prop_decoder {
bool decode(gpuinfo& info) {
bool success = true;

uint64_t raw_gpu_id {};
uint64_t raw_core_features {};
uint64_t raw_thread_features {};

Expand All @@ -856,6 +859,9 @@ class prop_decoder {
// Bus width stored as log2(bus width) in top 8 bits
info.num_bus_bits = 1UL << ((value >> 24) & 0xFF);
break;
case prop_id_t::raw_gpu_id:
raw_gpu_id = value;
break;
case prop_id_t::raw_core_features:
raw_core_features = value;
break;
Expand All @@ -875,6 +881,31 @@ class prop_decoder {
}
}

// Decode architecture versions
constexpr uint64_t bits4 { 0xF };
constexpr uint64_t bits8 { 0xFF };

constexpr uint64_t compat_shift { 28 };
constexpr uint64_t compat { 0xF };
bool is_64bit_id = ((raw_gpu_id >> compat_shift) & bits4) == compat;

// Old-style 32-bit ID
if (!is_64bit_id)
{
constexpr uint64_t arch_major_offset { 28 };
constexpr uint64_t arch_minor_offset { 24 };
info.architecture_major = (raw_gpu_id >> arch_major_offset) & bits4;
info.architecture_minor = (raw_gpu_id >> arch_minor_offset) & bits4;
}
// New-style 64-bit ID
else
{
constexpr uint64_t arch_major_offset { 56 };
constexpr uint64_t arch_minor_offset { 48 };
info.architecture_major = (raw_gpu_id >> arch_major_offset) & bits8;
info.architecture_minor = (raw_gpu_id >> arch_minor_offset) & bits8;
}

info.num_exec_engines = get_num_exec_engines(
info.gpu_id,
info.num_shader_cores,
Expand Down Expand Up @@ -1121,6 +1152,14 @@ bool instance::init_props_pre_r21() {
return false;
}

// Old core must have 32-bit GPU ID
uint32_t raw_gpu_id = props.props.raw_props.gpu_id;
constexpr unsigned int arch_major_offset { 28 };
constexpr unsigned int arch_minor_offset { 24 };
constexpr unsigned int nibble { 0xF };
info_.architecture_major = (raw_gpu_id >> arch_major_offset) & nibble;
info_.architecture_minor = (raw_gpu_id >> arch_minor_offset) & nibble;

info_.gpu_id = props.props.core_props.product_id;
info_.num_l2_bytes = 1UL << props.props.l2_props.log2_cache_size;
info_.num_l2_slices = props.props.l2_props.num_l2_slices;
Expand Down
10 changes: 8 additions & 2 deletions source/libgpuinfo.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2021-2023 ARM Limited.
* Copyright (c) 2021-2024 Arm Limited.
*
* SPDX-License-Identifier: MIT
*
Expand Down Expand Up @@ -64,7 +64,7 @@

namespace libgpuinfo {

/** Mali GPU information. */
/** Arm GPU information. */
struct gpuinfo
{
/** GPU name */
Expand All @@ -76,6 +76,12 @@ struct gpuinfo
/** GPU ID */
uint32_t gpu_id;

/** GPU architecture major version */
uint32_t architecture_major;

/** GPU architecture minor version */
uint32_t architecture_minor;

/** Number of shader cores */
uint32_t num_shader_cores;

Expand Down

0 comments on commit 23b3713

Please sign in to comment.