NVIDIA / NVIDIA/cuda-python

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

Aperta
#1,719 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

cuda.bindings enhancement example P1
Lingua principale
Cython
Stelle
3.4k
Fork
329
Merge medio
1g 23h
PR unite (30g)
116

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia esaminando gli oggetti cuda.core indicati nella richiesta: Graph, GraphBuilder e Stream, insieme agli esempi di pulizia di #1711. Identifica quali oggetti richiedono la chiusura esplicita o la revoca delle risorse, quindi aggiorna gli esempi, la documentazione e i test pertinenti affinché utilizzino i gestori di contesto e verifichino la pulizia.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
hpc
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.