[PERF]: Handle generic sequences more efficiently
Nessuno ha ancora preso questa issue.
- Lingua principale
- Cython
- Stelle
- 3.4k
- Fork
- 329
- Merge medio
- 1g 23h
- PR unite (30g)
- 116
Descrizione
In driver, runtime and nvrtc, most of the sequence arguments are of a type like Optional[tuple[cuuint64_t] | list[cuuint64_t]].
They are then converted to C arrays using code like:
for idx in range(elementStridesLen):
elementStridesStatic[idx] = <cydriver.cuuint32_t>(<cuuint32_t?> elementStrides[idx])._pvt_ptr[0]
elementStrides[idx] here uses the generic PySequence_GetItem, which first must check whether the sequence is a list or tuple before getting the item. This check is performed repeatedly for each item, even though the type of the sequence remains constant. The branch predictor may or may not be able to smooth this out.
Ideally, we would use the PySequence_Fast family of functions. Unfortunately, Cython's wrappers of low-level Python/C API functions involving borrowing are broken -- we would probably need to revert to raw C snippets to make that work.
Alternatively, we could do something like:
if type(seq) is list:
for idx in range(len(seq)):
# use cpython.PyList_GetItemInt...
elif type(seq) is tuple:
for idx in range(len(seq)):
# use cpython.PyTuple_GetItemInt...
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
Inizia individuando i loop generici di conversione delle sequenze nelle aree driver, runtime e nvrtc. Leggi i wrapper Cython relativi all’accesso alle sequenze e le API PySequence_Fast documentate, quindi confronta i possibili percorsi di accesso descritti nell’issue. Il lavoro è completato quando le conversioni interessate utilizzano un approccio efficiente e supportato senza modificarne il comportamento.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- c, python
- Ambito
- performance
- Tipo di issue
- Refactoring
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Tranquilla
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 48/100