HALDLS
ppu.h
Go to the documentation of this file.
1 #pragma once
2 #include <array>
3 #include <iosfwd>
4 
5 #include "halco/common/geometry.h"
6 #include "halco/common/iter_all.h"
7 #include "halco/common/typed_heap_array.h"
8 #include "halco/hicann-dls/vx/ppu.h"
9 #include "haldls/cerealization.h"
10 #include "haldls/vx/common.h"
12 #include "haldls/vx/genpybind.h"
13 #include "haldls/vx/traits.h"
14 #include "hate/visibility.h"
15 
16 namespace fisch::vx {
17 class OmnibusChipOverJTAG;
18 class Omnibus;
19 } // namespace fisch::vx
20 
21 namespace haldls {
22 namespace vx GENPYBIND_TAG_HALDLS_VX {
23 
24 class GENPYBIND(visible) PPUMemoryWord
25 {
26 public:
27  typedef halco::hicann_dls::vx::PPUMemoryWordOnDLS coordinate_type;
28  typedef std::true_type is_leaf_node;
29 
30  struct GENPYBIND(inline_base("*")) Value
31  : public halco::common::detail::RantWrapper<Value, uint_fast32_t, 0xffffffff, 0>
32  {
33  constexpr explicit Value(uintmax_t const val = 0) : rant_t(val) {}
34  };
35 
36  typedef uint32_t raw_type;
37  // verify that the underlying word size matches the value type size
38  static_assert(
39  static_cast<raw_type>(-1) == Value::max, "ray_type size does not match Value type.");
40 
41  explicit PPUMemoryWord(Value value = Value()) SYMBOL_VISIBLE;
42 
43  GENPYBIND(getter_for(value))
44  Value get_value() const SYMBOL_VISIBLE;
45  GENPYBIND(setter_for(value))
46  void set_value(Value const& value) SYMBOL_VISIBLE;
47 
48  bool operator==(PPUMemoryWord const& other) const SYMBOL_VISIBLE;
49  bool operator!=(PPUMemoryWord const& other) const SYMBOL_VISIBLE;
50 
51  GENPYBIND(stringstream)
52  friend std::ostream& operator<<(std::ostream& os, PPUMemoryWord const& pmw) SYMBOL_VISIBLE;
53 
54  static size_t constexpr config_size_in_words GENPYBIND(hidden) = 1;
55  template <typename AddressT>
56  static std::array<AddressT, config_size_in_words> addresses(coordinate_type const& word)
57  SYMBOL_VISIBLE GENPYBIND(hidden);
58  template <typename WordT>
59  std::array<WordT, config_size_in_words> encode() const SYMBOL_VISIBLE GENPYBIND(hidden);
60  template <typename WordT>
61  void decode(std::array<WordT, config_size_in_words> const& data) SYMBOL_VISIBLE
62  GENPYBIND(hidden);
63 
64 private:
65  friend class cereal::access;
66  template <class Archive>
67  void serialize(Archive& ar, std::uint32_t const version) SYMBOL_VISIBLE;
68 
69  Value m_value;
70 };
71 
72 EXTERN_INSTANTIATE_CEREAL_SERIALIZE(PPUMemoryWord)
73 
74 class GENPYBIND(visible) PPUMemoryBlock
75 {
76 public:
77  typedef halco::hicann_dls::vx::PPUMemoryBlockOnDLS coordinate_type;
78  typedef std::false_type has_local_data;
79 
80  typedef std::vector<PPUMemoryWord> words_type;
81 
82  typedef halco::hicann_dls::vx::PPUMemoryBlockSize size_type;
83 
84  explicit PPUMemoryBlock(
85  size_type size = size_type(halco::hicann_dls::vx::PPUMemoryWordOnPPU::size)) SYMBOL_VISIBLE;
86 
87  PPUMemoryWord& at(size_t index) SYMBOL_VISIBLE;
88  PPUMemoryWord const& at(size_t index) const SYMBOL_VISIBLE;
89  PPUMemoryWord& operator[](size_t index) SYMBOL_VISIBLE;
90  PPUMemoryWord const& operator[](size_t index) const SYMBOL_VISIBLE;
91 
92  PPUMemoryBlock get_subblock(size_t begin, size_type length) const SYMBOL_VISIBLE;
93  void set_subblock(size_t begin, PPUMemoryBlock const& subblock) SYMBOL_VISIBLE;
94 
95  size_type size() const SYMBOL_VISIBLE;
96 
97  GENPYBIND(getter_for(words))
98  words_type const& get_words() const SYMBOL_VISIBLE;
99  GENPYBIND(setter_for(words))
100  void set_words(words_type const& words) SYMBOL_VISIBLE;
101 
102  bool operator==(PPUMemoryBlock const& other) const SYMBOL_VISIBLE;
103  bool operator!=(PPUMemoryBlock const& other) const SYMBOL_VISIBLE;
104  GENPYBIND(stringstream)
105  friend std::ostream& operator<<(std::ostream& os, PPUMemoryBlock const& pmb) SYMBOL_VISIBLE;
110  std::string to_string() const SYMBOL_VISIBLE;
111 
112  friend detail::VisitPreorderImpl<PPUMemoryBlock>;
113 
114 private:
115  friend class cereal::access;
116  template <class Archive>
117  void serialize(Archive& ar, std::uint32_t const version) SYMBOL_VISIBLE;
118 
119  words_type m_words;
120 };
121 
122 EXTERN_INSTANTIATE_CEREAL_SERIALIZE(PPUMemoryBlock)
123 
124 class GENPYBIND(visible) PPUMemory
125 {
126 public:
127  typedef halco::hicann_dls::vx::PPUMemoryOnDLS coordinate_type;
128  typedef std::false_type has_local_data;
129 
130  typedef halco::common::
131  typed_heap_array<PPUMemoryWord, halco::hicann_dls::vx::PPUMemoryWordOnPPU>
132  words_type GENPYBIND(opaque);
133 
134  explicit PPUMemory(words_type const& words = words_type()) SYMBOL_VISIBLE;
135 
136  GENPYBIND(getter_for(words))
137  words_type get_words() const SYMBOL_VISIBLE;
138  GENPYBIND(setter_for(words))
139  void set_words(words_type const& words) SYMBOL_VISIBLE;
140 
141  PPUMemoryWord::Value get_word(halco::hicann_dls::vx::PPUMemoryWordOnPPU const& pos) const
142  SYMBOL_VISIBLE;
143  void set_word(
144  halco::hicann_dls::vx::PPUMemoryWordOnPPU const& pos,
145  PPUMemoryWord::Value const& word) SYMBOL_VISIBLE;
146 
147  PPUMemoryBlock get_block(halco::hicann_dls::vx::PPUMemoryBlockOnPPU const& block_coord) const
148  SYMBOL_VISIBLE;
149  void set_block(
150  halco::hicann_dls::vx::PPUMemoryBlockOnPPU const& block_coord,
151  PPUMemoryBlock const& block) SYMBOL_VISIBLE;
152 
159  void load_from_file(std::string const& filename) SYMBOL_VISIBLE;
160 
161  bool operator==(PPUMemory const& other) const SYMBOL_VISIBLE;
162  bool operator!=(PPUMemory const& other) const SYMBOL_VISIBLE;
163  GENPYBIND(stringstream)
164  friend std::ostream& operator<<(std::ostream& os, PPUMemory const& pm) SYMBOL_VISIBLE;
165 
166  friend detail::VisitPreorderImpl<PPUMemory>;
167 
168 private:
169  friend class cereal::access;
170  template <class Archive>
171  void serialize(Archive& ar, std::uint32_t const version) SYMBOL_VISIBLE;
172 
173  words_type m_words;
174 };
175 
176 EXTERN_INSTANTIATE_CEREAL_SERIALIZE(PPUMemory)
177 
178 class GENPYBIND(visible) PPUControlRegister : public DifferentialWriteTrait
179 {
180 public:
181  typedef halco::hicann_dls::vx::PPUControlRegisterOnDLS coordinate_type;
182  typedef std::true_type is_leaf_node;
183 
184  PPUControlRegister() SYMBOL_VISIBLE;
185 
186  GENPYBIND(getter_for(cache_controller_enable))
187  bool get_cache_controller_enable() const SYMBOL_VISIBLE;
188  GENPYBIND(setter_for(cache_controller_enable))
189  void set_cache_controller_enable(bool const value) SYMBOL_VISIBLE;
190 
191  GENPYBIND(getter_for(inhibit_reset))
192  bool get_inhibit_reset() const SYMBOL_VISIBLE;
193  GENPYBIND(setter_for(inhibit_reset))
194  void set_inhibit_reset(bool const value) SYMBOL_VISIBLE;
195 
196  /* - force_clock_on: Forces the clock to be on, even if the ppu is sleeping
197  * - force_clock_off: Forces the clock to be off, which is weaker than
198  * forcing the clock on
199  * None of these is needed in normal operation. Setting the inhibit_reset
200  * bit starts the execution. If the program finishes, the clock is stopped again. */
201  GENPYBIND(getter_for(force_clock_on))
202  bool get_force_clock_on() const SYMBOL_VISIBLE;
203  GENPYBIND(setter_for(force_clock_on))
204  void set_force_clock_on(bool const value) SYMBOL_VISIBLE;
205  GENPYBIND(getter_for(force_clock_off))
206  bool get_force_clock_off() const SYMBOL_VISIBLE;
207  GENPYBIND(setter_for(force_clock_off))
208  void set_force_clock_off(bool const value) SYMBOL_VISIBLE;
209 
210  GENPYBIND(stringstream)
211  friend std::ostream& operator<<(std::ostream&, PPUControlRegister const&) SYMBOL_VISIBLE;
212 
213  bool operator==(PPUControlRegister const& other) const SYMBOL_VISIBLE;
214  bool operator!=(PPUControlRegister const& other) const SYMBOL_VISIBLE;
215 
216  static size_t constexpr config_size_in_words GENPYBIND(hidden) = 1;
217  template <typename AddressT>
218  static std::array<AddressT, config_size_in_words> addresses(coordinate_type const& coord)
219  SYMBOL_VISIBLE GENPYBIND(hidden);
220  template <typename WordT>
221  std::array<WordT, config_size_in_words> encode() const SYMBOL_VISIBLE GENPYBIND(hidden);
222  template <typename WordT>
223  void decode(std::array<WordT, config_size_in_words> const& data) SYMBOL_VISIBLE
224  GENPYBIND(hidden);
225 
226 private:
227  friend class cereal::access;
228  template <class Archive>
229  void serialize(Archive& ar, std::uint32_t const version) SYMBOL_VISIBLE;
230 
231  bool m_cache_controller_enable;
232  bool m_inhibit_reset;
233  bool m_force_clock_on;
234  bool m_force_clock_off;
235 };
236 
237 EXTERN_INSTANTIATE_CEREAL_SERIALIZE(PPUControlRegister)
238 
239 class GENPYBIND(visible) PPUStatusRegister
240 {
241 public:
242  typedef halco::hicann_dls::vx::PPUStatusRegisterOnDLS coordinate_type;
243  typedef std::true_type is_leaf_node;
244 
245  PPUStatusRegister() SYMBOL_VISIBLE;
246 
247  // Read only property
248  GENPYBIND(getter_for(sleep))
249  bool get_sleep() const SYMBOL_VISIBLE;
250 
251  GENPYBIND(stringstream)
252  friend std::ostream& operator<<(std::ostream&, PPUStatusRegister const&) SYMBOL_VISIBLE;
253 
254  bool operator==(PPUStatusRegister const& other) const SYMBOL_VISIBLE;
255  bool operator!=(PPUStatusRegister const& other) const SYMBOL_VISIBLE;
256 
257  static size_t constexpr read_config_size_in_words GENPYBIND(hidden) = 1;
258  static size_t constexpr write_config_size_in_words GENPYBIND(hidden) = 0;
259  template <typename AddressT>
260  static std::array<AddressT, read_config_size_in_words> read_addresses(
261  coordinate_type const& coord) SYMBOL_VISIBLE GENPYBIND(hidden);
262  template <typename AddressT>
263  static std::array<AddressT, write_config_size_in_words> write_addresses(
264  coordinate_type const& coord) SYMBOL_VISIBLE GENPYBIND(hidden);
265  template <typename WordT>
266  std::array<WordT, write_config_size_in_words> encode() const SYMBOL_VISIBLE GENPYBIND(hidden);
267  template <typename WordT>
268  void decode(std::array<WordT, read_config_size_in_words> const& data) SYMBOL_VISIBLE
269  GENPYBIND(hidden);
270 
271 private:
272  friend class cereal::access;
273  template <class Archive>
274  void serialize(Archive& ar, std::uint32_t const version) SYMBOL_VISIBLE;
275 
276  bool m_sleep;
277 };
278 
279 EXTERN_INSTANTIATE_CEREAL_SERIALIZE(PPUStatusRegister)
280 
281 namespace detail {
282 
283 template <>
284 struct BackendContainerTrait<PPUMemoryWord>
285  : public BackendContainerBase<
286  PPUMemoryWord,
287  fisch::vx::word_access_type::Omnibus,
288  fisch::vx::word_access_type::OmnibusChipOverJTAG>
289 {};
290 
291 template <>
292 struct BackendContainerTrait<PPUMemoryBlock>
293  : public BackendContainerBase<
294  PPUMemoryBlock,
295  fisch::vx::word_access_type::Omnibus,
296  fisch::vx::word_access_type::OmnibusChipOverJTAG>
297 {};
298 
299 template <>
300 struct BackendContainerTrait<PPUMemory>
301  : public BackendContainerBase<
302  PPUMemory,
303  fisch::vx::word_access_type::Omnibus,
304  fisch::vx::word_access_type::OmnibusChipOverJTAG>
305 {};
306 
307 template <>
308 struct VisitPreorderImpl<PPUMemoryBlock>
309 {
310  template <typename ContainerT, typename VisitorT>
311  static void call(
312  ContainerT& config, PPUMemoryBlock::coordinate_type const& coord, VisitorT&& visitor)
313  {
314  using namespace halco::hicann_dls::vx;
315  auto const ppu_coord = coord.toPPUOnDLS();
316 
317  if (coord.toPPUMemoryBlockOnPPU().toPPUMemoryBlockSize() != config.size()) {
318  std::stringstream ss;
319  ss << "container size(" << config.size() << ") and " << coord << " size do not match.";
320  throw std::runtime_error(ss.str());
321  }
322 
323  visitor(coord, config);
324 
325  for (size_t counter = 0; counter < config.size(); counter++) {
326  auto word_coord = PPUMemoryWordOnDLS(
327  PPUMemoryWordOnPPU(coord.toPPUMemoryBlockOnPPU().toMin() + counter), ppu_coord);
328  visit_preorder(config.m_words.at(counter), word_coord, visitor);
329  }
330  }
331 };
332 
333 template <>
335 {
336  template <typename ContainerT, typename VisitorT>
337  static void call(
338  ContainerT& config, PPUMemory::coordinate_type const& coord, VisitorT&& visitor)
339  {
340  using halco::common::iter_all;
341  using namespace halco::hicann_dls::vx;
342 
343  visitor(coord, config);
344 
345  for (auto const word : iter_all<PPUMemoryWordOnPPU>()) {
346  // No std::forward for visitor argument, as we want to pass a reference to the
347  // nested visitor in any case, even if it was passed as an rvalue to this function.
349  config.m_words[word], PPUMemoryWordOnDLS(word, coord.toPPUOnDLS()), visitor);
350  }
351  }
352 };
353 
354 template <>
356  : public BackendContainerBase<
357  PPUStatusRegister,
358  fisch::vx::word_access_type::Omnibus,
359  fisch::vx::word_access_type::OmnibusChipOverJTAG>
360 {};
361 
362 template <>
364  : public BackendContainerBase<
365  PPUControlRegister,
366  fisch::vx::word_access_type::Omnibus,
367  fisch::vx::word_access_type::OmnibusChipOverJTAG>
368 {};
369 
370 template <>
372 {
373  return PPUMemoryBlock(coord.toPPUMemoryBlockSize());
374 }
375 
376 } // namespace detail
377 
378 } // namespace vx
379 } // namespace haldls
380 
381 namespace std {
382 
383 HALCO_GEOMETRY_HASH_CLASS(haldls::vx::PPUMemoryWord::Value)
384 
385 } // namespace std
halco::hicann_dls::vx::PPUMemoryBlockOnDLS coordinate_type
Definition: ppu.h:77
halco::hicann_dls::vx::PPUMemoryOnDLS coordinate_type
Definition: ppu.h:127
halco::hicann_dls::vx::PPUMemoryWordOnDLS coordinate_type
Definition: ppu.h:27
std::true_type is_leaf_node
Definition: ppu.h:28
#define GENPYBIND_TAG_HALDLS_VX
Definition: genpybind.h:4
PPUMemoryBlock coordinate_to_container(PPUMemoryBlock::coordinate_type const &coord)
Definition: ppu.h:371
haldls::vx::PPUMemoryBlock PPUMemoryBlock
Definition: is_readable.h:22
void visit_preorder(ContainerT &config, CoordinateT const &coord, VisitorT &&visitor)
Apply the specified visitor to all containers in a hierarchy by doing a pre-order tree traversal.
Definition: common.h:37
Backend container trait base.
Definition: traits.h:77
static void call(ContainerT &config, PPUMemory::coordinate_type const &coord, VisitorT &&visitor)
Definition: ppu.h:337
Implementation detail of the visit_preorder() free function (q.v.).
Definition: common.h:17