Ignore:
Timestamp:
Mar 15, 2016, 10:20:07 PM (3 years ago)
Author:
nmedfort
Message:

Added the kernel instance class; removed original mmap file access in favour of the boost mmap system. corrected PrintRegister? routine.

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

Legend:

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

    r4970 r4974  
    2222 * @brief initialize
    2323 ** ------------------------------------------------------------------------------------------------------------- */
    24 void CarryManager::initialize(PabloFunction * const function, KernelBuilder * const kBuilder) {
     24void CarryManager::initialize(PabloFunction * const function, kernel::KernelBuilder * const kBuilder) {
    2525    mRootScope = function->getEntryBlock();
    2626    mCarryInfoVector.resize(mRootScope->enumerateScopes(0) + 1);
     
    2828    const unsigned totalCarryDataSize = std::max<unsigned>(enumerate(mRootScope, 0, 0), 1);
    2929    mCarryPackPtr.resize(totalCarryDataSize, nullptr);
    30     mCarryInPack.resize(totalCarryDataSize);
     30    mCarryInPack.resize(totalCarryDataSize, nullptr);
    3131    mCarryOutPack.resize(totalCarryDataSize, nullptr);
    3232    mTotalCarryDataBitBlocks = totalCarryDataSize;
     
    5656    mCarryOutPack[summaryPack()] = Constant::getNullValue(mCarryPackType);
    5757    assert (mCarrySummary.empty());
    58     std::fill(mCarryInPack.begin(), mCarryInPack.end(), nullptr);
    5958}
    6059
     
    153152        storeCarryOut(index);
    154153    }
    155     if (LLVM_LIKELY(shiftAmount == 1)) {
    156         Value * ahead = iBuilder->mvmd_dslli(DSSLI_FIELDWIDTH, value, carryIn, iBuilder->getBitBlockWidth()/DSSLI_FIELDWIDTH -1);
    157         result = iBuilder->simd_or(iBuilder->simd_srli(DSSLI_FIELDWIDTH, ahead, DSSLI_FIELDWIDTH-1), iBuilder->simd_slli(DSSLI_FIELDWIDTH, value, 1));
    158     } else if (shiftAmount % 8 == 0) { // Use a single whole-byte shift, if possible.
     154    if (LLVM_UNLIKELY((shiftAmount % 8) == 0)) { // Use a single whole-byte shift, if possible.
    159155        result = iBuilder->mvmd_dslli(8, value, carryIn, (iBuilder->getBitBlockWidth() / 8) - (shiftAmount / 8));
    160     } else if (shiftAmount < DSSLI_FIELDWIDTH) {
    161         Value * ahead = iBuilder->mvmd_dslli(DSSLI_FIELDWIDTH, value, carryIn, iBuilder->getBitBlockWidth()/DSSLI_FIELDWIDTH - 1);
    162         result = iBuilder->simd_or(iBuilder->simd_srli(DSSLI_FIELDWIDTH, ahead, DSSLI_FIELDWIDTH-shiftAmount), iBuilder->simd_slli(DSSLI_FIELDWIDTH, value, shiftAmount));
     156    } else if (LLVM_LIKELY(shiftAmount < DSSLI_FIELDWIDTH)) {
     157        Value * ahead = iBuilder->mvmd_dslli(DSSLI_FIELDWIDTH, value, carryIn, iBuilder->getBitBlockWidth() / DSSLI_FIELDWIDTH - 1);
     158        result = iBuilder->simd_or(iBuilder->simd_srli(DSSLI_FIELDWIDTH, ahead, DSSLI_FIELDWIDTH - shiftAmount), iBuilder->simd_slli(DSSLI_FIELDWIDTH, value, shiftAmount));
    163159    } else {
    164160        Value* advanceq_longint = iBuilder->CreateBitCast(carryIn, iBuilder->getIntNTy(mBitBlockWidth));
     
    196192    const unsigned bufsize = mCarryInfo->longAdvanceBufferSize(shiftAmount);
    197193    Value * indexMask = iBuilder->getInt64(bufsize - 1);  // A mask to implement circular buffer indexing
    198     Value * blockIndex = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getBlockIndexScalar());
     194    Value * blockIndex = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getBlockNo());
    199195    Value * loadIndex0 = iBuilder->CreateAdd(iBuilder->CreateAnd(iBuilder->CreateSub(blockIndex, iBuilder->getInt64(advanceEntries)), indexMask), advBaseIndex);
    200196    Value * storeIndex = iBuilder->CreateAdd(iBuilder->CreateAnd(blockIndex, indexMask), advBaseIndex);
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4970 r4974  
    5959    ~CarryManager();
    6060   
    61     void initialize(PabloFunction * const function, KernelBuilder * const kBuilder);
     61    void initialize(PabloFunction * const function, kernel::KernelBuilder * const kBuilder);
    6262
    6363    void reset();
     
    140140    Value * mCarryBitBlockPtr;
    141141    Value * mPopcountBasePtr;
    142     KernelBuilder * mKernelBuilder;
     142    kernel::KernelBuilder * mKernelBuilder;
    143143    unsigned mPabloCountCount; // Number of Pablo "Count" operations
    144144    unsigned mTotalCarryDataBitBlocks;
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4970 r4974  
    6666namespace pablo {
    6767
     68#define DSSLI_FIELDWIDTH 64
     69
    6870PabloCompiler::PabloCompiler(Module * m, IDISA::IDISA_Builder * b)
    6971: mMod(m)
     
    8183}
    8284
    83 void PabloCompiler::setKernel(KernelBuilder * kBuilder){
     85void PabloCompiler::setKernel(kernel::KernelBuilder * kBuilder){
    8486    mKernelBuilder = kBuilder;
    8587}
     
    131133    mCarryManager->initialize(function, mKernelBuilder);
    132134
    133     mKernelBuilder->prepareFunction();
    134 
    135     mFunction = mKernelBuilder->getDoBlockFunction();
    136 
    137     for(unsigned i = 0; i < mKernelBuilder->getSegmentBlocks(); ++i){
    138 
    139         mCarryManager->reset();
    140 
    141         for (unsigned j = 0; j < function->getNumOfParameters(); ++j) {
    142             mMarkerMap.insert(std::make_pair(function->getParameter(j), mKernelBuilder->getInputStream(j)));
    143         }
    144 
    145         compileBlock(function->getEntryBlock());
    146 
    147         for (unsigned j = 0; j < function->getNumOfResults(); ++j) {
    148             const auto f = mMarkerMap.find(function->getResult(j));
    149             Value * result = nullptr;
    150             if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
    151                 result = iBuilder->allZeroes();
    152             } else {
    153                 result = f->second;
    154             }
    155             iBuilder->CreateBlockAlignedStore(result, mKernelBuilder->getOutputStream(j));
    156         }
    157 
    158         mMarkerMap.clear();
    159 
    160         mKernelBuilder->increment();
    161     }   
     135    mFunction = mKernelBuilder->prepareFunction();
     136
     137    mCarryManager->reset();
     138
     139    for (unsigned j = 0; j < function->getNumOfParameters(); ++j) {
     140        mMarkerMap.insert(std::make_pair(function->getParameter(j), mKernelBuilder->getInputStream(j)));
     141    }
     142
     143    compileBlock(function->getEntryBlock());
     144
     145    for (unsigned j = 0; j < function->getNumOfResults(); ++j) {
     146        const auto f = mMarkerMap.find(function->getResult(j));
     147        Value * result = nullptr;
     148        if (LLVM_UNLIKELY(f == mMarkerMap.end())) {
     149            result = iBuilder->allZeroes();
     150        } else {
     151            result = f->second;
     152        }
     153        iBuilder->CreateBlockAlignedStore(result, mKernelBuilder->getOutputStream(j));
     154    }
    162155
    163156    mKernelBuilder->finalize();
     
    414407            throw std::runtime_error("Lookahead input type must be a Var object");
    415408        }
    416         Value * index = nullptr;
    417         for (unsigned i = 0; i < mPabloFunction->getNumOfParameters(); ++i) {
    418             if (mPabloFunction->getParameter(i) == var) {
    419                 index = iBuilder->getInt32(i);
     409        unsigned index = 0;
     410        for (; index < mPabloFunction->getNumOfParameters(); ++index) {
     411            if (mPabloFunction->getParameter(index) == var) {
    420412                break;
    421413            }
    422414        }
    423         if (LLVM_UNLIKELY(index == nullptr)) {
     415        if (LLVM_UNLIKELY(index >= mPabloFunction->getNumOfParameters())) {
    424416            throw std::runtime_error("Lookahead has an illegal Var operand");
    425417        }
    426         Type * const streamType = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
    427418        const unsigned offset = l->getAmount() / iBuilder->getBitBlockWidth();
    428419        const unsigned shift = (l->getAmount() % iBuilder->getBitBlockWidth());
    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);
    431         Value * result = iBuilder->CreateOr(iBuilder->CreateLShr(b0, shift), iBuilder->CreateShl(b1, iBuilder->getBitBlockWidth() - shift), "lookahead");
    432         expr = iBuilder->CreateBitCast(result, iBuilder->getBitBlockType());
     420        Value * const v0 = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(index, offset));
     421        Value * const v1 = iBuilder->CreateBlockAlignedLoad(mKernelBuilder->getInputStream(index, offset + 1));
     422        if (LLVM_UNLIKELY((shift % 8) == 0)) { // Use a single whole-byte shift, if possible.
     423            expr = iBuilder->mvmd_dslli(8, v1, v0, (shift / 8));
     424        } else if (LLVM_LIKELY(shift < DSSLI_FIELDWIDTH)) {
     425            Value * ahead = iBuilder->mvmd_dslli(DSSLI_FIELDWIDTH, v1, v0, 1);
     426            ahead = iBuilder->simd_slli(DSSLI_FIELDWIDTH, ahead, DSSLI_FIELDWIDTH - shift);
     427            Value * value = iBuilder->simd_srli(DSSLI_FIELDWIDTH, v0, shift);
     428            expr = iBuilder->simd_or(value, ahead);
     429        } else {
     430            Type  * const streamType = iBuilder->getIntNTy(iBuilder->getBitBlockWidth());
     431            Value * b0 = iBuilder->CreateBitCast(v0, streamType);
     432            Value * b1 = iBuilder->CreateBitCast(v1, streamType);
     433            Value * result = iBuilder->CreateOr(iBuilder->CreateShl(b1, iBuilder->getBitBlockWidth() - shift), iBuilder->CreateLShr(b0, shift));
     434            expr = iBuilder->CreateBitCast(result, mBitBlockType);
     435        }
    433436    } else {
    434437        std::string tmp;
     
    441444    mMarkerMap[stmt] = expr;
    442445    if (DumpTrace) {
    443         iBuilder->genPrintRegister(stmt->getName()->to_string(), expr);
     446        iBuilder->CallPrintRegister(stmt->getName()->to_string(), expr);
    444447    }
    445448   
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4970 r4974  
    5151
    5252    llvm::Function * compile(PabloFunction * function);
    53     void setKernel(KernelBuilder * kBuilder);
     53    void setKernel(kernel::KernelBuilder * kBuilder);
    5454
    5555private:
     
    7676    const PabloBlock *                  mPabloBlock;
    7777
    78     KernelBuilder *                     mKernelBuilder;
     78    kernel::KernelBuilder *             mKernelBuilder;
    7979
    8080    unsigned                            mWhileDepth;
Note: See TracChangeset for help on using the changeset viewer.