Ignore:
Timestamp:
Jul 17, 2015, 1:41:26 PM (4 years ago)
Author:
cameron
Message:

Carry Manager progress and bug fix

Location:
icGREP/icgrep-devel/icgrep/pablo
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/pablo/carry_data.cpp

    r4679 r4682  
    1313
    1414namespace pablo {
    15  
    16    
    17 const unsigned bitsPerPack = 64;
    1815
     16   
     17unsigned alignCeiling(unsigned toAlign, unsigned alignment) {
     18    return ((toAlign - 1) | (alignment - 1)) + 1;
     19}
    1920
    20 void AlignUpwards(unsigned & toAlign, unsigned alignment) {
    21     if ((toAlign & (alignment - 1)) != 0) {
    22         toAlign = (toAlign + alignment) & (alignment - 1);
     21void EnsurePackHasSpace(unsigned & packedTotalBits, unsigned addedBits) {
     22    unsigned bitsInCurrentPack = packedTotalBits % PACK_SIZE;
     23    if ((bitsInCurrentPack > 0) && (bitsInCurrentPack + addedBits > PACK_SIZE)) {
     24      packedTotalBits = alignCeiling(packedTotalBits, PACK_SIZE);
    2325    }
    2426}
    2527
    26 void EnsurePackHasSpace(unsigned & packedTotalBits, unsigned addedBits) {
    27     unsigned bitsInCurrentPack = packedTotalBits % bitsPerPack;
    28     if (bitsInCurrentPack + addedBits > bitsPerPack) {
    29         AlignUpwards(packedTotalBits, bitsPerPack);
    30     }
    31 }
    32    
    33    
    3428unsigned PabloBlockCarryData::enumerate(PabloBlock & blk) {
    3529    for (Statement * stmt : blk) {
     
    7468    nested.frameOffsetinBits = advance1.frameOffsetinBits + advance1.entries;
    7569#else
    76     addWithCarry.frameOffsetinBits = longAdvance.frameOffsetinBits + longAdvance.allocatedBitBlocks * BLOCK_SIZE;
     70    shortAdvance.frameOffsetinBits = longAdvance.frameOffsetinBits + longAdvance.allocatedBitBlocks * BLOCK_SIZE;
     71    addWithCarry.frameOffsetinBits = shortAdvance.frameOffsetinBits + shortAdvance.entries * BLOCK_SIZE;
    7772    advance1.frameOffsetinBits = addWithCarry.frameOffsetinBits + addWithCarry.entries * BLOCK_SIZE;
    78     shortAdvance.frameOffsetinBits = advance1.frameOffsetinBits + advance1.entries * BLOCK_SIZE;
    79     nested.frameOffsetinBits = shortAdvance.frameOffsetinBits + shortAdvance.entries * BLOCK_SIZE;
     73    nested.frameOffsetinBits = advance1.frameOffsetinBits + advance1.entries * BLOCK_SIZE;
    8074#endif
    8175    unsigned nestedframePosition = nested.frameOffsetinBits;
     
    117111        // Need extra space for the summary variable, always the last
    118112        // entry within an if block.
    119         AlignUpwards(scopeCarryDataBits, BLOCK_SIZE);
     113        scopeCarryDataBits = alignCeiling(scopeCarryDataBits, PACK_SIZE);
    120114        summary.frameOffsetinBits = scopeCarryDataBits;
    121         summary.allocatedBits = BLOCK_SIZE;
    122         scopeCarryDataBits += BLOCK_SIZE;
     115        summary.allocatedBits = PACK_SIZE;
     116        scopeCarryDataBits += PACK_SIZE;
    123117    }
    124118    else {
  • icGREP/icgrep-devel/icgrep/pablo/carry_data.h

    r4676 r4682  
    2121unsigned const LongAdvanceBase = 64;
    2222
     23#ifdef PACKING
     24const unsigned PACK_SIZE = 64;
     25#else
     26const unsigned PACK_SIZE = BLOCK_SIZE;
     27#endif
     28
     29
    2330static unsigned power2ceil (unsigned v) {
    2431    unsigned ceil = 1;
    2532    while (ceil < v) ceil *= 2;
    2633    return ceil;
     34}
     35
     36static unsigned alignCeiling(unsigned toAlign, unsigned alignment) {
     37    return ((toAlign - 1) | (alignment - 1)) + 1;
     38}
     39
     40static unsigned fullOrPartialBlocks(unsigned bits, unsigned block_size) {
     41    return alignCeiling(bits, block_size) / block_size;
    2742}
    2843
     
    5974       
    6075    unsigned longAdvanceCarryDataOffset(unsigned advanceIndex)  const {
    61         return longAdvance.frameOffsetinBits / BLOCK_SIZE + advanceIndex;
     76        return fullOrPartialBlocks(longAdvance.frameOffsetinBits, BLOCK_SIZE) + advanceIndex;
    6277    }
    6378   
    6479    unsigned longAdvanceEntries(unsigned shift_amount) const {
    65         return (shift_amount + BLOCK_SIZE - 1)/BLOCK_SIZE;
     80        return fullOrPartialBlocks(shift_amount, BLOCK_SIZE);
    6681    }
    6782   
     
    7388   
    7489    unsigned shortAdvanceCarryDataOffset(unsigned advanceIndex)  const {
    75         return shortAdvance.frameOffsetinBits / BLOCK_SIZE + advanceIndex;
     90        return fullOrPartialBlocks(shortAdvance.frameOffsetinBits, PACK_SIZE) + advanceIndex;
    7691    }
    7792   
    7893    unsigned unitAdvanceCarryDataOffset(unsigned advanceIndex)  const {
    79         return advance1.frameOffsetinBits / BLOCK_SIZE + advanceIndex;
     94        return fullOrPartialBlocks(advance1.frameOffsetinBits, PACK_SIZE) + advanceIndex;
    8095    }
    8196   
    8297    unsigned carryOpCarryDataOffset(unsigned idx)  const {
    83         return addWithCarry.frameOffsetinBits / BLOCK_SIZE + idx;
     98        return fullOrPartialBlocks(addWithCarry.frameOffsetinBits, PACK_SIZE) + idx;
    8499    }
    85100   
    86101    unsigned summaryCarryDataIndex()  const {
    87         return summary.frameOffsetinBits / BLOCK_SIZE;
     102        return fullOrPartialBlocks(summary.frameOffsetinBits, PACK_SIZE);
    88103    }
    89104   
    90     unsigned getLocalCarryDataSize () { return nested.frameOffsetinBits / BLOCK_SIZE; }
     105    unsigned getLocalCarryPackIndex () { return shortAdvance.frameOffsetinBits / PACK_SIZE; }
    91106
    92     unsigned getScopeCarryDataSize () { return scopeCarryDataBits / BLOCK_SIZE; }
     107    unsigned getLocalCarryDataSize () { return fullOrPartialBlocks(nested.frameOffsetinBits - shortAdvance.frameOffsetinBits, PACK_SIZE); }
     108
     109    unsigned getScopeCarryDataSize () { return fullOrPartialBlocks(scopeCarryDataBits, PACK_SIZE); }
    93110   
    94111    bool blockHasCarries() const { return scopeCarryDataBits > 0;}
    95112   
    96     bool explicitSummaryRequired() const { return (ifDepth > 0) && (scopeCarryDataBits > BLOCK_SIZE);}
     113    bool explicitSummaryRequired() const { return (ifDepth > 0) && (scopeCarryDataBits > PACK_SIZE);}
    97114   
    98115private:
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.cpp

    r4678 r4682  
    6464    /* Methods for getting and setting individual carry values. */
    6565   
     66//#define LOAD_STORE_ON_BLOCK_ENTRY_EXIT   
    6667Value * CarryManager::getCarryOpCarryIn(int localIndex) {
    6768    unsigned cd_index = mCurrentScopeIndex + mCarryInfo->carryOpCarryDataOffset(localIndex);
     69#ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    6870    if (mCarryInfo->getWhileDepth() == 0) {
    6971       Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd_index));
    7072       mCarryInVector[cd_index] = mBuilder->CreateAlignedLoad(packPtr, BLOCK_SIZE/8);
    7173    }
     74#endif
    7275    return mCarryInVector[cd_index];
    7376}
     
    7679    unsigned cd_index = mCurrentScopeIndex + mCarryInfo->carryOpCarryDataOffset(localIndex);
    7780    mCarryOutVector[cd_index] = carry_out;
     81#ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    7882    if (mCarryInfo->getWhileDepth() == 0) {
    7983       Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(cd_index));
    8084       mBuilder->CreateAlignedStore(carry_out, packPtr, BLOCK_SIZE/8);
    8185    }
     86#endif
    8287}
    8388
     
    98103    unsigned carryDataIndex = mCurrentScopeIndex + mCarryInfo->unitAdvanceCarryDataOffset(localIndex);
    99104    mCarryOutVector[carryDataIndex] = strm;
     105#ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    100106    if (mCarryInfo->getWhileDepth() == 0) {
    101107        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carryDataIndex));
     
    103109        mBuilder->CreateAlignedStore(strm, packPtr, BLOCK_SIZE/8);
    104110    }
     111#endif
    105112    Value * carry_in = mCarryInVector[carryDataIndex];
    106113    Value* result_value;
     
    122129    unsigned carryDataIndex = mCurrentScopeIndex + mCarryInfo->shortAdvanceCarryDataOffset(localIndex);
    123130    mCarryOutVector[carryDataIndex] = strm;
     131#ifndef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    124132    if (mCarryInfo->getWhileDepth() == 0) {
    125133        Value * packPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carryDataIndex));
     
    127135        mBuilder->CreateAlignedStore(strm, packPtr, BLOCK_SIZE/8);
    128136    }
     137#endif
    129138    Value * carry_in = mCarryInVector[carryDataIndex];
    130139    Value* advanceq_longint = mBuilder->CreateBitCast(carry_in, mBuilder->getIntNTy(BLOCK_SIZE));
     
    237246    }
    238247    else {
     248        auto localCarryIndex = mCurrentScopeIndex + mCarryInfo->getLocalCarryPackIndex();
    239249        auto localCarryPacks = mCarryInfo->getLocalCarryDataSize();
    240250        if (localCarryPacks > 0) {
    241             carry_summary = mCarryOutVector[mCurrentScopeIndex];
     251            carry_summary = mCarryOutVector[localCarryIndex];
    242252            for (auto i = 1; i < localCarryPacks; i++) {
    243253                //carry_summary = mBuilder->CreateOr(carry_summary, mPabloBlock->mCarryOutPack[i]);           
    244                 carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutVector[mCurrentScopeIndex+i]);
     254                carry_summary = mBuilder->CreateOr(carry_summary, mCarryOutVector[localCarryIndex+i]);
    245255            }
    246256        }
     
    273283
    274284void CarryManager::ensureCarriesLoadedLocal() {
    275 #if 0
     285#ifdef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    276286    if ((mCarryInfo->getScopeCarryDataSize() == 0 ) || (mCarryInfo->getWhileDepth() > 0)) return;
    277     if (mCarryInfo->explicitSummaryRequired()) {
    278         auto localCarryIndex = mCurrentScopeIndex + mCarryInfo->getLocalCarryDataOffset();
     287    if ((mCarryInfo->getIfDepth() == 0) || mCarryInfo->explicitSummaryRequired()) {
     288        auto localCarryIndex = mCurrentScopeIndex + mCarryInfo->getLocalCarryPackIndex();
    279289        auto localCarryPacks = mCarryInfo->getLocalCarryDataSize();
    280         for (auto i = 0; i < localCarryPacks; i++) {       
     290        //std::cerr << "ensureCarriesLoadedLocal: localCarryIndex =  " << localCarryIndex << "localCarryPacks =  " << localCarryPacks << std::endl;
     291        for (auto i = localCarryIndex; i < localCarryIndex + localCarryPacks; i++) {       
    281292            mCarryInVector[i] = mBuilder->CreateAlignedLoad(mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(i)), BLOCK_SIZE/8, false);
    282293        }
     
    286297
    287298void CarryManager::ensureCarriesStoredLocal() {
    288 #if 0
     299#ifdef LOAD_STORE_ON_BLOCK_ENTRY_EXIT
    289300    if ((mCarryInfo->getScopeCarryDataSize() == 0 ) || (mCarryInfo->getWhileDepth() > 0)) return;
    290     auto localCarryIndex = mCurrentScopeIndex + mCarryInfo->getLocalCarryDataOffset();
     301    auto localCarryIndex = mCurrentScopeIndex + mCarryInfo->getLocalCarryPackIndex();
    291302    auto localCarryPacks = mCarryInfo->getLocalCarryDataSize();
    292     for (auto i = 0; i < localCarryPacks; i++) {       
     303    //std::cerr << "ensureCarriesStoredLocal: localCarryIndex =  " << localCarryIndex << "localCarryPacks =  " << localCarryPacks << std::endl;
     304    for (auto i = localCarryIndex; i < localCarryIndex + localCarryPacks; i++) {       
    293305        Value * storePtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(i));
    294306        mBuilder->CreateAlignedStore(mCarryOutVector[i], storePtr, BLOCK_SIZE/8, false);
    295     }
    296     if (mCarryInfo->getScopeCarryDataSize() > 1) {
    297         const unsigned carrySummaryIndex = mCurrentScopeIndex + mCarryInfo->summaryCarryDataIndex();
    298         Value * summaryPtr = mBuilder->CreateGEP(mCarryDataPtr, mBuilder->getInt64(carrySummaryIndex));
    299         mBuilder->CreateAlignedStore(mCarryOutVector[carrySummaryIndex], summaryPtr, BLOCK_SIZE/8, false);
    300307    }
    301308#endif
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4680 r4682  
    391391void PabloCompiler::compileBlock(PabloBlock & block) {
    392392    mPabloBlock = & block;
     393    mCarryManager->ensureCarriesLoadedLocal();
    393394    for (const Statement * statement : block) {
    394395        compileStatement(statement);
    395396    }
     397    mCarryManager->ensureCarriesStoredLocal();
    396398    mPabloBlock = block.getParent();
    397399}
Note: See TracChangeset for help on using the changeset viewer.