Skip to content

[Migrated] Large array variable initialization (let arr = [0; 32 * 1024];) compiles very slowly. #64

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

Open
rust-gpu-bot opened this issue Nov 13, 2024 · 2 comments

Comments

@rust-gpu-bot
Copy link

Issue automatically imported from old repo: EmbarkStudios/rust-gpu#1132
Old labels: t: bug
Originally creatd by pyranota on 2024-02-11T13:28:58Z


EDIT(@eddyb): while there are reasons to avoid such arrays, the slowdown is the immediate Rust-GPU bug - I've left unchanged the original text, but used strikethrough for parts that don't apply, IMO.


User should not be able to create large sized arrays in rust-gpu shaders.
Stack is limited, and large sized data-structures should be moved in buffers.
Plus it makes compilation incredibly slow (I assume this syntax [0; SIZE] translates to spirv's [0, 0, 0, 0, 0, ... SIZE])

Expected Behaviour

spirv-builder should throw an error, when user creates large array in stack

Example & Steps To Reproduce

  1. Setup basic rust-gpu shader
  2. let arr = [0; 32 * 1024];
  3. cargo build

System Info

  • Rust: rustc 1.75.0 (82e1608df 2023-12-21)
  • OS: Pop!_OS
  • GPU: nvidia 1060
  • SPIR-V: SPIRV-Tools v2022.2-dev unknown hash, 2022-02-16T16:37:15
@rust-gpu-bot
Copy link
Author

Comment from eddyb (CONTRIBUTOR) on 2024-02-20T12:14:25Z


I suspect let mut array = [0; 32 * 1024]; is worse than something like:

let mut array = MaybeUninit::<[_; 32 * 1024]>::zeroed().assume_init();
// or `core::mem::zeroed`?

I think we have an optimization for e.g. memset(0), but not [expr; N].
(haven't checked the code though, but it could be as simple as using the better approach in more places)

@rust-gpu-bot
Copy link
Author

Comment from pyranota on 2024-02-20T12:57:44Z


Thank you for correction, @eddyb

LegNeato pushed a commit to LegNeato/rust-gpu that referenced this issue Mar 26, 2025
* Update cust to 2021 edition

* Add support for malloc pitch and 2d copy between host and device in cust
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

1 participant