-1

I am programming in CUDA and problem in large array

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

#define arraySize 356


int main()
{
srand((unsigned)time( NULL ));
char a[arraySize];
char b[arraySize];
char sigma[5] = "1234";

int i = 0;
int j = 0;
for(i=0; i<arraySize; i++)
{
    a[i] = sigma[rand() % 4];
    b[i] = sigma[rand() % 4];
}

for(i=0 ;i<arraySize; i++)
{
    printf("%c",a[i]);
}

printf("\n");

for(i=0 ;i<arraySize; i++)
{
    printf("%c",b[i]);
}

    int c[(arraySize)*(arraySize)];
    int c1[(arraySize)*(arraySize)];

getch();
    return 0;
}

when modify arraySize>356 get error:

Unhandled exception at 0x5499cb17 (msvcr100d.dll) in cuda2.exe: 0xC00000FD: Stack overflow.

and cursor go to chkstk.asm

...
        cs10:
            cmp     ecx, eax                ; Is new TOS
            jb      short cs20              ; in probed page?
            mov     eax, ecx                ; yes.
            pop     ecx
            xchg    esp, eax                ; update esp
            mov     eax, dword ptr [eax]    ; get return address
            mov     dword ptr [esp], eax    ; and put it at new TOS
            ret

    ; Find next lower page and probe
    cs20:
            sub     eax, _PAGESIZE_         ; decrease by PAGESIZE
            *test    dword ptr [eax],eax     ; probe page.*
            jmp     short cs10

    _chkstk endp

            end
...

please help me

RAM = 8GB

GPU = NVIDIA Geforce GT 540M/1GB DDR3

Windows 7 64bit;

Visual Studio 2010;

4

1 回答 1

1

问题几乎可以肯定是您在堆栈上分配了大变量(数组)。当你这样分配时:

int c[(arraySize)*(arraySize)];

您正在创建一个存储在堆栈上的变量。堆栈对其大小有限制。相反,您应该使用以下方法从系统堆中分配malloc

int *c;
c = (int *)malloc(arraySize*arraySize*sizeof(int));

你会有更好的结果。正如@talonmies 指出的那样,这与CUDA 无关,您的代码也没有。所以我要删除 CUDA 标签。

于 2013-10-08T19:16:18.660 回答