NVIDIA / NVIDIA/cuda-python

Discussion: Should functions in lowpp layer be `def` rather than `cpdef`?

Open
#2,766 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Functions in the lowpp layer are currently declared with cpdef, so they are exposed to both Cython and Python. However, we have always claimed that the Cython interface is not stable, and shouldn't be relied on.

A couple discoveries today are making me wonder whether we want to keep exposing the lowpp layer to Cython at all:

  • Calling a cpdef function from Python has an additional 50ns of overhead vs. a def function (the Python layer delegates to an underlying layer and there is additional work done at that boundary).
  • cpdef functions can not have their return type annotated, which is a blocker for proper .pyi support for the lowpp layer.

Is Cython access at the lowpp layer providing any value here? Could we just s/cpdef/def/g and get more performance and a more Pythonic experience?

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

Start by locating the functions in the lowpp layer and reviewing how they are exposed to Cython and Python. Compare the existing cpdef behavior with the stated .pyi and performance constraints, then check the discussion for a decision. Done means the project has agreed whether Cython exposure should remain; the issue does not identify specific files or tests.

Written by the indexing model from the issue text.

Assessment

Domain
backend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.