Ignore:
Timestamp:
Dec 5, 2016, 1:08:23 PM (3 years ago)
Author:
cameron
Message:

Automate instance creation

Location:
icGREP/icgrep-devel/icgrep
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/IDISA/idisa_builder.h

    r5217 r5220  
    8181    void CallPrintInt(const std::string & name, Value * const value);
    8282
     83    VectorType * fwVectorType(unsigned fw);
     84
    8385    Constant * simd_himask(unsigned fw);
    8486    Constant * simd_lomask(unsigned fw);
     
    172174    Constant *          mPrintRegisterFunction;
    173175   
    174     VectorType * fwVectorType(unsigned fw);
    175176};
    176177
  • icGREP/icgrep-devel/icgrep/editd/editd.cpp

    r5217 r5220  
    245245    MatchResults.allocateBuffer();
    246246   
    247     Value * editdInstance = editdk.createInstance({});
    248     Value * scanMatchInstance = editdScanK.createInstance({});
    249    
    250     generatePipelineLoop(iBuilder, {&editdk, &editdScanK}, {editdInstance, scanMatchInstance}, fileSize);
     247    generatePipelineLoop(iBuilder, {&editdk, &editdScanK}, fileSize);
    251248       
    252249    iBuilder->CreateRetVoid();
     
    319316    CCResults.setStreamSetBuffer(outputStream, fileSize);
    320317   
    321     Value * s2pInstance = s2pk.createInstance({});
    322     Value * cccInstance = ccck.createInstance({});
    323    
    324     generatePipelineLoop(iBuilder, {&s2pk, &ccck}, {s2pInstance, cccInstance}, fileSize);
     318    generatePipelineLoop(iBuilder, {&s2pk, &ccck}, fileSize);
    325319       
    326320    iBuilder->CreateRetVoid();
     
    491485    iBuilder->CreateStore(Constant::getNullValue(strideCarryTy), strideCarry);
    492486
    493     Value * editdInstance = editdk.createInstance({pattStream, strideCarry});
     487    editdk.setInitialArguments({pattStream, strideCarry});
    494488   
    495     generatePipelineLoop(iBuilder, {&editdk}, {editdInstance}, inputSize);
     489    generatePipelineLoop(iBuilder, {&editdk}, inputSize);
    496490       
    497491    iBuilder->CreateRetVoid();
     
    607601
    608602    MatchResults.setStreamSetBuffer(inputStream, fileSize);
    609     Value * scanMatchInstance = editdScanK.createInstance({});
    610603   
    611     generatePipelineLoop(iBuilder, {&editdScanK}, {scanMatchInstance}, fileSize);
     604    generatePipelineLoop(iBuilder, {&editdScanK}, fileSize);
    612605       
    613606    iBuilder->CreateRetVoid();
  • icGREP/icgrep-devel/icgrep/editd/editdscan_kernel.cpp

    r5202 r5220  
    3838
    3939    std::vector<Value * > matchWordVectors;
    40     for(int d = 0; d <= mEditDistance; d++){
     40    for(unsigned d = 0; d <= mEditDistance; d++){
    4141        Value * matches = iBuilder->CreateBlockAlignedLoad(matchResultsPtr, {iBuilder->getInt32(0), iBuilder->getInt32(d)});
    4242        matchWordVectors.push_back(iBuilder->CreateBitCast(matches, scanwordVectorType));
     
    4444   
    4545    for(unsigned i = 0; i < fieldCount; ++i){       
    46         for(int d = 0; d <= mEditDistance; d++){
     46        for(unsigned d = 0; d <= mEditDistance; d++){
    4747            Value * matchWord = iBuilder->CreateExtractElement(matchWordVectors[d], ConstantInt::get(T, i));
    4848            iBuilder->CreateCall(scanWordFunction, {matchWord, iBuilder->getInt32(d), scanwordPos});
  • icGREP/icgrep-devel/icgrep/grep_engine.cpp

    r5217 r5220  
    223223    scanMatchK.generateKernel({&MatchResults}, {});
    224224           
    225     Value * scanMatchInstance = scanMatchK.createInstance({inputStream, fileSize, fileIdx});
    226    
    227     generatePipelineLoop(iBuilder, {&scanMatchK}, {scanMatchInstance}, fileSize);
     225    scanMatchK.setInitialArguments({inputStream, fileSize, fileIdx});
     226   
     227    generatePipelineLoop(iBuilder, {&scanMatchK}, fileSize);
    228228    iBuilder->CreateRetVoid();
    229229
     
    345345    BasisBits.allocateBuffer();
    346346
    347     Value * s2pInstance = s2pk.createInstance({});
    348  
    349347    Type * pthreadTy = size_ty;
    350348    FunctionType * funVoidPtrVoidTy = FunctionType::get(voidTy, int8PtrTy, false);   
     
    371369    if (CountOnly) {       
    372370        icgrepK.generateKernel({&BasisBits}, {});       
    373         Value * icgrepInstance = icgrepK.createInstance({});
    374371        if (pipelineParallel){
    375             generatePipelineParallel(iBuilder, {&s2pk, &icgrepK}, {s2pInstance, icgrepInstance});
     372            generatePipelineParallel(iBuilder, {&s2pk, &icgrepK});
    376373        } else if (segmentPipelineParallel){
    377             generateSegmentParallelPipeline(iBuilder, {&s2pk, &icgrepK}, {s2pInstance, icgrepInstance}, fileSize);
     374            generateSegmentParallelPipeline(iBuilder, {&s2pk, &icgrepK}, fileSize);
    378375        } else {
    379             generatePipelineLoop(iBuilder, {&s2pk, &icgrepK}, {s2pInstance, icgrepInstance}, fileSize);
    380         }
    381 
    382         Value * matchCount = icgrepK.createGetAccumulatorCall(icgrepInstance, "matchedLineCount");
     376            generatePipelineLoop(iBuilder, {&s2pk, &icgrepK}, fileSize);
     377        }
     378
     379        Value * matchCount = icgrepK.createGetAccumulatorCall(icgrepK.getInstance(), "matchedLineCount");
    383380
    384381        iBuilder->CreateRet(matchCount);
     
    391388
    392389            icgrepK.generateKernel({&BasisBits},  {&MatchResults});
    393             Value * icgrepInstance = icgrepK.createInstance({});
    394 
    395             generatePipelineLoop(iBuilder, {&s2pk, &icgrepK}, {s2pInstance, icgrepInstance}, fileSize);
     390            generatePipelineLoop(iBuilder, {&s2pk, &icgrepK}, fileSize);
    396391
    397392        }
     
    402397
    403398            icgrepK.generateKernel({&BasisBits}, {&MatchResults});
    404             Value * icgrepInstance = icgrepK.createInstance({});
    405399
    406400            kernel::ScanMatchKernel scanMatchK(iBuilder, mGrepType);
    407401            scanMatchK.generateKernel({&MatchResults}, {});               
    408             Value * scanMatchInstance = scanMatchK.createInstance({iBuilder->CreateBitCast(inputStream, int8PtrTy), fileSize, fileIdx});
     402            scanMatchK.setInitialArguments({iBuilder->CreateBitCast(inputStream, int8PtrTy), fileSize, fileIdx});
    409403
    410404            if (pipelineParallel){
    411                 generatePipelineParallel(iBuilder, {&s2pk, &icgrepK, &scanMatchK}, {s2pInstance, icgrepInstance, scanMatchInstance});
     405                generatePipelineParallel(iBuilder, {&s2pk, &icgrepK, &scanMatchK});
    412406            } else if (segmentPipelineParallel){
    413                 generateSegmentParallelPipeline(iBuilder, {&s2pk, &icgrepK, &scanMatchK}, {s2pInstance, icgrepInstance, scanMatchInstance}, fileSize);
     407                generateSegmentParallelPipeline(iBuilder, {&s2pk, &icgrepK, &scanMatchK}, fileSize);
    414408            }  else{
    415                 generatePipelineLoop(iBuilder, {&s2pk, &icgrepK, &scanMatchK}, {s2pInstance, icgrepInstance, scanMatchInstance}, fileSize);
     409                generatePipelineLoop(iBuilder, {&s2pk, &icgrepK, &scanMatchK}, fileSize);
    416410            }
    417411        }
  • icGREP/icgrep-devel/icgrep/kernels/interface.cpp

    r5217 r5220  
    9595
    9696
    97 Value * KernelInterface::createInstance(std::vector<Value *> args) {
    98     Value * kernelInstance = iBuilder->CreateCacheAlignedAlloca(mKernelStateType);
     97void KernelInterface::setInitialArguments(std::vector<Value *> args) {
     98    mInitialArguments = args;
     99}
     100
     101void KernelInterface::createInstance() {
     102    mKernelInstance = iBuilder->CreateCacheAlignedAlloca(mKernelStateType);
    99103    Module * m = iBuilder->getModule();
    100     std::vector<Value *> init_args = {kernelInstance};
    101     for (auto a : args) {
     104    std::vector<Value *> init_args = {mKernelInstance};
     105    for (auto a : mInitialArguments) {
    102106        init_args.push_back(a);
    103107    }
     
    108112    }
    109113    iBuilder->CreateCall(initMethod, init_args);
    110     return kernelInstance;
    111114}
    112115
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5202 r5220  
    5353    void addKernelDeclarations(Module * client);
    5454   
    55     virtual llvm::Value * createInstance(std::vector<llvm::Value *> initialParameters);
     55    void setInitialArguments(std::vector<llvm::Value *> initialParameters);
     56    virtual void createInstance();
     57    llvm::Value * getInstance() {return mKernelInstance;};
    5658
    5759    llvm::Value * createDoSegmentCall(llvm::Value * kernelInstance, llvm::Value * blkCount);
     
    101103    IDISA::IDISA_Builder * const iBuilder;
    102104    std::string mKernelName;
     105    std::vector<Value *> mInitialArguments;
    103106    std::vector<Binding> mStreamSetInputs;
    104107    std::vector<Binding> mStreamSetOutputs;
     
    107110    std::vector<Binding> mInternalScalars;
    108111    llvm::Type * mKernelStateType;
     112    llvm::Value * mKernelInstance;
    109113    unsigned mLookAheadPositions;
    110114   
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5217 r5220  
    403403}
    404404
    405 Value * KernelBuilder::createInstance(std::vector<Value *> args) {
    406     Value * kernelInstance = iBuilder->CreateCacheAlignedAlloca(mKernelStateType);
     405void KernelBuilder::createInstance() {
     406    mKernelInstance = iBuilder->CreateCacheAlignedAlloca(mKernelStateType);
    407407    Module * m = iBuilder->getModule();
    408     std::vector<Value *> init_args = {kernelInstance};
    409     for (auto a : args) {
     408    std::vector<Value *> init_args = {mKernelInstance};
     409    for (auto a : mInitialArguments) {
    410410        init_args.push_back(a);
    411411    }
     
    422422    }
    423423    iBuilder->CreateCall(initMethod, init_args);
    424     return kernelInstance;
    425424}
    426425
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5217 r5220  
    4646    void generateKernel(std::vector<StreamSetBuffer *> input_buffers, std::vector<StreamSetBuffer *> output_buffers);
    4747   
    48     llvm::Value * createInstance(std::vector<Value *> args) override;
     48    void createInstance() override;
    4949
    5050    Function * generateThreadFunction(std::string name);
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.cpp

    r5217 r5220  
    9494}
    9595
    96 void generateSegmentParallelPipeline(IDISA::IDISA_Builder * iBuilder, std::vector<KernelBuilder *> kernels, std::vector<Value *> instances, Value * fileSize) {
     96void generateSegmentParallelPipeline(IDISA::IDISA_Builder * iBuilder, std::vector<KernelBuilder *> kernels, Value * fileSize) {
    9797   
    9898    unsigned threadNum = codegen::ThreadNum;
     
    103103    Type * const voidPtrTy = TypeBuilder<void *, false>::get(m->getContext());
    104104    Type * const int8PtrTy = iBuilder->getInt8PtrTy();
     105
     106    for (auto k : kernels) k->createInstance();
     107
    105108    Type * const pthreadsTy = ArrayType::get(size_ty, threadNum);
    106109    AllocaInst * const pthreads = iBuilder->CreateAlloca(pthreadsTy);
     
    114117    std::vector<Type *> structTypes;
    115118    structTypes.push_back(size_ty);//input size
    116     for (unsigned i = 0; i < instances.size(); i++) {
    117         structTypes.push_back(instances[i]->getType());
     119    for (unsigned i = 0; i < kernels.size(); i++) {
     120        structTypes.push_back(kernels[i]->getInstance()->getType());
    118121    }
    119122    Type * sharedStructType = StructType::get(m->getContext(), structTypes);
     
    122125    Value * sizePtr = iBuilder->CreateGEP(sharedStruct, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    123126    iBuilder->CreateStore(fileSize, sizePtr);
    124     for (unsigned i = 0; i < instances.size(); i++) {
     127    for (unsigned i = 0; i < kernels.size(); i++) {
    125128        Value * ptr = iBuilder->CreateGEP(sharedStruct, {iBuilder->getInt32(0), iBuilder->getInt32(i+1)});
    126         iBuilder->CreateStore(instances[i], ptr);
     129        iBuilder->CreateStore(kernels[i]->getInstance(), ptr);
    127130    }
    128131
     
    152155}
    153156
    154 void generatePipelineParallel(IDISA::IDISA_Builder * iBuilder, std::vector<KernelBuilder *> kernels, std::vector<Value *> instances) {
     157void generatePipelineParallel(IDISA::IDISA_Builder * iBuilder, std::vector<KernelBuilder *> kernels) {
    155158 
    156159    Module * m = iBuilder->getModule();
     
    161164
    162165    Type * const pthreadsTy = ArrayType::get(pthreadTy, kernels.size());
     166
     167    for (auto k : kernels) k->createInstance();
     168
    163169    AllocaInst * const pthreads = iBuilder->CreateAlloca(pthreadsTy);
    164170    std::vector<Value *> pthreadsPtrs;
     
    180186
    181187    for (unsigned i = 0; i < kernels.size(); i++) {
    182         iBuilder->CreateCall(pthreadCreateFunc, std::vector<Value *>({pthreadsPtrs[i], nullVal, kernel_functions[i], iBuilder->CreateBitCast(instances[i], int8PtrTy)}));
     188        iBuilder->CreateCall(pthreadCreateFunc, std::vector<Value *>({pthreadsPtrs[i], nullVal, kernel_functions[i], iBuilder->CreateBitCast(kernels[i]->getInstance(), int8PtrTy)}));
    183189    }
    184190
     
    194200
    195201
    196 void generatePipelineLoop(IDISA::IDISA_Builder * iBuilder, std::vector<KernelBuilder *> kernels, std::vector<Value *> instances, Value * fileSize) {
     202void generatePipelineLoop(IDISA::IDISA_Builder * iBuilder, std::vector<KernelBuilder *> kernels, Value * fileSize) {
    197203   
    198204    BasicBlock * entryBlock = iBuilder->GetInsertBlock();
     
    205211    BasicBlock * segmentBlock = BasicBlock::Create(iBuilder->getContext(), "segmentLoop", main, 0);
    206212    BasicBlock * exitBlock = BasicBlock::Create(iBuilder->getContext(), "exitBlock", main, 0);
     213    for (auto k : kernels) k->createInstance();
    207214    iBuilder->CreateBr(segmentBlock);
    208215    iBuilder->SetInsertPoint(segmentBlock);
    209216    Constant * segBlocks = ConstantInt::get(size_ty, segmentSize * iBuilder->getStride() / iBuilder->getBitBlockWidth());
    210217    for (unsigned i = 0; i < kernels.size(); i++) {
    211         kernels[i]->createDoSegmentCall(instances[i], segBlocks);
    212     }
    213     Value * endSignal = kernels.back()->getTerminationSignal(instances.back());
     218        kernels[i]->createDoSegmentCall(kernels[i]->getInstance(), segBlocks);
     219    }
     220    Value * endSignal = kernels.back()->getTerminationSignal(kernels.back()->getInstance());
    214221    iBuilder->CreateCondBr(endSignal, exitBlock, segmentBlock);
    215222    iBuilder->SetInsertPoint(exitBlock);
  • icGREP/icgrep-devel/icgrep/kernels/pipeline.h

    r5165 r5220  
    1010#include <kernels/kernel.h>
    1111
    12 void generateSegmentParallelPipeline(IDISA::IDISA_Builder * iBuilder, std::vector<kernel::KernelBuilder *> kernels, std::vector<llvm::Value *> instances, Value * fileSize);
     12void generateSegmentParallelPipeline(IDISA::IDISA_Builder * iBuilder, std::vector<kernel::KernelBuilder *> kernels, Value * fileSize);
    1313
    14 void generatePipelineLoop(IDISA::IDISA_Builder * iBuilder, std::vector<kernel::KernelBuilder *> kernels, std::vector<llvm::Value *> instances, llvm::Value * totalBytes);
     14void generatePipelineLoop(IDISA::IDISA_Builder * iBuilder, std::vector<kernel::KernelBuilder *> kernels, llvm::Value * totalBytes);
    1515
    16 void generatePipelineParallel(IDISA::IDISA_Builder * iBuilder, std::vector<kernel::KernelBuilder *> kernels, std::vector<llvm::Value *> instances);
     16void generatePipelineParallel(IDISA::IDISA_Builder * iBuilder, std::vector<kernel::KernelBuilder *> kernels);
    1717
    1818#endif // PIPELINE_H
  • icGREP/icgrep-devel/icgrep/u8u16.cpp

    r5217 r5220  
    340340        U16out.allocateBuffer();
    341341    }
    342     Value * s2pInstance = s2pk.createInstance({});
    343     Value * u8u16Instance = u8u16k.createInstance({});
    344     Value * delInstance = delK.createInstance({});
    345     Value * p2sInstance = p2sk.createInstance({});
    346     Value * stdoutInstance = stdoutK.createInstance({});
    347342
    348343    Type * pthreadTy = size_ty;
     
    369364
    370365    if (segmentPipelineParallel){
    371         generateSegmentParallelPipeline(iBuilder, {&s2pk, &u8u16k, &delK, &p2sk, &stdoutK}, {s2pInstance, u8u16Instance, delInstance, p2sInstance, stdoutInstance}, fileSize);
     366        generateSegmentParallelPipeline(iBuilder, {&s2pk, &u8u16k, &delK, &p2sk, &stdoutK}, fileSize);
    372367    } else {
    373         generatePipelineLoop(iBuilder, {&s2pk, &u8u16k, &delK, &p2sk, &stdoutK}, {s2pInstance, u8u16Instance, delInstance, p2sInstance, stdoutInstance}, fileSize);
     368        generatePipelineLoop(iBuilder, {&s2pk, &u8u16k, &delK, &p2sk, &stdoutK}, fileSize);
    374369    }
    375370
  • icGREP/icgrep-devel/icgrep/wc.cpp

    r5217 r5220  
    176176    BasisBits.allocateBuffer();
    177177   
    178     Value * s2pInstance = s2pk.createInstance({});
    179     Value * wcInstance = wck.createInstance({});
    180    
    181     generatePipelineLoop(iBuilder, {&s2pk, &wck}, {s2pInstance, wcInstance}, fileSize);
    182    
    183     Value * lineCount = wck.createGetAccumulatorCall(wcInstance, "lineCount");
    184     Value * wordCount = wck.createGetAccumulatorCall(wcInstance, "wordCount");
    185     Value * charCount = wck.createGetAccumulatorCall(wcInstance, "charCount");
     178    generatePipelineLoop(iBuilder, {&s2pk, &wck}, fileSize);
     179   
     180    Value * lineCount = wck.createGetAccumulatorCall(wck.getInstance(), "lineCount");
     181    Value * wordCount = wck.createGetAccumulatorCall(wck.getInstance(), "wordCount");
     182    Value * charCount = wck.createGetAccumulatorCall(wck.getInstance(), "charCount");
    186183
    187184    iBuilder->CreateCall(record_counts_routine, std::vector<Value *>({lineCount, wordCount, charCount, fileSize, fileIdx}));
Note: See TracChangeset for help on using the changeset viewer.