“Unable to read memory” on 262144 element after successful cudaMallocManaged

I’m getting:

Unhandled exception at 0x00007FF6FB22EFFB in MN2.exe: 0xC0000006: In page error writing location 0x0000000208300000 (status code 0xC0000022).

when iterating over 262144 (exactly the same every time) element of an array allocated with cudaMallocManaged (which returned 0)

I thought it may have something to do with heap/stack allocation limits in VC++ compiler but the problem didn’t get resolved after setting “Heap Reserve Size” and “Stack Reserve Size” to 10000000 both.

int main()
    float *mat;
    cudaMallocManaged(&mat, 1000 * 1000);
    for (int i = 0; i < 1000 * 1000; i++)
        mat[i] = 0.0f;
    return 0;

I’m using VC++ and CUDA 10.1 on windows 10.

What is the reason of this error and how can I resolve it? Declaring arrays with more dimensions isn’t an acceptable solution here.

Try this:

cudaMallocManaged(&mat, sizeof(*mat) * 1000 * 1000);

Thank you, I have just noticed how dumb I am.