NVIDIA / NVIDIA/cuda-python

[FEA]: Add context managers to objects where resource cleanup is required

Offen
#1,719 1 Kommentar 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

cuda.bindings enhancement example P1
Vorherrschende Sprache
Cython
Sterne
3.4k
Forks
329
Ø Merge
1 T. 23 Std.
Gemergte PRs (30 T.)
116

Beschreibung

Is this a duplicate?
Area

cuda.core

Is your feature request related to a problem? Please describe.

#1711 illustrates a number of places where users are required to perform explicit cleanup of objects, by updating the examples to use try/finally and performing cleanup within the finally.

#1586 is related and probably a part of this work, but not as broad as this.

Describe the solution you'd like

We should implement context managers on any objects that need an explicit close or other resource revocation.

This includes at least Graph, GraphBuilder, Stream, possibly others.

Once these context managers are added, we should update any examples/docs/tests to use them.

Describe alternatives you've considered

I have read of resistance to this idea elsewhere based on the performance issues with contextlib.contextmanager, and if we provide them, users will use them over manual resource deallocation and pay the performance penalty everywhere.

However, context managers as a general concept (implemented with __enter__ and __exit__) do not have a major performance problem relative to correctly written code with a try/finally, as far as I know. I'm happy to be corrected on that, if there is in fact a performance problem vs. /correct/ code.

I think supporting context managers would be a major ergonomic improvement over manual tracking of context or even try/finally (which doesn't compose as well as with).

Additional context

No response

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit der Überprüfung der in der Anfrage genannten cuda.core-Objekte: Graph, GraphBuilder und Stream sowie der Bereinigungsbeispiele aus #1711. Ermittle, welche Objekte ein explizites Schließen oder die explizite Freigabe von Ressourcen erfordern, und aktualisiere anschließend die relevanten Beispiele, die Dokumentation und die Tests so, dass sie Kontextmanager verwenden und die Bereinigung überprüfen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
hpc
Issue-Typ
Feature
Schwierigkeit
5/5
Geschätzter Aufwand
Über eine Woche
Aktivitätsstatus
Veraltet
Klarheit
Muss geklärt werden
Anfängerfreundlichkeit
25/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.