使用基因加权遗传算法自动选择 GCC 优化选项
我正在做一个项目,用于自动处理 gcc 编译器优化选项,无需程序员指定。我决定使用旅行商算法和遗传算法来根据执行速度选择最佳优化。该应用程序将以问题(C++ 代码)作为输入,对 GCC 编译器中的所有可用优化选项进行排列组合,并存储执行所需的时间。
现在,可以在 Shell 脚本中对此进行编程吗?或者我必须用 C++ 本身进行编程吗?
这是基础论文的链接。 http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=4625477
如果我对整个概念的理解有误,请告诉我。如果你能引导我走上正确的道路并提出任何建议,那将非常有帮助。
谢谢。
I'm doing a project for handling gcc compiler optimization options automatically without programmer specification. I decided to use the Travelling salesman algorithm and GA for selecting the best optimization based on speed of execution. This application would take a problem (C++ code) as input and do permutation combination on all the available optimization options in GCC compiler and store the time taken for execution.
Now, is it possible to program this in a Shell Script? or do i have to program in C++ itself?
Heres a link to the base paper.
http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?arnumber=4625477
Please let me know if I'm wrong about the whole concept. It would be very helpful if u could lead me in the right path and suggest anything.
Thankyou.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
Milepost Ctuning 项目正是针对这一点(Grigori Fursin、Albert Cohen,均来自 INRIA),使用机器学习技术来调整 GCC优化。
您可以使用 GCC MELT 扩展来执行同样的操作。
The Milepost Ctuning project worked exactly on that (Grigori Fursin, Albert Cohen, both at INRIA), using machine learning techniques to tune GCC optimizations.
You could use GCC MELT extensions to do likewise.
我认为这明确地证明了一个古老的建议:海湾合作委员会有太多的选择。
不过,至于回答你的具体问题,我认为你要做的事情最终没有多大价值。主要问题之一是你得到的基因只适用于特定的架构、环境和 gcc 版本。
另外,我很确定在大多数现实生活中熟悉 GCC 的人会比你的算法更好。
我并不是想对你的游行或任何事情下雨,这确实是一项有趣的技术/智力练习。我会编写一个 C/C++ 程序,输出 shell 脚本/命令行,然后运行生成的脚本/命令行,对其进行计时,并存储运行所需的时间以及结果的正确性 。某些优化可能会导致某些代码以不同的方式执行,从而导致不正确的结果。确保您的测试用例正在输出数值数据,以便您可以计算优化后的程序与您期望的结果的接近程度。
您的测试用例永远不会覆盖足够的范围,在这里,您的适应度函数将主要是猜测(因为它将在很大程度上取决于当时机器上运行的其他进程以及它们正在做什么)。进化需要很长时间。
I think this categorically proves the age-old proposal that GCC has far too many options.
As for answering your specific question, though, I think you are going about doing something that, in the end, isn't of very much value. One of the main problems is that your resulting gene will only be good for a specific architecture, environment and gcc version.
Also, I'm pretty sure someone familiar with GCC would be better than your algorithm in most real-life cases.
I don't mean to rain on your parade or anything, it's certainly an interesting technical/intellectual exercise. I'd write a C/C++ program that output a shell script/command line then ran the resultant script/command line, timed it, and stored the time it took to run and the correctness of the result. Some optimisations may cause certain code to execute differently, resulting in an incorrect result. Make sure your test-case is outputting numerical data so you can calculate how close your optimised program got to the result you were expecting.
Your test-cases will never cover enough ground, here, and your fitness function is going to be mostly guesswork (since it'll depend a lot upon what other processes were running on the machine at the time and what they were doing). It will take a long time to evolve.