Changeset 5190


Ignore:
Timestamp:
Oct 12, 2016, 8:20:26 PM (2 years ago)
Author:
cameron
Message:

Empty external file buffer for output; use memmove vs memcpy for copyback

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
2 edited

Legend:

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

    r5188 r5190  
    9999
    100100void ExternalFileBuffer::setStreamSetBuffer(llvm::Value * ptr, Value * fileSize) {
    101 
     101   
    102102    Type * const size_ty = iBuilder->getSizeTy();
    103103    Type * const int1ty = iBuilder->getInt1Ty();
    104 
     104   
    105105    PointerType * t = getStreamBufferPointerType();   
    106106    mStreamSetBufferPtr = iBuilder->CreatePointerBitCastOrAddrSpaceCast(ptr, t);
    107 
     107   
    108108    mStreamSetStructPtr = iBuilder->CreateCacheAlignedAlloca(mStreamSetStructType);
    109109    iBuilder->CreateStore(fileSize, iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
    110110    iBuilder->CreateStore(ConstantInt::get(size_ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}));
    111111    iBuilder->CreateStore(ConstantInt::get(int1ty, 1), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)}));
     112    iBuilder->CreateStore(mStreamSetBufferPtr, iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)}));
     113}
     114
     115void ExternalFileBuffer::setEmptyBuffer(llvm::Value * ptr) {
     116   
     117    Type * const size_ty = iBuilder->getSizeTy();
     118    Type * const int1ty = iBuilder->getInt1Ty();
     119   
     120    PointerType * t = getStreamBufferPointerType();   
     121    mStreamSetBufferPtr = iBuilder->CreatePointerBitCastOrAddrSpaceCast(ptr, t);
     122   
     123    mStreamSetStructPtr = iBuilder->CreateCacheAlignedAlloca(mStreamSetStructType);
     124    iBuilder->CreateStore(ConstantInt::get(size_ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iProducer_pos)}));
     125    iBuilder->CreateStore(ConstantInt::get(size_ty, 0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iConsumer_pos)}));
     126    iBuilder->CreateStore(ConstantInt::get(int1ty,0), iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iEnd_of_input)}));
    112127    iBuilder->CreateStore(mStreamSetBufferPtr, iBuilder->CreateGEP(mStreamSetStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)}));
    113128}
     
    151166    Type * const i8_ptr = PointerType::get(i8, mAddrSpace);
    152167    Module * M = iBuilder->getModule();
    153     Function * memcpyFunc = cast<Function>(M->getOrInsertFunction("llvm.memcpy.p0i8.p0i8.i" + std::to_string(sizeof(size_t) * 8),
     168    Function * memmoveFunc = cast<Function>(M->getOrInsertFunction("llvm.memmove.p0i8.p0i8.i" + std::to_string(sizeof(size_t) * 8),
    154169                                                                  iBuilder->getVoidTy(), i8_ptr, i8_ptr, iBuilder->getSizeTy(), i32, i1, nullptr));
    155170    Function * current = iBuilder->GetInsertBlock()->getParent();
     
    180195    Constant * blockBytes = ConstantInt::get(iBuilder->getSizeTy(), mStreamSetType.StreamCount() * mStreamSetType.StreamFieldWidth() * iBuilder->getStride()/8);
    181196    Value * copyLength = iBuilder->CreateMul(copyBlocks, blockBytes);
    182     //iBuilder->CallPrintInt("memcpy copyLength", copyLength);
     197    //iBuilder->CallPrintInt("memmove copyLength", copyLength);
    183198    // Must copy back one full block for each of the streams in the stream set.
    184199    Value * handle = iBuilder->CreateGEP(bufferStructPtr, {iBuilder->getInt32(0), iBuilder->getInt32(iBuffer_ptr)});
    185200    Value * bufferPtr = iBuilder->CreateLoad(handle);
    186     //iBuilder->CallPrintInt("memcpy bufferPtr", iBuilder->CreatePtrToInt(bufferPtr, iBuilder->getSizeTy()));
     201    //iBuilder->CallPrintInt("memmove bufferPtr", iBuilder->CreatePtrToInt(bufferPtr, iBuilder->getSizeTy()));
    187202
    188203    Value * copyFrom = iBuilder->CreateGEP(bufferPtr, {iBuilder->CreateSub(new_consumer_block, consumerBlock)});
    189     //iBuilder->CallPrintInt("memcpy copyFrom", iBuilder->CreatePtrToInt(copyFrom, iBuilder->getSizeTy()));
     204    //iBuilder->CallPrintInt("memmove copyFrom", iBuilder->CreatePtrToInt(copyFrom, iBuilder->getSizeTy()));
    190205    Value * alignment = ConstantInt::get(iBuilder->getInt32Ty(), iBuilder->getBitBlockWidth()/8);
    191206   
    192     iBuilder->CreateCall(memcpyFunc, {iBuilder->CreateBitCast(bufferPtr, i8_ptr), iBuilder->CreateBitCast(copyFrom, i8_ptr), copyLength, alignment, ConstantInt::getNullValue(i1)});
     207    iBuilder->CreateCall(memmoveFunc, {iBuilder->CreateBitCast(bufferPtr, i8_ptr), iBuilder->CreateBitCast(copyFrom, i8_ptr), copyLength, alignment, ConstantInt::getNullValue(i1)});
    193208    iBuilder->CreateBr(setConsumerPosExit);
    194209    // Copy back done, store the new consumer position.
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5188 r5190  
    113113
    114114    void setStreamSetBuffer(llvm::Value * ptr, llvm::Value * fileSize);
     115    void setEmptyBuffer(llvm::Value * buffer_ptr);
    115116   
    116117    // Can't allocate - raise an error. */
Note: See TracChangeset for help on using the changeset viewer.