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"
14 #include "hate/visibility.h"
17 class OmnibusChipOverJTAG;
30 struct GENPYBIND(inline_base("*
")) Value
31 : public halco::common::detail::RantWrapper<Value, uint_fast32_t, 0xffffffff, 0>
33 constexpr explicit Value(uintmax_t const val = 0) : rant_t(val) {}
36 typedef uint32_t raw_type;
37 // verify that the underlying word size matches the value type size
39 static_cast<raw_type>(-1) == Value::max, "ray_type size does not match
Value type.
");
41 explicit PPUMemoryWord(Value value = Value()) SYMBOL_VISIBLE;
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;
48 bool operator==(PPUMemoryWord const& other) const SYMBOL_VISIBLE;
49 bool operator!=(PPUMemoryWord const& other) const SYMBOL_VISIBLE;
51 GENPYBIND(stringstream)
52 friend std::ostream& operator<<(std::ostream& os, PPUMemoryWord const& pmw) SYMBOL_VISIBLE;
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
65 friend class cereal::access;
66 template <class Archive>
67 void serialize(Archive& ar, std::uint32_t const version) SYMBOL_VISIBLE;
72 EXTERN_INSTANTIATE_CEREAL_SERIALIZE(PPUMemoryWord)
74 class GENPYBIND(visible) PPUMemoryBlock
77 typedef halco::hicann_dls::vx::PPUMemoryBlockOnDLS coordinate_type;
78 typedef std::false_type has_local_data;
80 typedef std::vector<PPUMemoryWord> words_type;
82 typedef halco::hicann_dls::vx::PPUMemoryBlockSize size_type;
84 explicit PPUMemoryBlock(
85 size_type size = size_type(halco::hicann_dls::vx::PPUMemoryWordOnPPU::size)) SYMBOL_VISIBLE;
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;
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;
95 size_type size() const SYMBOL_VISIBLE;
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;
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;
112 friend detail::VisitPreorderImpl<PPUMemoryBlock>;
115 friend class cereal::access;
116 template <class Archive>
117 void serialize(Archive& ar, std::uint32_t const version) SYMBOL_VISIBLE;
122 EXTERN_INSTANTIATE_CEREAL_SERIALIZE(PPUMemoryBlock)
124 class GENPYBIND(visible) PPUMemory
127 typedef halco::hicann_dls::vx::PPUMemoryOnDLS coordinate_type;
128 typedef std::false_type has_local_data;
130 typedef halco::common::
131 typed_heap_array<PPUMemoryWord, halco::hicann_dls::vx::PPUMemoryWordOnPPU>
132 words_type GENPYBIND(opaque);
134 explicit PPUMemory(words_type const& words = words_type()) SYMBOL_VISIBLE;
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;
141 PPUMemoryWord::Value get_word(halco::hicann_dls::vx::PPUMemoryWordOnPPU const& pos) const
144 halco::hicann_dls::vx::PPUMemoryWordOnPPU const& pos,
145 PPUMemoryWord::Value const& word) SYMBOL_VISIBLE;
147 PPUMemoryBlock get_block(halco::hicann_dls::vx::PPUMemoryBlockOnPPU const& block_coord) const
150 halco::hicann_dls::vx::PPUMemoryBlockOnPPU const& block_coord,
151 PPUMemoryBlock const& block) SYMBOL_VISIBLE;
159 void load_from_file(std::string const& filename) SYMBOL_VISIBLE;
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;
166 friend detail::VisitPreorderImpl<PPUMemory>;
169 friend class cereal::access;
170 template <class Archive>
171 void serialize(Archive& ar, std::uint32_t const version) SYMBOL_VISIBLE;
176 EXTERN_INSTANTIATE_CEREAL_SERIALIZE(PPUMemory)
178 class GENPYBIND(visible) PPUControlRegister : public DifferentialWriteTrait
181 typedef halco::hicann_dls::vx::PPUControlRegisterOnDLS coordinate_type;
182 typedef std::true_type is_leaf_node;
184 PPUControlRegister() SYMBOL_VISIBLE;
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;
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;
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;
210 GENPYBIND(stringstream)
211 friend std::ostream& operator<<(std::ostream&, PPUControlRegister const&) SYMBOL_VISIBLE;
213 bool operator==(PPUControlRegister const& other) const SYMBOL_VISIBLE;
214 bool operator!=(PPUControlRegister const& other) const SYMBOL_VISIBLE;
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
227 friend class cereal::access;
228 template <class Archive>
229 void serialize(Archive& ar, std::uint32_t const version) SYMBOL_VISIBLE;
231 bool m_cache_controller_enable;
232 bool m_inhibit_reset;
233 bool m_force_clock_on;
234 bool m_force_clock_off;
237 EXTERN_INSTANTIATE_CEREAL_SERIALIZE(PPUControlRegister)
239 class GENPYBIND(visible) PPUStatusRegister
242 typedef halco::hicann_dls::vx::PPUStatusRegisterOnDLS coordinate_type;
243 typedef std::true_type is_leaf_node;
245 PPUStatusRegister() SYMBOL_VISIBLE;
247 // Read only property
248 GENPYBIND(getter_for(sleep))
249 bool get_sleep() const SYMBOL_VISIBLE;
251 GENPYBIND(stringstream)
252 friend std::ostream& operator<<(std::ostream&, PPUStatusRegister const&) SYMBOL_VISIBLE;
254 bool operator==(PPUStatusRegister const& other) const SYMBOL_VISIBLE;
255 bool operator!=(PPUStatusRegister const& other) const SYMBOL_VISIBLE;
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
272 friend class cereal::access;
273 template <class Archive>
274 void serialize(Archive& ar, std::uint32_t const version) SYMBOL_VISIBLE;
279 EXTERN_INSTANTIATE_CEREAL_SERIALIZE(PPUStatusRegister)
284 struct BackendContainerTrait<PPUMemoryWord>
285 : public BackendContainerBase<
287 fisch::vx::word_access_type::Omnibus,
288 fisch::vx::word_access_type::OmnibusChipOverJTAG>
292 struct BackendContainerTrait<PPUMemoryBlock>
293 : public BackendContainerBase<
295 fisch::vx::word_access_type::Omnibus,
296 fisch::vx::word_access_type::OmnibusChipOverJTAG>
300 struct BackendContainerTrait<PPUMemory>
301 : public BackendContainerBase<
303 fisch::vx::word_access_type::Omnibus,
304 fisch::vx::word_access_type::OmnibusChipOverJTAG>
308 struct VisitPreorderImpl<PPUMemoryBlock>
310 template <typename ContainerT, typename VisitorT>
312 ContainerT& config, PPUMemoryBlock::coordinate_type const& coord, VisitorT&& visitor)
314 using namespace halco::hicann_dls::vx;
315 auto const ppu_coord = coord.toPPUOnDLS();
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());
323 visitor(coord, config);
325 for (
size_t counter = 0; counter < config.size(); counter++) {
326 auto word_coord = PPUMemoryWordOnDLS(
327 PPUMemoryWordOnPPU(coord.toPPUMemoryBlockOnPPU().toMin() + counter), ppu_coord);
336 template <
typename ContainerT,
typename VisitorT>
340 using halco::common::iter_all;
343 visitor(coord, config);
345 for (
auto const word : iter_all<PPUMemoryWordOnPPU>()) {
349 config.m_words[word], PPUMemoryWordOnDLS(word, coord.toPPUOnDLS()), visitor);
358 fisch::vx::word_access_type::Omnibus,
359 fisch::vx::word_access_type::OmnibusChipOverJTAG>
366 fisch::vx::word_access_type::Omnibus,
367 fisch::vx::word_access_type::OmnibusChipOverJTAG>
halco::hicann_dls::vx::PPUMemoryBlockOnDLS coordinate_type
halco::hicann_dls::vx::PPUMemoryOnDLS coordinate_type
halco::hicann_dls::vx::PPUMemoryWordOnDLS coordinate_type
std::true_type is_leaf_node
#define GENPYBIND_TAG_HALDLS_VX
PPUMemoryBlock coordinate_to_container(PPUMemoryBlock::coordinate_type const &coord)
haldls::vx::PPUMemoryBlock PPUMemoryBlock
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.
Backend container trait base.
static void call(ContainerT &config, PPUMemory::coordinate_type const &coord, VisitorT &&visitor)
Implementation detail of the visit_preorder() free function (q.v.).