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
222 // Call aligning function to init values
223 shiftOffsetDown(0, 1);
224
225 // Custom data is NULL for now
226 customData_ = NULL;
227
228 // Set default C++ pointers
229 setByteArray_ = NULL;
230 getByteArray_ = NULL;
231 setUInt_ = NULL;
232 getUInt_ = NULL;
233 setInt_ = NULL;
234 getInt_ = NULL;
235 setBool_ = NULL;
236 getBool_ = NULL;
237 setString_ = NULL;
238 getString_ = NULL;
239 setFloat_ = NULL;
240 getFloat_ = NULL;
241 setFloat16_ = NULL;
242 getFloat16_ = NULL;
243 setFloat8_ = NULL;
244 getFloat8_ = NULL;
245 setDouble_ = NULL;
246 getDouble_ = NULL;
247 setFixed_ = NULL;
248 getFixed_ = NULL;
249 setBFloat16_ = NULL;
250 getBFloat16_ = NULL;
251 setTensorFloat32_ = NULL;
252 getTensorFloat32_ = NULL;
253 setFloat6_ = NULL;
254 getFloat6_ = NULL;
255 setFloat4_ = NULL;
256 getFloat4_ = NULL;
257
258 // Define set function
259 switch (modelId_) {
260 case rim::PyFunc:
261 break;
262
263 case rim::Bytes:
264 setByteArray_ = &rim::Block::setByteArray;
265 break;
266
267 case rim::UInt:
268 if (valueBits_ > 64)
269 setByteArray_ = &rim::Block::setByteArray;
270 else
271 setUInt_ = &rim::Block::setUInt;
272 break;
273
274 case rim::Int:
275 if (valueBits_ > 64)
276 setByteArray_ = &rim::Block::setByteArray;
277 else
278 setInt_ = &rim::Block::setInt;
279 break;
280
281 case rim::Bool:
282 setBool_ = &rim::Block::setBool;
283 break;
284
285 case rim::String:
286 setString_ = &rim::Block::setString;
287 break;
288
289 case rim::Float:
290 setFloat_ = &rim::Block::setFloat;
291 break;
292
293 case rim::Float16:
294 setFloat16_ = &rim::Block::setFloat16;
295 break;
296
297 case rim::Float8:
298 setFloat8_ = &rim::Block::setFloat8;
299 break;
300
301 case rim::BFloat16:
302 setBFloat16_ = &rim::Block::setBFloat16;
303 break;
304
306 setTensorFloat32_ = &rim::Block::setTensorFloat32;
307 break;
308
309 case rim::Float6:
310 setFloat6_ = &rim::Block::setFloat6;
311 break;
312
313 case rim::Float4:
314 setFloat4_ = &rim::Block::setFloat4;
315 break;
316
317 case rim::Double:
318 setDouble_ = &rim::Block::setDouble;
319 break;
320
321 case rim::Fixed:
322 setFixed_ = &rim::Block::setFixed;
323 break;
324
325 case rim::UFixed:
326 setFixed_ = &rim::Block::setUFixed;
327 break;
328
329 default:
330 break;
331 }
332
333 // Define get function, C++
334 switch (modelId_) {
335 case rim::PyFunc:
336 break;
337
338 case rim::Bytes:
339 getByteArray_ = &rim::Block::getByteArray;
340 break;
341
342 case rim::UInt:
343 if (valueBits_ > 64)
344 getByteArray_ = &rim::Block::getByteArray;
345 else
346 getUInt_ = &rim::Block::getUInt;
347 break;
348
349 case rim::Int:
350 if (valueBits_ > 64)
351 getByteArray_ = &rim::Block::getByteArray;
352 else
353 getInt_ = &rim::Block::getInt;
354 break;
355
356 case rim::Bool:
357 getBool_ = &rim::Block::getBool;
358 break;
359
360 case rim::String:
361 getString_ = &rim::Block::getString;
362 break;
363
364 case rim::Float:
365 getFloat_ = &rim::Block::getFloat;
366 break;
367
368 case rim::Float16:
369 getFloat16_ = &rim::Block::getFloat16;
370 break;
371
372 case rim::Float8:
373 getFloat8_ = &rim::Block::getFloat8;
374 break;
375
376 case rim::BFloat16:
377 getBFloat16_ = &rim::Block::getBFloat16;
378 break;
379
381 getTensorFloat32_ = &rim::Block::getTensorFloat32;
382 break;
383
384 case rim::Float6:
385 getFloat6_ = &rim::Block::getFloat6;
386 break;
387
388 case rim::Float4:
389 getFloat4_ = &rim::Block::getFloat4;
390 break;
391
392 case rim::Double:
393 getDouble_ = &rim::Block::getDouble;
394 break;
395
396 case rim::Fixed:
397 getFixed_ = &rim::Block::getFixed;
398 break;
399
400 case rim::UFixed:
401 getFixed_ = &rim::Block::getUFixed;
402 break;
403
404 default:
405 break;
406 }
407
408#ifndef NO_PYTHON
409
410 // Define set function, python
411 switch (modelId_) {
412 case rim::PyFunc:
413 setFuncPy_ = &rim::Block::setPyFunc;
414 break;
415
416 case rim::Bytes:
417 setFuncPy_ = &rim::Block::setByteArrayPy;
418 break;
419
420 case rim::UInt:
421 if (valueBits_ > 64)
422 setFuncPy_ = &rim::Block::setPyFunc;
423 else
424 setFuncPy_ = &rim::Block::setUIntPy;
425 break;
426
427 case rim::Int:
428 if (valueBits_ > 64)
429 setFuncPy_ = &rim::Block::setPyFunc;
430 else
431 setFuncPy_ = &rim::Block::setIntPy;
432 break;
433
434 case rim::Bool:
435 setFuncPy_ = &rim::Block::setBoolPy;
436 break;
437
438 case rim::String:
439 setFuncPy_ = &rim::Block::setStringPy;
440 break;
441
442 case rim::Float:
443 setFuncPy_ = &rim::Block::setFloatPy;
444 break;
445
446 case rim::Float16:
447 setFuncPy_ = &rim::Block::setFloat16Py;
448 break;
449
450 case rim::Float8:
451 setFuncPy_ = &rim::Block::setFloat8Py;
452 break;
453
454 case rim::BFloat16:
455 setFuncPy_ = &rim::Block::setBFloat16Py;
456 break;
457
459 setFuncPy_ = &rim::Block::setTensorFloat32Py;
460 break;
461
462 case rim::Float6:
463 setFuncPy_ = &rim::Block::setFloat6Py;
464 break;
465
466 case rim::Float4:
467 setFuncPy_ = &rim::Block::setFloat4Py;
468 break;
469
470 case rim::Double:
471 setFuncPy_ = &rim::Block::setDoublePy;
472 break;
473
474 case rim::Fixed:
475 case rim::UFixed:
476 setFuncPy_ = &rim::Block::setFixedPy;
477 break;
478
479 default:
480 getFuncPy_ = NULL;
481 break;
482 }
483
484 // Define get function, python
485 switch (modelId_) {
486 case rim::PyFunc:
487 getFuncPy_ = &rim::Block::getPyFunc;
488 break;
489
490 case rim::Bytes:
491 getFuncPy_ = &rim::Block::getByteArrayPy;
492 break;
493
494 case rim::UInt:
495 if (valueBits_ > 64)
496 getFuncPy_ = &rim::Block::getPyFunc;
497 else
498 getFuncPy_ = &rim::Block::getUIntPy;
499 break;
500
501 case rim::Int:
502 if (valueBits_ > 64)
503 getFuncPy_ = &rim::Block::getPyFunc;
504 else
505 getFuncPy_ = &rim::Block::getIntPy;
506 break;
507
508 case rim::Bool:
509 getFuncPy_ = &rim::Block::getBoolPy;
510 break;
511
512 case rim::String:
513 getFuncPy_ = &rim::Block::getStringPy;
514 break;
515
516 case rim::Float:
517 getFuncPy_ = &rim::Block::getFloatPy;
518 break;
519
520 case rim::Float16:
521 getFuncPy_ = &rim::Block::getFloat16Py;
522 break;
523
524 case rim::Float8:
525 getFuncPy_ = &rim::Block::getFloat8Py;
526 break;
527
528 case rim::BFloat16:
529 getFuncPy_ = &rim::Block::getBFloat16Py;
530 break;
531
533 getFuncPy_ = &rim::Block::getTensorFloat32Py;
534 break;
535
536 case rim::Float6:
537 getFuncPy_ = &rim::Block::getFloat6Py;
538 break;
539
540 case rim::Float4:
541 getFuncPy_ = &rim::Block::getFloat4Py;
542 break;
543
544 case rim::Double:
545 getFuncPy_ = &rim::Block::getDoublePy;
546 break;
547
548 case rim::Fixed:
549 case rim::UFixed:
550 getFuncPy_ = &rim::Block::getFixedPy;
551 break;
552
553 default:
554 getFuncPy_ = NULL;
555 break;
556 }
557
558#endif
559}
560
561// Destroy the variable
562rim::Variable::~Variable() {
563 if (lowTranByte_ != NULL) free(lowTranByte_);
564 if (highTranByte_ != NULL) free(highTranByte_);
565 if (fastByte_ != NULL) free(fastByte_);
566}
567
568// Shift offset down
569void rim::Variable::shiftOffsetDown(uint32_t shift, uint32_t minSize) {
570 uint32_t x;
571
572 if (shift != 0) {
573 offset_ -= shift;
574 for (x = 0; x < bitOffset_.size(); x++) bitOffset_[x] += shift * 8;
575 }
576
577 // Standard variable
578 if (numValues_ == 0) {
579 // Compute total bit range of accessed bytes
580 varBytes_ = static_cast<int>(std::ceil(
581 static_cast<float>(bitOffset_[bitOffset_.size() - 1] + bitSize_[bitSize_.size() - 1]) /
582 (static_cast<float>(minSize) * 8.0))) *
583 minSize;
584
585 // Compute the lowest byte, aligned to min access
586 lowTranByte_[0] =
587 static_cast<int>(std::floor(static_cast<float>(bitOffset_[0]) / (static_cast<float>(minSize) * 8.0))) *
588 minSize;
589
590 // Compute the highest byte, aligned to min access
591 highTranByte_[0] = varBytes_ - 1;
592 staleHighByte_ = highTranByte_[0];
593
594 // List variable
595 } else {
596 for (x = 0; x < numValues_; x++) {
597 lowTranByte_[x] =
598 static_cast<uint32_t>(std::floor(
599 (static_cast<float>(bitOffset_[0]) + static_cast<float>(x) * static_cast<float>(valueStride_)) /
600 (static_cast<float>(minSize) * 8.0))) *
601 minSize;
602 highTranByte_[x] = static_cast<uint32_t>(
603 std::ceil((static_cast<float>(bitOffset_[0]) +
604 static_cast<float>(x) * static_cast<float>(valueStride_) + valueBits_) /
605 (static_cast<float>(minSize) * 8.0))) *
606 minSize -
607 1;
608 }
609
610 // Compute total bit range of accessed bytes
611 varBytes_ = highTranByte_[numValues_ - 1] + 1;
612 staleHighByte_ = highTranByte_[numValues_ - 1];
613 }
614
615 // Adjust fast copy locations
616 if (fastByte_ != NULL) {
617 if (numValues_ == 0) {
618 fastByte_[0] = bitOffset_[0] / 8;
619
620 // List variable
621 } else {
622 for (x = 0; x < numValues_; x++) fastByte_[x] = (bitOffset_[0] + (valueStride_ * x)) / 8;
623 }
624 }
625
626 staleLowByte_ = lowTranByte_[0];
627}
628
629void rim::Variable::updatePath(std::string path) {
630 path_ = path;
631}
632
634double rim::Variable::minimum() {
635 return minValue_;
636}
637
639double rim::Variable::maximum() {
640 return maxValue_;
641}
642
644uint32_t rim::Variable::varBytes() {
645 return varBytes_;
646}
647
649uint64_t rim::Variable::offset() {
650 return offset_;
651}
652
654bool rim::Variable::verifyEn() {
655 return verifyEn_;
656}
657
659bool rim::Variable::overlapEn() {
660 return overlapEn_;
661}
662
664bool rim::Variable::bulkOpEn() {
665 return bulkOpEn_;
666}
667
668#ifndef NO_PYTHON
669// Create a Variable
670rim::VariableWrap::VariableWrap(std::string name,
671 std::string mode,
672 bp::object minimum,
673 bp::object maximum,
674 uint64_t offset,
675 bp::object bitOffset,
676 bp::object bitSize,
677 bool overlapEn,
678 bool verify,
679 bool bulkOpEn,
680 bool updateNotify,
681 bp::object model,
682 bp::object listData,
683 uint32_t retryCount)
684
685 : rim::Variable(name,
686 mode,
687 py_object_convert<double>(minimum),
688 py_object_convert<double>(maximum),
689 offset,
690 py_list_to_std_vector<uint32_t>(bitOffset),
691 py_list_to_std_vector<uint32_t>(bitSize),
692 overlapEn,
693 verify,
694 bulkOpEn,
695 updateNotify,
696 bp::extract<uint32_t>(model.attr("modelId")),
697 bp::extract<bool>(model.attr("isBigEndian")),
698 bp::extract<bool>(model.attr("bitReverse")),
699 bp::extract<uint32_t>(model.attr("binPoint")),
700 bp::extract<uint32_t>(listData.attr("numValues")),
701 bp::extract<uint32_t>(listData.attr("valueBits")),
702 bp::extract<uint32_t>(listData.attr("valueStride")),
703 retryCount) {
704 model_ = model;
705}
706
708void rim::VariableWrap::set(bp::object& value, int32_t index) {
709 if (setFuncPy_ == NULL || block_->blockPyTrans()) return;
710 (block_->*setFuncPy_)(value, this, index);
711}
712
714bp::object rim::VariableWrap::get(int32_t index) {
715 if (getFuncPy_ == NULL) {
716 bp::handle<> handle(bp::borrowed(Py_None));
717 return bp::object(handle);
718 }
719 return (block_->*getFuncPy_)(this, index);
720}
721
722// Set data using python function
723bp::object rim::VariableWrap::toBytes(bp::object& value) {
724 return model_.attr("toBytes")(value);
725}
726
727// Get data using python function
728bp::object rim::VariableWrap::fromBytes(bp::object& value) {
729 return model_.attr("fromBytes")(value);
730}
731
732void rim::VariableWrap::defQueueUpdate() {
733 rim::Variable::queueUpdate();
734}
735
736// Queue update
737void rim::VariableWrap::queueUpdate() {
739
740 if (bp::override pb = this->get_override("_queueUpdate")) {
741 try {
742 pb();
743 return;
744 } catch (...) {
745 PyErr_Print();
746 }
747 }
748}
749
750bp::object rim::VariableWrap::bitOffset() {
751 return std_vector_to_py_list<uint32_t>(bitOffset_);
752}
753
754bp::object rim::VariableWrap::bitSize() {
755 return std_vector_to_py_list<uint32_t>(bitSize_);
756}
757
758#endif // ! NO_PYTHON
759
760void rim::Variable::queueUpdate() {}
761
762void rim::Variable::rateTest() {
763 uint64_t x;
764
765 struct timeval stime;
766 struct timeval etime;
767 struct timeval dtime;
768
769 uint64_t count = 1000000;
770 double durr;
771 double rate;
772 uint32_t ret;
773
774 gettimeofday(&stime, NULL);
775 for (x = 0; x < count; ++x) {
776 ret = getUInt();
777 }
778 gettimeofday(&etime, NULL);
779
780 timersub(&etime, &stime, &dtime);
781 durr = dtime.tv_sec + static_cast<float>(dtime.tv_usec) / 1.0e6;
782 rate = count / durr;
783
784 printf("\nVariable c++ get: Read %" PRIu64 " times in %f seconds. Rate = %f\n", count, durr, rate);
785
786 gettimeofday(&stime, NULL);
787 for (x = 0; x < count; ++x) {
788 setUInt(x);
789 }
790 gettimeofday(&etime, NULL);
791
792 timersub(&etime, &stime, &dtime);
793 durr = dtime.tv_sec + static_cast<float>(dtime.tv_usec) / 1.0e6;
794 rate = count / durr;
795
796 printf("\nVariable c++ set: Wrote %" PRIu64 " times in %f seconds. Rate = %f\n", count, durr, rate);
797}
798
799void rim::Variable::setLogLevel(uint32_t level) {
800 if (block_) block_->setLogLevel(level);
801}
802
803void rim::Variable::read() {
804 block_->read(this);
805}
806
808std::string rim::Variable::getDumpValue(bool read) {
809 std::stringstream ret;
810 uint32_t x;
811 int32_t index;
812
813 uint8_t byteData[valueBytes_];
814
815 memset(byteData, 0, valueBytes_);
816
817 if (read) block_->read(this);
818
819 ret << path_ << " =";
820
821 if (numValues_ == 0)
822 index = -1;
823 else
824 index = 0;
825
826 while (index < static_cast<int32_t>(numValues_)) {
827 ret << " ";
828
829 switch (modelId_) {
830 case rim::Bytes:
831 (block_->*getByteArray_)(byteData, this, index);
832 ret << "0x";
833 for (x = 0; x < valueBytes_; x++)
834 ret << std::setfill('0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
835 break;
836
837 case rim::UInt:
838 if (valueBits_ > 64) {
839 (block_->*getByteArray_)(byteData, this, index);
840 ret << "0x";
841 for (x = 0; x < valueBytes_; x++)
842 ret << std::setfill('0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
843 } else {
844 ret << (block_->*getUInt_)(this, index);
845 }
846 break;
847
848 case rim::Int:
849 if (valueBits_ > 64) {
850 (block_->*getByteArray_)(byteData, this, index);
851 ret << "0x";
852 for (x = 0; x < valueBytes_; x++)
853 ret << std::setfill('0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
854 } else {
855 ret << (block_->*getInt_)(this, index);
856 }
857 break;
858
859 case rim::Bool:
860 ret << (block_->*getBool_)(this, index);
861 break;
862
863 case rim::String:
864 ret << (block_->*getString_)(this, index);
865 break;
866
867 case rim::Float:
868 ret << (block_->*getFloat_)(this, index);
869 break;
870
871 case rim::Double:
872 ret << (block_->*getDouble_)(this, index);
873 break;
874
875 case rim::Fixed:
876 ret << block_->getFixed(this, index);
877 break;
878
879 case rim::UFixed:
880 ret << block_->getUFixed(this, index);
881 break;
882
883 default:
884 ret << "UNDEFINED";
885 break;
886 }
887 index++;
888 }
889
890 ret << "\n";
891 return ret.str();
892}
893
895// C++ Byte Array
897
898void rim::Variable::setByteArray(uint8_t* value, int32_t index) {
899 if (setByteArray_ == NULL)
900 throw(rogue::GeneralError::create("Variable::setByteArray", "Wrong set type for variable %s", path_.c_str()));
901
902 (block_->*setByteArray_)(value, this, index);
903 block_->write(this, index);
904}
905
906void rim::Variable::getByteArray(uint8_t* value, int32_t index) {
907 if (getByteArray_ == NULL)
908 throw(rogue::GeneralError::create("Variable::getByteArray", "Wrong get type for variable %s", path_.c_str()));
909
910 block_->read(this, index);
911 (block_->*getByteArray_)(value, this, index);
912}
913
915// C++ Uint
917
918void rim::Variable::setUInt(uint64_t& value, int32_t index) {
919 if (setUInt_ == NULL)
920 throw(rogue::GeneralError::create("Variable::setUInt", "Wrong set type for variable %s", path_.c_str()));
921
922 (block_->*setUInt_)(value, this, index);
923 block_->write(this, index);
924}
925
926uint64_t rim::Variable::getUInt(int32_t index) {
927 if (getUInt_ == NULL)
928 throw(rogue::GeneralError::create("Variable::getUInt", "Wrong get type for variable %s", path_.c_str()));
929
930 block_->read(this, index);
931 return (block_->*getUInt_)(this, index);
932}
933
935// C++ int
937
938void rim::Variable::setInt(int64_t& value, int32_t index) {
939 if (setInt_ == NULL)
940 throw(rogue::GeneralError::create("Variable::setInt", "Wrong set type for variable %s", path_.c_str()));
941
942 (block_->*setInt_)(value, this, index);
943 block_->write(this, index);
944}
945
946int64_t rim::Variable::getInt(int32_t index) {
947 if (getInt_ == NULL)
948 throw(rogue::GeneralError::create("Variable::getInt", "Wrong get type for variable %s", path_.c_str()));
949
950 block_->read(this, index);
951 return (block_->*getInt_)(this, index);
952}
953
955// C++ bool
957
958void rim::Variable::setBool(bool& value, int32_t index) {
959 if (setBool_ == NULL)
960 throw(rogue::GeneralError::create("Variable::setBool", "Wrong set type for variable %s", path_.c_str()));
961
962 (block_->*setBool_)(value, this, index);
963 block_->write(this, index);
964}
965
966bool rim::Variable::getBool(int32_t index) {
967 if (getBool_ == NULL)
968 throw(rogue::GeneralError::create("Variable::getBool", "Wrong get type for variable %s", path_.c_str()));
969
970 block_->read(this, index);
971 return (block_->*getBool_)(this, index);
972}
973
975// C++ String
977
978void rim::Variable::setString(const std::string& value, int32_t index) {
979 if (setString_ == NULL)
980 throw(rogue::GeneralError::create("Variable::setString", "Wrong set type for variable %s", path_.c_str()));
981
982 (block_->*setString_)(value, this, index);
983 block_->write(this, index);
984}
985
986std::string rim::Variable::getString(int32_t index) {
987 if (getString_ == NULL)
988 throw(rogue::GeneralError::create("Variable::getString", "Wrong get type for variable %s", path_.c_str()));
989
990 block_->read(this, index);
991 return (block_->*getString_)(this, index);
992}
993
994void rim::Variable::getValue(std::string& valueRet, int32_t index) {
995 if (getString_ == NULL) {
996 throw(rogue::GeneralError::create("Variable::getValue", "Wrong get type for variable %s", path_.c_str()));
997 } else {
998 block_->read(this, index);
999 block_->getValue(this, valueRet, index);
1000 }
1001}
1002
1004// C++ Float
1006
1007void rim::Variable::setFloat(float& value, int32_t index) {
1008 if (setFloat_ == NULL)
1009 throw(rogue::GeneralError::create("Variable::setFloat", "Wrong set type for variable %s", path_.c_str()));
1010
1011 (block_->*setFloat_)(value, this, index);
1012 block_->write(this, index);
1013}
1014
1015float rim::Variable::getFloat(int32_t index) {
1016 if (getFloat_ == NULL)
1017 throw(rogue::GeneralError::create("Variable::getFloat", "Wrong get type for variable %s", path_.c_str()));
1018
1019 block_->read(this, index);
1020 return (block_->*getFloat_)(this, index);
1021}
1022
1024// C++ Float16 (half-precision)
1026
1027void rim::Variable::setFloat16(float& value, int32_t index) {
1028 if (setFloat16_ == NULL)
1029 throw(rogue::GeneralError::create("Variable::setFloat16", "Wrong set type for variable %s", path_.c_str()));
1030
1031 (block_->*setFloat16_)(value, this, index);
1032 block_->write(this, index);
1033}
1034
1035float rim::Variable::getFloat16(int32_t index) {
1036 if (getFloat16_ == NULL)
1037 throw(rogue::GeneralError::create("Variable::getFloat16", "Wrong get type for variable %s", path_.c_str()));
1038
1039 block_->read(this, index);
1040 return (block_->*getFloat16_)(this, index);
1041}
1042
1044// C++ Float8 (E4M3)
1046
1047void rim::Variable::setFloat8(float& value, int32_t index) {
1048 if (setFloat8_ == NULL)
1049 throw(rogue::GeneralError::create("Variable::setFloat8", "Wrong set type for variable %s", path_.c_str()));
1050
1051 (block_->*setFloat8_)(value, this, index);
1052 block_->write(this, index);
1053}
1054
1055float rim::Variable::getFloat8(int32_t index) {
1056 if (getFloat8_ == NULL)
1057 throw(rogue::GeneralError::create("Variable::getFloat8", "Wrong get type for variable %s", path_.c_str()));
1058
1059 block_->read(this, index);
1060 return (block_->*getFloat8_)(this, index);
1061}
1062
1064// C++ BFloat16 (Brain Float 16)
1066
1067void rim::Variable::setBFloat16(float& value, int32_t index) {
1068 if (setBFloat16_ == NULL)
1069 throw(rogue::GeneralError::create("Variable::setBFloat16", "Wrong set type for variable %s", path_.c_str()));
1070
1071 (block_->*setBFloat16_)(value, this, index);
1072 block_->write(this, index);
1073}
1074
1075float rim::Variable::getBFloat16(int32_t index) {
1076 if (getBFloat16_ == NULL)
1077 throw(rogue::GeneralError::create("Variable::getBFloat16", "Wrong get type for variable %s", path_.c_str()));
1078
1079 block_->read(this, index);
1080 return (block_->*getBFloat16_)(this, index);
1081}
1082
1084// C++ TensorFloat32 (NVIDIA TF32)
1086
1087void rim::Variable::setTensorFloat32(float& value, int32_t index) {
1088 if (setTensorFloat32_ == NULL)
1089 throw(rogue::GeneralError::create("Variable::setTensorFloat32", "Wrong set type for variable %s", path_.c_str()));
1090
1091 (block_->*setTensorFloat32_)(value, this, index);
1092 block_->write(this, index);
1093}
1094
1095float rim::Variable::getTensorFloat32(int32_t index) {
1096 if (getTensorFloat32_ == NULL)
1097 throw(rogue::GeneralError::create("Variable::getTensorFloat32", "Wrong get type for variable %s", path_.c_str()));
1098
1099 block_->read(this, index);
1100 return (block_->*getTensorFloat32_)(this, index);
1101}
1102
1104// C++ Float6 (E3M2)
1106
1107void rim::Variable::setFloat6(float& value, int32_t index) {
1108 if (setFloat6_ == NULL)
1109 throw(rogue::GeneralError::create("Variable::setFloat6", "Wrong set type for variable %s", path_.c_str()));
1110
1111 (block_->*setFloat6_)(value, this, index);
1112 block_->write(this, index);
1113}
1114
1115float rim::Variable::getFloat6(int32_t index) {
1116 if (getFloat6_ == NULL)
1117 throw(rogue::GeneralError::create("Variable::getFloat6", "Wrong get type for variable %s", path_.c_str()));
1118
1119 block_->read(this, index);
1120 return (block_->*getFloat6_)(this, index);
1121}
1122
1124// C++ Float4 (E2M1)
1126
1127void rim::Variable::setFloat4(float& value, int32_t index) {
1128 if (setFloat4_ == NULL)
1129 throw(rogue::GeneralError::create("Variable::setFloat4", "Wrong set type for variable %s", path_.c_str()));
1130
1131 (block_->*setFloat4_)(value, this, index);
1132 block_->write(this, index);
1133}
1134
1135float rim::Variable::getFloat4(int32_t index) {
1136 if (getFloat4_ == NULL)
1137 throw(rogue::GeneralError::create("Variable::getFloat4", "Wrong get type for variable %s", path_.c_str()));
1138
1139 block_->read(this, index);
1140 return (block_->*getFloat4_)(this, index);
1141}
1142
1144// C++ double
1146
1147void rim::Variable::setDouble(double& value, int32_t index) {
1148 if (setDouble_ == NULL)
1149 throw(rogue::GeneralError::create("Variable::setDouble", "Wrong set type for variable %s", path_.c_str()));
1150
1151 (block_->*setDouble_)(value, this, index);
1152 block_->write(this, index);
1153}
1154
1155double rim::Variable::getDouble(int32_t index) {
1156 if (getDouble_ == NULL)
1157 throw(rogue::GeneralError::create("Variable::getDouble", "Wrong get type for variable %s", path_.c_str()));
1158
1159 block_->read(this, index);
1160 return (block_->*getDouble_)(this, index);
1161}
1162
1164// C++ fixed point
1166
1167void rim::Variable::setFixed(double& value, int32_t index) {
1168 if (setFixed_ == NULL)
1169 throw(rogue::GeneralError::create("Variable::setFixed", "Wrong set type for variable %s", path_.c_str()));
1170
1171 (block_->*setFixed_)(value, this, index);
1172 block_->write(this, index);
1173}
1174
1175double rim::Variable::getFixed(int32_t index) {
1176 if (getFixed_ == NULL)
1177 throw(rogue::GeneralError::create("Variable::getFixed", "Wrong get type for variable %s", path_.c_str()));
1178
1179 block_->read(this, index);
1180 return (block_->*getFixed_)(this, index);
1181}
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:649
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:664
double maximum()
Returns maximum value.
Definition Variable.cpp:639
double minimum()
Returns minimum value.
Definition Variable.cpp:634
bool overlapEn()
Returns overlap-enable flag.
Definition Variable.cpp:659
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