Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Perf: Reduce StridedMemoryView construction time #449

Open
leofang opened this issue Feb 14, 2025 · 1 comment
Open

Perf: Reduce StridedMemoryView construction time #449

leofang opened this issue Feb 14, 2025 · 1 comment
Labels
cuda.core Everything related to the cuda.core module enhancement Any code-related improvements P1 Medium priority - Should do triage Needs the team's attention

Comments

@leofang
Copy link
Member

leofang commented Feb 14, 2025

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

@leofang leofang added cuda.core Everything related to the cuda.core module enhancement Any code-related improvements P0 High priority - Must do! labels Feb 14, 2025
@leofang
Copy link
Member Author

leofang commented Feb 18, 2025

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.

@leofang leofang added P1 Medium priority - Should do triage Needs the team's attention and removed P0 High priority - Must do! labels Feb 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cuda.core Everything related to the cuda.core module enhancement Any code-related improvements P1 Medium priority - Should do triage Needs the team's attention
Projects
None yet
Development

No branches or pull requests

1 participant