2013-10-08 37 views
0

我在CUDA編程和問題,在大陣修改大陣和錯誤的CUDA

#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; 
} 

修改時ARRAYSIZE> 356得到錯誤:

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

和光標去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 
... 

請幫我

RAM = 8GB

GPU = NVIDIA的GeForce GT 540M/1GB DDR3

視窗7的64位;

Visual Studio 2010;

+0

我根本沒有看到任何* CUDA代碼。這個問題與CUDA有什麼關係。 – talonmies

回答

1

問題幾乎可以肯定的是,您正在堆棧上分配大型變量(數組)。當您這樣分配時:

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

您正在創建一個存儲在堆棧上的變量。堆棧的大小有限制。 相反,你應該從分配使用malloc系統堆的:

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

而且你將有更好的結果。正如@talonmies指出的那樣,這與CUDA無關,而且niether會執行您的代碼。所以我刪除了CUDA標籤。