Ignore:
Timestamp:
Aug 28, 2017, 4:00:17 PM (21 months ago)
Author:
nmedfort
Message:

Bug fixes for multigrep mode. Optional PabloKernel? branch hit counter added. Minor optimizations.

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

Legend:

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

    r5564 r5620  
    1717#include <re/re_name.h>
    1818#include <llvm/Support/raw_ostream.h>
     19#include <boost/uuid/sha1.hpp>
    1920
    2021using NameMap = UCD::UCDCompiler::NameMap;
     
    2728using namespace UCD;
    2829
    29 CharClassesKernel::CharClassesKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, std::vector<UCD::UnicodeSet> multiplexedCCs)
    30 : PabloKernel(iBuilder,
    31               "cc",
     30inline static std::string sha1sum(const std::string & str) {
     31    char buffer[41];    // 40 hex-digits and the terminating null
     32    uint32_t digest[5]; // 160 bits in total
     33    boost::uuids::detail::sha1 sha1;
     34    sha1.process_bytes(str.c_str(), str.size());
     35    sha1.get_digest(digest);
     36    snprintf(buffer, sizeof(buffer), "%.8x%.8x%.8x%.8x%.8x",
     37             digest[0], digest[1], digest[2], digest[3], digest[4]);
     38    return std::string(buffer);
     39}
     40
     41inline std::string signature(const std::vector<UCD::UnicodeSet> & ccs) {
     42    if (LLVM_UNLIKELY(ccs.empty())) {
     43        return "[]";
     44    } else {
     45        std::string tmp;
     46        raw_string_ostream out(tmp);
     47        char joiner = '[';
     48        for (const auto & set : ccs) {
     49            out << joiner;
     50            set.print(out);
     51            joiner = ',';
     52        }
     53        out << ']';
     54        return out.str();
     55    }
     56}
     57
     58CharClassesSignature::CharClassesSignature(const std::vector<UCD::UnicodeSet> & ccs)
     59: mSignature(signature(ccs)) {
     60
     61}
     62
     63
     64CharClassesKernel::CharClassesKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, std::vector<UnicodeSet> && ccs)
     65: CharClassesSignature(ccs)
     66, PabloKernel(iBuilder,
     67              "cc" + sha1sum(mSignature),
    3268              {Binding{iBuilder->getStreamSetTy(8), "basis"}},
    33               {Binding{iBuilder->getStreamSetTy(multiplexedCCs.size(), 1), "charclasses"}})
    34 , mMultiplexedCCs(multiplexedCCs) {
     69              {Binding{iBuilder->getStreamSetTy(ccs.size(), 1), "charclasses"}})
     70, mCCs(std::move(ccs)) {
    3571
     72}
     73
     74std::string CharClassesKernel::makeSignature(const std::unique_ptr<kernel::KernelBuilder> &) {
     75    return mSignature;
    3676}
    3777
     
    3979    CC_Compiler ccc(this, getInput(0));
    4080    auto & pb = ccc.getBuilder();
    41     unsigned n = mMultiplexedCCs.size();
     81    unsigned n = mCCs.size();
    4282
    4383    NameMap nameMap;
    4484    std::vector<Name *> names;
    4585    for (unsigned i = 0; i < n; i++) {
    46         Name * name = re::makeName("cc" + std::to_string(i), makeCC(std::move(mMultiplexedCCs[i])));
     86        Name * name = re::makeName("cc" + std::to_string(i), makeCC(std::move(mCCs[i])));
    4787        nameMap.emplace(name, nullptr);
    4888        names.push_back(name);
     
    5696    }
    5797
    58     // The first UnicodeSet in the vector multiplexedCCs represents the last bit of the character class basis bit streams.
     98    // The first UnicodeSet in the vector ccs represents the last bit of the character class basis bit streams.
    5999    std::reverse(names.begin(), names.end());
    60100    for (unsigned i = 0; i < names.size(); i++) {
     
    68108            }
    69109        } else {
    70           throw std::runtime_error("Can't compile character classes.");
     110            throw std::runtime_error("Can't compile character classes.");
    71111        }
    72112    }
  • icGREP/icgrep-devel/icgrep/kernels/charclasses.h

    r5578 r5620  
    1414namespace kernel {
    1515
    16 class CharClassesKernel : public pablo::PabloKernel {
     16struct CharClassesSignature {
     17    CharClassesSignature(const std::vector<UCD::UnicodeSet> & ccs);
     18protected:
     19    const std::string mSignature;
     20};
     21
     22class CharClassesKernel : public CharClassesSignature, public pablo::PabloKernel {
    1723public:
    18     CharClassesKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, std::vector<UCD::UnicodeSet> multiplexedCCs);
    19     bool hasSignature() const override { return false; }
     24    CharClassesKernel(const std::unique_ptr<kernel::KernelBuilder> & iBuilder, std::vector<UCD::UnicodeSet> && ccs);
     25    bool hasSignature() const override { return true; }
     26    std::string makeSignature(const std::unique_ptr<kernel::KernelBuilder> & iBuilder) override;
     27    bool isCachable() const override { return true; }
    2028protected:
    2129    void generatePabloMethod() override;
    2230protected:
    23     std::vector<UCD::UnicodeSet> mMultiplexedCCs;
     31    std::vector<UCD::UnicodeSet> mCCs;
    2432};
    2533
  • icGREP/icgrep-devel/icgrep/kernels/interface.h

    r5611 r5620  
    9494    }
    9595       
    96     void setName(std::string newName) { mKernelName = newName; }
    97 
    9896    virtual bool isCachable() const = 0;
    9997
     
    173171    llvm::Function * getTerminateFunction(llvm::Module * const module) const;
    174172
    175     KernelInterface(std::string kernelName,
     173    KernelInterface(const std::string && kernelName,
    176174                    std::vector<Binding> && stream_inputs,
    177175                    std::vector<Binding> && stream_outputs,
     
    198196    llvm::StructType *                      mKernelStateType;
    199197    unsigned                                mLookAheadPositions;
    200     std::string                             mKernelName;
     198    const std::string                       mKernelName;
    201199    std::vector<llvm::Value *>              mInitialArguments;
    202200    std::vector<Binding>                    mStreamSetInputs;
  • icGREP/icgrep-devel/icgrep/kernels/kernel.cpp

    r5615 r5620  
    191191    // will be able to add instrumentation to cached modules without recompilation.
    192192    addScalar(idb->getInt64Ty(), CYCLECOUNT_SCALAR);
    193    
    194     mKernelStateType = StructType::create(idb->getContext(), mKernelFields, getName());
    195    
     193    // NOTE: StructType::create always creates a new type even if an identical one exists.
     194    mKernelStateType = getModule()->getTypeByName(getName());
     195    if (LLVM_LIKELY(mKernelStateType == nullptr)) {
     196        mKernelStateType = StructType::create(idb->getContext(), mKernelFields, getName());
     197    }
    196198    processingRateAnalysis();
    197199}
     
    11601162        name += "_EA";
    11611163    }
     1164    name += "_O" + std::to_string((int)codegen::OptLevel);
    11621165    return name;
    11631166}
  • icGREP/icgrep-devel/icgrep/kernels/streamset.cpp

    r5618 r5620  
    811811}
    812812
     813inline StructType * getDynamicBufferStructType(const std::unique_ptr<kernel::KernelBuilder> & b, Type * baseType, const unsigned addrSpace) {
     814    IntegerType * sizeTy = b->getSizeTy();
     815    PointerType * typePtr = baseType->getPointerTo(addrSpace);
     816    return StructType::get(typePtr, typePtr, sizeTy, sizeTy, sizeTy, sizeTy, sizeTy, nullptr);
     817}
     818
    813819DynamicBuffer::DynamicBuffer(const std::unique_ptr<kernel::KernelBuilder> & b, Type * type, size_t initialCapacity, size_t overflow, unsigned swizzle, unsigned addrSpace)
    814820: StreamSetBuffer(BufferKind::DynamicBuffer, type, resolveStreamSetType(b, type), initialCapacity, addrSpace)
    815 , mBufferStructType(StructType::get(resolveStreamSetType(b, type)->getPointerTo(addrSpace), resolveStreamSetType(b, type)->getPointerTo(addrSpace),
    816                                     b->getSizeTy(), b->getSizeTy(), b->getSizeTy(), b->getSizeTy(), b->getSizeTy(), nullptr))
     821, mBufferStructType(getDynamicBufferStructType(b, mType, addrSpace))
    817822, mSwizzleFactor(swizzle)
    818823, mOverflowBlocks(overflow)
Note: See TracChangeset for help on using the changeset viewer.