Changeset 5706 for icGREP/icgrepdevel/icgrep/kernels/interface.cpp
 Timestamp:
 Oct 25, 2017, 4:57:58 PM (19 months ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

icGREP/icgrepdevel/icgrep/kernels/interface.cpp
r5646 r5706 20 20 using namespace llvm; 21 21 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 } 22 namespace kernel { 127 23 128 24 void KernelInterface::addKernelDeclarations(const std::unique_ptr<kernel::KernelBuilder> & idb) { … … 141 37 std::vector<Type *> initParameters = {selfType}; 142 38 for (auto binding : mScalarInputs) { 143 initParameters.push_back(binding. type);39 initParameters.push_back(binding.getType()); 144 40 } 145 41 initParameters.insert(initParameters.end(), mStreamSetOutputs.size(), consumerTy); … … 151 47 auto args = initFunc>arg_begin(); 152 48 args>setName("self"); 153 for ( autobinding : mScalarInputs) {154 (++args)>setName(binding. name);49 for (const Binding & binding : mScalarInputs) { 50 (++args)>setName(binding.getName()); 155 51 } 156 for ( autobinding : mStreamSetOutputs) {157 (++args)>setName(binding. name+ "ConsumerLocks");52 for (const Binding & binding : mStreamSetOutputs) { 53 (++args)>setName(binding.getName() + "ConsumerLocks"); 158 54 } 159 55 160 56 // Create the doSegment function prototype. 161 57 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); 163 61 164 62 FunctionType * const doSegmentType = FunctionType::get(voidTy, params, false); … … 170 68 args>setName("self"); 171 69 (++args)>setName("doFinal"); 70 // if (mHasPrincipleItemCount) { 71 // (++args)>setName("principleAvailableItemCount"); 72 // } 172 73 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 //} 174 78 } 175 79 … … 182 86 Type * outputType[n]; 183 87 for (unsigned i = 0; i < n; ++i) { 184 outputType[i] = mScalarOutputs[i]. type;88 outputType[i] = mScalarOutputs[i].getType(); 185 89 } 186 90 if (n == 1) { … … 201 105 } 202 106 107 void 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 203 113 Function * KernelInterface::getInitFunction(Module * const module) const { 204 114 const auto name = getName() + INIT_SUFFIX; … … 210 120 } 211 121 212 Function * KernelInterface::getDoSegmentFunction( llvm::Module * const module) const {122 Function * KernelInterface::getDoSegmentFunction(Module * const module) const { 213 123 const auto name = getName() + DO_SEGMENT_SUFFIX; 214 124 Function * f = module>getFunction(name); … … 227 137 return f; 228 138 } 139 140 CallInst * 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 146 void 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 155 void KernelInterface::normalizeStreamProcessingRates() { 156 157 } 158 159 }
Note: See TracChangeset
for help on using the changeset viewer.