What is the max index of an array? Errors appear at 16,777217 and every 2nd value there after.

Jul 3, 2013 at 1:15 PM
Edited Jul 3, 2013 at 1:16 PM
Ive been experimenting with Cudafy.net, and performing some benchmarks vs the CPU. Unfortunately i start getting errors once my array is larger than 16,777,216 elements. Ive therefore simplified my kernel so its just copying data ie I pass in an array containing time ticks i got from my database. I then copy them to the output array on the GPU, copy the output array back onto the host and then check it against the initial values from the database. This is still causing errors after 16,777,216.

Things i have checked thus far:

Ive changed the data type of the output array from float to long, and errors still begin to occur at 16,777,217 and every second value there after.

Ive modified the kernel so that it only begins populating the array at 16,777,210. I still began encountering errors at 16,777,217.

Im using a EVGA GTX 660 SC. Ive read that overclocked cards are prone to errors, so i reduced the clock speed of the card. I still experienced the same errors.

Ive tried changing the order memory is allocated on the GPU. No change in results.

Ive recorded the free memory available on the device and its still ~ 500MB.

Current thoughts:

From the above, i have a feeling there is a limit to the max index of an array, esp since changing the data type had no effect on the results.

Is this the case? Has anyone else experienced this issue before? Im assuming its not a hard error but im no guru!

Any help would be appreciated!

p.s. here is the link to the question on SO. (if im not suppose to post it, please let me know and i will remove it.)

SO question and code
Jul 3, 2013 at 2:46 PM
Not sure how useful posting about a niche product like CUDAfy on SO is...
What is the simplest code you can write that gives the same error?
        public void Test_LongArray()
            int n = 1024 * 1024 * 32;
            int[] longArray = new int[n];
            Random rand = new Random();
            for (int i = 0; i < n; i++)
                longArray[i] = rand.Next();
            int[] output = new int[n];
            int[] longArray_dev = _gpu.CopyToDevice(longArray);
            _gpu.CopyFromDevice(longArray_dev, output);
            Assert.IsTrue(Compare(longArray, output, 0, 0, n));
Except this does not give an error.
Jul 3, 2013 at 3:05 PM
Firstly thank you confirming its not an issue. Ive spent just shy of 2days trying to nail this down. Its turned out that the issue is that im using float in my kernel for the grid and block dimensions.
        float threadIndex = thread.threadIdx.x;
        float blockIndex = thread.blockIdx.x;
        float threadsPerBlock = thread.blockDim.x;
        int tickPosition = (int)(threadIndex + (blockIndex * threadsPerBlock));
once i change them all to int, the issue is resolved.... what a fool :(

Thanks again :)
Jul 3, 2013 at 3:09 PM
@NickKopp Could you please delete the following? https://cudafy.codeplex.com/workitem/838
Thanks very much.
Jul 3, 2013 at 4:07 PM
This kind of stuff happens. I just ran some tests myself and before I knew it I was suspecting the 2D addressing... Fixed your problem above but had another where I was passing int arrays into kernel expecting floats. Not nice. Luckily spotted that, too, but this escalates quickly and time passes. A bit of fresh air helps but on a rainy day like this that is not always an attractive option.