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)));
223 shiftOffsetDown(0, 1);
229 setByteArray_ = NULL;
230 getByteArray_ = NULL;
251 setTensorFloat32_ = NULL;
252 getTensorFloat32_ = NULL;
264 setByteArray_ = &rim::Block::setByteArray;
269 setByteArray_ = &rim::Block::setByteArray;
271 setUInt_ = &rim::Block::setUInt;
276 setByteArray_ = &rim::Block::setByteArray;
278 setInt_ = &rim::Block::setInt;
282 setBool_ = &rim::Block::setBool;
286 setString_ = &rim::Block::setString;
290 setFloat_ = &rim::Block::setFloat;
294 setFloat16_ = &rim::Block::setFloat16;
298 setFloat8_ = &rim::Block::setFloat8;
302 setBFloat16_ = &rim::Block::setBFloat16;
306 setTensorFloat32_ = &rim::Block::setTensorFloat32;
310 setFloat6_ = &rim::Block::setFloat6;
314 setFloat4_ = &rim::Block::setFloat4;
318 setDouble_ = &rim::Block::setDouble;
322 setFixed_ = &rim::Block::setFixed;
326 setFixed_ = &rim::Block::setUFixed;
339 getByteArray_ = &rim::Block::getByteArray;
344 getByteArray_ = &rim::Block::getByteArray;
346 getUInt_ = &rim::Block::getUInt;
351 getByteArray_ = &rim::Block::getByteArray;
353 getInt_ = &rim::Block::getInt;
357 getBool_ = &rim::Block::getBool;
361 getString_ = &rim::Block::getString;
365 getFloat_ = &rim::Block::getFloat;
369 getFloat16_ = &rim::Block::getFloat16;
373 getFloat8_ = &rim::Block::getFloat8;
377 getBFloat16_ = &rim::Block::getBFloat16;
381 getTensorFloat32_ = &rim::Block::getTensorFloat32;
385 getFloat6_ = &rim::Block::getFloat6;
389 getFloat4_ = &rim::Block::getFloat4;
393 getDouble_ = &rim::Block::getDouble;
397 getFixed_ = &rim::Block::getFixed;
401 getFixed_ = &rim::Block::getUFixed;
413 setFuncPy_ = &rim::Block::setPyFunc;
417 setFuncPy_ = &rim::Block::setByteArrayPy;
422 setFuncPy_ = &rim::Block::setPyFunc;
424 setFuncPy_ = &rim::Block::setUIntPy;
429 setFuncPy_ = &rim::Block::setPyFunc;
431 setFuncPy_ = &rim::Block::setIntPy;
435 setFuncPy_ = &rim::Block::setBoolPy;
439 setFuncPy_ = &rim::Block::setStringPy;
443 setFuncPy_ = &rim::Block::setFloatPy;
447 setFuncPy_ = &rim::Block::setFloat16Py;
451 setFuncPy_ = &rim::Block::setFloat8Py;
455 setFuncPy_ = &rim::Block::setBFloat16Py;
459 setFuncPy_ = &rim::Block::setTensorFloat32Py;
463 setFuncPy_ = &rim::Block::setFloat6Py;
467 setFuncPy_ = &rim::Block::setFloat4Py;
471 setFuncPy_ = &rim::Block::setDoublePy;
476 setFuncPy_ = &rim::Block::setFixedPy;
487 getFuncPy_ = &rim::Block::getPyFunc;
491 getFuncPy_ = &rim::Block::getByteArrayPy;
496 getFuncPy_ = &rim::Block::getPyFunc;
498 getFuncPy_ = &rim::Block::getUIntPy;
503 getFuncPy_ = &rim::Block::getPyFunc;
505 getFuncPy_ = &rim::Block::getIntPy;
509 getFuncPy_ = &rim::Block::getBoolPy;
513 getFuncPy_ = &rim::Block::getStringPy;
517 getFuncPy_ = &rim::Block::getFloatPy;
521 getFuncPy_ = &rim::Block::getFloat16Py;
525 getFuncPy_ = &rim::Block::getFloat8Py;
529 getFuncPy_ = &rim::Block::getBFloat16Py;
533 getFuncPy_ = &rim::Block::getTensorFloat32Py;
537 getFuncPy_ = &rim::Block::getFloat6Py;
541 getFuncPy_ = &rim::Block::getFloat4Py;
545 getFuncPy_ = &rim::Block::getDoublePy;
550 getFuncPy_ = &rim::Block::getFixedPy;
569void rim::Variable::shiftOffsetDown(uint32_t shift, uint32_t minSize) {
574 for (x = 0; x < bitOffset_.size(); x++) bitOffset_[x] += shift * 8;
578 if (numValues_ == 0) {
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))) *
587 static_cast<int>(std::floor(
static_cast<float>(bitOffset_[0]) / (
static_cast<float>(minSize) * 8.0))) *
591 highTranByte_[0] = varBytes_ - 1;
592 staleHighByte_ = highTranByte_[0];
596 for (x = 0; x < numValues_; 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))) *
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))) *
611 varBytes_ = highTranByte_[numValues_ - 1] + 1;
612 staleHighByte_ = highTranByte_[numValues_ - 1];
616 if (fastByte_ != NULL) {
617 if (numValues_ == 0) {
618 fastByte_[0] = bitOffset_[0] / 8;
622 for (x = 0; x < numValues_; x++) fastByte_[x] = (bitOffset_[0] + (valueStride_ * x)) / 8;
626 staleLowByte_ = lowTranByte_[0];
762void rim::Variable::rateTest() {
765 struct timeval stime;
766 struct timeval etime;
767 struct timeval dtime;
769 uint64_t count = 1000000;
774 gettimeofday(&stime, NULL);
775 for (x = 0; x < count; ++x) {
778 gettimeofday(&etime, NULL);
780 timersub(&etime, &stime, &dtime);
781 durr = dtime.tv_sec +
static_cast<float>(dtime.tv_usec) / 1.0e6;
784 printf(
"\nVariable c++ get: Read %" PRIu64
" times in %f seconds. Rate = %f\n", count, durr, rate);
786 gettimeofday(&stime, NULL);
787 for (x = 0; x < count; ++x) {
790 gettimeofday(&etime, NULL);
792 timersub(&etime, &stime, &dtime);
793 durr = dtime.tv_sec +
static_cast<float>(dtime.tv_usec) / 1.0e6;
796 printf(
"\nVariable c++ set: Wrote %" PRIu64
" times in %f seconds. Rate = %f\n", count, durr, rate);
808std::string rim::Variable::getDumpValue(
bool read) {
809 std::stringstream ret;
813 uint8_t byteData[valueBytes_];
815 memset(byteData, 0, valueBytes_);
817 if (read) block_->read(
this);
819 ret << path_ <<
" =";
826 while (index <
static_cast<int32_t
>(numValues_)) {
831 (block_->*getByteArray_)(byteData,
this, index);
833 for (x = 0; x < valueBytes_; x++)
834 ret << std::setfill(
'0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
838 if (valueBits_ > 64) {
839 (block_->*getByteArray_)(byteData,
this, index);
841 for (x = 0; x < valueBytes_; x++)
842 ret << std::setfill(
'0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
844 ret << (block_->*getUInt_)(
this, index);
849 if (valueBits_ > 64) {
850 (block_->*getByteArray_)(byteData,
this, index);
852 for (x = 0; x < valueBytes_; x++)
853 ret << std::setfill(
'0') << std::setw(2) << std::hex << static_cast<uint32_t>(byteData[x]);
855 ret << (block_->*getInt_)(
this, index);
860 ret << (block_->*getBool_)(
this, index);
864 ret << (block_->*getString_)(
this, index);
868 ret << (block_->*getFloat_)(
this, index);
872 ret << (block_->*getDouble_)(
this, index);
876 ret << block_->getFixed(
this, index);
880 ret << block_->getUFixed(
this, index);