Ignore:
Timestamp:
Mar 31, 2017, 3:05:41 PM (2 years ago)
Author:
nmedfort
Message:

Replaced stdin input stream with mmap'ed buffer and aligned each read call to the page size.

File:
1 edited

Legend:

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

    r5381 r5386  
    123123}
    124124
     125void StreamSetBuffer::releaseBuffer(Value * /* self */) {
     126    /* do nothing: memory is stack allocated */
     127}
     128
    125129// Single Block Buffer
    126130
     
    162166    initialSize = ConstantExpr::getIntegerCast(initialSize, iBuilder->getSizeTy(), false);
    163167    iBuilder->CreateStore(initialSize, capacityPtr);
    164     Value * addr = iBuilder->CreateAlignedMalloc(initialSize, iBuilder->getCacheAlignment());
    165     iBuilder->CreateMemZero(addr, initialSize, iBuilder->getCacheAlignment());
     168    Value * addr = iBuilder->CreateAnonymousMMap(initialSize);
    166169    Value * const addrPtr = iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    167170    addr = iBuilder->CreatePointerCast(addr, addrPtr->getType()->getPointerElementType());
     
    185188    Value * const reserved = iBuilder->CreateAdd(iBuilder->CreateMul(position, blockSize), requested);
    186189    iBuilder->CreateLikelyCondBr(iBuilder->CreateICmpULT(reserved, currentSize), resume, expand);
    187 
    188190    iBuilder->SetInsertPoint(expand);
    189191    Value * const reservedSize = iBuilder->CreateShl(reserved, 1);
    190     Value * newAddr = iBuilder->CreateAlignedMalloc(reservedSize, iBuilder->getCacheAlignment());
    191192    Value * const baseAddrPtr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    192193    Value * const baseAddr = iBuilder->CreateLoad(baseAddrPtr);
    193     iBuilder->CreateMemCpy(newAddr, baseAddr, currentSize, iBuilder->getCacheAlignment());
    194     iBuilder->CreateAlignedFree(baseAddr);
    195     Value * const remainingSize = iBuilder->CreateSub(reservedSize, currentSize);
    196     iBuilder->CreateMemZero(iBuilder->CreateGEP(newAddr, currentSize), remainingSize, iBuilder->getBitBlockWidth() / 8);
     194    Value * newAddr = iBuilder->CreateMRemap(baseAddr, currentSize, reservedSize);
    197195    newAddr = iBuilder->CreatePointerCast(newAddr, baseAddr->getType());
    198196    iBuilder->CreateStore(reservedSize, capacityPtr);
     
    205203Value * ExtensibleBuffer::getBaseAddress(Value * const self) const {
    206204    return iBuilder->CreateLoad(iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)}));
     205}
     206
     207void ExtensibleBuffer::releaseBuffer(Value * self) {
     208    Value * const sizePtr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     209    Value * size = iBuilder->CreateLoad(sizePtr);
     210    iBuilder->CreateMUnmap(getBaseAddress(self), size);
    207211}
    208212
     
    447451}
    448452
     453void ExpandableBuffer::releaseBuffer(Value * self) {
     454    iBuilder->CreateAlignedFree(getBaseAddress(self));
     455}
     456
    449457Value * ExpandableBuffer::getStreamSetBlockPtr(Value *, Value *) const {
    450458    report_fatal_error("Expandable buffers: getStreamSetBlockPtr is not supported.");
Note: See TracChangeset for help on using the changeset viewer.