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

new version using the kernels.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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
Note: See TracChangeset for help on using the changeset viewer.