89void rim::Variable::setup_python() {
91 bp::class_<rim::VariableWrap, rim::VariableWrapPtr, boost::noncopyable>(
"Variable",
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);
128rim::Variable::Variable(std::string name,
133 std::vector<uint32_t> bitOffset,
134 std::vector<uint32_t> bitSize,
145 uint32_t valueStride,
146 uint32_t retryCount) {
155 bitOffset_ = bitOffset;
157 overlapEn_ = overlapEn;
158 verifyEn_ = verifyEn;
159 byteReverse_ = byteReverse;
160 bitReverse_ = bitReverse;
161 bulkOpEn_ = bulkOpEn;
162 updateNotify_ = updateNotify;
165 binPoint_ = binPoint;
166 numValues_ = numValues;
167 valueBits_ = valueBits;
168 valueStride_ = valueStride;
169 retryCount_ = retryCount;
172 if (numValues_ == 0) {
174 bitTotal_ = bitSize_[0];
175 for (x = 1; x < bitSize_.size(); x++) bitTotal_ += bitSize_[x];
178 byteSize_ =
static_cast<int>(std::ceil(
static_cast<float>(bitTotal_) / 8.0));
180 lowTranByte_ =
reinterpret_cast<uint32_t*
>(malloc(
sizeof(uint32_t)));
181 highTranByte_ =
reinterpret_cast<uint32_t*
>(malloc(
sizeof(uint32_t)));
184 valueBytes_ = byteSize_;
185 valueBits_ = bitTotal_;
186 valueStride_ = bitTotal_;
191 bitTotal_ = bitSize_[0];
194 byteSize_ =
static_cast<int>(std::ceil(
static_cast<float>(bitTotal_) / 8.0));
197 valueBytes_ =
static_cast<uint32_t
>(std::ceil(
static_cast<float>(valueBits_) / 8.0));
200 lowTranByte_ =
reinterpret_cast<uint32_t*
>(malloc(numValues_ *
sizeof(uint32_t)));
201 highTranByte_ =
reinterpret_cast<uint32_t*
>(malloc(numValues_ *
sizeof(uint32_t)));
210 if ((bitOffset_.size() == 1) && (bitOffset_[0] % 8 == 0) && (bitSize_[0] % 8 == 0)) {
212 if (numValues_ == 0) {
213 fastByte_ =
reinterpret_cast<uint32_t*
>(malloc(
sizeof(uint32_t)));
216 }
else if ((valueBits_ % 8) == 0 && (valueStride_ % 8) == 0) {
217 fastByte_ =
reinterpret_cast<uint32_t*
>(malloc(numValues_ *
sizeof(uint32_t)));
224 shiftOffsetDown(0, 1);
230 setByteArray_ = NULL;
231 getByteArray_ = NULL;
252 setTensorFloat32_ = NULL;
253 getTensorFloat32_ = NULL;
265 setByteArray_ = &rim::Block::setByteArray;
270 setByteArray_ = &rim::Block::setByteArray;
272 setUInt_ = &rim::Block::setUInt;
277 setByteArray_ = &rim::Block::setByteArray;
279 setInt_ = &rim::Block::setInt;
283 setBool_ = &rim::Block::setBool;
287 setString_ = &rim::Block::setString;
291 setFloat_ = &rim::Block::setFloat;
295 setFloat16_ = &rim::Block::setFloat16;
299 setFloat8_ = &rim::Block::setFloat8;
303 setBFloat16_ = &rim::Block::setBFloat16;
307 setTensorFloat32_ = &rim::Block::setTensorFloat32;
311 setFloat6_ = &rim::Block::setFloat6;
315 setFloat4_ = &rim::Block::setFloat4;
319 setDouble_ = &rim::Block::setDouble;
323 setFixed_ = &rim::Block::setFixed;
327 setFixed_ = &rim::Block::setUFixed;
340 getByteArray_ = &rim::Block::getByteArray;
345 getByteArray_ = &rim::Block::getByteArray;
347 getUInt_ = &rim::Block::getUInt;
352 getByteArray_ = &rim::Block::getByteArray;
354 getInt_ = &rim::Block::getInt;
358 getBool_ = &rim::Block::getBool;
362 getString_ = &rim::Block::getString;
366 getFloat_ = &rim::Block::getFloat;
370 getFloat16_ = &rim::Block::getFloat16;
374 getFloat8_ = &rim::Block::getFloat8;
378 getBFloat16_ = &rim::Block::getBFloat16;
382 getTensorFloat32_ = &rim::Block::getTensorFloat32;
386 getFloat6_ = &rim::Block::getFloat6;
390 getFloat4_ = &rim::Block::getFloat4;
394 getDouble_ = &rim::Block::getDouble;
398 getFixed_ = &rim::Block::getFixed;
402 getFixed_ = &rim::Block::getUFixed;
414 setFuncPy_ = &rim::Block::setPyFunc;
418 setFuncPy_ = &rim::Block::setByteArrayPy;
423 setFuncPy_ = &rim::Block::setPyFunc;
425 setFuncPy_ = &rim::Block::setUIntPy;
430 setFuncPy_ = &rim::Block::setPyFunc;
432 setFuncPy_ = &rim::Block::setIntPy;
436 setFuncPy_ = &rim::Block::setBoolPy;
440 setFuncPy_ = &rim::Block::setStringPy;
444 setFuncPy_ = &rim::Block::setFloatPy;
448 setFuncPy_ = &rim::Block::setFloat16Py;
452 setFuncPy_ = &rim::Block::setFloat8Py;
456 setFuncPy_ = &rim::Block::setBFloat16Py;
460 setFuncPy_ = &rim::Block::setTensorFloat32Py;
464 setFuncPy_ = &rim::Block::setFloat6Py;
468 setFuncPy_ = &rim::Block::setFloat4Py;
472 setFuncPy_ = &rim::Block::setDoublePy;
477 setFuncPy_ = &rim::Block::setFixedPy;
488 getFuncPy_ = &rim::Block::getPyFunc;
492 getFuncPy_ = &rim::Block::getByteArrayPy;
497 getFuncPy_ = &rim::Block::getPyFunc;
499 getFuncPy_ = &rim::Block::getUIntPy;
504 getFuncPy_ = &rim::Block::getPyFunc;
506 getFuncPy_ = &rim::Block::getIntPy;
510 getFuncPy_ = &rim::Block::getBoolPy;
514 getFuncPy_ = &rim::Block::getStringPy;
518 getFuncPy_ = &rim::Block::getFloatPy;
522 getFuncPy_ = &rim::Block::getFloat16Py;
526 getFuncPy_ = &rim::Block::getFloat8Py;
530 getFuncPy_ = &rim::Block::getBFloat16Py;
534 getFuncPy_ = &rim::Block::getTensorFloat32Py;
538 getFuncPy_ = &rim::Block::getFloat6Py;
542 getFuncPy_ = &rim::Block::getFloat4Py;
546 getFuncPy_ = &rim::Block::getDoublePy;
551 getFuncPy_ = &rim::Block::getFixedPy;
570void rim::Variable::shiftOffsetDown(uint32_t shift, uint32_t minSize) {
575 for (x = 0; x < bitOffset_.size(); x++) bitOffset_[x] += shift * 8;
581 const uint64_t minBits =
static_cast<uint64_t
>(minSize) * 8;
584 if (numValues_ == 0) {
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);
591 lowTranByte_[0] =
static_cast<uint32_t
>((
static_cast<uint64_t
>(bitOffset_[0]) / minBits) * minSize);
594 highTranByte_[0] = varBytes_ - 1;
595 staleHighByte_ = highTranByte_[0];
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);
607 varBytes_ = highTranByte_[numValues_ - 1] + 1;
608 staleHighByte_ = highTranByte_[numValues_ - 1];
612 if (fastByte_ != NULL) {
613 if (numValues_ == 0) {
614 fastByte_[0] = bitOffset_[0] / 8;
618 for (x = 0; x < numValues_; x++) fastByte_[x] = (bitOffset_[0] + (valueStride_ * x)) / 8;
622 staleLowByte_ = lowTranByte_[0];
758void rim::Variable::rateTest() {
761 struct timeval stime;
762 struct timeval etime;
763 struct timeval dtime;
765 uint64_t count = 1000000;
770 gettimeofday(&stime, NULL);
771 for (x = 0; x < count; ++x) {
774 gettimeofday(&etime, NULL);
776 timersub(&etime, &stime, &dtime);
777 durr = dtime.tv_sec +
static_cast<float>(dtime.tv_usec) / 1.0e6;
780 printf(
"\nVariable c++ get: Read %" PRIu64
" times in %f seconds. Rate = %f\n", count, durr, rate);
782 gettimeofday(&stime, NULL);
783 for (x = 0; x < count; ++x) {
786 gettimeofday(&etime, NULL);
788 timersub(&etime, &stime, &dtime);
789 durr = dtime.tv_sec +
static_cast<float>(dtime.tv_usec) / 1.0e6;
792 printf(
"\nVariable c++ set: Wrote %" PRIu64
" times in %f seconds. Rate = %f\n", count, durr, rate);
804std::string rim::Variable::getDumpValue(
bool read) {
805 std::stringstream ret;
809 uint8_t byteData[valueBytes_];
811 memset(byteData, 0, valueBytes_);
813 if (read) block_->read(
this);
815 ret << path_ <<
" =";
822 while (index <
static_cast<int32_t
>(numValues_)) {
827 (block_->*getByteArray_)(byteData,
this, index);
829 for (x = 0; x < valueBytes_; x++)
830 ret << std::setfill(
'0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
834 if (valueBits_ > 64) {
835 (block_->*getByteArray_)(byteData,
this, index);
837 for (x = 0; x < valueBytes_; x++)
838 ret << std::setfill(
'0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
840 ret << (block_->*getUInt_)(
this, index);
845 if (valueBits_ > 64) {
846 (block_->*getByteArray_)(byteData,
this, index);
848 for (x = 0; x < valueBytes_; x++)
849 ret << std::setfill(
'0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
851 ret << (block_->*getInt_)(
this, index);
856 ret << (block_->*getBool_)(
this, index);
860 ret << (block_->*getString_)(
this, index);
864 ret << (block_->*getFloat_)(
this, index);
868 ret << (block_->*getDouble_)(
this, index);
872 ret << block_->getFixed(
this, index);
876 ret << block_->getUFixed(
this, index);
880 ret << block_->getFloat16(
this, index);
884 ret << block_->getFloat8(
this, index);
888 ret << block_->getBFloat16(
this, index);
892 ret << block_->getTensorFloat32(
this, index);
896 ret << block_->getFloat6(
this, index);
900 ret << block_->getFloat4(
this, index);