rogue
Loading...
Searching...
No Matches
Variable.cpp
Go to the documentation of this file.
1
17#include "rogue/Directives.h"
18
20
21#include <sys/time.h>
22
23#include <cmath>
24#include <cstdio>
25#include <cstring>
26#include <iomanip>
27#include <iostream>
28#include <memory>
29#include <sstream>
30#include <string>
31#include <vector>
32
33#include "rogue/GeneralError.h"
34#include "rogue/GilRelease.h"
35#include "rogue/ScopedGil.h"
38
40
41#ifndef NO_PYTHON
42 #include <boost/python.hpp>
43namespace bp = boost::python;
44#endif
45
47rim::VariablePtr rim::Variable::create(std::string name,
48 std::string mode,
49 double minimum,
50 double maximum,
51 uint64_t offset,
52 std::vector<uint32_t> bitOffset,
53 std::vector<uint32_t> bitSize,
54 bool overlapEn,
55 bool verify,
56 bool bulkOpEn,
57 bool updateNotify,
58 uint32_t modelId,
59 bool byteReverse,
60 bool bitReverse,
61 uint32_t binPoint,
62 uint32_t numValues,
63 uint32_t valueBits,
64 uint32_t valueStride,
65 uint32_t retryCount) {
66 rim::VariablePtr v = std::make_shared<rim::Variable>(name,
67 mode,
68 minimum,
69 maximum,
70 offset,
71 bitOffset,
72 bitSize,
74 verify,
76 updateNotify,
77 modelId,
78 byteReverse,
79 bitReverse,
80 binPoint,
85 return (v);
86}
87
88// Setup class for use in python
89void rim::Variable::setup_python() {
90#ifndef NO_PYTHON
91 bp::class_<rim::VariableWrap, rim::VariableWrapPtr, boost::noncopyable>("Variable",
92 bp::init<std::string,
93 std::string,
94 bp::object,
95 bp::object,
96 uint64_t,
97 bp::object,
98 bp::object,
99 bool,
100 bool,
101 bool,
102 bool,
103 bp::object,
104 bp::object,
105 uint32_t>())
106 .def("_varBytes", &rim::Variable::varBytes)
107 .def("_offset", &rim::Variable::offset)
108 .def("_shiftOffsetDown", &rim::Variable::shiftOffsetDown)
109 .def("_updatePath", &rim::Variable::updatePath)
110 .def("_overlapEn", &rim::Variable::overlapEn)
111 .def("_verifyEn", &rim::Variable::verifyEn)
112 .def("_bitOffset", &rim::VariableWrap::bitOffset)
113 .def("_bitSize", &rim::VariableWrap::bitSize)
114 .def("_get", &rim::VariableWrap::get)
115 .def("_set", &rim::VariableWrap::set)
116 .def("_rateTest", &rim::VariableWrap::rateTest)
117 .def("_queueUpdate", &rim::Variable::queueUpdate, &rim::VariableWrap::defQueueUpdate)
118 .def("_setLogLevel", &rim::Variable::setLogLevel)
119 .def("_getDumpValue", &rim::Variable::getDumpValue)
120 .def("_numValues", &rim::Variable::numValues)
121 .def("_valueBits", &rim::Variable::valueBits)
122 .def("_valueStride", &rim::Variable::valueStride)
123 .def("_retryCount", &rim::Variable::retryCount);
124#endif
125}
126
127// Create a Hub device with a given offset
128rim::Variable::Variable(std::string name,
129 std::string mode,
130 double minimum,
131 double maximum,
132 uint64_t offset,
133 std::vector<uint32_t> bitOffset,
134 std::vector<uint32_t> bitSize,
135 bool overlapEn,
136 bool verifyEn,
137 bool bulkOpEn,
138 bool updateNotify,
139 uint32_t modelId,
140 bool byteReverse,
141 bool bitReverse,
142 uint32_t binPoint,
143 uint32_t numValues,
144 uint32_t valueBits,
145 uint32_t valueStride,
146 uint32_t retryCount) {
147 uint32_t x;
148 uint32_t bl;
149
150 name_ = name;
151 path_ = name;
152 mode_ = mode;
153 modelId_ = modelId;
154 offset_ = offset;
155 bitOffset_ = bitOffset;
156 bitSize_ = bitSize;
157 overlapEn_ = overlapEn;
158 verifyEn_ = verifyEn;
159 byteReverse_ = byteReverse;
160 bitReverse_ = bitReverse;
161 bulkOpEn_ = bulkOpEn;
162 updateNotify_ = updateNotify;
163 minValue_ = minimum;
164 maxValue_ = maximum;
165 binPoint_ = binPoint;
166 numValues_ = numValues;
167 valueBits_ = valueBits;
168 valueStride_ = valueStride;
169 retryCount_ = retryCount;
170
171 // Not a list variable
172 if (numValues_ == 0) {
173 // Compute bit total
174 bitTotal_ = bitSize_[0];
175 for (x = 1; x < bitSize_.size(); x++) bitTotal_ += bitSize_[x];
176
177 // Compute rounded up byte size
178 byteSize_ = static_cast<int>(std::ceil(static_cast<float>(bitTotal_) / 8.0));
179
180 lowTranByte_ = reinterpret_cast<uint32_t*>(malloc(sizeof(uint32_t)));
181 highTranByte_ = reinterpret_cast<uint32_t*>(malloc(sizeof(uint32_t)));
182
183 // Init remaining fields
184 valueBytes_ = byteSize_;
185 valueBits_ = bitTotal_;
186 valueStride_ = bitTotal_;
187
188 // List variables
189 } else {
190 // Compute bit total
191 bitTotal_ = bitSize_[0];
192
193 // Compute rounded up byte size
194 byteSize_ = static_cast<int>(std::ceil(static_cast<float>(bitTotal_) / 8.0));
195
196 // Compute total bit range of accessed bits
197 valueBytes_ = static_cast<uint32_t>(std::ceil(static_cast<float>(valueBits_) / 8.0));
198
199 // High and low byte tracking
200 lowTranByte_ = reinterpret_cast<uint32_t*>(malloc(numValues_ * sizeof(uint32_t)));
201 highTranByte_ = reinterpret_cast<uint32_t*>(malloc(numValues_ * sizeof(uint32_t)));
202 }
203
204 // Byte array for fast copies
205 fastByte_ = NULL;
206
207 // Determine if fast byte copies can be utilized
208 // Bit offset vector must have one entry, the offset must be byte aligned and the total number of bits must be byte
209 // aligned
210 if ((bitOffset_.size() == 1) && (bitOffset_[0] % 8 == 0) && (bitSize_[0] % 8 == 0)) {
211 // Standard variable
212 if (numValues_ == 0) {
213 fastByte_ = reinterpret_cast<uint32_t*>(malloc(sizeof(uint32_t)));
214
215 // List variable
216 } else if ((valueBits_ % 8) == 0 && (valueStride_ % 8) == 0) {
217 fastByte_ = reinterpret_cast<uint32_t*>(malloc(numValues_ * sizeof(uint32_t)));
218 }
219 }
220 stale_ = false;
221 block_ = NULL;
222
223 // Call aligning function to init values
224 shiftOffsetDown(0, 1);
225
226 // Custom data is NULL for now
227 customData_ = NULL;
228
229 // Set default C++ pointers
230 setByteArray_ = NULL;
231 getByteArray_ = NULL;
232 setUInt_ = NULL;
233 getUInt_ = NULL;
234 setInt_ = NULL;
235 getInt_ = NULL;
236 setBool_ = NULL;
237 getBool_ = NULL;
238 setString_ = NULL;
239 getString_ = NULL;
240 setFloat_ = NULL;
241 getFloat_ = NULL;
242 setFloat16_ = NULL;
243 getFloat16_ = NULL;
244 setFloat8_ = NULL;
245 getFloat8_ = NULL;
246 setDouble_ = NULL;
247 getDouble_ = NULL;
248 setFixed_ = NULL;
249 getFixed_ = NULL;
250 setBFloat16_ = NULL;
251 getBFloat16_ = NULL;
252 setTensorFloat32_ = NULL;
253 getTensorFloat32_ = NULL;
254 setFloat6_ = NULL;
255 getFloat6_ = NULL;
256 setFloat4_ = NULL;
257 getFloat4_ = NULL;
258
259 // Define set function
260 switch (modelId_) {
261 case rim::PyFunc:
262 break;
263
264 case rim::Bytes:
265 setByteArray_ = &rim::Block::setByteArray;
266 break;
267
268 case rim::UInt:
269 if (valueBits_ > 64)
270 setByteArray_ = &rim::Block::setByteArray;
271 else
272 setUInt_ = &rim::Block::setUInt;
273 break;
274
275 case rim::Int:
276 if (valueBits_ > 64)
277 setByteArray_ = &rim::Block::setByteArray;
278 else
279 setInt_ = &rim::Block::setInt;
280 break;
281
282 case rim::Bool:
283 setBool_ = &rim::Block::setBool;
284 break;
285
286 case rim::String:
287 setString_ = &rim::Block::setString;
288 break;
289
290 case rim::Float:
291 setFloat_ = &rim::Block::setFloat;
292 break;
293
294 case rim::Float16:
295 setFloat16_ = &rim::Block::setFloat16;
296 break;
297
298 case rim::Float8:
299 setFloat8_ = &rim::Block::setFloat8;
300 break;
301
302 case rim::BFloat16:
303 setBFloat16_ = &rim::Block::setBFloat16;
304 break;
305
307 setTensorFloat32_ = &rim::Block::setTensorFloat32;
308 break;
309
310 case rim::Float6:
311 setFloat6_ = &rim::Block::setFloat6;
312 break;
313
314 case rim::Float4:
315 setFloat4_ = &rim::Block::setFloat4;
316 break;
317
318 case rim::Double:
319 setDouble_ = &rim::Block::setDouble;
320 break;
321
322 case rim::Fixed:
323 setFixed_ = &rim::Block::setFixed;
324 break;
325
326 case rim::UFixed:
327 setFixed_ = &rim::Block::setUFixed;
328 break;
329
330 default:
331 break;
332 }
333
334 // Define get function, C++
335 switch (modelId_) {
336 case rim::PyFunc:
337 break;
338
339 case rim::Bytes:
340 getByteArray_ = &rim::Block::getByteArray;
341 break;
342
343 case rim::UInt:
344 if (valueBits_ > 64)
345 getByteArray_ = &rim::Block::getByteArray;
346 else
347 getUInt_ = &rim::Block::getUInt;
348 break;
349
350 case rim::Int:
351 if (valueBits_ > 64)
352 getByteArray_ = &rim::Block::getByteArray;
353 else
354 getInt_ = &rim::Block::getInt;
355 break;
356
357 case rim::Bool:
358 getBool_ = &rim::Block::getBool;
359 break;
360
361 case rim::String:
362 getString_ = &rim::Block::getString;
363 break;
364
365 case rim::Float:
366 getFloat_ = &rim::Block::getFloat;
367 break;
368
369 case rim::Float16:
370 getFloat16_ = &rim::Block::getFloat16;
371 break;
372
373 case rim::Float8:
374 getFloat8_ = &rim::Block::getFloat8;
375 break;
376
377 case rim::BFloat16:
378 getBFloat16_ = &rim::Block::getBFloat16;
379 break;
380
382 getTensorFloat32_ = &rim::Block::getTensorFloat32;
383 break;
384
385 case rim::Float6:
386 getFloat6_ = &rim::Block::getFloat6;
387 break;
388
389 case rim::Float4:
390 getFloat4_ = &rim::Block::getFloat4;
391 break;
392
393 case rim::Double:
394 getDouble_ = &rim::Block::getDouble;
395 break;
396
397 case rim::Fixed:
398 getFixed_ = &rim::Block::getFixed;
399 break;
400
401 case rim::UFixed:
402 getFixed_ = &rim::Block::getUFixed;
403 break;
404
405 default:
406 break;
407 }
408
409#ifndef NO_PYTHON
410
411 // Define set function, python
412 switch (modelId_) {
413 case rim::PyFunc:
414 setFuncPy_ = &rim::Block::setPyFunc;
415 break;
416
417 case rim::Bytes:
418 setFuncPy_ = &rim::Block::setByteArrayPy;
419 break;
420
421 case rim::UInt:
422 if (valueBits_ > 64)
423 setFuncPy_ = &rim::Block::setPyFunc;
424 else
425 setFuncPy_ = &rim::Block::setUIntPy;
426 break;
427
428 case rim::Int:
429 if (valueBits_ > 64)
430 setFuncPy_ = &rim::Block::setPyFunc;
431 else
432 setFuncPy_ = &rim::Block::setIntPy;
433 break;
434
435 case rim::Bool:
436 setFuncPy_ = &rim::Block::setBoolPy;
437 break;
438
439 case rim::String:
440 setFuncPy_ = &rim::Block::setStringPy;
441 break;
442
443 case rim::Float:
444 setFuncPy_ = &rim::Block::setFloatPy;
445 break;
446
447 case rim::Float16:
448 setFuncPy_ = &rim::Block::setFloat16Py;
449 break;
450
451 case rim::Float8:
452 setFuncPy_ = &rim::Block::setFloat8Py;
453 break;
454
455 case rim::BFloat16:
456 setFuncPy_ = &rim::Block::setBFloat16Py;
457 break;
458
460 setFuncPy_ = &rim::Block::setTensorFloat32Py;
461 break;
462
463 case rim::Float6:
464 setFuncPy_ = &rim::Block::setFloat6Py;
465 break;
466
467 case rim::Float4:
468 setFuncPy_ = &rim::Block::setFloat4Py;
469 break;
470
471 case rim::Double:
472 setFuncPy_ = &rim::Block::setDoublePy;
473 break;
474
475 case rim::Fixed:
476 case rim::UFixed:
477 setFuncPy_ = &rim::Block::setFixedPy;
478 break;
479
480 default:
481 getFuncPy_ = NULL;
482 break;
483 }
484
485 // Define get function, python
486 switch (modelId_) {
487 case rim::PyFunc:
488 getFuncPy_ = &rim::Block::getPyFunc;
489 break;
490
491 case rim::Bytes:
492 getFuncPy_ = &rim::Block::getByteArrayPy;
493 break;
494
495 case rim::UInt:
496 if (valueBits_ > 64)
497 getFuncPy_ = &rim::Block::getPyFunc;
498 else
499 getFuncPy_ = &rim::Block::getUIntPy;
500 break;
501
502 case rim::Int:
503 if (valueBits_ > 64)
504 getFuncPy_ = &rim::Block::getPyFunc;
505 else
506 getFuncPy_ = &rim::Block::getIntPy;
507 break;
508
509 case rim::Bool:
510 getFuncPy_ = &rim::Block::getBoolPy;
511 break;
512
513 case rim::String:
514 getFuncPy_ = &rim::Block::getStringPy;
515 break;
516
517 case rim::Float:
518 getFuncPy_ = &rim::Block::getFloatPy;
519 break;
520
521 case rim::Float16:
522 getFuncPy_ = &rim::Block::getFloat16Py;
523 break;
524
525 case rim::Float8:
526 getFuncPy_ = &rim::Block::getFloat8Py;
527 break;
528
529 case rim::BFloat16:
530 getFuncPy_ = &rim::Block::getBFloat16Py;
531 break;
532
534 getFuncPy_ = &rim::Block::getTensorFloat32Py;
535 break;
536
537 case rim::Float6:
538 getFuncPy_ = &rim::Block::getFloat6Py;
539 break;
540
541 case rim::Float4:
542 getFuncPy_ = &rim::Block::getFloat4Py;
543 break;
544
545 case rim::Double:
546 getFuncPy_ = &rim::Block::getDoublePy;
547 break;
548
549 case rim::Fixed:
550 case rim::UFixed:
551 getFuncPy_ = &rim::Block::getFixedPy;
552 break;
553
554 default:
555 getFuncPy_ = NULL;
556 break;
557 }
558
559#endif
560}
561
562// Destroy the variable
563rim::Variable::~Variable() {
564 if (lowTranByte_ != NULL) free(lowTranByte_);
565 if (highTranByte_ != NULL) free(highTranByte_);
566 if (fastByte_ != NULL) free(fastByte_);
567}
568
569// Shift offset down
570void rim::Variable::shiftOffsetDown(uint32_t shift, uint32_t minSize) {
571 uint32_t x;
572
573 if (shift != 0) {
574 offset_ -= shift;
575 for (x = 0; x < bitOffset_.size(); x++) bitOffset_[x] += shift * 8;
576 }
577
578 // Byte ranges are computed in 64-bit integer arithmetic. The previous float
579 // path lost precision once a bit position exceeded 2^24 (2 MiB into the
580 // block), shifting the high byte of large list variables by one.
581 const uint64_t minBits = static_cast<uint64_t>(minSize) * 8;
582
583 // Standard variable
584 if (numValues_ == 0) {
585 // Compute total bit range of accessed bytes
586 const uint64_t highBit =
587 static_cast<uint64_t>(bitOffset_[bitOffset_.size() - 1]) + bitSize_[bitSize_.size() - 1];
588 varBytes_ = static_cast<uint32_t>(((highBit + minBits - 1) / minBits) * minSize);
589
590 // Compute the lowest byte, aligned to min access
591 lowTranByte_[0] = static_cast<uint32_t>((static_cast<uint64_t>(bitOffset_[0]) / minBits) * minSize);
592
593 // Compute the highest byte, aligned to min access
594 highTranByte_[0] = varBytes_ - 1;
595 staleHighByte_ = highTranByte_[0];
596
597 // List variable
598 } else {
599 for (x = 0; x < numValues_; x++) {
600 const uint64_t lowBit = static_cast<uint64_t>(bitOffset_[0]) + static_cast<uint64_t>(x) * valueStride_;
601 const uint64_t highBit = lowBit + valueBits_;
602 lowTranByte_[x] = static_cast<uint32_t>((lowBit / minBits) * minSize);
603 highTranByte_[x] = static_cast<uint32_t>(((highBit + minBits - 1) / minBits) * minSize - 1);
604 }
605
606 // Compute total bit range of accessed bytes
607 varBytes_ = highTranByte_[numValues_ - 1] + 1;
608 staleHighByte_ = highTranByte_[numValues_ - 1];
609 }
610
611 // Adjust fast copy locations
612 if (fastByte_ != NULL) {
613 if (numValues_ == 0) {
614 fastByte_[0] = bitOffset_[0] / 8;
615
616 // List variable
617 } else {
618 for (x = 0; x < numValues_; x++) fastByte_[x] = (bitOffset_[0] + (valueStride_ * x)) / 8;
619 }
620 }
621
622 staleLowByte_ = lowTranByte_[0];
623}
624
625void rim::Variable::updatePath(std::string path) {
626 path_ = path;
627}
628
630double rim::Variable::minimum() {
631 return minValue_;
632}
633
635double rim::Variable::maximum() {
636 return maxValue_;
637}
638
640uint32_t rim::Variable::varBytes() {
641 return varBytes_;
642}
643
645uint64_t rim::Variable::offset() {
646 return offset_;
647}
648
650bool rim::Variable::verifyEn() {
651 return verifyEn_;
652}
653
655bool rim::Variable::overlapEn() {
656 return overlapEn_;
657}
658
660bool rim::Variable::bulkOpEn() {
661 return bulkOpEn_;
662}
663
664#ifndef NO_PYTHON
665// Create a Variable
666rim::VariableWrap::VariableWrap(std::string name,
667 std::string mode,
668 bp::object minimum,
669 bp::object maximum,
670 uint64_t offset,
671 bp::object bitOffset,
672 bp::object bitSize,
673 bool overlapEn,
674 bool verify,
675 bool bulkOpEn,
676 bool updateNotify,
677 bp::object model,
678 bp::object listData,
679 uint32_t retryCount)
680
681 : rim::Variable(name,
682 mode,
683 py_object_convert<double>(minimum),
684 py_object_convert<double>(maximum),
685 offset,
686 py_list_to_std_vector<uint32_t>(bitOffset),
687 py_list_to_std_vector<uint32_t>(bitSize),
688 overlapEn,
689 verify,
690 bulkOpEn,
691 updateNotify,
692 bp::extract<uint32_t>(model.attr("modelId")),
693 bp::extract<bool>(model.attr("isBigEndian")),
694 bp::extract<bool>(model.attr("bitReverse")),
695 bp::extract<uint32_t>(model.attr("binPoint")),
696 bp::extract<uint32_t>(listData.attr("numValues")),
697 bp::extract<uint32_t>(listData.attr("valueBits")),
698 bp::extract<uint32_t>(listData.attr("valueStride")),
699 retryCount) {
700 model_ = model;
701}
702
704void rim::VariableWrap::set(bp::object& value, int32_t index) {
705 if (setFuncPy_ == NULL || block_->blockPyTrans()) return;
706 (block_->*setFuncPy_)(value, this, index);
707}
708
710bp::object rim::VariableWrap::get(int32_t index) {
711 if (getFuncPy_ == NULL) {
712 bp::handle<> handle(bp::borrowed(Py_None));
713 return bp::object(handle);
714 }
715 return (block_->*getFuncPy_)(this, index);
716}
717
718// Set data using python function
719bp::object rim::VariableWrap::toBytes(bp::object& value) {
720 return model_.attr("toBytes")(value);
721}
722
723// Get data using python function
724bp::object rim::VariableWrap::fromBytes(bp::object& value) {
725 return model_.attr("fromBytes")(value);
726}
727
728void rim::VariableWrap::defQueueUpdate() {
729 rim::Variable::queueUpdate();
730}
731
732// Queue update
733void rim::VariableWrap::queueUpdate() {
735
736 if (bp::override pb = this->get_override("_queueUpdate")) {
737 try {
738 pb();
739 return;
740 } catch (...) {
741 PyErr_Print();
742 }
743 }
744}
745
746bp::object rim::VariableWrap::bitOffset() {
747 return std_vector_to_py_list<uint32_t>(bitOffset_);
748}
749
750bp::object rim::VariableWrap::bitSize() {
751 return std_vector_to_py_list<uint32_t>(bitSize_);
752}
753
754#endif // ! NO_PYTHON
755
756void rim::Variable::queueUpdate() {}
757
758void rim::Variable::rateTest() {
759 uint64_t x;
760
761 struct timeval stime;
762 struct timeval etime;
763 struct timeval dtime;
764
765 uint64_t count = 1000000;
766 double durr;
767 double rate;
768 uint32_t ret;
769
770 gettimeofday(&stime, NULL);
771 for (x = 0; x < count; ++x) {
772 ret = getUInt();
773 }
774 gettimeofday(&etime, NULL);
775
776 timersub(&etime, &stime, &dtime);
777 durr = dtime.tv_sec + static_cast<float>(dtime.tv_usec) / 1.0e6;
778 rate = count / durr;
779
780 printf("\nVariable c++ get: Read %" PRIu64 " times in %f seconds. Rate = %f\n", count, durr, rate);
781
782 gettimeofday(&stime, NULL);
783 for (x = 0; x < count; ++x) {
784 setUInt(x);
785 }
786 gettimeofday(&etime, NULL);
787
788 timersub(&etime, &stime, &dtime);
789 durr = dtime.tv_sec + static_cast<float>(dtime.tv_usec) / 1.0e6;
790 rate = count / durr;
791
792 printf("\nVariable c++ set: Wrote %" PRIu64 " times in %f seconds. Rate = %f\n", count, durr, rate);
793}
794
795void rim::Variable::setLogLevel(uint32_t level) {
796 if (block_) block_->setLogLevel(level);
797}
798
799void rim::Variable::read() {
800 block_->read(this);
801}
802
804std::string rim::Variable::getDumpValue(bool read) {
805 std::stringstream ret;
806 uint32_t x;
807 int32_t index;
808
809 uint8_t byteData[valueBytes_];
810
811 memset(byteData, 0, valueBytes_);
812
813 if (read) block_->read(this);
814
815 ret << path_ << " =";
816
817 if (numValues_ == 0)
818 index = -1;
819 else
820 index = 0;
821
822 while (index < static_cast<int32_t>(numValues_)) {
823 ret << " ";
824
825 switch (modelId_) {
826 case rim::Bytes:
827 (block_->*getByteArray_)(byteData, this, index);
828 ret << "0x";
829 for (x = 0; x < valueBytes_; x++)
830 ret << std::setfill('0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
831 break;
832
833 case rim::UInt:
834 if (valueBits_ > 64) {
835 (block_->*getByteArray_)(byteData, this, index);
836 ret << "0x";
837 for (x = 0; x < valueBytes_; x++)
838 ret << std::setfill('0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
839 } else {
840 ret << (block_->*getUInt_)(this, index);
841 }
842 break;
843
844 case rim::Int:
845 if (valueBits_ > 64) {
846 (block_->*getByteArray_)(byteData, this, index);
847 ret << "0x";
848 for (x = 0; x < valueBytes_; x++)
849 ret << std::setfill('0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
850 } else {
851 ret << (block_->*getInt_)(this, index);
852 }
853 break;
854
855 case rim::Bool:
856 ret << (block_->*getBool_)(this, index);
857 break;
858
859 case rim::String:
860 ret << (block_->*getString_)(this, index);
861 break;
862
863 case rim::Float:
864 ret << (block_->*getFloat_)(this, index);
865 break;
866
867 case rim::Double:
868 ret << (block_->*getDouble_)(this, index);
869 break;
870
871 case rim::Fixed:
872 ret << block_->getFixed(this, index);
873 break;
874
875 case rim::UFixed:
876 ret << block_->getUFixed(this, index);
877 break;
878
879 case rim::Float16:
880 ret << block_->getFloat16(this, index);
881 break;
882
883 case rim::Float8:
884 ret << block_->getFloat8(this, index);
885 break;
886
887 case rim::BFloat16:
888 ret << block_->getBFloat16(this, index);
889 break;
890
892 ret << block_->getTensorFloat32(this, index);
893 break;
894
895 case rim::Float6:
896 ret << block_->getFloat6(this, index);
897 break;
898
899 case rim::Float4:
900 ret << block_->getFloat4(this, index);
901 break;
902
903 default:
904 ret << "UNDEFINED";
905 break;
906 }
907 index++;
908 }
909
910 ret << "\n";
911 return ret.str();
912}
913
915// C++ Byte Array
917
918void rim::Variable::setByteArray(uint8_t* value, int32_t index) {
919 if (setByteArray_ == NULL)
920 throw(rogue::GeneralError::create("Variable::setByteArray", "Wrong set type for variable %s", path_.c_str()));
921
922 (block_->*setByteArray_)(value, this, index);
923 block_->write(this, index);
924}
925
926void rim::Variable::getByteArray(uint8_t* value, int32_t index) {
927 if (getByteArray_ == NULL)
928 throw(rogue::GeneralError::create("Variable::getByteArray", "Wrong get type for variable %s", path_.c_str()));
929
930 block_->read(this, index);
931 (block_->*getByteArray_)(value, this, index);
932}
933
935// C++ Uint
937
938void rim::Variable::setUInt(uint64_t& value, int32_t index) {
939 if (setUInt_ == NULL)
940 throw(rogue::GeneralError::create("Variable::setUInt", "Wrong set type for variable %s", path_.c_str()));
941
942 (block_->*setUInt_)(value, this, index);
943 block_->write(this, index);
944}
945
946uint64_t rim::Variable::getUInt(int32_t index) {
947 if (getUInt_ == NULL)
948 throw(rogue::GeneralError::create("Variable::getUInt", "Wrong get type for variable %s", path_.c_str()));
949
950 block_->read(this, index);
951 return (block_->*getUInt_)(this, index);
952}
953
955// C++ int
957
958void rim::Variable::setInt(int64_t& value, int32_t index) {
959 if (setInt_ == NULL)
960 throw(rogue::GeneralError::create("Variable::setInt", "Wrong set type for variable %s", path_.c_str()));
961
962 (block_->*setInt_)(value, this, index);
963 block_->write(this, index);
964}
965
966int64_t rim::Variable::getInt(int32_t index) {
967 if (getInt_ == NULL)
968 throw(rogue::GeneralError::create("Variable::getInt", "Wrong get type for variable %s", path_.c_str()));
969
970 block_->read(this, index);
971 return (block_->*getInt_)(this, index);
972}
973
975// C++ bool
977
978void rim::Variable::setBool(bool& value, int32_t index) {
979 if (setBool_ == NULL)
980 throw(rogue::GeneralError::create("Variable::setBool", "Wrong set type for variable %s", path_.c_str()));
981
982 (block_->*setBool_)(value, this, index);
983 block_->write(this, index);
984}
985
986bool rim::Variable::getBool(int32_t index) {
987 if (getBool_ == NULL)
988 throw(rogue::GeneralError::create("Variable::getBool", "Wrong get type for variable %s", path_.c_str()));
989
990 block_->read(this, index);
991 return (block_->*getBool_)(this, index);
992}
993
995// C++ String
997
998void rim::Variable::setString(const std::string& value, int32_t index) {
999 if (setString_ == NULL)
1000 throw(rogue::GeneralError::create("Variable::setString", "Wrong set type for variable %s", path_.c_str()));
1001
1002 (block_->*setString_)(value, this, index);
1003 block_->write(this, index);
1004}
1005
1006std::string rim::Variable::getString(int32_t index) {
1007 if (getString_ == NULL)
1008 throw(rogue::GeneralError::create("Variable::getString", "Wrong get type for variable %s", path_.c_str()));
1009
1010 block_->read(this, index);
1011 return (block_->*getString_)(this, index);
1012}
1013
1014void rim::Variable::getValue(std::string& valueRet, int32_t index) {
1015 if (getString_ == NULL) {
1016 throw(rogue::GeneralError::create("Variable::getValue", "Wrong get type for variable %s", path_.c_str()));
1017 } else {
1018 block_->read(this, index);
1019 block_->getValue(this, valueRet, index);
1020 }
1021}
1022
1024// C++ Float
1026
1027void rim::Variable::setFloat(float& value, int32_t index) {
1028 if (setFloat_ == NULL)
1029 throw(rogue::GeneralError::create("Variable::setFloat", "Wrong set type for variable %s", path_.c_str()));
1030
1031 (block_->*setFloat_)(value, this, index);
1032 block_->write(this, index);
1033}
1034
1035float rim::Variable::getFloat(int32_t index) {
1036 if (getFloat_ == NULL)
1037 throw(rogue::GeneralError::create("Variable::getFloat", "Wrong get type for variable %s", path_.c_str()));
1038
1039 block_->read(this, index);
1040 return (block_->*getFloat_)(this, index);
1041}
1042
1044// C++ Float16 (half-precision)
1046
1047void rim::Variable::setFloat16(float& value, int32_t index) {
1048 if (setFloat16_ == NULL)
1049 throw(rogue::GeneralError::create("Variable::setFloat16", "Wrong set type for variable %s", path_.c_str()));
1050
1051 (block_->*setFloat16_)(value, this, index);
1052 block_->write(this, index);
1053}
1054
1055float rim::Variable::getFloat16(int32_t index) {
1056 if (getFloat16_ == NULL)
1057 throw(rogue::GeneralError::create("Variable::getFloat16", "Wrong get type for variable %s", path_.c_str()));
1058
1059 block_->read(this, index);
1060 return (block_->*getFloat16_)(this, index);
1061}
1062
1064// C++ Float8 (E4M3)
1066
1067void rim::Variable::setFloat8(float& value, int32_t index) {
1068 if (setFloat8_ == NULL)
1069 throw(rogue::GeneralError::create("Variable::setFloat8", "Wrong set type for variable %s", path_.c_str()));
1070
1071 (block_->*setFloat8_)(value, this, index);
1072 block_->write(this, index);
1073}
1074
1075float rim::Variable::getFloat8(int32_t index) {
1076 if (getFloat8_ == NULL)
1077 throw(rogue::GeneralError::create("Variable::getFloat8", "Wrong get type for variable %s", path_.c_str()));
1078
1079 block_->read(this, index);
1080 return (block_->*getFloat8_)(this, index);
1081}
1082
1084// C++ BFloat16 (Brain Float 16)
1086
1087void rim::Variable::setBFloat16(float& value, int32_t index) {
1088 if (setBFloat16_ == NULL)
1089 throw(rogue::GeneralError::create("Variable::setBFloat16", "Wrong set type for variable %s", path_.c_str()));
1090
1091 (block_->*setBFloat16_)(value, this, index);
1092 block_->write(this, index);
1093}
1094
1095float rim::Variable::getBFloat16(int32_t index) {
1096 if (getBFloat16_ == NULL)
1097 throw(rogue::GeneralError::create("Variable::getBFloat16", "Wrong get type for variable %s", path_.c_str()));
1098
1099 block_->read(this, index);
1100 return (block_->*getBFloat16_)(this, index);
1101}
1102
1104// C++ TensorFloat32 (NVIDIA TF32)
1106
1107void rim::Variable::setTensorFloat32(float& value, int32_t index) {
1108 if (setTensorFloat32_ == NULL)
1109 throw(rogue::GeneralError::create("Variable::setTensorFloat32", "Wrong set type for variable %s", path_.c_str()));
1110
1111 (block_->*setTensorFloat32_)(value, this, index);
1112 block_->write(this, index);
1113}
1114
1115float rim::Variable::getTensorFloat32(int32_t index) {
1116 if (getTensorFloat32_ == NULL)
1117 throw(rogue::GeneralError::create("Variable::getTensorFloat32", "Wrong get type for variable %s", path_.c_str()));
1118
1119 block_->read(this, index);
1120 return (block_->*getTensorFloat32_)(this, index);
1121}
1122
1124// C++ Float6 (E3M2)
1126
1127void rim::Variable::setFloat6(float& value, int32_t index) {
1128 if (setFloat6_ == NULL)
1129 throw(rogue::GeneralError::create("Variable::setFloat6", "Wrong set type for variable %s", path_.c_str()));
1130
1131 (block_->*setFloat6_)(value, this, index);
1132 block_->write(this, index);
1133}
1134
1135float rim::Variable::getFloat6(int32_t index) {
1136 if (getFloat6_ == NULL)
1137 throw(rogue::GeneralError::create("Variable::getFloat6", "Wrong get type for variable %s", path_.c_str()));
1138
1139 block_->read(this, index);
1140 return (block_->*getFloat6_)(this, index);
1141}
1142
1144// C++ Float4 (E2M1)
1146
1147void rim::Variable::setFloat4(float& value, int32_t index) {
1148 if (setFloat4_ == NULL)
1149 throw(rogue::GeneralError::create("Variable::setFloat4", "Wrong set type for variable %s", path_.c_str()));
1150
1151 (block_->*setFloat4_)(value, this, index);
1152 block_->write(this, index);
1153}
1154
1155float rim::Variable::getFloat4(int32_t index) {
1156 if (getFloat4_ == NULL)
1157 throw(rogue::GeneralError::create("Variable::getFloat4", "Wrong get type for variable %s", path_.c_str()));
1158
1159 block_->read(this, index);
1160 return (block_->*getFloat4_)(this, index);
1161}
1162
1164// C++ double
1166
1167void rim::Variable::setDouble(double& value, int32_t index) {
1168 if (setDouble_ == NULL)
1169 throw(rogue::GeneralError::create("Variable::setDouble", "Wrong set type for variable %s", path_.c_str()));
1170
1171 (block_->*setDouble_)(value, this, index);
1172 block_->write(this, index);
1173}
1174
1175double rim::Variable::getDouble(int32_t index) {
1176 if (getDouble_ == NULL)
1177 throw(rogue::GeneralError::create("Variable::getDouble", "Wrong get type for variable %s", path_.c_str()));
1178
1179 block_->read(this, index);
1180 return (block_->*getDouble_)(this, index);
1181}
1182
1184// C++ fixed point
1186
1187void rim::Variable::setFixed(double& value, int32_t index) {
1188 if (setFixed_ == NULL)
1189 throw(rogue::GeneralError::create("Variable::setFixed", "Wrong set type for variable %s", path_.c_str()));
1190
1191 (block_->*setFixed_)(value, this, index);
1192 block_->write(this, index);
1193}
1194
1195double rim::Variable::getFixed(int32_t index) {
1196 if (getFixed_ == NULL)
1197 throw(rogue::GeneralError::create("Variable::getFixed", "Wrong get type for variable %s", path_.c_str()));
1198
1199 block_->read(this, index);
1200 return (block_->*getFixed_)(this, index);
1201}
static GeneralError create(std::string src, const char *fmt,...)
Creates a formatted error instance.
RAII helper that acquires the Python GIL for a scope.
Definition ScopedGil.h:35
Memory variable descriptor and typed accessor facade.
Definition Variable.h:62
uint32_t retryCount()
Returns retry count.
Definition Variable.h:538
uint64_t offset()
Returns variable byte offset.
Definition Variable.cpp:645
uint32_t modelId() const
Returns model ID of the variable.
Definition Variable.h:459
const std::string & mode() const
Returns variable mode string.
Definition Variable.h:487
bool bulkOpEn()
Returns bulk-operation enable flag.
Definition Variable.cpp:660
double maximum()
Returns maximum value.
Definition Variable.cpp:635
double minimum()
Returns minimum value.
Definition Variable.cpp:630
bool overlapEn()
Returns overlap-enable flag.
Definition Variable.cpp:655
uint32_t valueBits()
Returns number of bits per value.
Definition Variable.h:523
uint32_t numValues()
Returns number of values.
Definition Variable.h:518
uint32_t valueStride()
Returns byte stride per value.
Definition Variable.h:533
const std::string & name() const
Returns variable name.
Definition Variable.h:474
static const uint8_t Fixed
Block access type for fixed-point numeric data.
Definition Constants.h:134
T py_object_convert(const boost::python::object &obj)
Definition Block.h:59
static const uint8_t Double
Block access type for double-precision (double) data.
Definition Constants.h:127
static const uint8_t Float4
Block access type for 4-bit E2M1 floating-point data.
Definition Constants.h:183
static const uint8_t Bytes
Block access type for raw byte data.
Definition Constants.h:85
static const uint8_t UInt
Block access type for unsigned integer data.
Definition Constants.h:92
static const uint8_t String
Block access type for string data.
Definition Constants.h:113
static const uint8_t Float8
Block access type for 8-bit E4M3 floating-point data.
Definition Constants.h:155
static const uint8_t PyFunc
Block access type for Python callback functions.
Definition Constants.h:78
static const uint8_t Float6
Block access type for 6-bit E3M2 floating-point data.
Definition Constants.h:176
static const uint8_t Bool
Block access type for boolean data.
Definition Constants.h:106
static const uint8_t Float16
Block access type for half-precision floating-point data.
Definition Constants.h:148
std::vector< T > py_list_to_std_vector(const boost::python::object &iterable)
Definition Block.h:42
static const uint8_t UFixed
Block access type for unsigned fixed-point numeric data.
Definition Constants.h:141
static const uint8_t BFloat16
Block access type for BFloat16 (Brain Float 16) data.
Definition Constants.h:162
static const uint8_t Float
Block access type for floating-point (float) data.
Definition Constants.h:120
static const uint8_t TensorFloat32
Block access type for TensorFloat32 (NVIDIA TF32) data.
Definition Constants.h:169
std::shared_ptr< rogue::interfaces::memory::Variable > VariablePtr
Definition Variable.h:43
static const uint8_t Int
Block access type for signed integer data.
Definition Constants.h:99