IPB

Welcome Guest ( Log In | Register )

> Simple 2D Array Program Crashing
Odc
post Oct 15 2009, 02:53 PM
Post #1



*

Group: Members
Posts: 9
Joined: 7-June 09
Member No.: 158,307
Org.: Durham University



I've just started to learn CUDA and have created a simple program that creates a 2D array of int, assigns the memory on the device and then copies the array onto the device. Eventually I want to expand this into a graph searching algorithm. However, when using an array with 1,000 verticies (indicies) it simply crashes. As far as I can tell, its populating the array on the host that causes the crash.

Call me a noob but I thought that an array of this size was perfectly acceptable?

Here's my code anyway

CODE
#include <stdio.h>
#include <cuda.h>

__global__ void myKernel(int* deviceArrayPtr, int pitch)
{

}

main()
{
int* deviceArrayPtr;
size_t devicePitch, hostPitch, width, height;
int hostArray[1000][1000];

width = 1000;
height = 1000;
for(int i = 0; i < 1000; i ++)
for(int j = 0; j < 1000; j ++)
hostArray[i][j] = 20; //20 is an abitrary number

//Allocates memory on the device
cudaMallocPitch((void**)&deviceArrayPtr, &devicePitch, width * sizeof(int), height);

hostPitch = devicePitch;

//Copies hostArray onto the pre-allocated device memory
cudaMemcpy2D(deviceArrayPtr, devicePitch, &hostArray, hostPitch, width * sizeof(int), height, cudaMemcpyHostToDevice);

myKernel <<< 100, 512 >>> (deviceArrayPtr, devicePitch);
}



Anyone have any ideas about this?
Go to the top of the page
 
+Quote Post

Posts in this topic
- Odc   Simple 2D Array Program Crashing   Oct 15 2009, 02:53 PM
- - Thibaud   Hi ! I've just got the same problem two ho...   Oct 15 2009, 03:15 PM
- - Odc   QUOTE (Thibaud @ Oct 15 2009, 04:15 PM) H...   Oct 15 2009, 04:03 PM


Reply to this topicStart new topic

 



Copyright 2008 NVIDIA Corporation.  Terms of Use | Legal Info | Privacy Policy Time is now: 9th February 2010 - 11:50 PM
Unites States Argentina Brazil Chile China Colombia France Germany India Italy Japan Korea Mexico Poland Russia Spain Taiwan United Kingdom Venezuela