Changeset eeacdad
- Timestamp:
- 09/28/18 12:44:11 (6 years ago)
- Branches:
- master, pympi
- Children:
- b060d3c
- Parents:
- 2c47b73
- git-author:
- Hal Finkel <hfinkel@…> (09/28/18 12:44:11)
- git-committer:
- Hal Finkel <hfinkel@…> (09/28/18 12:44:11)
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
GenericIO.cxx
r2c47b73 reeacdad 368 368 static bool sz_initialized = false; 369 369 370 static int GetSZDT(GenericIO::Variable &Var) { 371 if (Var.hasElementType<float>()) 372 return SZ_FLOAT; 373 else if (Var.hasElementType<double>()) 374 return SZ_DOUBLE; 375 else if (Var.hasElementType<uint8_t>()) 376 return SZ_UINT8; 377 else if (Var.hasElementType<int8_t>()) 378 return SZ_INT8; 379 else if (Var.hasElementType<uint16_t>()) 380 return SZ_UINT16; 381 else if (Var.hasElementType<int16_t>()) 382 return SZ_INT16; 383 else if (Var.hasElementType<uint32_t>()) 384 return SZ_UINT32; 385 else if (Var.hasElementType<int32_t>()) 386 return SZ_INT32; 387 else if (Var.hasElementType<uint64_t>()) 388 return SZ_UINT64; 389 else if (Var.hasElementType<int64_t>()) 390 return SZ_INT64; 391 else 392 return -1; 393 } 394 370 395 #ifndef GENERICIO_NO_MPI 371 396 void GenericIO::write() { … … 501 526 memset(&LocalBlockHeaders[i], 0, sizeof(BlockHeader<IsBigEndian>)); 502 527 if (ShouldCompress) { 528 void *OrigData = Vars[i].Data; 529 bool FreeOrigData = false; 530 size_t OrigUnitSize = Vars[i].Size; 531 size_t OrigDataSize = NElems*Vars[i].Size; 532 533 int FilterIdx = 0; 534 if (Vars[i].LCI.Mode != LossyCompressionInfo::LCModeNone) { 535 int SZDT = GetSZDT(Vars[i]); 536 if (SZDT == -1) 537 goto nosz; 538 539 int EBM; 540 switch (Vars[i].LCI.Mode) { 541 case LossyCompressionInfo::LCModeAbs: 542 EBM = ABS; 543 break; 544 case LossyCompressionInfo::LCModeRel: 545 EBM = REL; 546 break; 547 case LossyCompressionInfo::LCModeAbsAndRel: 548 EBM = ABS_AND_REL; 549 break; 550 case LossyCompressionInfo::LCModeAbsOrRel: 551 EBM = ABS_OR_REL; 552 break; 553 case LossyCompressionInfo::LCModePSNR: 554 EBM = PSNR; 555 break; 556 } 557 558 size_t LOutSize; 559 unsigned char *LCompressedData = SZ_compress_args(SZDT, Vars[i].Data, &LOutSize, EBM, 560 Vars[i].LCI.AbsErrThreshold, Vars[i].LCI.RelErrThreshold, 561 Vars[i].LCI.PSNRThreshold, 0, 0, 0, 0, NElems); 562 if (!LCompressedData) 563 goto nosz; 564 if (LOutSize >= NElems*Vars[i].Size) { 565 free(LCompressedData); 566 goto nosz; 567 } 568 569 OrigData = LCompressedData; 570 FreeOrigData = true; 571 OrigUnitSize = 1; 572 OrigDataSize = LOutSize; 573 574 strncpy(LocalBlockHeaders[i].Filters[FilterIdx++], LossyCompressName, FilterNameSize); 575 } 576 nosz: 577 503 578 LocalCData[i].resize(sizeof(CompressHeader<IsBigEndian>)); 504 579 505 580 CompressHeader<IsBigEndian> *CH = (CompressHeader<IsBigEndian>*) &LocalCData[i][0]; 506 CH->OrigCRC = crc64_omp( Vars[i].Data, Vars[i].Size*NElems);581 CH->OrigCRC = crc64_omp(OrigData, OrigDataSize); 507 582 508 583 #ifdef _OPENMP … … 526 601 #endif 527 602 528 LocalCData[i].resize(LocalCData[i].size() + NElems*Vars[i].Size);529 if (blosc_compress(9, 1, Vars[i].Size, NElems*Vars[i].Size, Vars[i].Data,603 LocalCData[i].resize(LocalCData[i].size() + OrigDataSize); 604 if (blosc_compress(9, 1, OrigUnitSize, OrigDataSize, OrigData, 530 605 &LocalCData[i][0] + sizeof(CompressHeader<IsBigEndian>), 531 NElems*Vars[i].Size) <= 0) 606 OrigDataSize) <= 0) { 607 if (FreeOrigData) 608 free(OrigData); 609 532 610 goto nocomp; 533 534 strncpy(LocalBlockHeaders[i].Filters[0], CompressName, FilterNameSize); 611 } 612 613 if (FreeOrigData) 614 free(OrigData); 615 616 strncpy(LocalBlockHeaders[i].Filters[FilterIdx++], CompressName, FilterNameSize); 535 617 size_t CNBytes, CCBytes, CBlockSize; 536 618 blosc_cbuffer_sizes(&LocalCData[i][0] + sizeof(CompressHeader<IsBigEndian>), … … 1435 1517 1436 1518 vector<unsigned char> LData; 1519 bool HasSZ = false; 1437 1520 void *Data = VarData; 1438 1521 bool HasExtraSpace = Vars[i].HasExtraSpace; … … 1445 1528 Offset = BH->Start; 1446 1529 1447 if (strncmp(BH->Filters[0], CompressName, FilterNameSize) == 0) { 1530 int FilterIdx = 0; 1531 1532 if (strncmp(BH->Filters[FilterIdx], LossyCompressName, FilterNameSize) == 0) { 1533 ++FilterIdx; 1534 HasSZ = true; 1535 } 1536 1537 if (strncmp(BH->Filters[FilterIdx], CompressName, FilterNameSize) == 0) { 1448 1538 LData.resize(ReadSize); 1449 1539 Data = &LData[0]; 1450 1540 HasExtraSpace = true; 1451 } else if (BH->Filters[ 0][0] != '\0') {1541 } else if (BH->Filters[FilterIdx][0] != '\0') { 1452 1542 stringstream ss; 1453 1543 ss << "Unknown filter \"" << BH->Filters[0] << "\" on variable " << Vars[i].Name; … … 1574 1664 } 1575 1665 1666 if (!sz_initialized) { 1667 SZ_Init(NULL); 1668 sz_initialized = true; 1669 } 1670 1576 1671 #ifdef _OPENMP 1577 1672 blosc_set_nthreads(omp_get_max_threads()); … … 1579 1674 #endif 1580 1675 1676 void *OrigData = VarData; 1677 size_t OrigDataSize = Vars[i].Size*RH->NElems; 1678 1679 if (HasSZ) { 1680 size_t CNBytes, CCBytes, CBlockSize; 1681 blosc_cbuffer_sizes(&LData[0] + sizeof(CompressHeader<IsBigEndian>), 1682 &CNBytes, &CCBytes, &CBlockSize); 1683 1684 OrigData = malloc(CNBytes); 1685 OrigDataSize = CNBytes; 1686 } 1687 1581 1688 blosc_decompress(&LData[0] + sizeof(CompressHeader<IsBigEndian>), 1582 VarData, Vars[i].Size*RH->NElems);1583 1584 if (CH->OrigCRC != crc64_omp( VarData, Vars[i].Size*RH->NElems)) {1689 OrigData, OrigDataSize); 1690 1691 if (CH->OrigCRC != crc64_omp(OrigData, OrigDataSize)) { 1585 1692 ++NErrs[2]; 1586 1693 break; 1587 1694 } 1695 1696 if (HasSZ) { 1697 int SZDT = GetSZDT(Vars[i]); 1698 size_t LDSz = SZ_decompress_args(SZDT, (unsigned char *)OrigData, OrigDataSize, 1699 VarData, 0, 0, 0, 0, RH->NElems); 1700 free(OrigData); 1701 1702 if (LDSz != Vars[i].Size*RH->NElems) 1703 throw runtime_error("Variable " + Vars[i].Name + 1704 ": SZ decompression yielded the wrong amount of data"); 1705 } 1588 1706 } 1589 1707 1590 1708 // Byte swap the data if necessary. 1591 if (IsBigEndian != isBigEndian() )1709 if (IsBigEndian != isBigEndian() && !HasSZ) 1592 1710 for (size_t j = 0; 1593 1711 j < RH->NElems*(Vars[i].Size/Vars[i].ElementSize); ++j) { -
GenericIO.h
r6461f57 reeacdad 288 288 ElementSize(VI.ElementSize), LCI(LCI) {} 289 289 290 template <typename ET> 291 bool hasElementType() { 292 if (ElementSize != sizeof(ET)) 293 return false; 294 if (IsFloat != !std::numeric_limits<ET>::is_integer) 295 return false; 296 if (IsSigned != std::numeric_limits<ET>::is_signed) 297 return false; 298 299 return true; 300 } 301 290 302 std::string Name; 291 303 std::size_t Size;
Note: See TracChangeset
for help on using the changeset viewer.