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

Automate instance creation

File:
1 edited

Legend:

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