Skip to content

Instantly share code, notes, and snippets.

@psiha
Last active October 7, 2019 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save psiha/f1a29ea3b6fad2eb89fa7b1d1fc9d912 to your computer and use it in GitHub Desktop.
Save psiha/f1a29ea3b6fad2eb89fa7b1d1fc9d912 to your computer and use it in GitHub Desktop.
System topology
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;
};
@psiha
Copy link
Author

psiha commented Oct 7, 2019

Points of discussion:

  1. for hierarchical resources (such as CPU packages above): should a child node have a 'pointer' to its parent (e.g. should one be able to retrieve the parent cpu::core instance from a cpu::processor instance)?
  2. mechanism for returning/reporting 'N/A'/'does not apply' info (e.g. tribools, optionals...)
  3. optional callbacks for topology changes
  4. whether info like system_topology::*_execution_resource should perhaps go to the executors proposal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment