Last active
October 7, 2019 13:57
-
-
Save psiha/f1a29ea3b6fad2eb89fa7b1d1fc9d912 to your computer and use it in GitHub Desktop.
System topology
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct gpu { /*todo*/ }; | |
struct cpu // a type-of system_resource (intentionally not derving from it - avoid paying for RTTI if the user does not need it) | |
{ | |
enum vendor { /*e.g. AMD, Intel, Samsung, Apple...*/ }; | |
enum isa { /*e.g. x86, ARMv8, ...*/ }; | |
enum microarchitecture { /*e.g. Haswell, Cortex A75, ...*/ }; | |
struct register_bank | |
{ | |
// TODO, in principle overlaps with SIMD TS | |
static constexpr register_bank get( isa concrete_isa ) noexcept; | |
}; | |
struct cache | |
{ | |
uint32_t size; | |
uint32_t associativity; | |
uint32_t sets; | |
uint32_t partitions; | |
uint32_t line_size; | |
bool unified; | |
bool inclusive; | |
bool complex_indexing; | |
}; | |
struct processor // basic/final processing unit i.e. logical core within a physical core | |
{ | |
struct | |
{ | |
uint32_t smt ; // SMT (hyperthread) ID within a core | |
auto platform; // OS specific ID, e.g. on Linux for accessing /sys/devices/system/cpu/cpu<platform>/ | |
auto hardware; // HW vendor specific ID (if any), e.g. APIC ID for x86 | |
} id; | |
}; | |
struct core // physical core | |
{ | |
enum state_t { online, throttled, offline }; | |
auto id; | |
bool out_of_order; // TODO free function to get this from microarchitecture | |
microarchitecture arch; | |
uint64_t nominal_frequency; | |
uint64_t current_frequency() const noexcept; | |
uint8_t temperature() const noexcept; | |
state_t state() const noexcept; | |
cache instruction_cache; | |
cache data_cache_levels[]; | |
processor processors[]; | |
}; | |
struct cluster | |
{ | |
auto id; | |
core cores[]; | |
}; | |
struct package | |
{ | |
auto id; | |
string_view name() const noexcept; // SoC or processor chip model name | |
template <typename Resource> | |
ranges::view<Resource const> integrated_other_resources() const; // e.g. an integrated GPU; Resource can be system_resource, for polymorphic traversal of all available additional HW resources, or e.g. gpu for querying just about GPU(s) | |
cluster clusters[]; | |
}; | |
package packages[]; | |
} // struct cpu | |
using system_resource = std::variant<cpu, gpu, ...>; | |
class system_topology | |
{ | |
public: | |
cpu cpus[]; | |
gpu gpus[]; | |
// TODO memory, information/queries about interconnections between individual components etc... | |
using default_execution_resource = cpu; // execution hardware used for firing up the 'C++ abstract machine' and entering main | |
using current_execution_resource = /*compilation context dependent*/; | |
template <class TravesalPolicy> | |
ranges::view</*type based on TravesalPolicy*/> traverse( TravesalPolicy const & ) const noexcept; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Points of discussion: