Ignore:
Timestamp:
Oct 8, 2016, 7:33:08 PM (3 years ago)
Author:
cameron
Message:

Linear buffers; stdout_kernel; cache-aligned alloca, restructured u8u16, clean-ups

File:
1 edited

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5141 r5185  
    152152}
    153153   
    154 static Function * create_write(Module * const mod) {
    155     Function * write = mod->getFunction("write");
    156     if (write == nullptr) {
    157         FunctionType *write_type =
    158         TypeBuilder<long(int, char *, long), false>::get(mod->getContext());
    159         write = cast<Function>(mod->getOrInsertFunction("write", write_type,
    160                                                         AttributeSet().addAttribute(mod->getContext(), 2U, Attribute::NoAlias)));
    161     }
    162     return write;
    163 }
    164    
    165    
    166    
     154
    167155void p2s_16Kernel_withCompressedOutput::generateDoBlockMethod() {
    168156    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
     
    170158    Type * i32 = iBuilder->getIntNTy(32);
    171159    Type * bitBlockPtrTy = llvm::PointerType::get(iBuilder->getBitBlockType(), 0);
    172     Type * i8PtrTy = iBuilder->getInt8PtrTy();
    173 
    174     Function * writefn = create_write(m);
    175 
    176     Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    177    
    178     iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
     160
     161    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
     162   
     163    iBuilder->SetInsertPoint(BasicBlock::Create(iBuilder->getContext(), "entry", doBlockFunction, 0));
     164    Constant * stride = ConstantInt::get(iBuilder->getSizeTy(), iBuilder->getStride());
     165
    179166    Value * self = getParameter(doBlockFunction, "self");
    180167    Value * blockNo = getScalarField(self, blockNoScalar);
    181168    Value * basisBitsBlock_ptr = getStreamSetBlockPtr(self, "basisBits", blockNo);
    182169    Value * delCountBlock_ptr = getStreamSetBlockPtr(self, "deletionCounts", blockNo);
    183     Value * i16UnitsGenerated = getScalarField(self, "unitsGenerated");  // units generated to buffer
    184     Value * i16UnitsWritten = getScalarField(self, "unitsWritten");  // units written to stdout
    185    
    186     Value * i16StreamBase_ptr = iBuilder->CreateBitCast(getStreamSetBasePtr(self, "i16Stream"), PointerType::get(iBuilder->getInt16Ty(), 0));
    187     Value * u16_output_ptr = iBuilder->CreateGEP(i16StreamBase_ptr, iBuilder->CreateSub(i16UnitsGenerated, i16UnitsWritten));
     170    Value * i16UnitsGenerated = getProducedItemCount(self); // units generated to buffer
     171    Value * i16BlockNo = iBuilder->CreateUDiv(i16UnitsGenerated, stride);
     172   
     173    Value * i16StreamBase_ptr = iBuilder->CreateBitCast(getStreamSetBlockPtr(self, "i16Stream", i16BlockNo), PointerType::get(iBuilder->getInt16Ty(), 0));
     174   
     175    Value * u16_output_ptr = iBuilder->CreateGEP(i16StreamBase_ptr, iBuilder->CreateURem(i16UnitsGenerated, stride));
    188176
    189177   
     
    222210   
    223211    i16UnitsGenerated = iBuilder->CreateAdd(i16UnitsGenerated, iBuilder->CreateZExt(offset, iBuilder->getSizeTy()));
    224     setScalarField(self, "unitsGenerated", i16UnitsGenerated);
    225    
    226     Value * unitsInBuffer = iBuilder->CreateSub(i16UnitsGenerated, i16UnitsWritten);
    227     Value * lessThanABlockRemaining = iBuilder->CreateICmpUGT(unitsInBuffer, ConstantInt::get(iBuilder->getSizeTy(), (getStreamSetBufferSize(self, "i16Stream") - 1) * iBuilder->getBitBlockWidth()));
    228     BasicBlock * flushStmts = BasicBlock::Create(iBuilder->getContext(), "flush", doBlockFunction, 0);
    229     BasicBlock * exitStmts = BasicBlock::Create(iBuilder->getContext(), "exit", doBlockFunction, 0);
    230     iBuilder->CreateCondBr(lessThanABlockRemaining, flushStmts, exitStmts);
    231    
    232     iBuilder->SetInsertPoint(flushStmts);
    233     iBuilder->CreateCall(writefn, std::vector<Value *>({iBuilder->getInt32(1), iBuilder->CreateBitCast(i16StreamBase_ptr, i8PtrTy), iBuilder->CreateAdd(unitsInBuffer, unitsInBuffer)}));
    234     setScalarField(self, "unitsWritten", i16UnitsGenerated); // Everything generated has now been written.
    235     iBuilder->CreateBr(exitStmts);
    236    
    237     iBuilder->SetInsertPoint(exitStmts);
     212    setProducedItemCount(self, i16UnitsGenerated);
    238213    iBuilder->CreateRetVoid();
    239214    iBuilder->restoreIP(savePoint);
     
    243218    IDISA::IDISA_Builder::InsertPoint savePoint = iBuilder->saveIP();
    244219    Module * m = iBuilder->getModule();
    245     Type * i8PtrTy = iBuilder->getInt8PtrTy();
    246     Function * writefn = create_write(m);
    247220    Function * doBlockFunction = m->getFunction(mKernelName + doBlock_suffix);
    248221    Function * finalBlockFunction = m->getFunction(mKernelName + finalBlock_suffix);
     
    256229        doBlockArgs.push_back(&*args++);
    257230    }
     231    Value * i16UnitsGenerated = getProducedItemCount(self); // units generated to buffer
     232
    258233    iBuilder->CreateCall(doBlockFunction, doBlockArgs);
    259     Value * i16UnitsGenerated = getScalarField(self, "unitsGenerated");  // units generated to buffer
    260     Value * i16UnitsWritten = getScalarField(self, "unitsWritten");  // units written to stdout
    261     Value * unitsInBuffer = iBuilder->CreateSub(i16UnitsGenerated, i16UnitsWritten);
    262     Value * mustFlush = iBuilder->CreateICmpUGT(unitsInBuffer, ConstantInt::get(iBuilder->getSizeTy(), 0));
    263    
    264     BasicBlock * flushStmts = BasicBlock::Create(iBuilder->getContext(), "flush", finalBlockFunction, 0);
    265     BasicBlock * exitStmts = BasicBlock::Create(iBuilder->getContext(), "exit", finalBlockFunction, 0);
    266     iBuilder->CreateCondBr(mustFlush, flushStmts, exitStmts);
    267    
    268     iBuilder->SetInsertPoint(flushStmts);
    269     Value * i16StreamBase_ptr = iBuilder->CreateBitCast(getStreamSetBasePtr(self, "i16Stream"), PointerType::get(iBuilder->getInt16Ty(), 0));
    270     iBuilder->CreateCall(writefn, std::vector<Value *>({iBuilder->getInt32(1), iBuilder->CreateBitCast(i16StreamBase_ptr, i8PtrTy), iBuilder->CreateAdd(unitsInBuffer, unitsInBuffer)}));
    271     setScalarField(self, "unitsWritten", i16UnitsGenerated); // Everything generated has now been written.
    272     iBuilder->CreateBr(exitStmts);
    273    
    274     iBuilder->SetInsertPoint(exitStmts);
    275     iBuilder->CreateRetVoid();
    276     iBuilder->restoreIP(savePoint);
    277 }
    278    
    279    
    280 }
     234    i16UnitsGenerated = getProducedItemCount(self); // units generated to buffer
     235    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
     236        Value * ssStructPtr = getStreamSetStructPtr(self, mStreamSetOutputs[i].ssName);
     237        Value * producerPosPtr = mStreamSetOutputBuffers[i]->getProducerPosPtr(ssStructPtr);
     238        iBuilder->CreateAlignedStore(i16UnitsGenerated, producerPosPtr, sizeof(size_t))->setOrdering(AtomicOrdering::Release);
     239    }
     240    iBuilder->CreateRetVoid();
     241    iBuilder->restoreIP(savePoint);
     242}
     243   
     244   
     245}
Note: See TracChangeset for help on using the changeset viewer.