Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plugin Architecture #152

Open
wookayin opened this issue Apr 10, 2023 · 0 comments
Open

Plugin Architecture #152

wookayin opened this issue Apr 10, 2023 · 0 comments

Comments

@wookayin
Copy link
Owner

wookayin commented Apr 10, 2023

A new major feature: it'd be great to allow more programmatic and flexible customization through plugins.

Example applications

  • This arbitrary information/metadata (e.g. docker container, slurm job, etc.) associated with running processes on GPU
  • Custom formatting (see also Fully configurable output format #51, Config #151)
  • Display additional information that are not necessarily pertaining to "GPU" stats (e.g. show CPU/RAM stats in addition)

(The following are subject to change and be updated)

Design

Similar to pytest's plugin architecture, which is a great example of modular plugin architecture design.

  • Plugins can be third-party modules (pip-installable) outside gpustat core, or a local file (e.g., gpustat_conf.py, ~/.config/gpustat/gpustat_conf.py, similar to pytest's conftest.py)
    • Site-packages plugins are discovered through setuptools entry points: e.g., entry_points={"gpustat": ["gpustat-slurm = gpustat_slurm"]}
    • A side note: Recommend users to have "Framework :: gpustat" in the PyPI classifiers
  • Plugins has priority.
    • Determines the order in which plugins (including core) will be executed in sequence.
    • Core plugins will be 0

Hooks and Plugin APIs

Two major categories are: data-related hooks and format-related hooks. Names are tentative.

Metadata:

  • name: The name of the plugin.
  • priority: The priority (execution order) of the plugin.

Data:

  • add_options: Configure command-line ArgParser.
  • configure: Called only once at the beginning of the program (no matter interactive or not).
  • before_query: Called every time new_query() is used, after nvmlInit. Once in one-shot mode; Multiple times on interactive mode.
  • query_device: Fill in the entry by querying each GPU device.
  • get_process_info: Fill in the process entry by querying by PID. Heavy jobs are not recommended (use on_new_query instead).
  • after_query: Called every time after all query is done (used for cleanup).

Formatting:

  • repr_process: Tweak computing process representation to display
  • repr_gpu: Tweak GPUStat.__repr__ (how it will be displayed)
  • print_header: Prints additional information before GPU lines.
  • print_footer: Prints additional information after GPU lines.

Etc.

Any comments or suggestions will be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant