Ignore:
Timestamp:
Feb 10, 2017, 1:48:34 PM (2 years ago)
Author:
nmedfort
Message:

Adjusted pablo compiler to use getInputStream and getOutputStream when accessing packed stream fields.

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

Legend:

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

    r5297 r5310  
    6666, const std::vector<CC *> & charClasses
    6767, unsigned basisBitsCount)
    68 : PabloKernel(iBuilder, ccSetName +"_kernel") {
    69 
    70     CC_Compiler ccc(this, basisBitsCount);
     68: PabloKernel(iBuilder, ccSetName +"_kernel", {Binding{iBuilder->getStreamSetTy(basisBitsCount), "basis"}}) {
     69    CC_Compiler ccc(this, getInput(0));
    7170    auto & builder = ccc.getBuilder();
    7271    for (CC * cc : charClasses) {
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5307 r5310  
    6262    }
    6363    for (unsigned i = 0; i < mStreamSetOutputs.size(); i++) {
    64         mStreamSetNameMap.emplace(mStreamSetOutputs[i].name, mStreamSetInputs.size() + i);
     64        mStreamSetNameMap.emplace(mStreamSetOutputs[i].name, i);
    6565    }
    6666}
     
    253253}
    254254
    255 inline static uint64_t log2(const uint64_t x) {
    256     return (64 - __builtin_clzll(x)) - 1;
    257 }
    258 
    259 inline static uint32_t log2(const uint32_t x) {
    260     return (32 - __builtin_clz(x)) - 1;
    261 }
    262 
    263255inline Value * KernelBuilder::computeBlockIndex(const std::vector<Binding> & bindings, const std::string & name, Value * itemCount) const {
    264256    for (const Binding & b : bindings) {
     
    266258            const auto divisor = (b.step == 0) ? iBuilder->getBitBlockWidth() : b.step;
    267259            if (LLVM_LIKELY((divisor & (divisor - 1)) == 0)) {
    268                 return iBuilder->CreateLShr(itemCount, log2(divisor));
     260                return iBuilder->CreateLShr(itemCount, std::log2(divisor));
    269261            } else {
    270262                return iBuilder->CreateUDiv(itemCount, iBuilder->getSize(divisor));
     
    277269Value * KernelBuilder::getInputStream(const std::string & name, Value * streamIndex) const {
    278270    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    279     const StreamSetBuffer * const buf = getStreamSetBuffer(name);
     271    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    280272    return buf->getStream(getStreamSetBufferPtr(name), streamIndex, blockIndex);
    281273}
     
    283275Value * KernelBuilder::getInputStream(const std::string & name, Value * streamIndex, Value * packIndex) const {
    284276    Value * const blockIndex = computeBlockIndex(mStreamSetInputs, name, getProcessedItemCount(name));
    285     const StreamSetBuffer * const buf = getStreamSetBuffer(name);
     277    const StreamSetBuffer * const buf = getInputStreamSetBuffer(name);
    286278    return buf->getStream(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex);
    287279}
     
    289281Value * KernelBuilder::getOutputStream(const std::string & name, Value * streamIndex) const {
    290282    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
    291     const StreamSetBuffer * const buf = getStreamSetBuffer(name);
     283    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    292284    return buf->getStream(getStreamSetBufferPtr(name), streamIndex, blockIndex);
    293285}
     
    295287Value * KernelBuilder::getOutputStream(const std::string & name, Value * streamIndex, Value * packIndex) const {
    296288    Value * const blockIndex = computeBlockIndex(mStreamSetOutputs, name, getProducedItemCount(name));
    297     const StreamSetBuffer * const buf = getStreamSetBuffer(name);
     289    const StreamSetBuffer * const buf = getOutputStreamSetBuffer(name);
    298290    return buf->getStream(getStreamSetBufferPtr(name), streamIndex, blockIndex, packIndex);
    299291}
    300292
    301 Value * KernelBuilder::getRawItemPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
    302     return getStreamSetBuffer(name)->getRawItemPointer(getStreamSetBufferPtr(name), streamIndex, absolutePosition);
     293Value * KernelBuilder::getRawInputPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
     294    return getInputStreamSetBuffer(name)->getRawItemPointer(getStreamSetBufferPtr(name), streamIndex, absolutePosition);
     295}
     296
     297Value * KernelBuilder::getRawOutputPointer(const std::string & name, Value * streamIndex, Value * absolutePosition) const {
     298    return getOutputStreamSetBuffer(name)->getRawItemPointer(getStreamSetBufferPtr(name), streamIndex, absolutePosition);
    303299}
    304300
     
    306302    const auto f = mStreamSetNameMap.find(name);
    307303    if (LLVM_UNLIKELY(f == mStreamSetNameMap.end())) {
    308         report_fatal_error("Kernel " + getName() + " does not contain stream set: " + name);
     304        throw std::runtime_error("Kernel " + getName() + " does not contain stream set: " + name);
    309305    }
    310306    return f->second;
    311 }
    312 
    313 const StreamSetBuffer * KernelBuilder::getStreamSetBuffer(const std::string & name) const {
    314     const unsigned structIdx = getStreamSetIndex(name);
    315     if (structIdx < mStreamSetInputs.size()) {
    316         return mStreamSetInputBuffers[structIdx];
    317     } else {
    318         return mStreamSetOutputBuffers[structIdx - mStreamSetInputs.size()];
    319     }
    320307}
    321308
     
    341328}
    342329
    343 Value * KernelBuilder::getStreamSetPtr(const std::string & name, Value * blockNo) const {
    344     return getStreamSetBuffer(name)->getStreamSetPtr(getStreamSetBufferPtr(name), blockNo);
     330Value * KernelBuilder::getInputStreamSetPtr(const std::string & name, Value * blockNo) const {
     331    return getInputStreamSetBuffer(name)->getStreamSetPtr(getStreamSetBufferPtr(name), blockNo);
    345332}
    346333
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5307 r5310  
    183183    llvm::Value * getOutputStream(const std::string & name, llvm::Value * streamIndex, llvm::Value * packIndex) const;
    184184
    185     llvm::Value * getRawItemPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
     185    llvm::Value * getRawInputPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
     186
     187    llvm::Value * getRawOutputPointer(const std::string & name, llvm::Value * streamIndex, llvm::Value * absolutePosition) const;
    186188
    187189    llvm::Value * getScalarFieldPtr(const std::string & name) const {
     
    193195    }
    194196
    195     llvm::Value * getStreamSetPtr(const std::string & name, llvm::Value * blockNo) const;
     197    llvm::Value * getInputStreamSetPtr(const std::string & name, llvm::Value * blockNo) const;
    196198
    197199    inline llvm::Value * getProcessedItemCount(const std::string & name) const {
     
    241243    unsigned getStreamSetIndex(const std::string & name) const;
    242244
    243     const parabix::StreamSetBuffer * getStreamSetBuffer(const std::string & name) const;
     245    const parabix::StreamSetBuffer * getInputStreamSetBuffer(const std::string & name) const {
     246        return mStreamSetInputBuffers[getStreamSetIndex(name)];
     247    }
     248
     249    const parabix::StreamSetBuffer * getOutputStreamSetBuffer(const std::string & name) const {
     250        return mStreamSetOutputBuffers[getStreamSetIndex(name)];
     251    }
    244252
    245253    void callGenerateInitMethod();
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.cpp

    r5307 r5310  
    182182    Value * i16UnitsFinal = iBuilder->CreateAdd(i16UnitsGenerated, iBuilder->CreateZExt(offset, iBuilder->getSizeTy()));
    183183    setProducedItemCount("i16Stream", i16UnitsFinal);
    184     const auto b  = getStreamSetBuffer("i16Stream");
     184    const auto b  = getOutputStreamSetBuffer("i16Stream");
    185185
    186186    if (auto cb = dyn_cast<CircularCopybackBuffer>(b)) {
  • icGREP/icgrep-devel/icgrep/kernels/stdout_kernel.cpp

    r5307 r5310  
    2626    Value * itemsToDo = iBuilder->CreateSub(producerPos[0], processed);
    2727    // There may be two memory areas if we are at the physical end of a circular buffer.
    28     const auto b  = getStreamSetBuffer("codeUnitBuffer");
     28    const auto b  = getInputStreamSetBuffer("codeUnitBuffer");
    2929    Value * wraparound = nullptr;
    3030    if (isa<CircularBuffer>(b) || isa<CircularCopybackBuffer>(b)) {
     
    9696    Value * itemsToDo = iBuilder->CreateSub(producerPos[0], processed);
    9797    // There may be two memory areas if we are at the physical end of a circular buffer.
    98     auto const &b  = getStreamSetBuffer("codeUnitBuffer");
     98    const auto b  = getInputStreamSetBuffer("codeUnitBuffer");
    9999    Value * wraparound = nullptr;
    100100    if (isa<CircularBuffer>(b) || isa<CircularCopybackBuffer>(b)) {
Note: See TracChangeset for help on using the changeset viewer.