Ignore:
Timestamp:
Mar 11, 2016, 4:44:53 PM (3 years ago)
Author:
nmedfort
Message:

Added ability to name internal state types; removed unnecessary predefined states. Some progress towards supporting segment size > 1

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

Legend:

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

    r4968 r4970  
    2828    const unsigned totalCarryDataSize = std::max<unsigned>(enumerate(mRootScope, 0, 0), 1);
    2929    mCarryPackPtr.resize(totalCarryDataSize, nullptr);
    30     mCarryInPack.resize(totalCarryDataSize, nullptr);
     30    mCarryInPack.resize(totalCarryDataSize);
    3131    mCarryOutPack.resize(totalCarryDataSize, nullptr);
    3232    mTotalCarryDataBitBlocks = totalCarryDataSize;
    3333    ArrayType* cdArrayTy = ArrayType::get(mBitBlockType, mTotalCarryDataBitBlocks);
    34     mCdArrayIdx = kBuilder->addInternalStateType(cdArrayTy);
     34    mCdArrayIdx = kBuilder->addInternalState(cdArrayTy);
    3535    if (mPabloCountCount > 0) {
    3636        ArrayType* pcArrayTy = ArrayType::get(iBuilder->getIntNTy(64), mPabloCountCount);
    37         mPcArrayIdx = kBuilder->addInternalStateType(pcArrayTy);
     37        mPcArrayIdx = kBuilder->addInternalState(pcArrayTy);
     38    }
     39    mKernelBuilder = kBuilder;
     40}
     41
     42/** ------------------------------------------------------------------------------------------------------------- *
     43 * @brief reset
     44 ** ------------------------------------------------------------------------------------------------------------- */
     45void CarryManager::reset() {
     46    Value * cdArrayPtr = mKernelBuilder->getInternalState(mCdArrayIdx);
     47    mCarryPackBasePtr = iBuilder->CreateBitCast(cdArrayPtr, PointerType::get(mCarryPackType, 0));
     48    mCarryBitBlockPtr = iBuilder->CreateBitCast(cdArrayPtr, PointerType::get(mBitBlockType, 0));
     49    if (mPabloCountCount > 0) {
     50        Value * pcArrayPtr = mKernelBuilder->getInternalState(mPcArrayIdx);
     51        mPopcountBasePtr = iBuilder->CreateBitCast(pcArrayPtr, Type::getInt64PtrTy(iBuilder->getContext()));
    3852    }
    3953    mCurrentScope = mRootScope;
     
    4155    mCarryInfo = mCarryInfoVector[0];
    4256    mCarryOutPack[summaryPack()] = Constant::getNullValue(mCarryPackType);
    43 }
    44 
    45 /** ------------------------------------------------------------------------------------------------------------- *
    46  * @brief initialize_setPtrs
    47  ** ------------------------------------------------------------------------------------------------------------- */
    48 void CarryManager::initialize_setPtrs(KernelBuilder * kBuilder) {
    49     Value * cdArrayPtr = kBuilder->getInternalState(mCdArrayIdx);
    50     mCarryPackBasePtr = iBuilder->CreateBitCast(cdArrayPtr, PointerType::get(mCarryPackType, 0));
    51     mCarryBitBlockPtr = iBuilder->CreateBitCast(cdArrayPtr, PointerType::get(mBitBlockType, 0));
    52     if (mPabloCountCount > 0) {
    53         Value * pcArrayPtr = kBuilder->getInternalState(mPcArrayIdx);
    54         mPopcountBasePtr = iBuilder->CreateBitCast(pcArrayPtr, Type::getInt64PtrTy(iBuilder->getContext()));
    55     }
    56     setBlockNo(kBuilder);
    57     mCurrentScope = mRootScope;
    58     mCurrentFrameIndex = 0;
    59     mCarryInfo = mCarryInfoVector[0];
    60     mCarryOutPack[summaryPack()] = Constant::getNullValue(mCarryPackType);
    61 }
    62 
    63 /** ------------------------------------------------------------------------------------------------------------- *
    64  * @brief setBlockNo
    65  ** ------------------------------------------------------------------------------------------------------------- */
    66 void CarryManager::setBlockNo(KernelBuilder * kBuilder) {
    67     mBlockNo = iBuilder->CreateUDiv(iBuilder->CreateBlockAlignedLoad(kBuilder->getInternalState(mFilePosIdx)), iBuilder->getInt64(mBitBlockWidth));
     57    assert (mCarrySummary.empty());
     58    std::fill(mCarryInPack.begin(), mCarryInPack.end(), nullptr);
    6859}
    6960
     
    205196    const unsigned bufsize = mCarryInfo->longAdvanceBufferSize(shiftAmount);
    206197    Value * indexMask = iBuilder->getInt64(bufsize - 1);  // A mask to implement circular buffer indexing
    207     Value * loadIndex0 = iBuilder->CreateAdd(iBuilder->CreateAnd(iBuilder->CreateSub(mBlockNo, iBuilder->getInt64(advanceEntries)), indexMask), advBaseIndex);
    208     Value * storeIndex = iBuilder->CreateAdd(iBuilder->CreateAnd(mBlockNo, indexMask), advBaseIndex);
     198    Value * blockIndex = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getBlockIndexScalar());
     199    Value * loadIndex0 = iBuilder->CreateAdd(iBuilder->CreateAnd(iBuilder->CreateSub(blockIndex, iBuilder->getInt64(advanceEntries)), indexMask), advBaseIndex);
     200    Value * storeIndex = iBuilder->CreateAdd(iBuilder->CreateAnd(blockIndex, indexMask), advBaseIndex);
    209201    Value * carry_block0 = iBuilder->CreateBlockAlignedLoad(iBuilder->CreateGEP(mCarryBitBlockPtr, loadIndex0));
    210202    // If the long advance is an exact multiple of mBITBLOCK_WIDTH, we simply return the oldest
     
    215207    }
    216208    // Otherwise we need to combine data from the two oldest blocks.
    217     Value * loadIndex1 = iBuilder->CreateAdd(iBuilder->CreateAnd(iBuilder->CreateSub(mBlockNo, iBuilder->getInt64(advanceEntries-1)), indexMask), advBaseIndex);
     209    Value * loadIndex1 = iBuilder->CreateAdd(iBuilder->CreateAnd(iBuilder->CreateSub(blockIndex, iBuilder->getInt64(advanceEntries-1)), indexMask), advBaseIndex);
    218210    Value * carry_block1 = iBuilder->CreateBlockAlignedLoad(iBuilder->CreateGEP(mCarryBitBlockPtr, loadIndex1));
    219211    Value* block0_shr = iBuilder->CreateLShr(iBuilder->CreateBitCast(carry_block0, iBuilder->getIntNTy(mBitBlockWidth)), mBitBlockWidth - block_shift);
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4959 r4970  
    1313#include <pablo/carry_data.h>
    1414#include <llvm/IR/Constants.h>
    15 #include "../kernels/kernel.h"
     15#include <kernels/kernel.h>
    1616
    1717/*
     
    4848    , mCarryBitBlockPtr(nullptr)
    4949    , mPopcountBasePtr(nullptr)
    50     , mBlockNo(nullptr)
     50    , mKernelBuilder(nullptr)
    5151    , mPabloCountCount(0)
    5252    , mTotalCarryDataBitBlocks(0)
     
    6161    void initialize(PabloFunction * const function, KernelBuilder * const kBuilder);
    6262
    63     void initialize_setPtrs(KernelBuilder * const kBuilder);
     63    void reset();
    6464
    65     void setBlockNo(KernelBuilder * kBuilder);
    66     Value * getBlockNo() const;
    67    
    6865    unsigned enumerate(PabloBlock * blk, unsigned ifDepth, unsigned whileDepth);
    6966         
     
    143140    Value * mCarryBitBlockPtr;
    144141    Value * mPopcountBasePtr;
    145     Value * mBlockNo;
     142    KernelBuilder * mKernelBuilder;
    146143    unsigned mPabloCountCount; // Number of Pablo "Count" operations
    147144    unsigned mTotalCarryDataBitBlocks;
     
    163160}
    164161
    165 inline Value * CarryManager::getBlockNo() const {
    166     return mBlockNo;
    167 }
    168 
    169162}
    170163
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4968 r4970  
    7373, mPabloFunction(nullptr)
    7474, mPabloBlock(nullptr)
    75 , mKBuilder(nullptr)
     75, mKernelBuilder(nullptr)
    7676, mWhileDepth(0)
    7777, mIfDepth(0)
    7878, mFunction(nullptr)
    79 , mMaxWhileDepth(0)
    80 , mFilePosIdx(2) {
     79, mMaxWhileDepth(0) {
    8180   
    8281}
    8382
    8483void PabloCompiler::setKernel(KernelBuilder * kBuilder){
    85     mKBuilder = kBuilder;   
     84    mKernelBuilder = kBuilder;
    8685}
    8786
     
    124123
    125124    for (unsigned i = 0; i < function->getNumOfParameters(); ++i) {
    126         mKBuilder->addInputStream(1, function->getParameter(i)->getName()->to_string());
     125        mKernelBuilder->addInputStream(1, function->getParameter(i)->getName()->to_string());
    127126    }
    128127    for (unsigned i = 0; i < function->getNumOfResults(); ++i) {
    129         mKBuilder->addOutputStream(1);
    130     }
    131 
    132     mCarryManager->initialize(function, mKBuilder);
    133 
    134     mKBuilder->prepareFunction();
    135 
    136     mFunction = mKBuilder->getDoBlockFunction();
    137 
    138     mCarryManager->initialize_setPtrs(mKBuilder);
    139 
    140     for(unsigned i = 0; i < mKBuilder->getSegmentBlocks(); i++){
     128        mKernelBuilder->addOutputStream(1);
     129    }
     130
     131    mCarryManager->initialize(function, mKernelBuilder);
     132
     133    mKernelBuilder->prepareFunction();
     134
     135    mFunction = mKernelBuilder->getDoBlockFunction();
     136
     137    for(unsigned i = 0; i < mKernelBuilder->getSegmentBlocks(); ++i){
     138
     139        mCarryManager->reset();
    141140
    142141        for (unsigned j = 0; j < function->getNumOfParameters(); ++j) {
    143             mMarkerMap.insert(std::make_pair(function->getParameter(j), mKBuilder->getInputStream(j)));
     142            mMarkerMap.insert(std::make_pair(function->getParameter(j), mKernelBuilder->getInputStream(j)));
    144143        }
    145144
    146145        compileBlock(function->getEntryBlock());
    147 
    148         Value * filePos = mKBuilder->getInternalState(mFilePosIdx);
    149         filePos = iBuilder->CreateBlockAlignedLoad(filePos);
    150         filePos = iBuilder->CreateAdd(filePos, iBuilder->getInt64(iBuilder->getBitBlockWidth()));
    151         mKBuilder->setInternalState(mFilePosIdx, filePos);
    152 
    153         mCarryManager->setBlockNo(mKBuilder);
    154146
    155147        for (unsigned j = 0; j < function->getNumOfResults(); ++j) {
     
    161153                result = f->second;
    162154            }
    163             iBuilder->CreateBlockAlignedStore(result, mKBuilder->getOutputStream(j));
     155            iBuilder->CreateBlockAlignedStore(result, mKernelBuilder->getOutputStream(j));
    164156        }
    165157
    166158        mMarkerMap.clear();
    167159
    168         mKBuilder->increment();
     160        mKernelBuilder->increment();
    169161    }   
    170162
    171     mKBuilder->finalize();
     163    mKernelBuilder->finalize();
    172164}
    173165
     
    178170    Examine(function.getEntryBlock());
    179171}
    180 
    181172
    182173void PabloCompiler::Examine(PabloBlock * block) {
     
    192183}
    193184
    194 void PabloCompiler::compileBlock(PabloBlock * block) {
     185void PabloCompiler::compileBlock(const PabloBlock * const block) {
    195186    mPabloBlock = block;
    196187    for (const Statement * statement : *block) {
     
    436427        const unsigned offset = l->getAmount() / iBuilder->getBitBlockWidth();
    437428        const unsigned shift = (l->getAmount() % iBuilder->getBitBlockWidth());
    438         Value * const b0 = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(mKBuilder->getInputStream(offset), index), streamType);
    439         Value * const b1 = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(mKBuilder->getInputStream(offset + 1), index), streamType);
     429        Value * const b0 = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(offset), index), streamType);
     430        Value * const b1 = iBuilder->CreateBitCast(iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(offset + 1), index), streamType);
    440431        Value * result = iBuilder->CreateOr(iBuilder->CreateLShr(b0, shift), iBuilder->CreateShl(b1, iBuilder->getBitBlockWidth() - shift), "lookahead");
    441432        expr = iBuilder->CreateBitCast(result, iBuilder->getBitBlockType());
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4959 r4970  
    5858    void Examine(PabloBlock * block);
    5959
    60     void compileBlock(PabloBlock * block);
     60    void compileBlock(const PabloBlock * const block);
    6161    void compileStatement(const Statement * stmt);
    6262    void compileIf(const If * ifStmt);
     
    7373    CarryManager *                      mCarryManager;
    7474
    75     PabloFunction *                     mPabloFunction;
    76     PabloBlock *                        mPabloBlock;
     75    const PabloFunction *               mPabloFunction;
     76    const PabloBlock *                  mPabloBlock;
    7777
    78     KernelBuilder *                     mKBuilder;
     78    KernelBuilder *                     mKernelBuilder;
    7979
    8080    unsigned                            mWhileDepth;
     
    8484
    8585    unsigned                            mMaxWhileDepth;
    86     int                                 mFilePosIdx;
    8786};
    8887
Note: See TracChangeset for help on using the changeset viewer.