geopm 3.1.1.dev410+g40bf96ed
GEOPM - Global Extensible Open Power Manager
Loading...
Searching...
No Matches
TreeComm.hpp
Go to the documentation of this file.
1/*
2 * Copyright (c) 2015 - 2024 Intel Corporation
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef TREECOMM_HPP_INCLUDE
7#define TREECOMM_HPP_INCLUDE
8
9#include <stddef.h>
10#include <cstdint>
11#include <memory>
12#include <vector>
13
14namespace geopm
15{
16 class Comm;
17
19 {
20 public:
21 TreeComm() = default;
22 virtual ~TreeComm() = default;
27 virtual int num_level_controlled(void) const = 0;
32 virtual int max_level(void) const = 0;
36 virtual int root_level(void) const = 0;
38 virtual int level_rank(int level) const = 0;
41 virtual int level_size(int level) const = 0;
43 virtual void send_up(int level, const std::vector<double> &sample) = 0;
45 virtual void send_down(int level, const std::vector<std::vector<double> > &policy) = 0;
48 virtual bool receive_up(int level, std::vector<std::vector<double> > &sample) = 0;
50 virtual bool receive_down(int level, std::vector<double> &policy) = 0;
53 virtual size_t overhead_send(void) const = 0;
55 static std::vector<int> fan_out(const std::shared_ptr<Comm> &comm);
56 };
57
58 class TreeCommLevel;
59
60 class TreeCommImp : public TreeComm
61 {
62 public:
63 TreeCommImp(std::shared_ptr<Comm> comm,
64 int num_send_down,
65 int num_send_up);
66 TreeCommImp(std::shared_ptr<Comm> comm,
67 const std::vector<int> &fan_out,
68 int num_level_ctl,
69 int num_send_down,
70 int num_send_up,
71 std::vector<std::shared_ptr<TreeCommLevel> > mock_level);
72 virtual ~TreeCommImp();
73 int num_level_controlled(void) const override;
74 int max_level(void) const override;
75 int root_level(void) const override;
76 int level_rank(int level) const override;
77 int level_size(int level) const override;
78 void send_down(int level, const std::vector<std::vector<double> > &policy) override;
79 void send_up(int level, const std::vector<double> &sample) override;
80 bool receive_down(int level, std::vector<double> &policy) override;
81 bool receive_up(int level, std::vector<std::vector<double> > &sample) override;
82 size_t overhead_send(void) const override;
83 private:
84 int num_level_controlled(const std::vector<int> &coords);
85 std::vector<std::shared_ptr<TreeCommLevel> > init_level(
86 std::shared_ptr<Comm> comm_cart, int root_level);
87 std::shared_ptr<Comm> m_comm;
90 std::vector<int> m_fan_out;
91 int m_root_level;
93 int m_num_level_ctl;
95 int m_max_level;
97 int m_num_node;
98 int m_num_send_down;
99 int m_num_send_up;
100 std::vector<std::shared_ptr<TreeCommLevel> > m_level_ctl;
101 };
102}
103
104#endif
Definition TreeComm.hpp:19
virtual int num_level_controlled(void) const =0
Returns the number of tree levels controlled by the Controller on this node. This determines which le...
TreeComm()=default
virtual ~TreeComm()=default
virtual int root_level(void) const =0
Returns the level of the root of the tree, which is equal to the number of levels in the tree.
virtual int level_rank(int level) const =0
Returns the rank of the given level.
virtual void send_up(int level, const std::vector< double > &sample)=0
Send samples up to the parent within a level.
virtual int max_level(void) const =0
Returns the number of tree levels participated in by the Controller on this node. This determines whi...
virtual bool receive_down(int level, std::vector< double > &policy)=0
Receive policies from the parent within a level.
virtual size_t overhead_send(void) const =0
Returns the total number of bytes sent from the entire tree.
virtual void send_down(int level, const std::vector< std::vector< double > > &policy)=0
Send policies down to children within a level.
virtual int level_size(int level) const =0
Returns the number of children for each parent in the given level.
virtual bool receive_up(int level, std::vector< std::vector< double > > &sample)=0
Receive samples from children within a level.
static std::vector< int > fan_out(const std::shared_ptr< Comm > &comm)
Returns the number of children at each level.
Definition TreeComm.cpp:177
Definition TreeComm.hpp:61
void send_down(int level, const std::vector< std::vector< double > > &policy) override
Send policies down to children within a level.
Definition TreeComm.cpp:141
virtual ~TreeCommImp()
Definition TreeComm.cpp:99
void send_up(int level, const std::vector< double > &sample) override
Send samples up to the parent within a level.
Definition TreeComm.cpp:132
bool receive_down(int level, std::vector< double > &policy) override
Receive policies from the parent within a level.
Definition TreeComm.cpp:159
int level_size(int level) const override
Returns the number of children for each parent in the given level.
Definition TreeComm.cpp:123
int max_level(void) const override
Returns the number of tree levels participated in by the Controller on this node. This determines whi...
Definition TreeComm.cpp:69
int num_level_controlled(void) const override
Returns the number of tree levels controlled by the Controller on this node. This determines which le...
Definition TreeComm.cpp:104
int level_rank(int level) const override
Returns the rank of the given level.
Definition TreeComm.cpp:114
size_t overhead_send(void) const override
Returns the total number of bytes sent from the entire tree.
Definition TreeComm.cpp:168
int root_level(void) const override
Returns the level of the root of the tree, which is equal to the number of levels in the tree.
Definition TreeComm.cpp:109
bool receive_up(int level, std::vector< std::vector< double > > &sample) override
Receive samples from children within a level.
Definition TreeComm.cpp:150
Definition TreeCommLevel.hpp:15
Definition Accumulator.cpp:12