Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Large Array sizes cause thread to stackoverflow #227

Answered by 9prady9
MEisebitt asked this question in Q&A
Discussion options

While running the following:

use arrayfire::{Array, Dim4, set_device, info};
fn main() {
 set_device(0);
 info();
 let values: [f64; 1_000_000] = [3.5; 1_000_000];
 Array::<f64>::new(&values, Dim4::new(&[1_000_000, 1, 1, 1]));

I get the following error:

thread 'main' has overflowed its stack
error: process didn't exit successfully: `target\release\par.exe` (exit code: 0xc00000fd, STATUS_STACK_OVERFLOW)

If I make the Array smaller (change every occurrence of 1_000_000 to 100_000 for example) it works fine.
This seems weird as Array::new calls for Dim4 for which the documentation says it can take u64:

pub fn new(dims: &[u64; 4]) -> Self
pub const MAX: u64 = u64::max_value(); // 18_446_744_073_709_551_615u64
You must be logged in to vote

Closing this case since the issue isn't related to this crate.

Replies: 13 comments

Comment options

Please run the program with RUST_BACKTRACE=1 you can set this env by export RUST_BACKTRACE=1

It doesn't seem like ArrayFire error, if a GPU runs out of memory, the crate will panic with an error out of memory.

Which OS are you running on ? what is your GPU ?

Dim4 stores u64 values that represent of the length of given dimension(axis). ArrayFire can store array shapes up to 4 dimensions, hence the Dim4. You have to consider the size of array [M N O P] you are creating on the GPU and how much memory your GPU has. Dim4 members being u64, doesn't translate to being capable of having huge array's like [u64_MAX, u64_MAX, 1, 1] - your GPU memory will decide if you can create such Array on GPU.

You must be logged in to vote
0 replies
Comment options

I never worked with the backtrace, how do I use it correctly on Windows ?
(I used set RUST_BACKTRACE=1 in cmd but it seems like the output does not change)

I'm using Windows 10 64bit with a GeForce GTX 1060 6GB (6144MB).

Ok, I understand that even though the function can take u64 everything is limited by my GPU.
But one million doubles should be 8MB which is way below what it should be capable.

You must be logged in to vote
0 replies
Comment options

I never worked with the backtrace, how do I use it correctly on Windows ?
(I used set RUST_BACKTRACE=1 in cmd but it seems like the output does not change)

I'm using Windows 10 64bit with a GeForce GTX 1060 6GB (6144MB).

Ok, I understand that even though the function can take u64 everything is limited by my GPU.
But one million doubles should be 8MB which is way below what it should be capable.

True, but it is very unlikely that causes a stack overflow error. I have tried the same snippet on GTX 1060 3GB card and it works fine.

Did you try just the following and check if it works.

fn main() {
 set_device(0);
 info();
 let values: [f64; 1_000_000] = [3.5; 1_000_000];
}

I am not sure if set does the trick environment variables in windows command prompt. I know how to set them in powershell. $Env:RUST_BACKTRACE=1 and you can check if it is set by doing echo $env:RUST_BACKTRACE

You must be logged in to vote
0 replies
Comment options

Regrading the Powershell:
I did also try it your way but it also doesn't produce a backtrace.

Regarding the overflow:
It seems like you are right and the problem isn't from the Arrayfire or GPU side.
I thought I tested it, but it turns out even

fn main() {
 let values: [f64; 1_000_000] = [3.5; 1_000_000];
}

produces the error. So it seems like the problem originates from rust itself.

You must be logged in to vote
0 replies
Comment options

Closing this case since the issue isn't related to this crate.

You must be logged in to vote
0 replies
Answer selected by 9prady9
Comment options

On a sidenote:

Rust only stackoverflows in the non-release compiled version, but with Arrayfire it overflows in both cases

You must be logged in to vote
0 replies
Comment options

It is most likely to do with something like this rust-lang/rust-clippy#4520 but I am not 100% certain - this is something that came up with quick googling. I doubt it can be related to ArrayFire crate if it is failing even in one configuration without ArrayFire Code.

Having said that, I have tried your code on rust play ground seems to work fine for me there as well.
Here is the perma link
https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=ff4d73801f87aa4d7951d6f0e80ce683

You must be logged in to vote
0 replies
Comment options

What is the rust version you are using ?

You must be logged in to vote
0 replies
Comment options

I figured out what it is:

It is expected that optimizations can affect stack usage. We don't generally give guarantees about this. In particular, Windows' default stack size is only 1 MB, which you are easily exceeding by allocating 1_000_000 doubles.

rust-lang/rust#72922

So sadly the windows stack size does not allow me to allocate more on the GPU. Except passing a Vec might be a solution.

You must be logged in to vote
0 replies
Comment options

I figured out what it is:

It is expected that optimizations can affect stack usage. We don't generally give guarantees about this. In particular, Windows' default stack size is only 1 MB, which you are easily exceeding by allocating 1_000_000 doubles.

rust-lang/rust#72922

So sadly the windows stack size does not allow me to allocate more on the GPU. Except passing a Vec might be a solution.

That doesn't sound right, do you mean it doesn't allow you to allocate more on the host RAM ? GPU doesn't have any such limitations and rust doesn't control that.

You must be logged in to vote
0 replies
Comment options

Well, I would assume it doesn't allow me to allocate more on the part of the RAM that is managed by the stack. But I probably can do more on the heap which would help if I could assign a Vector into Array::new.

You must be logged in to vote
0 replies
Comment options

Array::new takes a slice into a vector. so it should work fine.

You must be logged in to vote
0 replies
Comment options

Perfect, thanks for all the help 👍

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
Converted from issue

This discussion was converted from issue #227 on December 09, 2020 05:15.

AltStyle によって変換されたページ (->オリジナル) /