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

Transparent Huge Pages Support #2149

Open
michaeleisel opened this issue May 1, 2024 · 2 comments
Open

Transparent Huge Pages Support #2149

michaeleisel opened this issue May 1, 2024 · 2 comments

Comments

@michaeleisel
Copy link

When working with CPU tensors on Linux, transparent huge pages (THP) can provide a big speedup. For example, I see a 15% increase in speed for my code when I turn it on. However, for many operating systems such as Ubuntu, the default behavior for THP is "madvise", which means that madvise must be called with the proper flags on each memory segment that we want THP for. In NumPy, they turn on THP with madvise for any arrays that are 4 MB or larger, when they're on Linux 4.6+ (initial commit: numpy/numpy@7180479). It would be great to have similar behavior for candle. I'm not exactly sure how this would be implemented, as CpuStorage takes a Vec that may have already been paged in, but maybe calling madvise somehow for all usages of CpuStorage in cpu_backend.rs would cover the broad strokes.

@LaurentMazare
Copy link
Collaborator

Interesting, could you maybe provide a way to replicate your 15% speedups? I'm pretty curious about which parts get actually accelerated by THP, if it's more loading the tensors vs the actual ops and if it's in the ops which ones benefit the most of it.

@michaeleisel
Copy link
Author

michaeleisel commented May 1, 2024

Here are some operations and their speeds without THP (left) and with THP (right):
Tensor::ones((5000, 5000), ...): 22 vs. 63 iters/sec
a + a, where a is a 5,000x5,000 tensor: 19 vs. 42 iters/sec
a.matmul(a), where a is a 5,000x5,000 tensor: 1.65 vs. 1.73 iters/sec

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants