Writing gem5 configuration scripts with Pycharm

北战南征 提交于 2020-05-15 04:17:07

问题


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.


回答1:


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 at configs/common which gets found because of the above m5.util.addToPath('../../') call, so add configs/ to the PYTHONPATH as shown at: PyCharm and PYTHONPATH

  • import m5 comes from src/python/m5 so add src/python to the PYTHONPATH as above

  • from caches import * comes from the sibling learning_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 to SimObject('AtomicSimpleCPU.py') in src/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



来源:https://stackoverflow.com/questions/51982735/writing-gem5-configuration-scripts-with-pycharm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!