Ignore:
Timestamp:
Feb 23, 2016, 9:07:05 AM (3 years ago)
Author:
lindanl
Message:

new version using the kernels.

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

Legend:

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

    r4927 r4939  
    55 */
    66
    7 #include <include/simd-lib/bitblock.hpp>
    87#include <stdexcept>
    98#include <pablo/carry_data.h>
     
    6160 * @brief initialize
    6261 ** ------------------------------------------------------------------------------------------------------------- */
    63 void CarryManager::initialize(Module * m, PabloBlock * pb) {
     62void CarryManager::initialize(PabloBlock * pb, KernelBuilder * kBuilder) {
    6463    mRootScope = pb;
    6564    mCarryInfoVector.resize(doScopeCount(pb));
     
    7574   
    7675    ArrayType* cdArrayTy = ArrayType::get(mBitBlockType, mTotalCarryDataBitBlocks);
    77     GlobalVariable* cdArray = new GlobalVariable(*m, cdArrayTy, /*isConstant=*/false, GlobalValue::CommonLinkage, /*Initializer=*/0, "process_block_carry_data");
    78     cdArray->setAlignment(mBitBlockWidth / 8);
    79     ConstantAggregateZero* cdInitData = ConstantAggregateZero::get(cdArrayTy);
    80     cdArray->setInitializer(cdInitData);
     76    mCdArrayIdx = kBuilder->extendKernelInternalStateType(cdArrayTy);
    8177   
    82     mCarryPackBasePtr = iBuilder->CreateBitCast(cdArray, PointerType::get(mCarryPackType, 0));
    83     mCarryBitBlockPtr = iBuilder->CreateBitCast(cdArray, PointerType::get(mBitBlockType, 0));
    84    
    85     generateCarryDataInitializer(m);
    86    
    87     // Popcount data is stored after all the carry data.
    8878    if (mPabloCountCount > 0) {
    8979        ArrayType* pcArrayTy = ArrayType::get(iBuilder->getIntNTy(64), mPabloCountCount);
    90         GlobalVariable* pcArray = new GlobalVariable(*m, pcArrayTy, /*isConstant=*/false, GlobalValue::CommonLinkage, 0, "popcount_data");
    91         cdArray->setAlignment(mBitBlockWidth/8);
    92         ConstantAggregateZero* pcInitData = ConstantAggregateZero::get(pcArrayTy);
    93         pcArray->setInitializer(pcInitData);
    94         mPopcountBasePtr = iBuilder->CreateBitCast(pcArray, Type::getInt64PtrTy(iBuilder->getContext()));
    95     }
    96     // Carry Data area will have one extra bit block to store the block number.
    97     GlobalVariable* blkNo = new GlobalVariable(*m, iBuilder->getIntNTy(64), /*isConstant=*/false, GlobalValue::CommonLinkage, 0, "blockNo");
    98     blkNo->setAlignment(16);
    99     blkNo->setInitializer(iBuilder->getInt64(0));
    100     mBlockNoPtr = blkNo;
    101     mBlockNo = iBuilder->CreateLoad(mBlockNoPtr);
    102     /*  Set the current scope to PabloRoot */
     80        mPcArrayIdx = kBuilder->extendKernelInternalStateType(pcArrayTy);
     81    }
     82 
    10383    mCurrentScope = mRootScope;
    10484    mCurrentFrameIndex = 0;
    10585    mCarryInfo = mCarryInfoVector[0];
    10686    mCarryOutPack[summaryPack()] = Constant::getNullValue(mCarryPackType);
     87}
     88
     89void CarryManager::initialize_setPtrs(KernelBuilder * kBuilder) {
     90   
     91    Value * cdArrayPtr = kBuilder->getKernelInternalStatePtr(mCdArrayIdx);
     92 
     93    mCarryPackBasePtr = iBuilder->CreateBitCast(cdArrayPtr, PointerType::get(mCarryPackType, 0));
     94    mCarryBitBlockPtr = iBuilder->CreateBitCast(cdArrayPtr, PointerType::get(mBitBlockType, 0));
     95   
     96   
     97    if (mPabloCountCount > 0) {
     98        Value * pcArrayPtr = kBuilder->getKernelInternalStatePtr(mPcArrayIdx);
     99        mPopcountBasePtr = iBuilder->CreateBitCast(pcArrayPtr, Type::getInt64PtrTy(iBuilder->getContext()));
     100    }
     101 
     102    mBlockNo = iBuilder->CreateUDiv(kBuilder->getKernelInternalState(mFilePosIdx), iBuilder->getInt64(mBitBlockWidth));
     103    mCurrentScope = mRootScope;
     104    mCurrentFrameIndex = 0;
     105    mCarryInfo = mCarryInfoVector[0];
     106    mCarryOutPack[summaryPack()] = Constant::getNullValue(mCarryPackType);
     107}
     108
     109void CarryManager::set_BlockNo(KernelBuilder * kBuilder){
     110    mBlockNo = iBuilder->CreateUDiv(kBuilder->getKernelInternalState(mFilePosIdx), iBuilder->getInt64(mBitBlockWidth));
    107111}
    108112
     
    301305
    302306/** ------------------------------------------------------------------------------------------------------------- *
    303  * @brief blendCarrySummaryWithOuterSummary
     307 * @brief addOuterSummaryToNestedSummary
    304308 ** ------------------------------------------------------------------------------------------------------------- */
    305309void CarryManager::addOuterSummaryToNestedSummary() {
     
    550554 * @brief generateBlockNoIncrement
    551555 ** ------------------------------------------------------------------------------------------------------------- */
    552 void CarryManager::generateBlockNoIncrement() {
    553     iBuilder->CreateStore(iBuilder->CreateAdd(mBlockNo, iBuilder->getInt64(1)), mBlockNoPtr);
    554 }
     556// void CarryManager::generateBlockNoIncrement() {
     557//     iBuilder->CreateStore(iBuilder->CreateAdd(mBlockNo, iBuilder->getInt64(1)), mBlockNoPtr);
     558// }
    555559
    556560/* Helper routines */
  • icGREP/icgrep-devel/icgrep/pablo/carry_manager.h

    r4927 r4939  
    1313#include <pablo/carry_data.h>
    1414#include <llvm/IR/Constants.h>
    15 
     15#include "../kernels/kernel.h"
    1616
    1717/*
     
    5353    , mTotalCarryDataBitBlocks(0)
    5454    , mCarryDataAllocationSize(0)
     55    , mFilePosIdx(2)
    5556    {
    5657
     
    5960    ~CarryManager();
    6061   
    61     void initialize(Module * m, PabloBlock * blk);
     62    void initialize(PabloBlock * blk, KernelBuilder * kBuilder);
     63
     64    void initialize_setPtrs(KernelBuilder * kBuilder);
     65
     66    void set_BlockNo(KernelBuilder * kBuilder);
    6267   
    6368    void generateCarryDataInitializer(Module * m);
     
    155160    std::vector<Value *> mCarryOutPack;
    156161    std::vector<Value *> mCarrySummary;
     162    int mCdArrayIdx;
     163    int mPcArrayIdx;
     164    int mFilePosIdx;
    157165};
    158166
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.cpp

    r4927 r4939  
    7373, mCarryManager(nullptr)
    7474, mInputType(nullptr)
     75, mKBuilder(nullptr)
    7576, mWhileDepth(0)
    7677, mIfDepth(0)
     
    7879, mInputAddressPtr(nullptr)
    7980, mOutputAddressPtr(nullptr)
    80 , mMaxWhileDepth(0) {
     81, mMaxWhileDepth(0)
     82, mFilePosIdx(2) {
    8183   
    8284}
     
    8486PabloCompiler::~PabloCompiler() {
    8587}
    86        
     88 
     89void PabloCompiler::setKernel(KernelBuilder * kBuilder){
     90    mKBuilder = kBuilder;   
     91}
     92
    8793llvm::Function * PabloCompiler::compile(PabloFunction * function) {
    8894
     
    98104
    99105    mCarryManager = new CarryManager(iBuilder);
    100    
    101     GenerateFunction(*function);
    102    
    103     iBuilder->SetInsertPoint(BasicBlock::Create(mMod->getContext(), "entry", mFunction,0));
    104 
    105     //The basis bits structure
    106     for (unsigned i = 0; i != function->getNumOfParameters(); ++i) {
    107         Value* indices[] = {iBuilder->getInt64(0), iBuilder->getInt32(i)};
    108         Value * gep = iBuilder->CreateGEP(mInputAddressPtr, indices);
    109         LoadInst * basisBit = iBuilder->CreateAlignedLoad(gep, iBuilder->getBitBlockWidth()/8, false, function->getParameter(i)->getName()->to_string());
    110         mMarkerMap[function->getParameter(i)] = basisBit;
    111         if (DumpTrace) {
    112             iBuilder->genPrintRegister(function->getParameter(i)->getName()->to_string(), basisBit);
    113         }
    114     }
    115      
    116     //Generate the IR instructions for the function.
    117    
    118     mCarryManager->initialize(mMod, mainScope);
    119 
    120     compileBlock(mainScope);
    121    
    122     mCarryManager->generateBlockNoIncrement();
    123 
    124     if (DumpTrace) {
    125         iBuilder->genPrintRegister("mBlockNo", iBuilder->CreateAlignedLoad(iBuilder->CreateBitCast(mCarryManager->getBlockNoPtr(), PointerType::get(mBitBlockType, 0)), iBuilder->getBitBlockWidth()/8, false));
    126     }
    127    
    128     // Write the output values out
    129     for (unsigned i = 0; i != function->getNumOfResults(); ++i) {
    130         assert (function->getResult(i));
    131         SetOutputValue(mMarkerMap[function->getResult(i)], i);
    132     }
    133 
    134     //Terminate the block
    135     ReturnInst::Create(mMod->getContext(), iBuilder->GetInsertBlock());
    136    
    137     // Clean up
     106
     107    GenerateKernel(mainScope, function);
     108       
    138109    delete mCarryManager;
    139110    mCarryManager = nullptr;
     
    144115    #endif
    145116
    146 //    llvm::PassManager pm;
    147 //    llvm::PassManagerBuilder pmb;
    148 //    pmb.OptLevel = 3;
    149 //    pmb.populateModulePassManager(pm);
    150 //    pm.run(*mMod);
    151117
    152118    if (LLVM_UNLIKELY(DumpGeneratedIR)) {
     
    167133
    168134    return mFunction;
     135}
     136
     137inline void PabloCompiler::GenerateKernel(PabloBlock * mainScope, PabloFunction * function) {
     138 
     139    for(int i=0; i<8; i++){
     140        mKBuilder->addKernelInputStream(1, "basis_bits");
     141    }
     142    mKBuilder->addKernelOutputStream(1);
     143    mKBuilder->addKernelOutputStream(1);
     144
     145    mCarryManager->initialize(mainScope, mKBuilder);
     146 
     147    int segBlocks = mKBuilder->getSegmentBlocks();
     148    mKBuilder->PrepareDoBlockFunction();
     149    struct Inputs inputs = mKBuilder->openDoBlock();
     150    struct Outputs outputs;
     151    mFunction = mKBuilder->getDoBlockFunction();
     152
     153    mCarryManager->initialize_setPtrs(mKBuilder);
     154
     155    valptr results[segBlocks][2];
     156    for(int j=0; j<segBlocks; j++){     
     157        for(int i=0; i<inputs.streams[j].size(); i++){
     158            mMarkerMap[function->getParameter(i)] = inputs.streams[j][i];
     159        }
     160
     161        compileBlock(mainScope);
     162
     163        Value * filePos = iBuilder->CreateAdd(mKBuilder->getKernelInternalState(mFilePosIdx), iBuilder->getInt64(iBuilder->getBitBlockWidth()));
     164        mKBuilder->changeKernelInternalState(mFilePosIdx, filePos);
     165
     166        mCarryManager->set_BlockNo(mKBuilder);
     167
     168        results[j][0] = mMarkerMap[function->getResult(0)];
     169        results[j][1] = mMarkerMap[function->getResult(1)];
     170        outputs.streams.push_back(results[j]);
     171    }   
     172
     173    mKBuilder->closeDoBlock(outputs);
     174    mKBuilder->finalizeMethods();
    169175}
    170176
  • icGREP/icgrep-devel/icgrep/pablo/pablo_compiler.h

    r4900 r4939  
    2929#include <llvm/IR/IRBuilder.h>
    3030#include <IDISA/idisa_builder.h>
     31#include <kernels/kernel.h>
    3132
    3233namespace llvm {
     
    7576    PabloCompiler(Module * m, IDISA::IDISA_Builder * b);
    7677    ~PabloCompiler();
    77     Function * compile(pablo::PabloFunction * function);
     78    Function * compile(pablo::PabloFunction * function);   
     79    void setKernel(KernelBuilder * kBuilder);
     80   
    7881private:
    7982    void GenerateFunction(PabloFunction & function);
     
    8891    void compileWhile(const While * whileStmt);
    8992    Value* compileExpression(const PabloAST * expr);
     93    void GenerateKernel(PabloBlock * block, PabloFunction * function);
    9094
    9195    ASTToValueMap                       mMarkerMap;
     
    100104
    101105    PabloBlock *                        mPabloBlock;
     106
     107    KernelBuilder *                     mKBuilder;
    102108   
    103109    unsigned                            mWhileDepth;
     
    109115
    110116    unsigned                            mMaxWhileDepth;
     117    int                                 mFilePosIdx;
    111118
    112119};
Note: See TracChangeset for help on using the changeset viewer.