"ErrorUnknown" on the second debug in the case of using shared memory

Sep 25, 2012 at 11:24 AM

I made a simple example of a case where using shared memory and global memory causes ErrorUnkown exception on the second run. The first run is succesful, and *.cdfy is created. However, if I begin to debug again, the second run causes gpu.Synchronize(); to throw ErrorUnknown -exception.

My question is: Am trying to perform something illegal here? Are you able to reproduce this case?

Source codes are as follows:


        public static void testKernel(GThread thread, int segmentCount, int pixelCount, double[] pointCoordinates, double[] result)
            #region Allocate shared memory

            int[] segmentIndex = thread.AllocateShared<int>("segmentIndex", blocksPerGrid * threadsPerBlock);
            double[,] endCoordinates = thread.AllocateShared<double>("endCoordinates", blocksPerGrid * threadsPerBlock, xyPair);


            #region Local memory variables

            int id = thread.blockDim.x * thread.blockIdx.x + thread.threadIdx.x;
            int X = 0;
            int Y = 1;                        

            #region Perform some operations
            endCoordinates[id, X] = 
                pointCoordinates[ToFlattenedIndex3D(segmentIndex[id], segmentCount, 0, pixelCount, X, 2)];    
            endCoordinates[id, Y] =
                pointCoordinates[ToFlattenedIndex3D(segmentIndex[id], segmentCount, 0, pixelCount, Y, 2)];    

            result[id] =
                endCoordinates[id, X] +
                endCoordinates[id, Y];     

        public static int ToFlattenedIndex2D(int a, int aLength, int b)
            return b * aLength + a;

        public static int ToFlattenedIndex3D(int a, int aLength, int b, int bLength, int c, int cLength)
            return a * bLength * cLength + b * cLength + c;

        public const int threadsPerBlock = 48;
        public const int blocksPerGrid = 2;
        public const int xyPair = 2;


Suggestions and any sort of help are much appreciated.

Best regards,


Sep 27, 2012 at 6:20 AM

Difficult to say with only partial code. Is the result correct for first run?  The error appears on a Synchronize call but that does not tell us where is actually happened. You'll need do write the code without async calls and then step through.  Then simplify the kernel by removing code - this will of course produce incorrect result data, but will show whether the code runs. The fact that is during a second run suggests that possibly you are addressing outside allocated memory - but that is just a wild guess.