Ignore:
Timestamp:
Sep 28, 2017, 11:47:58 AM (2 years ago)
Author:
cameron
Message:

Multiblock kernel builder support for ExternalBuffer? inputs; clean-up

File:
1 edited

Legend:

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

    r5647 r5650  
    140140}
    141141
    142 Value * StreamSetBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromPosition, bool reverse) const {
     142Value * StreamSetBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const b, Value * self, Value * fromPosition, Value * availItems, bool reverse) const {
     143    Constant * bufSize = b->getSize(mBufferBlocks * b->getStride());
     144    Value * itemsFromBase = b->CreateURem(fromPosition, bufSize);
     145    if (reverse) {
     146        Value * bufAvail = b->CreateSelect(b->CreateICmpEQ(itemsFromBase, b->getSize(0)), bufSize, itemsFromBase);
     147        return b->CreateSelect(b->CreateICmpULT(bufAvail, availItems), bufAvail, availItems);
     148    }
     149    else {
     150        Value * linearSpace = b->CreateSub(bufSize, itemsFromBase, "linearSpace");
     151        return b->CreateSelect(b->CreateICmpULT(availItems, linearSpace), availItems, linearSpace);
     152    }
     153}
     154
     155Value * StreamSetBuffer::getLinearlyWritableItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromPosition, bool reverse) const {
    143156    Constant * bufSize = iBuilder->getSize(mBufferBlocks * iBuilder->getStride());
    144157    Value * bufRem = iBuilder->CreateURem(fromPosition, bufSize);
     
    146159        return iBuilder->CreateSelect(iBuilder->CreateICmpEQ(bufRem, iBuilder->getSize(0)), bufSize, bufRem);
    147160    }
    148     else return iBuilder->CreateSub(bufSize, bufRem, "linearItems");
    149 }
    150 
    151 Value * StreamSetBuffer::getLinearlyAccessibleBlocks(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromBlock, bool reverse) const {
    152     Constant * bufBlocks = iBuilder->getSize(mBufferBlocks);
    153     Value * bufRem = iBuilder->CreateURem(fromBlock, bufBlocks);
    154     if (reverse) {
    155         return iBuilder->CreateSelect(iBuilder->CreateICmpEQ(bufRem, iBuilder->getSize(0)), bufBlocks, bufRem);
    156     }
    157     else return iBuilder->CreateSub(bufBlocks, bufRem, "linearBlocks");
    158 }
    159 
    160 Value * StreamSetBuffer::getLinearlyWritableItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromPosition, bool reverse) const {
    161     return getLinearlyAccessibleItems(iBuilder, self, fromPosition, reverse);
    162 }
    163 
    164 Value * StreamSetBuffer::getLinearlyWritableBlocks(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromBlock, bool reverse) const {
    165     return getLinearlyAccessibleBlocks(iBuilder, self, fromBlock, reverse);
     161    else return iBuilder->CreateSub(bufSize, bufRem, "linearSpace");
    166162}
    167163
     
    264260}
    265261
    266 Value * SourceBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromPosition, bool reverse) const {
     262Value * SourceBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromPosition, Value * availItems, bool reverse) const {
    267263    if (reverse) report_fatal_error("SourceBuffer cannot be accessed in reverse");
    268     return iBuilder->CreateSub(getCapacity(iBuilder, self), fromPosition);
    269 }
    270 
    271 Value * SourceBuffer::getLinearlyAccessibleBlocks(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromBlock, bool reverse) const {
    272     if (reverse) report_fatal_error("SourceBuffer cannot be accessed in reverse");
    273     return iBuilder->CreateSub(iBuilder->CreateUDiv(getCapacity(iBuilder, self), iBuilder->getSize(iBuilder->getBitBlockWidth())), fromBlock);
     264    Value * maxAvail = iBuilder->CreateSub(getCapacity(iBuilder, self), fromPosition);
     265    return iBuilder->CreateSelect(iBuilder->CreateICmpULT(availItems, maxAvail), availItems, maxAvail);
     266}
     267
     268Value * SourceBuffer::getLinearlyWritableItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromPosition, bool reverse) const {
     269    report_fatal_error("SourceBuffers cannot be written");
    274270}
    275271
     
    301297}
    302298
    303 Value * ExternalBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const, Value *, Value *, bool) const {
    304     report_fatal_error("External buffers: getLinearlyAccessibleItems is not supported.");
     299// All available items can be accessed.
     300Value * ExternalBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const, Value *, Value *, Value * availItems, bool) const {
     301    return availItems;
    305302}
    306303
     
    333330
    334331Value * CircularCopybackBuffer::getLinearlyWritableItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromPosition, bool reverse) const {
    335     Value * accessibleItems = getLinearlyAccessibleItems(iBuilder, self, fromPosition, reverse);
    336     if (reverse) return accessibleItems;
    337     return iBuilder->CreateAdd(accessibleItems, iBuilder->getSize(mOverflowBlocks * iBuilder->getBitBlockWidth()));
    338 }
    339 
    340 Value * CircularCopybackBuffer::getLinearlyWritableBlocks(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromBlock, bool reverse) const {
    341     Value * accessibleBlocks = getLinearlyAccessibleBlocks(iBuilder, self, fromBlock);
    342     if (reverse) return accessibleBlocks;
    343     return iBuilder->CreateAdd(accessibleBlocks, iBuilder->getSize(mOverflowBlocks));
     332    Value * writableProper = StreamSetBuffer::getLinearlyWritableItems(iBuilder, self, fromPosition, reverse);
     333    if (reverse) return writableProper;
     334    return iBuilder->CreateAdd(writableProper, iBuilder->getSize(mOverflowBlocks * iBuilder->getBitBlockWidth()));
    344335}
    345336
     
    412403
    413404Value * SwizzledCopybackBuffer::getLinearlyWritableItems(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromPosition, bool reverse) const {
    414     Value * accessibleItems = getLinearlyAccessibleItems(iBuilder, self, fromPosition, reverse);
    415     if (reverse) return accessibleItems;
    416     return iBuilder->CreateAdd(accessibleItems, iBuilder->getSize(mOverflowBlocks * iBuilder->getBitBlockWidth()));
    417 }
    418 
    419 Value * SwizzledCopybackBuffer::getLinearlyWritableBlocks(IDISA::IDISA_Builder * const iBuilder, Value * self, Value * fromBlock, bool reverse) const {
    420     Value * accessibleBlocks = getLinearlyAccessibleBlocks(iBuilder, self, fromBlock);
    421     if (reverse) return accessibleBlocks;
    422     return iBuilder->CreateAdd(accessibleBlocks, iBuilder->getSize(mOverflowBlocks));
    423 }
     405    Value * writableProper = StreamSetBuffer::getLinearlyWritableItems(iBuilder, self, fromPosition, reverse);
     406    if (reverse) return writableProper;
     407    return iBuilder->CreateAdd(writableProper, iBuilder->getSize(mOverflowBlocks * iBuilder->getBitBlockWidth()));
     408}
     409
    424410void SwizzledCopybackBuffer::genCopyBackLogic(IDISA::IDISA_Builder * const b, Value * handle, Value * priorProduced, Value * newProduced, const std::string Name) {
    425411    Constant * bufSize = b->getSize(mBufferBlocks * b->getBitBlockWidth());
     
    591577}
    592578
    593 Value * ExpandableBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const, Value *, Value *, bool) const {
     579Value * ExpandableBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const, Value *, Value *, Value *, bool) const {
    594580    report_fatal_error("Expandable buffers: getLinearlyAccessibleItems is not supported.");
    595581}
     
    682668
    683669
    684 Value * DynamicBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const b, Value * handle, Value * fromPosition, bool reverse) const {
     670Value * DynamicBuffer::getLinearlyAccessibleItems(IDISA::IDISA_Builder * const b, Value * handle, Value * fromPosition, Value * availItems, bool reverse) const {
    685671    Constant * blockSize = b->getSize(b->getBitBlockWidth());
    686672    Value * const bufBlocks = b->CreateLoad(b->CreateGEP(handle, {b->getInt32(0), b->getInt32(int(Field::WorkingBlocks))}));
     673    Value * bufSize = b->CreateMul(bufBlocks, blockSize);
     674    Value * itemsFromBase = b->CreateURem(fromPosition, bufSize);
     675    if (reverse) {
     676        Value * bufAvail = b->CreateSelect(b->CreateICmpEQ(itemsFromBase, b->getSize(0)), bufSize, itemsFromBase);
     677        return b->CreateSelect(b->CreateICmpULT(bufAvail, availItems), bufAvail, availItems);
     678    }
     679    else {
     680        Value * linearSpace = b->CreateSub(bufSize, itemsFromBase, "linearSpace");
     681        return b->CreateSelect(b->CreateICmpULT(availItems, linearSpace), availItems, linearSpace);
     682    }
     683}
     684
     685Value * DynamicBuffer::getLinearlyWritableItems(IDISA::IDISA_Builder * const b, Value * handle, Value * fromPosition, bool reverse) const {
     686    Constant * blockSize = b->getSize(b->getBitBlockWidth());
     687    Value * bufBlocks = b->CreateLoad(b->CreateGEP(handle, {b->getInt32(0), b->getInt32(int(Field::WorkingBlocks))}));
    687688    Value * bufSize = b->CreateMul(bufBlocks, blockSize);
    688689    Value * bufRem = b->CreateURem(fromPosition, bufSize);
     
    690691        return b->CreateSelect(b->CreateICmpEQ(bufRem, b->getSize(0)), bufSize, bufRem);
    691692    }
    692     return b->CreateSub(bufSize, bufRem, "linearItems");
    693 }
    694 
    695 Value * DynamicBuffer::getLinearlyWritableItems(IDISA::IDISA_Builder * const b, Value * handle, Value * fromPosition, bool reverse) const {
    696     Value * accessibleItems = getLinearlyAccessibleItems(b, handle, fromPosition, reverse);
    697     if (reverse || (mOverflowBlocks == 0))  return accessibleItems;
    698     return b->CreateAdd(accessibleItems, b->getSize(mOverflowBlocks * b->getBitBlockWidth()));
    699 }
    700 
    701 Value * DynamicBuffer::getLinearlyAccessibleBlocks(IDISA::IDISA_Builder * const b, Value * handle, Value * fromBlock, bool reverse) const {
    702     Value * const bufBlocks = b->CreateLoad(b->CreateGEP(handle, {b->getInt32(0), b->getInt32(int(Field::WorkingBlocks))}));
    703     Value * bufRem = b->CreateURem(fromBlock, bufBlocks);
    704     if (reverse) {
    705         return b->CreateSelect(b->CreateICmpEQ(bufRem, b->getSize(0)), bufBlocks, bufRem);
    706     }
    707     return b->CreateSub(bufBlocks, bufRem, "linearBlocks");
     693    bufSize = b->CreateMul(b->CreateAdd(bufBlocks, b->getSize(mOverflowBlocks)), blockSize);
     694    return b->CreateSub(bufSize, bufRem, "linearWritable");
    708695}
    709696
Note: See TracChangeset for help on using the changeset viewer.