Ignore:
Timestamp:
May 22, 2017, 12:14:19 PM (2 years ago)
Author:
nmedfort
Message:

Restructuring work for the Driver classes. Start of work to eliminate the memory leaks with the ExecutionEngine?. Replaced custom AlignedMalloc? with backend call to std::aligned_malloc. Salvaged some work on DistributionPass? for reevaluation.

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

Legend:

Unmodified
Added
Removed
  • icGREP/icgrep-devel/icgrep/kernels/deletion.h

    r5440 r5464  
    2727    DeletionKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount);
    2828    bool isCachable() const override { return true; }
    29     bool moduleIDisSignature() const override { return true; }
     29    bool hasSignature() const override { return false; }
    3030protected:
    3131    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
     
    4040    DeleteByPEXTkernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned fw, unsigned streamCount, bool shouldSwizzle);
    4141    bool isCachable() const override { return true; }
    42     bool moduleIDisSignature() const override { return true; }
     42    bool hasSignature() const override { return false; }
    4343protected:
    4444    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
     
    5959    SwizzledBitstreamCompressByCount(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned bitStreamCount, unsigned fieldWidth = 64);
    6060    bool isCachable() const override { return true; }
    61     bool moduleIDisSignature() const override { return true; }
     61    bool hasSignature() const override { return false; }
    6262protected:
    6363    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
  • icGREP/icgrep-devel/icgrep/kernels/grep_kernel.cpp

    r5454 r5464  
    1212#include <pablo/builder.hpp>
    1313#include <pablo/pe_count.h>
     14
     15#include <llvm/Support/raw_ostream.h>
    1416
    1517using namespace kernel;
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5460 r5464  
    193193std::string Kernel::makeSignature(const std::unique_ptr<kernel::KernelBuilder> & idb) {
    194194    assert ("KernelBuilder does not have a valid IDISA Builder" && idb.get());
    195     if (LLVM_LIKELY(moduleIDisSignature())) {
    196         return getModule()->getModuleIdentifier();
    197     } else {
     195    if (LLVM_UNLIKELY(hasSignature())) {
    198196        generateKernel(idb);
    199197        std::string signature;
     
    201199        WriteBitcodeToFile(getModule(), OS);
    202200        return signature;
     201    } else {
     202        return getModule()->getModuleIdentifier();
    203203    }
    204204}
  • icGREP/icgrep-devel/icgrep/kernels/kernel.h

    r5456 r5464  
    99#include "interface.h"
    1010#include <boost/container/flat_map.hpp>
    11 #include <IR_Gen/idisa_builder.h>
    12 #include <toolchain/pipeline.h>
    1311#include <llvm/IR/Constants.h>
    1412
    1513namespace llvm { class Function; }
    1614namespace llvm { class IntegerType; }
     15namespace llvm { class IndirectBrInst; }
     16namespace llvm { class PHINode; }
    1717namespace llvm { class LoadInst; }
    1818namespace llvm { class Type; }
     
    6363    // based on the semantics of the kernel. 
    6464    //
    65     // If no other mechanism is available, the default generateKernelSignature() method
    66     // uses the full LLVM IR (before optimization) of the kernel instance.
     65    // If no other mechanism is available, the default makeSignature() method uses the
     66    // full LLVM IR (before optimization) of the kernel instance.
    6767    //
    6868    // A kernel Module ID is short string that is used as a name for a particular kernel
    69     // instance.  Kernel Module IDs are used to look up and retrieve cached kernel instances
    70     // and so should be highly likely to uniquely identify a kernel instance.
     69    // instance.  Kernel Module IDs are used to look up and retrieve cached kernel
     70    // instances and so should be highly likely to uniquely identify a kernel instance.
    7171    //
    7272    // The ideal case is that a kernel Module ID serves as a full kernel signature thus
    73     // guaranteeing uniqueness.  In this case, the moduleIDisUnique() method
    74     // should return true.
     73    // guaranteeing uniqueness.  In this case, hasSignature() should return false.
    7574    //
    7675       
     
    8079
    8180    // Can the module ID itself serve as the unique signature?
    82     virtual bool moduleIDisSignature() const { return false; }
     81    virtual bool hasSignature() const { return true; }
    8382
    8483    // Create a module stub for the kernel, populated only with its Module ID.     
  • icGREP/icgrep-devel/icgrep/kernels/linebreak_kernel.h

    r5436 r5464  
    1616    LineBreakKernelBuilder(const std::unique_ptr<KernelBuilder> & b, unsigned basisBitsCount);
    1717    bool isCachable() const override { return true; }
    18     bool moduleIDisSignature() const override { return true; }
     18    bool hasSignature() const override { return false; }
    1919protected:
    2020    void generatePabloMethod() override;
  • icGREP/icgrep-devel/icgrep/kernels/p2s_kernel.h

    r5440 r5464  
    1616    P2SKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
    1717    bool isCachable() const override { return true; }
    18     bool moduleIDisSignature() const override { return true; }
     18    bool hasSignature() const override { return false; }
    1919private:
    2020    void generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
     
    2525    P2SKernelWithCompressedOutput(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
    2626    bool isCachable() const override { return true; }
    27     bool moduleIDisSignature() const override { return true; }
     27    bool hasSignature() const override { return false; }
    2828private:
    2929    void generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
     
    3434    P2S16Kernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
    3535    bool isCachable() const override { return true; }
    36     bool moduleIDisSignature() const override { return true; }
     36    bool hasSignature() const override { return false; }
    3737private:
    3838    void generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
     
    4343    P2S16KernelWithCompressedOutput(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
    4444    bool isCachable() const override { return true; }
    45     bool moduleIDisSignature() const override { return true; }
     45    bool hasSignature() const override { return false; }
    4646private:
    4747    void generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
  • icGREP/icgrep-devel/icgrep/kernels/radix64.h

    r5440 r5464  
    2323    expand3_4Kernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
    2424    bool isCachable() const override { return true; }
    25     bool moduleIDisSignature() const override { return true; }
     25    bool hasSignature() const override { return false; }
    2626private:
    2727    void generateDoSegmentMethod(const std::unique_ptr<KernelBuilder> &iBuilder) override;
     
    3232    radix64Kernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
    3333    bool isCachable() const override { return true; }
    34     bool moduleIDisSignature() const override { return true; }
     34    bool hasSignature() const override { return false; }
    3535private:
    3636    virtual void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
     
    4343    base64Kernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder);
    4444    bool isCachable() const override { return true; }
    45     bool moduleIDisSignature() const override { return true; }
     45    bool hasSignature() const override { return false; }
    4646private:
    4747    virtual void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
  • icGREP/icgrep-devel/icgrep/kernels/s2p_kernel.h

    r5440 r5464  
    1616    S2PKernel(const std::unique_ptr<kernel::KernelBuilder> & b, bool aligned = true);
    1717    bool isCachable() const override { return true; }
    18     bool moduleIDisSignature() const override { return true; }
     18    bool hasSignature() const override { return false; }
    1919protected:
    2020    void generateDoBlockMethod(const std::unique_ptr<KernelBuilder> & iBuilder) override;
  • icGREP/icgrep-devel/icgrep/kernels/scanmatchgen.h

    r5440 r5464  
    1818    ScanMatchKernel(const std::unique_ptr<kernel::KernelBuilder> & b, const GrepType grepType, const unsigned codeUnitWidth);
    1919    bool isCachable() const override { return true; }
    20     bool moduleIDisSignature() const override { return true; }
     20    bool hasSignature() const override { return false; }
    2121protected:
    2222    void generateDoBlockMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
  • icGREP/icgrep-devel/icgrep/kernels/source_kernel.cpp

    r5454 r5464  
    160160void ReadSourceKernel::generateInitializeMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    161161    ConstantInt * const bufferSize = iBuilder->getSize(64 * getpagesize());
    162     Value * const buffer = iBuilder->CreateAlignedMalloc(bufferSize, iBuilder->getCacheAlignment());
     162    Value * const buffer = iBuilder->CreateCacheAlignedMalloc(bufferSize);
    163163    iBuilder->setScalarField("buffer", buffer);
    164164    iBuilder->setScalarField("capacity", bufferSize);
     
    179179    assert(iBuilder->getKernel() == this);
    180180
    181     // The ReadSourceKernel begins by checking whether it needs to read another page of data
     181    // Check whether we need to read another page of data
    182182    ConstantInt * const segmentSize = iBuilder->getSize(mSegmentBlocks * iBuilder->getBitBlockWidth());
    183183    Value * bufferedSize = iBuilder->getBufferedSize("sourceBuffer");
     
    203203    inputStream = iBuilder->CreatePointerCast(inputStream, codeUnitPtrTy);
    204204    Value * const originalPtr = iBuilder->CreateGEP(inputStream, produced);
     205
    205206    Value * const buffer = iBuilder->CreatePointerCast(iBuilder->getScalarField("buffer"), codeUnitPtrTy);
    206207    Value * const capacity = iBuilder->getScalarField("capacity");
    207     Value * const canAppend = iBuilder->CreateICmpULT(iBuilder->CreateGEP(originalPtr, pageSize), iBuilder->CreateGEP(buffer, capacity));
     208
     209    Value * L = iBuilder->CreateGEP(originalPtr, pageSize);
     210
     211//    iBuilder->CallPrintInt("L", L);
     212
     213    Value * B = iBuilder->CreateGEP(buffer, capacity);
     214
     215//    iBuilder->CallPrintInt("B", B);
     216
     217    Value * const canAppend = iBuilder->CreateICmpULT(L, B);
    208218    iBuilder->CreateLikelyCondBr(canAppend, readData, waitOnConsumers);
    209219
     
    211221    iBuilder->SetInsertPoint(waitOnConsumers);
    212222    iBuilder->CreateConsumerWait();
     223
    213224    // Then determine how much data has been consumed and how much needs to be copied back, noting
    214225    // that our "unproduced" data must be block aligned.
    215     const auto alignment = iBuilder->getBitBlockWidth() / 8;
    216     Constant * const alignmentMask = ConstantExpr::getNeg(iBuilder->getSize(alignment));
     226    const auto blockAlignment = iBuilder->getBitBlockWidth() / 8;
     227    Constant * const alignmentMask = ConstantExpr::getNot(iBuilder->getSize(blockAlignment - 1));
    217228    Value * const consumed = iBuilder->CreateAnd(iBuilder->getConsumedItemCount("sourceBuffer"), alignmentMask);
    218229    Value * const remaining = iBuilder->CreateSub(bufferedSize, consumed);
    219230    Value * const unconsumedPtr = iBuilder->CreateGEP(inputStream, consumed);
    220231    Value * const consumedMajority = iBuilder->CreateICmpULT(iBuilder->CreateGEP(buffer, remaining), unconsumedPtr);
     232
     233//    iBuilder->CallPrintInt("consumedMajority", consumedMajority);
     234
    221235    BasicBlock * const copyBack = iBuilder->CreateBasicBlock("CopyBack");
    222236    BasicBlock * const expandAndCopyBack = iBuilder->CreateBasicBlock("ExpandAndCopyBack");
     
    227241    iBuilder->SetInsertPoint(copyBack);
    228242    // If so, just copy the data ...
    229     iBuilder->CreateMemCpy(buffer, unconsumedPtr, remaining, alignment);
     243    iBuilder->CreateMemCpy(buffer, unconsumedPtr, remaining, blockAlignment);
    230244    iBuilder->CreateBr(calculateLogicalAddress);
    231245    // Otherwise, allocate a buffer with twice the capacity and copy the unconsumed data back into it
    232246    iBuilder->SetInsertPoint(expandAndCopyBack);
    233247    Value * const expandedCapacity = iBuilder->CreateShl(capacity, 1);
    234     Value * const expandedBuffer = iBuilder->CreateAlignedMalloc(expandedCapacity, iBuilder->getCacheAlignment());
     248    Value * const expandedBuffer = iBuilder->CreateCacheAlignedMalloc(expandedCapacity);
    235249    Value * const expandedPtr = iBuilder->CreatePointerCast(expandedBuffer, codeUnitPtrTy);
    236     iBuilder->CreateMemCpy(expandedPtr, unconsumedPtr, remaining, alignment);
    237     iBuilder->CreateAlignedFree(buffer);
     250    iBuilder->CreateMemCpy(expandedPtr, unconsumedPtr, remaining, blockAlignment);
     251    iBuilder->CreateFree(buffer);
    238252    iBuilder->setScalarField("buffer", expandedBuffer);
    239253    iBuilder->setScalarField("capacity", expandedCapacity);
     
    285299
    286300void ReadSourceKernel::generateFinalizeMethod(const std::unique_ptr<KernelBuilder> & iBuilder) {
    287     iBuilder->CreateAlignedFree(iBuilder->getScalarField("buffer"));
     301    iBuilder->CreateFree(iBuilder->getScalarField("buffer"));
    288302}
    289303
  • icGREP/icgrep-devel/icgrep/kernels/source_kernel.h

    r5440 r5464  
    1515    MMapSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    1616    bool isCachable() const override { return true; }
    17     bool moduleIDisSignature() const override { return true; }
     17    bool hasSignature() const override { return false; }
    1818protected:
    1919    void linkExternalMethods(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
     
    3131    ReadSourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    3232    bool isCachable() const override { return true; }
    33     bool moduleIDisSignature() const override { return true; }
     33    bool hasSignature() const override { return false; }
    3434protected:
    3535    void generateInitializeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
     
    4444public:
    4545    MemorySourceKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, llvm::Type * type, unsigned blocksPerSegment = 1, unsigned codeUnitWidth = 8);
    46     bool moduleIDisSignature() const override { return true; }
     46    bool hasSignature() const override { return false; }
    4747protected:
    4848    void generateInitializeMethod(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5457 r5464  
    319319    Constant * const bufferWidth = ConstantExpr::getIntegerCast(ConstantExpr::getSizeOf(bufferType), iBuilder->getSizeTy(), false);
    320320    Constant * const size = ConstantExpr::getMul(iBuilder->getSize(mBufferBlocks * mInitialCapacity), bufferWidth);
    321     Value * const ptr = iBuilder->CreateAlignedMalloc(size, iBuilder->getCacheAlignment());
     321    const auto alignment = std::max(iBuilder->getCacheAlignment(), iBuilder->getBitBlockWidth() / 8);
     322    Value * const ptr = iBuilder->CreateAlignedMalloc(size, alignment);
    322323    iBuilder->CreateMemZero(ptr, size, bufferType->getPrimitiveSizeInBits() / 8);
    323324    Value * const streamSetPtr = iBuilder->CreateGEP(mStreamSetBufferPtr, {iBuilder->getInt32(0), iBuilder->getInt32(1)});
     
    385386
    386387        Value * size = iBuilder->CreateMul(newCapacity, iBuilder->getSize(mBufferBlocks));
    387         Value * newStreamSet = iBuilder->CreatePointerCast(iBuilder->CreateAlignedMalloc(iBuilder->CreateMul(size, vectorWidth), iBuilder->getCacheAlignment()), elementType->getPointerTo());
     388        const auto memAlign = std::max(iBuilder->getCacheAlignment(), iBuilder->getBitBlockWidth() / 8);
     389        Value * newStreamSet = iBuilder->CreatePointerCast(iBuilder->CreateAlignedMalloc(iBuilder->CreateMul(size, vectorWidth), memAlign), elementType->getPointerTo());
    388390        Value * const diffCapacity = iBuilder->CreateMul(iBuilder->CreateSub(newCapacity, capacity), vectorWidth);
    389391
     
    401403        }
    402404
    403         iBuilder->CreateAlignedFree(streamSet);
     405        iBuilder->CreateFree(streamSet);
    404406
    405407        iBuilder->CreateRet(newStreamSet);
     
    454456
    455457void ExpandableBuffer::releaseBuffer(IDISA::IDISA_Builder * const iBuilder, Value * self) const {
    456     iBuilder->CreateAlignedFree(getBaseAddress(iBuilder, self));
     458    iBuilder->CreateFree(getBaseAddress(iBuilder, self));
    457459}
    458460
Note: See TracChangeset for help on using the changeset viewer.