Ignore:
Timestamp:
Apr 28, 2017, 2:50:59 PM (2 years ago)
Author:
nmedfort
Message:

Refactored source kernels. icgrep from stdin should now be able to handle any file size.

Location:
icGREP/icgrep-devel/icgrep/kernels
Files:
2 added
4 deleted
4 edited

Legend:

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

    r5425 r5429  
    3434static const std::string BUFFER_PTR_SUFFIX = "_bufferPtr";
    3535
    36 static const std::string CONSUMER_SUFFIX = "_cls";
     36static const std::string CONSUMER_SUFFIX = "_consumerLocks";
    3737
    3838using namespace llvm;
     
    234234    }
    235235    for (auto binding : mStreamSetOutputs) {
    236         setConsumerState(binding.name, &*(args++));
     236        setConsumerLock(binding.name, &*(args++));
    237237    }
    238238    generateInitializeMethod();
     
    372372}
    373373
    374 llvm::Value * KernelBuilder::getConsumerState(const std::string & name) const {
     374llvm::Value * KernelBuilder::getConsumerLock(const std::string & name) const {
    375375    return getScalarField(name + CONSUMER_SUFFIX);
    376376}
    377377
    378 void KernelBuilder::setConsumerState(const std::string & name, llvm::Value * value) const {
     378void KernelBuilder::setConsumerLock(const std::string & name, llvm::Value * value) const {
    379379    setScalarField(name + CONSUMER_SUFFIX, value);
    380380}
     
    487487    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    488488    buf->reserveBytes(getStreamSetBufferPtr(name), iBuilder->CreateAdd(itemCount, value));
     489}
     490
     491BasicBlock * KernelBuilder::CreateWaitForConsumers() const {
     492
     493    const auto consumers = getStreamOutputs();
     494    BasicBlock * const entry = iBuilder->GetInsertBlock();
     495    if (consumers.empty()) {
     496        return entry;
     497    } else {
     498        Function * const parent = entry->getParent();
     499        IntegerType * const sizeTy = iBuilder->getSizeTy();
     500        ConstantInt * const zero = iBuilder->getInt32(0);
     501        ConstantInt * const one = iBuilder->getInt32(1);
     502        ConstantInt * const size0 = iBuilder->getSize(0);
     503
     504        Value * const segNo = acquireLogicalSegmentNo();
     505        const auto n = consumers.size();
     506        BasicBlock * load[n + 1];
     507        BasicBlock * wait[n];
     508        for (unsigned i = 0; i < n; ++i) {
     509            load[i] = BasicBlock::Create(iBuilder->getContext(), consumers[i].name + "Load", parent);
     510            wait[i] = BasicBlock::Create(iBuilder->getContext(), consumers[i].name + "Wait", parent);
     511        }
     512        load[n] = BasicBlock::Create(iBuilder->getContext(), "Resume", parent);
     513        iBuilder->CreateBr(load[0]);
     514        for (unsigned i = 0; i < n; ++i) {
     515
     516            iBuilder->SetInsertPoint(load[i]);
     517            Value * const outputConsumers = getConsumerLock(consumers[i].name);
     518
     519            Value * const consumerCount = iBuilder->CreateLoad(iBuilder->CreateGEP(outputConsumers, {zero, zero}));
     520            Value * const consumerPtr = iBuilder->CreateLoad(iBuilder->CreateGEP(outputConsumers, {zero, one}));
     521            Value * const noConsumers = iBuilder->CreateICmpEQ(consumerCount, size0);
     522            iBuilder->CreateUnlikelyCondBr(noConsumers, load[i + 1], wait[i]);
     523
     524            iBuilder->SetInsertPoint(wait[i]);
     525            PHINode * const consumerPhi = iBuilder->CreatePHI(sizeTy, 2);
     526            consumerPhi->addIncoming(size0, load[i]);
     527
     528            Value * const conSegPtr = iBuilder->CreateLoad(iBuilder->CreateGEP(consumerPtr, consumerPhi));
     529            Value * const processedSegmentCount = iBuilder->CreateAtomicLoadAcquire(conSegPtr);
     530            Value * const ready = iBuilder->CreateICmpEQ(segNo, processedSegmentCount);
     531            assert (ready->getType() == iBuilder->getInt1Ty());
     532            Value * const nextConsumerIdx = iBuilder->CreateAdd(consumerPhi, iBuilder->CreateZExt(ready, sizeTy));
     533            consumerPhi->addIncoming(nextConsumerIdx, wait[i]);
     534            Value * const next = iBuilder->CreateICmpEQ(nextConsumerIdx, consumerCount);
     535            iBuilder->CreateCondBr(next, load[i + 1], wait[i]);
     536        }
     537
     538        BasicBlock * const exit = load[n];
     539        iBuilder->SetInsertPoint(exit);
     540        return exit;
     541    }
     542
    489543}
    490544
     
    548602        report_fatal_error("Cannot initialize " + getName() + " before calling createInstance()");
    549603    }
     604
    550605    std::vector<Value *> args;
    551606    args.reserve(1 + mInitialArguments.size() + mStreamSetInputBuffers.size() + (mStreamSetOutputBuffers.size() * 2));
     
    602657        args.push_back(outputConsumers);
    603658    }
    604 
    605659
    606660    iBuilder->CreateCall(getInitFunction(), args);
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5425 r5429  
    135135    void releaseLogicalSegmentNo(llvm::Value * nextSegNo) const;
    136136
    137     llvm::Value * getConsumerState(const std::string & name) const;
    138 
    139137    // Get a parameter by name.
    140138    llvm::Argument * getParameter(llvm::Function * f, const std::string & name) const;
     
    258256    }
    259257
     258    llvm::BasicBlock * CreateWaitForConsumers() const;
    260259
    261260    llvm::BasicBlock * CreateBasicBlock(std::string && name) const;
     
    310309private:
    311310
    312     void setConsumerState(const std::string & name, llvm::Value * value) const;
     311    llvm::Value * getConsumerLock(const std::string & name) const;
     312
     313    void setConsumerLock(const std::string & name, llvm::Value * value) const;
    313314
    314315    llvm::Value * computeBlockIndex(const std::vector<Binding> & binding, const std::string & name, llvm::Value * itemCount) const;
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5425 r5429  
    2929
    3030void StreamSetBuffer::allocateBuffer() {
    31     Type * const ty = getType();
    32     ConstantInt * blocks = iBuilder->getSize(mBufferBlocks);
    33     mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(ty, iBuilder->getSize(mBufferBlocks));
    34     Constant * width = ConstantExpr::getMul(ConstantExpr::getSizeOf(ty), blocks);
    35     iBuilder->CreateMemZero(mStreamSetBufferPtr, width, iBuilder->getCacheAlignment());
     31    if (LLVM_LIKELY(mStreamSetBufferPtr == nullptr)) {
     32        Type * const ty = getType();
     33        mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(ty, iBuilder->getSize(mBufferBlocks));
     34        iBuilder->CreateAlignedStore(Constant::getNullValue(ty), mStreamSetBufferPtr, iBuilder->getCacheAlignment());
     35    } else {
     36        report_fatal_error("StreamSetBuffer::allocateBuffer() was called twice on the same stream set");
     37    }
    3638}
    3739
    3840Value * StreamSetBuffer::getStreamBlockPtr(Value * self, Value * streamIndex, Value * blockIndex, const bool /* readOnly */) const {
    3941    iBuilder->CreateAssert(iBuilder->CreateICmpULT(streamIndex, getStreamSetCount(self)), "StreamSetBuffer: out-of-bounds stream access");
    40     return iBuilder->CreateGEP(getStreamSetBlockPtr(getBaseAddress(self), blockIndex), {iBuilder->getInt32(0), streamIndex});
     42    return iBuilder->CreateGEP(getStreamSetBlockPtr(self, blockIndex), {iBuilder->getInt32(0), streamIndex});
    4143}
    4244
    4345Value * StreamSetBuffer::getStreamPackPtr(Value * self, Value * streamIndex, Value * blockIndex, Value * packIndex, const bool /* readOnly */) const {
    4446    iBuilder->CreateAssert(iBuilder->CreateICmpULT(streamIndex, getStreamSetCount(self)), "StreamSetBuffer: out-of-bounds stream access");
    45     return iBuilder->CreateGEP(getStreamSetBlockPtr(getBaseAddress(self), blockIndex), {iBuilder->getInt32(0), streamIndex, packIndex});
     47    return iBuilder->CreateGEP(getStreamSetBlockPtr(self, blockIndex), {iBuilder->getInt32(0), streamIndex, packIndex});
    4648}
    4749
     
    148150}
    149151
    150 // External File Buffer
    151 void ExternalFileBuffer::setStreamSetBuffer(Value * ptr) {
    152     mStreamSetBufferPtr = iBuilder->CreatePointerBitCastOrAddrSpaceCast(ptr, getPointerType());
    153 }
    154 
    155 void ExternalFileBuffer::allocateBuffer() {
    156     report_fatal_error("External buffers cannot be allocated.");
    157 }
    158 
    159 Value * ExternalFileBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
    160     return iBuilder->CreateGEP(self, blockIndex);
    161 }
    162 
    163 Value * ExternalFileBuffer::getLinearlyAccessibleItems(Value * self, Value *) const {
    164     report_fatal_error("External buffers: getLinearlyAccessibleItems is not supported.");
    165 }
    166 
    167152// Source File Buffer
    168 Value * SourceFileBuffer::getBufferedSize(Value * self) const {
     153Value * SourceBuffer::getBufferedSize(Value * self) const {
    169154    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    170155    return iBuilder->CreateLoad(ptr);
    171156}
    172157
    173 void SourceFileBuffer::setBufferedSize(Value * self, llvm::Value * size) const {
     158void SourceBuffer::setBufferedSize(Value * self, llvm::Value * size) const {
    174159    Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    175160    iBuilder->CreateStore(size, ptr);
    176161}
    177162
    178 void SourceFileBuffer::setBaseAddress(Value * self, Value * addr) const {
    179     Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     163void SourceBuffer::setBaseAddress(Value * self, Value * addr) const {
     164    Value * const ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    180165    iBuilder->CreateStore(iBuilder->CreatePointerCast(addr, ptr->getType()->getPointerElementType()), ptr);
    181166}
    182167
    183 Value * SourceFileBuffer::getBaseAddress(Value * const self) const {
    184     Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    185     return iBuilder->CreateLoad(ptr);
    186 }
    187 
    188 Value * SourceFileBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
    189     return iBuilder->CreateGEP(self, blockIndex);
    190 }
    191 
    192 Value * SourceFileBuffer::getLinearlyAccessibleItems(Value * self, Value *) const {
     168Value * SourceBuffer::getBaseAddress(Value * const self) const {
     169    Value * const ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
     170    Value * const addr = iBuilder->CreateLoad(ptr);
     171    return addr;
     172}
     173
     174Value * SourceBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
     175    return iBuilder->CreateGEP(getBaseAddress(self), blockIndex);
     176}
     177
     178Value * SourceBuffer::getLinearlyAccessibleItems(Value * self, Value *) const {
    193179    report_fatal_error("External buffers: getLinearlyAccessibleItems is not supported.");
    194180}
    195181
    196 // ExtensibleBuffer
    197 Value * ExtensibleBuffer::getLinearlyAccessibleItems(Value * self, Value * fromPosition) const {
    198     Value * capacityPtr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    199     Value * capacity = iBuilder->CreateLoad(capacityPtr);
    200     return iBuilder->CreateSub(capacity, fromPosition);
    201 }
    202 
    203 Value * ExtensibleBuffer::roundUpToPageSize(Value * const value) const {
    204     const auto pageSize = getpagesize();
    205     assert ((pageSize & (pageSize - 1)) == 0);
    206     Constant * const pageMask = ConstantInt::get(value->getType(), pageSize - 1);
    207     return iBuilder->CreateAnd(iBuilder->CreateAdd(value, pageMask), iBuilder->CreateNot(pageMask));
    208 }
    209 
    210 void ExtensibleBuffer::allocateBuffer() {
    211     Type * ty = getType();
    212     Value * instance = iBuilder->CreateCacheAlignedAlloca(ty);
    213     Value * const capacityPtr = iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    214 
    215     Type * const elementType = ty->getStructElementType(1)->getPointerElementType();
    216     Constant * size = ConstantExpr::getSizeOf(elementType);
    217     size = ConstantExpr::getMul(size, iBuilder->getSize(mBufferBlocks));
    218     size = ConstantExpr::getIntegerCast(size, iBuilder->getSizeTy(), false);
    219     Value * const initialSize = roundUpToPageSize(size);
    220 
    221     iBuilder->CreateStore(initialSize, capacityPtr);
    222     Value * addr = iBuilder->CreateAnonymousMMap(size);
    223     Value * const addrPtr = iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    224     addr = iBuilder->CreatePointerCast(addr, addrPtr->getType()->getPointerElementType());
    225     iBuilder->CreateStore(addr, addrPtr);
    226     Value * const bufferSizePtr = iBuilder->CreateGEP(instance, {iBuilder->getInt32(0), iBuilder->getInt32(2)});
    227     iBuilder->CreateStore(ConstantInt::getNullValue(bufferSizePtr->getType()->getPointerElementType()), bufferSizePtr);
    228     mStreamSetBufferPtr = instance;
    229 }
    230 
    231 Value * ExtensibleBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
    232     return iBuilder->CreateGEP(self, blockIndex);
    233 }
    234 
    235 void ExtensibleBuffer::reserveBytes(Value * const self, llvm::Value * const requiredSize) const {
    236 
    237     Value * const capacityPtr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    238     Value * const currentSize = iBuilder->CreateLoad(capacityPtr);
    239     BasicBlock * const entry = iBuilder->GetInsertBlock();
    240     Function * const parent = entry->getParent();
    241     IntegerType * const sizeTy = iBuilder->getSizeTy();
    242     ConstantInt * const zero = iBuilder->getInt32(0);
    243     ConstantInt * const one = iBuilder->getInt32(1);
    244 
    245     BasicBlock * const expand = BasicBlock::Create(iBuilder->getContext(), "expand", parent);
    246     BasicBlock * const resume = BasicBlock::Create(iBuilder->getContext(), "resume", parent);
    247 
    248     Value * noExpansionNeeded = iBuilder->CreateICmpULT(requiredSize, currentSize);
    249 
    250     kernel::KernelBuilder * const kernel = getProducer();
    251     auto consumers = kernel->getStreamOutputs();
    252     if (consumers.empty()) {
    253         iBuilder->CreateLikelyCondBr(noExpansionNeeded, resume, expand);
    254     } else { // we cannot risk expanding this buffer until all of the consumers have finished reading the data
    255 
    256         ConstantInt * const size0 = iBuilder->getSize(0);
    257         Value * const segNo = kernel->acquireLogicalSegmentNo();
    258         const auto n = consumers.size();
    259 
    260         BasicBlock * load[n + 1];
    261         BasicBlock * wait[n];
    262         for (unsigned i = 0; i < n; ++i) {
    263             load[i] = BasicBlock::Create(iBuilder->getContext(), consumers[i].name + "Load", parent);
    264             wait[i] = BasicBlock::Create(iBuilder->getContext(), consumers[i].name + "Wait", parent);
    265         }
    266         load[n] = expand;
    267         iBuilder->CreateLikelyCondBr(noExpansionNeeded, resume, load[0]);
    268 
    269         for (unsigned i = 0; i < n; ++i) {
    270 
    271             iBuilder->SetInsertPoint(load[i]);
    272             Value * const outputConsumers = kernel->getConsumerState(consumers[i].name);
    273 
    274             Value * const consumerCount = iBuilder->CreateLoad(iBuilder->CreateGEP(outputConsumers, {zero, zero}));
    275             Value * const consumerPtr = iBuilder->CreateLoad(iBuilder->CreateGEP(outputConsumers, {zero, one}));
    276             Value * const noConsumers = iBuilder->CreateICmpEQ(consumerCount, size0);
    277             iBuilder->CreateUnlikelyCondBr(noConsumers, load[i + 1], wait[i]);
    278 
    279             iBuilder->SetInsertPoint(wait[i]);
    280             PHINode * const consumerPhi = iBuilder->CreatePHI(sizeTy, 2);
    281             consumerPhi->addIncoming(size0, load[i]);
    282 
    283             Value * const conSegPtr = iBuilder->CreateLoad(iBuilder->CreateGEP(consumerPtr, consumerPhi));
    284             Value * const processedSegmentCount = iBuilder->CreateAtomicLoadAcquire(conSegPtr);
    285             Value * const ready = iBuilder->CreateICmpEQ(segNo, processedSegmentCount);
    286             assert (ready->getType() == iBuilder->getInt1Ty());
    287             Value * const nextConsumerIdx = iBuilder->CreateAdd(consumerPhi, iBuilder->CreateZExt(ready, sizeTy));
    288             consumerPhi->addIncoming(nextConsumerIdx, wait[i]);
    289             Value * const next = iBuilder->CreateICmpEQ(nextConsumerIdx, consumerCount);
    290             iBuilder->CreateCondBr(next, load[i + 1], wait[i]);
    291 
    292         }
    293         expand->moveAfter(wait[n - 1]);
    294         resume->moveAfter(expand);
    295     }
    296     iBuilder->SetInsertPoint(expand);
    297     Value * const reservedSize = roundUpToPageSize(iBuilder->CreateShl(requiredSize, 1));
    298     Value * const baseAddrPtr = iBuilder->CreateGEP(self, {zero, one});
    299 
    300     Value * const baseAddr = iBuilder->CreateLoad(baseAddrPtr);
    301     Value * newAddr = iBuilder->CreateMRemap(baseAddr, currentSize, reservedSize);
    302     newAddr = iBuilder->CreatePointerCast(newAddr, baseAddr->getType());
    303     iBuilder->CreateStore(newAddr, baseAddrPtr);
    304     iBuilder->CreateStore(reservedSize, capacityPtr);
    305     iBuilder->CreateBr(resume);
    306     iBuilder->SetInsertPoint(resume);
    307 }
    308 
    309 Value * ExtensibleBuffer::getBufferedSize(Value * self) const {
    310     Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(2)});
    311     return iBuilder->CreateLoad(ptr);
    312 }
    313 
    314 void ExtensibleBuffer::setBufferedSize(Value * self, llvm::Value * size) const {
    315     Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(2)});
    316     iBuilder->CreateStore(size, ptr);
    317 }
    318 
    319 Value * ExtensibleBuffer::getBaseAddress(Value * const self) const {
    320     Value * ptr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
    321     return iBuilder->CreateLoad(ptr);
    322 }
    323 
    324 void ExtensibleBuffer::releaseBuffer(Value * self) const {
    325     Value * const sizePtr = iBuilder->CreateGEP(self, {iBuilder->getInt32(0), iBuilder->getInt32(0)});
    326     Value * size = iBuilder->CreateLoad(sizePtr);
    327     iBuilder->CreateMUnmap(getBaseAddress(self), size);
     182// External File Buffer
     183void ExternalBuffer::allocateBuffer() {
     184    report_fatal_error("External buffers cannot be allocated.");
     185}
     186
     187Value * ExternalBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
     188    return iBuilder->CreateGEP(getBaseAddress(self), blockIndex);
     189}
     190
     191Value * ExternalBuffer::getLinearlyAccessibleItems(Value *, Value *) const {
     192    report_fatal_error("External buffers: getLinearlyAccessibleItems is not supported.");
    328193}
    329194
    330195// Circular Buffer
    331 
    332196Value * CircularBuffer::getStreamSetBlockPtr(Value * const self, Value * const blockIndex) const {
    333     return iBuilder->CreateGEP(self, modByBufferBlocks(blockIndex));
     197    return iBuilder->CreateGEP(getBaseAddress(self), modByBufferBlocks(blockIndex));
    334198}
    335199
    336200// CircularCopybackBuffer Buffer
    337 
    338201void CircularCopybackBuffer::allocateBuffer() {
    339202    mStreamSetBufferPtr = iBuilder->CreateCacheAlignedAlloca(getType(), iBuilder->getSize(mBufferBlocks + mOverflowBlocks));
     
    375238
    376239Value * CircularCopybackBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
    377     return iBuilder->CreateGEP(self, modByBufferBlocks(blockIndex));
     240    return iBuilder->CreateGEP(getBaseAddress(self), modByBufferBlocks(blockIndex));
    378241}
    379242
     
    420283
    421284Value * SwizzledCopybackBuffer::getStreamSetBlockPtr(Value * self, Value * blockIndex) const {
    422     return iBuilder->CreateGEP(self, modByBufferBlocks(blockIndex));
     285    return iBuilder->CreateGEP(getBaseAddress(self), modByBufferBlocks(blockIndex));
    423286}
    424287
     
    593456}
    594457
    595 ExternalFileBuffer::ExternalFileBuffer(IDISA::IDISA_Builder * b, Type * type, unsigned AddressSpace)
    596 : StreamSetBuffer(BufferKind::ExternalFileBuffer, b, type, resolveStreamSetType(b, type), 0, AddressSpace) {
     458SourceBuffer::SourceBuffer(IDISA::IDISA_Builder * b, Type * type, unsigned AddressSpace)
     459: StreamSetBuffer(BufferKind::SourceBuffer, b, type, StructType::get(resolveStreamSetType(b, type)->getPointerTo(), b->getSizeTy(), nullptr), 0, AddressSpace) {
     460    mUniqueID = "M"; // + std::to_string(bufferBlocks);
     461    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
     462}
     463
     464ExternalBuffer::ExternalBuffer(IDISA::IDISA_Builder * b, Type * type, llvm::Value * addr, unsigned AddressSpace)
     465: StreamSetBuffer(BufferKind::ExternalBuffer, b, type, resolveStreamSetType(b, type), 0, AddressSpace) {
    597466    mUniqueID = "E";
    598467    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
    599 }
    600 
    601 SourceFileBuffer::SourceFileBuffer(IDISA::IDISA_Builder * b, Type * type, unsigned AddressSpace)
    602 : StreamSetBuffer(BufferKind::SourceFileBuffer, b, type, StructType::get(resolveStreamSetType(b, type)->getPointerTo(), b->getSizeTy(), nullptr), 0, AddressSpace) {
    603 
    604 }
    605 
    606 ExtensibleBuffer::ExtensibleBuffer(IDISA::IDISA_Builder * b, Type * type, size_t bufferBlocks, unsigned AddressSpace)
    607 : StreamSetBuffer(BufferKind::ExtensibleBuffer, b, type, StructType::get(b->getSizeTy(), resolveStreamSetType(b, type)->getPointerTo(), b->getSizeTy(), nullptr), bufferBlocks, AddressSpace) {
    608     mUniqueID = "XT" + std::to_string(bufferBlocks);
    609     if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
     468    mStreamSetBufferPtr = b->CreatePointerBitCastOrAddrSpaceCast(addr, getPointerType());
    610469}
    611470
     
    614473    mUniqueID = "C" + std::to_string(bufferBlocks);
    615474    if (AddressSpace > 0) mUniqueID += "@" + std::to_string(AddressSpace);
    616 
    617475}
    618476
  • icGREP/icgrep-devel/icgrep/kernels/streamset.h

    r5411 r5429  
    2121    enum class BufferKind : unsigned {
    2222        BlockBuffer
    23         , ExternalFileBuffer
    24         , SourceFileBuffer
     23        , SourceBuffer
     24        , ExternalBuffer
    2525        , CircularBuffer
    2626        , CircularCopybackBuffer
    2727        , SwizzledCopybackBuffer
    2828        , ExpandableBuffer
    29         , ExtensibleBuffer
    3029    };
    3130
     
    143142};
    144143
    145 class ExternalFileBuffer final : public StreamSetBuffer {
    146 public:
    147     static inline bool classof(const StreamSetBuffer * b) {
    148         return b->getBufferKind() == BufferKind::ExternalFileBuffer;
    149     }
    150 
    151     ExternalFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
    152 
    153     void setStreamSetBuffer(llvm::Value * ptr);
     144class SourceBuffer final : public StreamSetBuffer {
     145public:
     146    static inline bool classof(const StreamSetBuffer * b) {
     147        return b->getBufferKind() == BufferKind::SourceBuffer;
     148    }
     149
     150    SourceBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
     151
     152    void setBaseAddress(llvm::Value * self, llvm::Value * addr) const override;
     153
     154    void setBufferedSize(llvm::Value * self, llvm::Value * size) const override;
     155
     156    llvm::Value * getBufferedSize(llvm::Value * self) const override;
     157
     158    llvm::Value * getLinearlyAccessibleItems(llvm::Value * self, llvm::Value * fromPosition) const override;
     159
     160protected:
     161
     162    llvm::Value * getBaseAddress(llvm::Value * self) const override;
     163
     164    llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const override;
     165
     166};
     167
     168class ExternalBuffer final : public StreamSetBuffer {
     169public:
     170    static inline bool classof(const StreamSetBuffer * b) {
     171        return b->getBufferKind() == BufferKind::ExternalBuffer;
     172    }
     173
     174    ExternalBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, llvm::Value * addr, unsigned AddressSpace = 0);
    154175
    155176    // Can't allocate - raise an error. */
     
    162183};
    163184
    164 class SourceFileBuffer final : public StreamSetBuffer {
    165 public:
    166     static inline bool classof(const StreamSetBuffer * b) {
    167         return b->getBufferKind() == BufferKind::SourceFileBuffer;
    168     }
    169 
    170     SourceFileBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, unsigned AddressSpace = 0);
    171 
    172     void setBaseAddress(llvm::Value * self, llvm::Value * addr) const override;
    173 
    174     void setBufferedSize(llvm::Value * self, llvm::Value * size) const override;
    175 
    176     llvm::Value * getBufferedSize(llvm::Value * self) const override;
    177 
    178     llvm::Value * getLinearlyAccessibleItems(llvm::Value * self, llvm::Value * fromPosition) const override;
    179 
    180 protected:
    181 
    182     llvm::Value * getBaseAddress(llvm::Value * self) const override;
    183 
    184     llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const override;
    185 };
    186 
    187 class ExtensibleBuffer final : public StreamSetBuffer {
    188 public:
    189     static inline bool classof(const StreamSetBuffer * b) {
    190         return b->getBufferKind() == BufferKind::ExtensibleBuffer;
    191     }
    192 
    193     ExtensibleBuffer(IDISA::IDISA_Builder * b, llvm::Type * type, size_t bufferBlocks, unsigned AddressSpace = 0);
    194 
    195     llvm::Value * getLinearlyAccessibleItems(llvm::Value * self,llvm::Value * fromPosition) const override;
    196 
    197     void allocateBuffer() override;
    198 
    199     void reserveBytes(llvm::Value * self, llvm::Value * required) const override;
    200 
    201     void setBufferedSize(llvm::Value * self, llvm::Value * size) const override;
    202 
    203     llvm::Value * getBufferedSize(llvm::Value * self) const override;
    204 
    205     void releaseBuffer(llvm::Value * self) const override;
    206 
    207 protected:
    208 
    209     llvm::Value * roundUpToPageSize(llvm::Value * const value) const;
    210 
    211     llvm::Value * getBaseAddress(llvm::Value * self) const override;
    212 
    213     llvm::Value * getStreamSetBlockPtr(llvm::Value * self, llvm::Value * blockNo) const override;
    214 
    215 };
    216    
    217185class CircularBuffer final : public StreamSetBuffer {
    218186public:
Note: See TracChangeset for help on using the changeset viewer.