MCPcopy Create free account
hub / github.com/alibaba/MNN / ReadSparseQuanData_c

Function ReadSparseQuanData_c

source/core/ConvolutionCommon.cpp:391–517  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

389}
390
391static int8_t *ReadSparseQuanData_c(BaseLoader* myfile, size_t* len, const float* alpha_ptr, size_t alpha_size, ConvolutionCommon::Int8Common* result, const IDSTQuan* quan, bool forceQuant, bool forceFloat, void* outputPtr) {
392 unsigned int shape[32];
393 uint32_t ucMapSize = 0;
394 bool useInt32 = quan->shapeInt32();
395 PSIMPLE_SET setWeight = CreateSimpleSet(256);
396 if (setWeight == nullptr) {
397 return nullptr;
398 }
399 std::shared_ptr<unsigned int> __autoReleaseSetWeight(nullptr, [setWeight](void *) { DestorySimpleSet(setWeight); });
400 unsigned int nnz;
401 unsigned char iIdxNeedBits;
402 int8_t *blob = nullptr;
403 // 1. weights blob shape(unsigned int32)
404 int ShapeDim = ReadBlobDim(myfile, shape, 32, useInt32);
405 size_t Size = sizeof(int8_t);
406 for (int i = 0; i < ShapeDim; i++)
407 Size *= shape[i];
408 bool canSetOutputPtr = outputPtr != nullptr;
409 if(!forceQuant && (forceFloat || !quan->has_scaleInt())) {
410 canSetOutputPtr = false;
411 }
412 if(canSetOutputPtr) {
413 blob = (int8_t *)outputPtr;
414 } else {
415 blob = (int8_t *)MNNMemoryAllocAlignZeroAlign((size_t)Size);
416 }
417 if (blob == nullptr)
418 return nullptr;
419 // 2. nnz
420 myfile->read((char *)&nnz, 4);
421 // 3. max_step use # bits () (unsigned char)
422 myfile->read((char *)&iIdxNeedBits, 1);
423 // read idx array
424 // 4. buf for steps ceil(nnz*step need bits/8)
425 AutoStorage<unsigned char> arrIdxBuffer(nnz);
426 unsigned char *arrIdx = arrIdxBuffer.get();
427 if (nullptr == arrIdx) {
428 return nullptr;
429 }
430 {
431 size_t bufLen = (size_t)(ceil(0.125 * iIdxNeedBits * nnz));
432 char *buf = (char *)MNNMemoryAllocAlignZeroAlign(bufLen * sizeof(char));
433 if (nullptr == buf) {
434 return nullptr;
435 }
436 myfile->read((char *)buf, bufLen);
437 SplitBufToArray((uint8_t *)buf, (uint32_t)bufLen, (uint8_t *)arrIdx, (uint32_t)nnz, (uint32_t)iIdxNeedBits);
438 MNNMemoryFreeAlign(buf);
439 }
440 // 5. Avalable values Count(unsigned char)
441 myfile->read((char *)&ucMapSize, 1);
442 if (0 == ucMapSize) {
443 ucMapSize = 256;
444 }
445 result->weightMap.resize(ucMapSize);
446 // 6. valueset(signed char * valueset_size)
447 for (int i = 0; i < ucMapSize; i++) {
448 int8_t tmp;

Callers 1

loadMethod · 0.85

Calls 15

CreateSimpleSetFunction · 0.85
DestorySimpleSetFunction · 0.85
ReadBlobDimFunction · 0.85
SplitBufToArrayFunction · 0.85
MNNMemoryFreeAlignFunction · 0.85
InsertSimpleSetFunction · 0.85
SimpleRankFunction · 0.85
CreateSimpleMapFunction · 0.85
DestroySimpleMapFunction · 0.85
InsertMapFunction · 0.85
_log2Function · 0.85

Tested by

no test coverage detected