Skip to content

Perf: Reduce StridedMemoryView construction time #449

Closed

Description

@leofang

Currently it takes 3.4 - 3.45 us (depending on stream-ordering or not) to create a memory view object:

In [4]: x = cp.empty((23, 4))

In [7]: %timeit s = StridedMemoryView(x, -1)
3.4 μs ± 8.7 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

In [8]: %timeit s = StridedMemoryView(x, 1)
3.45 μs ± 14.6 ns per loop (mean ± std. dev. of 7 runs, 100,000 loops each)

which could be a bit expensive in a tight loop. We should try to reduce it down to 1 us or O(100) ns if possible.

cc @shwina for vis

Activity

  1. added
    cuda.coreEverything related to the cuda.core module
    enhancementAny code-related improvements
    P0High priority - Must do!
    on Feb 14, 2025
  2. leofang commented on Feb 18, 2025

    @leofang
    MemberAuthor

    Among the 3.4 us run time, a rough capture of major components is

    • calling CuPy's __dlpack_device__() and __dlpack__(): 1.23 us
    • constructing Python objects like shape, strides, and dtype: ~1 us

    So it seems to me we are talking about pre-mature optimization here... We could defer the Python object construction but then 50% of the run time is out of cuda.core's control.

  3. added
    P1Medium priority - Should do
    triageNeeds the team's attention
    and removed
    P0High priority - Must do!
    on Feb 18, 2025
  4. added this to the cuda.core parking lot milestone on Jul 15, 2025
  5. leofang commented on Jul 15, 2025

    @leofang
    MemberAuthor

    cc @NaderAlAwar for vis

  6. leofang commented on Jul 25, 2025

    @leofang
    MemberAuthor

    It'd be interesting to see if lazily populating the attributes of StridedMemoryView could help reduce the construction time. A lot of times we don't need the full information, just pointer and shape/strides.

  7. added a commit that references this issue on Aug 21, 2025
    8c685be
  8. added a commit that references this issue on Aug 21, 2025
    a6100d6
  9. moved this from Todo to Done in CCCLon Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

P1Medium priority - Should docuda.coreEverything related to the cuda.core moduleenhancementAny code-related improvementstriageNeeds the team's attention

Type

No type

Projects

  • Status
    Done

Relationships

None yet

Development

No branches or pull requests

Issue actions