用Pycharm编写gem5配置脚本 [英] Writing gem5 configuration scripts with Pycharm
问题描述
为了使用更方便的IDE开发复杂的gem5 python配置脚本,必须添加gem5 lib 到项目.但是,对于那些不是python和Pycharm专家的人(例如我自己) 有一些困难.
对于那些不熟悉gem5的人来说,这是 简短说明:
gem5是检查硬件体系结构的开源模拟器. 可以从github下载:链接到github . 以下链接中介绍了安装过程.
<gem5_installation_dir>/gem5/configs/learning_gem5/part1
在上述路径中,有一个基本的python脚本文件:simple.py
该文件包含一些导入.
使用Pycharm编辑此文件需要一些依赖项,这些依赖项位于gem5安装目录中.
问题:
1)如何将gem5的那些依赖项添加到Pycharm中?
2)如何用gem5执行命令配置Pycharm?
任何帮助将不胜感激.
我在gem5/configs/learning_gem5/part1/two_level.py
下的gem5 d9cb548d83fa81858599807f54b52e5be35a6b03(2020年5月)上看到的一些指针:
-
from common
:由于上述m5.util.addToPath('../../')
调用而在configs/common
处找到公用,因此将configs/
添加到PYTHONPATH中,如下所示:可以可以在此处找到,但是基本上每个SimObject类都要经过一些繁重的代码自动生成才能使其工作,例如src/cpu/simple/AtomicSimpleCPU.py
由于src/cpu/simple/SConscript
中的SimObject('AtomicSimpleCPU.py')
.截至2017年,PyCharm表示他们还没有适当的本机C/C ++扩展设置的计划:使用IPDB (或无法为其设置IDE),并且如果您只是
grep
东西,则往往会很快猜到发生了什么.尽管对于C ++,我建议您设置Eclipse:如何为以下设备设置Eclipse IDE: gem5开发?In order to develop complex gem5 python configuration scripts with more convenient IDE the gem5 lib has to be added to the project. However, for those who are not experts in python and Pycharm (Such as myself) there are some difficulties.
For those who are unfamiliar with gem5, this is a short explanation:
gem5 is an open source simulator that inspects hardware architecture. It can be downloaded from github: link to github. The installation process is described at the following link.
<gem5_installation_dir>/gem5/configs/learning_gem5/part1
Inside the above path, there is a basic python script file: simple.py This file contains some imports. Editing this file with Pycharm requires some dependencies that are located in the gem5 installation directory. The questions: 1) How to add those dependencies of gem5 into Pycharm?
2) How to config the Pycharm with gem5 execution command?Any help would be appreciated.
解决方案A few pointers from what I see at gem5 d9cb548d83fa81858599807f54b52e5be35a6b03 (May 2020) under
gem5/configs/learning_gem5/part1/two_level.py
:from common
: common is atconfigs/common
which gets found because of the abovem5.util.addToPath('../../')
call, so addconfigs/
to the PYTHONPATH as shown at: PyCharm and PYTHONPATHimport m5
comes fromsrc/python/m5
so addsrc/python
to the PYTHONPATH as abovefrom caches import *
comes from the siblinglearning_gem5/part1/caches.py
, so likely this will be found automatically by PyCharm. Otherwise add that directory to the PYTHONPATH.from m5.objects import *
: this is likely the one you are really interested in as it contains all the interesting objects, but unfortunately PyCharm simply cannot handle it I believe since the SimObjects are added dynamically to that namespace at startup in a very convoluted way via PyBind11 native modules + code generation.A description of how this works in more detail can be found here, but basically every SimObject class goes through some heavy code autogeneration to make this work, say e.g.
src/cpu/simple/AtomicSimpleCPU.py
due toSimObject('AtomicSimpleCPU.py')
insrc/cpu/simple/SConscript
.As of 2017, PyCharm said they did not have plans for a proper native C/C++ extension setup: https://intellij-support.jetbrains.com/hc/en-us/community/posts/206018984-Developing-Python-extension-in-C-using-PyCharm
With that said, I've found that it is not worth to use an IDE for the Python part of gem5. This is because the Python tends to be very simple to understand with IPDB (or impossible to setup an IDE for), and if you just
grep
stuff you tend to quickly guess what is going on. For C++ though I do recommend setting up Eclipse: How to setup Eclipse IDE for gem5 development?Related: Add custom modules to PyCharm Linter
这篇关于用Pycharm编写gem5配置脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!