Ignore:
Timestamp:
Nov 12, 2018, 5:19:32 PM (6 months ago)
Author:
cameron
Message:

Fix FieldCompress? kernels to have user settable field width; update to use extraction method

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/deletion.cpp

    r6189 r6199  
    106106        kb->storeOutputStreamBlock("outputStreamSet", kb->getInt32(j), blockOffsetPhi, output);
    107107    }
    108 #ifndef STREAM_COMPRESS_USING_EXTRACTION_MASK
    109     Value * unitCount = kb->simd_popcount(mCompressFieldWidth, extractionMask);
    110     kb->storeOutputStreamBlock("unitCounts", kb->getInt32(0), blockOffsetPhi, kb->bitCast(unitCount));
    111 #endif
    112108    Value * nextBlk = kb->CreateAdd(blockOffsetPhi, kb->getSize(1));
    113109    blockOffsetPhi->addIncoming(nextBlk, processBlock);
     
    117113}
    118114
    119 #ifdef STREAM_COMPRESS_USING_EXTRACTION_MASK
    120 FieldCompressKernel::FieldCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b
     115FieldCompressKernel::FieldCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b, unsigned fw
    121116                                         , StreamSet * inputStreamSet, StreamSet * extractionMask
    122117                                         , StreamSet * outputStreamSet)
    123 : MultiBlockKernel("fieldCompress" + std::to_string(b->getBitBlockWidth() / inputStreamSet->getNumElements()) + "_" + std::to_string(inputStreamSet->getNumElements()),
     118: MultiBlockKernel("fieldCompress" + std::to_string(fw) + "_" + std::to_string(inputStreamSet->getNumElements()),
    124119// inputs
    125120{Binding{"inputStreamSet", inputStreamSet},
     
    128123{Binding{"outputStreamSet", outputStreamSet}},
    129124{}, {}, {})
    130 , mCompressFieldWidth(b->getBitBlockWidth() / inputStreamSet->getNumElements())
     125, mCompressFieldWidth(fw)
    131126, mStreamCount(inputStreamSet->getNumElements()) {
    132127
    133128}
    134 #else
    135 FieldCompressKernel::FieldCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b
    136                                          , StreamSet * inputStreamSet, StreamSet * extractionMask
    137                                          , StreamSet * outputStreamSet, StreamSet * unitCounts)
    138 : MultiBlockKernel("fieldCompress" + std::to_string(b->getBitBlockWidth() / inputStreamSet->getNumElements()) + "_" + std::to_string(inputStreamSet->getNumElements()),
    139 // inputs
    140 {Binding{"inputStreamSet", inputStreamSet},
    141 Binding{"extractionMask", extractionMask}},
    142 // outputs
    143 {Binding{"outputStreamSet", outputStreamSet},
    144 Binding{"unitCounts", unitCounts, FixedRate(), RoundUpTo(b->getBitBlockWidth())}},
    145 {}, {}, {})
    146 , mCompressFieldWidth(b->getBitBlockWidth() / inputStreamSet->getNumElements())
    147 , mStreamCount(inputStreamSet->getNumElements()) {
    148 
    149 }
    150 #endif
    151129
    152130void PEXTFieldCompressKernel::generateMultiBlockLogic(const std::unique_ptr<KernelBuilder> & kb, llvm::Value * const numOfBlocks) {
     
    154132    Type * fieldPtrTy = PointerType::get(fieldTy, 0);
    155133    Constant * PEXT_func = nullptr;
    156     Constant * popc_func = Intrinsic::getDeclaration(getModule(), Intrinsic::ctpop, fieldTy);
    157134    if (mPEXTWidth == 64) {
    158135        PEXT_func = Intrinsic::getDeclaration(kb->getModule(), Intrinsic::x86_bmi_pext_64);
     
    172149    Value * extractionMaskPtr = kb->getInputStreamBlockPtr("extractionMask", ZERO, blockOffsetPhi);
    173150    extractionMaskPtr = kb->CreatePointerCast(extractionMaskPtr, fieldPtrTy);
    174 #ifndef STREAM_COMPRESS_USING_EXTRACTION_MASK
    175     Value * unitCountPtr = kb->getOutputStreamBlockPtr("unitCounts", ZERO, blockOffsetPhi);
    176     unitCountPtr = kb->CreatePointerCast(unitCountPtr, fieldPtrTy);
    177151    for (unsigned i = 0; i < fieldsPerBlock; i++) {
    178152        mask[i] = kb->CreateLoad(kb->CreateGEP(extractionMaskPtr, kb->getInt32(i)));
    179         Value * popc = kb->CreateCall(popc_func, mask[i]);
    180         kb->CreateStore(popc, kb->CreateGEP(unitCountPtr, kb->getInt32(i)));
    181     }
    182 #else
    183     for (unsigned i = 0; i < fieldsPerBlock; i++) {
    184         mask[i] = kb->CreateLoad(kb->CreateGEP(extractionMaskPtr, kb->getInt32(i)));
    185     }
    186 #endif
     153    }
    187154    for (unsigned j = 0; j < mStreamCount; ++j) {
    188155        Value * inputPtr = kb->getInputStreamBlockPtr("inputStreamSet", kb->getInt32(j), blockOffsetPhi);
     
    207174                   {Binding{kb->getStreamSetTy(streamCount), "inputStreamSet"},
    208175                       Binding{kb->getStreamSetTy(), "extractionMask"}},
    209 #ifdef STREAM_COMPRESS_USING_EXTRACTION_MASK
    210176                   {Binding{kb->getStreamSetTy(streamCount), "outputStreamSet"}},
    211 #else
    212                    {Binding{kb->getStreamSetTy(streamCount), "outputStreamSet"},
    213                        Binding{kb->getStreamSetTy(), "unitCounts", FixedRate(), RoundUpTo(kb->getBitBlockWidth())}},
    214 #endif
    215177                   {}, {}, {})
    216178, mPEXTWidth(fieldWidth)
     
    221183StreamCompressKernel::StreamCompressKernel(const std::unique_ptr<kernel::KernelBuilder> & b
    222184                                           , StreamSet * source
    223                                            #ifdef STREAM_COMPRESS_USING_EXTRACTION_MASK
    224185                                           , StreamSet * extractionMask
    225                                            #else
    226                                            , StreamSet * unitCounts
    227                                            #endif
    228                                            , StreamSet * compresedOutput
     186                                           , StreamSet * compressedOutput
    229187                                           , const unsigned FieldWidth)
    230188: MultiBlockKernel("streamCompress" + std::to_string(FieldWidth) + "_" + std::to_string(source->getNumElements()),
    231189{Binding{"sourceStreamSet", source},
    232 #ifdef STREAM_COMPRESS_USING_EXTRACTION_MASK
    233190Binding{"extractionMask", extractionMask}},
    234 #else
    235 Binding{"unitCounts", unitCounts}},
    236 #endif
    237 {Binding{"compressedOutput", compresedOutput, BoundedRate(0, 1)}},
     191{Binding{"compressedOutput", compressedOutput, BoundedRate(0, 1)}},
    238192{}, {}, {})
    239193, mCompressedFieldWidth(FieldWidth)
     
    286240        pendingDataPhi[i]->addIncoming(pendingData[i], entry);
    287241    }
    288     #ifdef STREAM_COMPRESS_USING_EXTRACTION_MASK
    289     Value * fieldPopCounts = b->simd_popcount(fw, b->loadInputStreamBlock("extractionMask", ZERO, blockOffsetPhi));
    290     #else
    291     Value * fieldPopCounts = b->loadInputStreamBlock("unitCounts", ZERO, blockOffsetPhi);
    292     #endif
     242    Value * fieldPopCounts = b->simd_popcount(mCompressedFieldWidth, b->loadInputStreamBlock("extractionMask", ZERO, blockOffsetPhi));
    293243    // For each field determine the (partial) sum popcount of all fields up to and
    294244    // including the current field.
     
    317267    Value * pendingSum = b->simd_add(mCompressedFieldWidth, partialSum, splatPending);
    318268    Value * fieldNo = b->simd_srli(mCompressedFieldWidth, pendingSum, std::log2(mCompressedFieldWidth));
    319   //
    320269    // Now process the input data block of each stream in the input stream set.
    321270    //
Note: See TracChangeset for help on using the changeset viewer.