Ignore:
Timestamp:
Oct 25, 2017, 4:57:58 PM (19 months ago)
Author:
nmedfort
Message:

First stage of MultiBlockKernel? and pipeline restructuring

File:
1 edited

Legend:

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

    r5646 r5706  
    2020using namespace llvm;
    2121
    22 ProcessingRate FixedRatio(unsigned strmItems, unsigned referenceItems, std::string && referenceStreamSet) {
    23     return ProcessingRate(ProcessingRate::ProcessingRateKind::FixedRatio, strmItems, referenceItems, std::move(referenceStreamSet));
    24 }
    25 
    26 ProcessingRate MaxRatio(unsigned strmItems, unsigned referenceItems, std::string && referenceStreamSet) {
    27     return ProcessingRate(ProcessingRate::ProcessingRateKind::MaxRatio, strmItems, referenceItems, std::move(referenceStreamSet));
    28 }
    29 
    30 ProcessingRate RoundUpToMultiple(unsigned itemMultiple, std::string && referenceStreamSet) {
    31     return ProcessingRate(ProcessingRate::ProcessingRateKind::RoundUp, itemMultiple, itemMultiple, std::move(referenceStreamSet));
    32 }
    33 
    34 ProcessingRate Add1(std::string && referenceStreamSet) {
    35     return ProcessingRate(ProcessingRate::ProcessingRateKind::Add1, 0, 1, std::move(referenceStreamSet));
    36 }
    37 
    38 ProcessingRate UnknownRate() {
    39     return ProcessingRate(ProcessingRate::ProcessingRateKind::Unknown, 0, 1, "");
    40 }
    41 
    42 unsigned ProcessingRate::calculateRatio(unsigned referenceItems, bool doFinal) const {
    43     if (mKind == ProcessingRate::ProcessingRateKind::FixedRatio || mKind == ProcessingRate::ProcessingRateKind::MaxRatio) {
    44         if (mRatioNumerator == mRatioDenominator) {
    45             return referenceItems;
    46         }
    47         unsigned strmItems = referenceItems * mRatioNumerator;
    48         return (strmItems + mRatioDenominator - 1) / mRatioDenominator;
    49     }
    50     if (mKind == ProcessingRate::ProcessingRateKind::RoundUp) {
    51         return ((referenceItems + mRatioDenominator - 1) / mRatioDenominator) * mRatioDenominator;
    52     }
    53     if (mKind == ProcessingRate::ProcessingRateKind::Add1) {
    54         return doFinal ? referenceItems + 1 : referenceItems;
    55     }
    56     report_fatal_error("Processing rate calculation attempted for variable or unknown rate.");
    57 }
    58 
    59 Value * ProcessingRate::CreateRatioCalculation(IDISA::IDISA_Builder * const b, Value * referenceItems, Value * doFinal) const {
    60     if (mKind == ProcessingRate::ProcessingRateKind::FixedRatio || mKind == ProcessingRate::ProcessingRateKind::MaxRatio) {
    61         if (mRatioNumerator == mRatioDenominator) {
    62             return referenceItems;
    63         }
    64         Type * const T = referenceItems->getType();
    65         Constant * const numerator = ConstantInt::get(T, mRatioNumerator);
    66         Constant * const denominator = ConstantInt::get(T, mRatioDenominator);
    67         Constant * const denominatorLess1 = ConstantInt::get(T, mRatioDenominator - 1);
    68         Value * strmItems = b->CreateMul(referenceItems, numerator);
    69         return b->CreateUDiv(b->CreateAdd(denominatorLess1, strmItems), denominator);
    70     }
    71     if (mKind == ProcessingRate::ProcessingRateKind::RoundUp) {
    72         Type * const T = referenceItems->getType();
    73         Constant * const denominator = ConstantInt::get(T, mRatioDenominator);
    74         Constant * const denominatorLess1 = ConstantInt::get(T, mRatioDenominator - 1);
    75         return b->CreateMul(b->CreateUDiv(b->CreateAdd(referenceItems, denominatorLess1), denominator), denominator);
    76     }
    77     if (mKind == ProcessingRate::ProcessingRateKind::Add1) {
    78         if (doFinal) {
    79             Type * const T = referenceItems->getType();
    80             referenceItems = b->CreateAdd(referenceItems, b->CreateZExt(doFinal, T));
    81         }
    82         return referenceItems;
    83     }
    84     report_fatal_error("Processing rate calculation attempted for variable or unknown rate.");
    85 }
    86 
    87 unsigned ProcessingRate::calculateMaxReferenceItems(const unsigned outputItems, const bool doFinal) const {
    88     if (mKind == ProcessingRate::ProcessingRateKind::FixedRatio || mKind == ProcessingRate::ProcessingRateKind::MaxRatio) {
    89         if (mRatioNumerator == mRatioDenominator) {
    90             return outputItems;
    91         }
    92         return (outputItems / mRatioNumerator) * mRatioDenominator;
    93     }
    94     if (mKind == ProcessingRate::ProcessingRateKind::RoundUp) {
    95         return (outputItems / mRatioDenominator) * mRatioDenominator;
    96     }
    97     if (mKind == ProcessingRate::ProcessingRateKind::Add1) {
    98         return outputItems - (doFinal ? 1 : 0);
    99     }
    100     report_fatal_error("Inverse processing rate calculation attempted for unknown rate.");
    101 }
    102 
    103 Value * ProcessingRate::CreateMaxReferenceItemsCalculation(IDISA::IDISA_Builder * const b, Value * outputItems, Value * doFinal) const {
    104     if (mKind == ProcessingRate::ProcessingRateKind::FixedRatio || mKind == ProcessingRate::ProcessingRateKind::MaxRatio) {
    105         if (mRatioNumerator == mRatioDenominator) {
    106             return outputItems;
    107         }
    108         Type * const T = outputItems->getType();
    109         Constant * const numerator = ConstantInt::get(T, mRatioNumerator);
    110         Constant * const denominator = ConstantInt::get(T, mRatioDenominator);
    111         return b->CreateMul(b->CreateUDiv(outputItems, numerator), denominator);
    112     }
    113     if (mKind == ProcessingRate::ProcessingRateKind::RoundUp) {
    114         Type * const T = outputItems->getType();
    115         Constant * const denominator = ConstantInt::get(T, mRatioDenominator);
    116         return b->CreateMul(b->CreateUDiv(outputItems, denominator), denominator);
    117     }
    118     if (mKind == ProcessingRate::ProcessingRateKind::Add1) {
    119         Type * const T = outputItems->getType();
    120         if (doFinal) {
    121             return b->CreateSub(outputItems, b->CreateZExt(doFinal, T));
    122         }
    123         return b->CreateSub(outputItems, ConstantInt::get(T, 1));
    124     }
    125     report_fatal_error("Inverse processing rate calculation attempted for unknown rate.");
    126 }
     22namespace kernel {
    12723
    12824void KernelInterface::addKernelDeclarations(const std::unique_ptr<kernel::KernelBuilder> & idb) {
     
    14137    std::vector<Type *> initParameters = {selfType};
    14238    for (auto binding : mScalarInputs) {
    143         initParameters.push_back(binding.type);
     39        initParameters.push_back(binding.getType());
    14440    }
    14541    initParameters.insert(initParameters.end(), mStreamSetOutputs.size(), consumerTy);
     
    15147    auto args = initFunc->arg_begin();
    15248    args->setName("self");
    153     for (auto binding : mScalarInputs) {
    154         (++args)->setName(binding.name);
     49    for (const Binding & binding : mScalarInputs) {
     50        (++args)->setName(binding.getName());
    15551    }
    156     for (auto binding : mStreamSetOutputs) {
    157         (++args)->setName(binding.name + "ConsumerLocks");
     52    for (const Binding & binding : mStreamSetOutputs) {
     53        (++args)->setName(binding.getName() + "ConsumerLocks");
    15854    }
    15955
    16056    // Create the doSegment function prototype.
    16157    std::vector<Type *> params = {selfType, idb->getInt1Ty()};
    162     params.insert(params.end(), mStreamSetInputs.size(), sizeTy);
     58
     59    const auto count = mStreamSetInputs.size();
     60    params.insert(params.end(), count, sizeTy);
    16361
    16462    FunctionType * const doSegmentType = FunctionType::get(voidTy, params, false);
     
    17068    args->setName("self");
    17169    (++args)->setName("doFinal");
     70//    if (mHasPrincipleItemCount) {
     71//        (++args)->setName("principleAvailableItemCount");
     72//    }
    17273    for (const Binding & input : mStreamSetInputs) {
    173         (++args)->setName(input.name + "AvailableItems");
     74        //const ProcessingRate & r = input.getRate();
     75        //if (!r.isDerived()) {
     76            (++args)->setName(input.getName() + "AvailableItems");
     77        //}
    17478    }
    17579
     
    18286        Type * outputType[n];
    18387        for (unsigned i = 0; i < n; ++i) {
    184             outputType[i] = mScalarOutputs[i].type;
     88            outputType[i] = mScalarOutputs[i].getType();
    18589        }
    18690        if (n == 1) {
     
    201105}
    202106
     107void  KernelInterface::setInstance(Value * const instance) {
     108    assert ("kernel instance cannot be null!" && instance);
     109    assert ("kernel instance must point to a valid kernel state type!" && (instance->getType()->getPointerElementType() == mKernelStateType));
     110    mKernelInstance = instance;
     111}
     112
    203113Function * KernelInterface::getInitFunction(Module * const module) const {
    204114    const auto name = getName() + INIT_SUFFIX;
     
    210120}
    211121
    212 Function * KernelInterface::getDoSegmentFunction(llvm::Module * const module) const {
     122Function * KernelInterface::getDoSegmentFunction(Module * const module) const {
    213123    const auto name = getName() + DO_SEGMENT_SUFFIX;
    214124    Function * f = module->getFunction(name);
     
    227137    return f;
    228138}
     139
     140CallInst * KernelInterface::makeDoSegmentCall(kernel::KernelBuilder & idb, const std::vector<llvm::Value *> & args) const {
     141    Function * const doSegment = getDoSegmentFunction(idb.getModule());
     142    assert (doSegment->getArgumentList().size() <= args.size());
     143    return idb.CreateCall(doSegment, args);
     144}
     145
     146void Binding::addAttribute(Attribute attribute) {
     147    for (Attribute & attr : attributes) {
     148        if (attr.getKind() == attribute.getKind()) {
     149            return;
     150        }
     151    }
     152    attributes.emplace_back(attribute);
     153}
     154
     155void KernelInterface::normalizeStreamProcessingRates() {
     156
     157}
     158
     159}
Note: See TracChangeset for help on using the changeset viewer.