Hi, I'm looking for APIs that compute instruction costs, and noticed several of them. 1. A series of APIs of TargetTransformInfo that compute the cost of instructions of a particular type (e.g. getArithmeticInstrCost and getShuffleCost) 2. TargetTransformInfo::getOperationCost 3. CostModel::getInstructionCost::getInstructionCost in lib/Analysis/CostModel.cpp Only the first one is used extensively in LLVM's code base, but the second and third one seems more recently added and more general, making me think if they are designed to replace the first approach. So, what's the recommended way to compute instruction costs? Thanks, Jingyue -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150114/e22d8e10/attachment.html>
On Wed, Jan 14, 2015 at 3:54 PM, Jingyue Wu <jingyue at google.com> wrote:> I'm looking for APIs that compute instruction costs, and noticed several > of them. > > 1. A series of APIs of TargetTransformInfo that compute the cost of > instructions of a particular type (e.g. getArithmeticInstrCost and > getShuffleCost) > 2. TargetTransformInfo::getOperationCost > 3. CostModel::getInstructionCost::getInstructionCost in > lib/Analysis/CostModel.cpp > > Only the first one is used extensively in LLVM's code base, but the second > and third one seems more recently added and more general, making me think > if they are designed to replace the first approach. > > So, what's the recommended way to compute instruction costs? >It depends on what for... #3 above is a *very* coarse, but target independent heuristic. It's used for basic things that don't need a lot of detail at all. #1 and #2 are both in TTI and useful to target-specific IR transforms such as the vectorizers and the partial unroller. I would expect #2 to be implemented in terms of #1 and generally just a wrapper that provides a generic interface. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150114/946141cf/attachment.html>
----- Original Message -----> From: "Jingyue Wu" <jingyue at google.com> > To: "LLVM Developers Mailing List" <llvmdev at cs.uiuc.edu> > Sent: Wednesday, January 14, 2015 5:54:26 PM > Subject: [LLVMdev] Instruction Cost > > Hi, > > I'm looking for APIs that compute instruction costs, and noticed > several of them....> > So, what's the recommended way to compute instruction costs?It depends on how you intend to use them.> 1. A series of APIs of TargetTransformInfo that compute the cost of > instructions of a particular type (e.g. getArithmeticInstrCost and > getShuffleCost)These are used by the vectorizers, and roughly, return costs in reciprocal throughput (the higher the throughput the lower the cost).> > 2. TargetTransformInfo::getOperationCostThis is used by TTI::getUserCost, and it intended to provide a cost appropriate for balancing size and performance (it is used by the inliner's cost model, etc.).> 3. CostModel::getInstructionCost::getInstructionCost in > lib/Analysis/CostModel.cppThis is a wrapper around the interfaces in class (1) (getArithmeticInstrCost, etc.) and may or may not be useful for any particular use case. This is used primarily to construct regression tests for the cost models.> > > Only the first one is used extensively in LLVM's code base, but the > second and third one seems more recently added and more general, > making me think if they are designed to replace the first approach.Hopefully this makes things clearer ;) -Hal> > > > Thanks, > Jingyue > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-- Hal Finkel Assistant Computational Scientist Leadership Computing Facility Argonne National Laboratory
CostModule::getInstructionCost also consults TTI ( http://llvm.org/docs/doxygen/html/CostModel_8cpp_source.html#l00380). No? Jingyue On Wed, Jan 14, 2015 at 4:05 PM, Chandler Carruth <chandlerc at google.com> wrote:> > On Wed, Jan 14, 2015 at 3:54 PM, Jingyue Wu <jingyue at google.com> wrote: > >> I'm looking for APIs that compute instruction costs, and noticed several >> of them. >> >> 1. A series of APIs of TargetTransformInfo that compute the cost of >> instructions of a particular type (e.g. getArithmeticInstrCost and >> getShuffleCost) >> 2. TargetTransformInfo::getOperationCost >> 3. CostModel::getInstructionCost::getInstructionCost in >> lib/Analysis/CostModel.cpp >> >> Only the first one is used extensively in LLVM's code base, but the >> second and third one seems more recently added and more general, making me >> think if they are designed to replace the first approach. >> >> So, what's the recommended way to compute instruction costs? >> > > It depends on what for... > > #3 above is a *very* coarse, but target independent heuristic. It's used > for basic things that don't need a lot of detail at all. > > #1 and #2 are both in TTI and useful to target-specific IR transforms such > as the vectorizers and the partial unroller. I would expect #2 to be > implemented in terms of #1 and generally just a wrapper that provides a > generic interface. >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150114/d6e9ab2f/attachment.html>
On Wed, Jan 14, 2015 at 5:08 PM, Hal Finkel <hfinkel at anl.gov> wrote:> > 1. A series of APIs of TargetTransformInfo that compute the cost of > > instructions of a particular type (e.g. getArithmeticInstrCost and > > getShuffleCost) > > These are used by the vectorizers, and roughly, return costs in reciprocal > throughput (the higher the throughput the lower the cost). >Do you think we could replace this with data from the CPU scheduling models (if it exists in a particular CPU's model)? One number for all CPUs may not always be adequate: http://llvm.org/bugs/show_bug.cgi?id=21356 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150114/89f620af/attachment.html>
Hi, 3. CostModel::getInstructionCost::getInstructionCost in> lib/Analysis/CostModel.cpp >I've been using the CostModel class in a project, and it has worked quite well. I don't have very high requirements on precision, though. Note that in order to use it, you'll probably have to create a public header file for the class. This thread here has some more details on this: http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-July/thread.html#74836 Cheers, Jonas -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150115/2ac2ec34/attachment.html>
Thanks all for replying! I'll try the CostModel class first. Jingyue On Thu, Jan 15, 2015 at 3:47 AM, Jonas Wagner <jonas.wagner at epfl.ch> wrote:> Hi, > > 3. CostModel::getInstructionCost::getInstructionCost in >> lib/Analysis/CostModel.cpp >> > > I've been using the CostModel class in a project, and it has worked quite > well. I don't have very high requirements on precision, though. > > Note that in order to use it, you'll probably have to create a public > header file for the class. This thread here has some more details on this: > http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-July/thread.html#74836 > > Cheers, > Jonas >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20150120/4148cfa1/attachment.html>