NVIDIA / NVIDIA/cuda-python

[PERF] Construction of known `cdef classes` can go through `__new__`

Open
#1,643 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cuda.bindings P2 performance
Dominant language
Cython
Stars
3.4k
Forks
329
Avg merge
1d 23h
Merged PRs (30d)
116

Description

In driver, runtime and nvrtc, when an instance of a cdef class is contructed (usually as a return value), it just uses the obvious Python-level constructor, for example:

cdef CUtensorMap tensorMap = CUtensorMap()

This makes a slow Python-like call (the ironically named PyObject_FastCall).

Instead, following Cythons fast instantiation advice, we can use __new__, which will make a faster C-level call to __cinit__.

cdef CUtensorMap tensorMap = CUtensorMap.__new__(CUtensorMap)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Search the driver, runtime, and nvrtc code for constructions of known cdef classes that use the Python-level constructor. Compare those sites with Cython's fast-instantiation guidance and update the applicable construction paths to use new; done means the relevant constructions consistently take the faster C-level path.

Written by the indexing model from the issue text.

Assessment

Domain
performance
Issue type
Refactor
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.