File indexing completed on 2025-01-18 10:01:40
0001
0002
0003
0004
0005 #pragma once
0006 #include <cstddef>
0007 #include <ostream>
0008 #include <vector>
0009
0010 class JProcessorMapping {
0011
0012 public:
0013
0014 enum class AffinityStrategy { None, MemoryBound, ComputeBound };
0015 enum class LocalityStrategy { Global, SocketLocal, NumaDomainLocal, CoreLocal, CpuLocal };
0016
0017 void initialize(AffinityStrategy affinity, LocalityStrategy locality);
0018
0019 inline size_t get_loc_count() const {
0020 return m_loc_count;
0021 }
0022
0023 inline size_t get_cpu_id(size_t worker_id) const {
0024 return (m_initialized) ? m_mapping[worker_id % m_mapping.size()].cpu_id : worker_id;
0025 }
0026
0027 inline size_t get_loc_id(size_t worker_id) const {
0028 return (m_initialized) ? m_mapping[worker_id % m_mapping.size()].location_id : 0;
0029 }
0030
0031 inline AffinityStrategy get_affinity() const {
0032 return m_affinity_strategy;
0033 }
0034
0035 inline LocalityStrategy get_locality() const {
0036 return m_locality_strategy;
0037 }
0038
0039 friend std::ostream& operator<<(std::ostream& os, const JProcessorMapping& m);
0040 friend std::ostream& operator<<(std::ostream& os, const AffinityStrategy& s);
0041 friend std::ostream& operator<<(std::ostream& os, const LocalityStrategy& s);
0042
0043 private:
0044
0045 struct Row {
0046 size_t location_id;
0047 size_t cpu_id;
0048 size_t core_id;
0049 size_t numa_domain_id;
0050 size_t socket_id;
0051 };
0052
0053 AffinityStrategy m_affinity_strategy = AffinityStrategy::None;
0054 LocalityStrategy m_locality_strategy = LocalityStrategy::Global;
0055 std::vector<Row> m_mapping;
0056 size_t m_loc_count = 1;
0057 bool m_initialized = false;
0058 std::string m_error_msg = "Not initialized yet";
0059 };
0060
0061