Access violation

I have a kernel that runs fine with up to some million threads but fails with some billion and I can’t find a reason.
The kernel looks like this:
global void GetPos2D_2(int *pos, const char *dict, char *txt, const int wapL, const int nEx, const int nEy)
{

int t = blockIdx.x * blockDim.x + threadIdx.x; //text
int d = blockIdx.y * blockDim.y + threadIdx.y; //dict

if (t < nEx && w < nEy)
{
bool same = true;
for (size_t i = 0; i < wapL; i++)
{
if (dict[d * wapL + i] != txt[t * wapL + i])
same = false;
}
if (same)
{
pos[t] = d;

	}
	
}

}

It checkes whether each word with exactly 32 chars of a text of about 200 000 words already exists in a dictionary dict and if yes saves its position in pos. With text and dictionary up to some thousand words it works fine. But with larger texts the kernel fails and I get this from Nsight:
CUDA Memory Checker detected 31 threads caused an access violation:
Launch Parameters
CUcontext = 1ce22760
CUstream = 24b7cba8
CUmodule = 2299ec08
CUfunction = 29442290
FunctionName = _Z10GetPos2D_2PiPKcPcijjii
GridId = 46
gridDim = {6571,559,1}
blockDim = {32,32,1}
sharedSize = 256
Parameters:
pos = 0x27a4d600 -1
wap = 0x3fd00000 97 ‘a’
txt = 0x3ff00000 106 ‘j’
wapL = 32
nEx = 210251
nEy = 17882
Parameters (raw):
0x27a4d600 0x3fd00000 0x3ff00000 0x00000020
0x0003354b 0x000045da 0x0003354b 0x000045da
GPU State:
Address Size Type Mem Block Thread blockIdx threadIdx PC Source

00d00274 1 adr ld s 83 609 {83,0,0} {1,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 610 {83,0,0} {2,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 611 {83,0,0} {3,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 612 {83,0,0} {4,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 613 {83,0,0} {5,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 614 {83,0,0} {6,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 615 {83,0,0} {7,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 616 {83,0,0} {8,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 617 {83,0,0} {9,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 618 {83,0,0} {10,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 619 {83,0,0} {11,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 620 {83,0,0} {12,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 621 {83,0,0} {13,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 622 {83,0,0} {14,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 623 {83,0,0} {15,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 624 {83,0,0} {16,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 625 {83,0,0} {17,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 626 {83,0,0} {18,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 627 {83,0,0} {19,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 628 {83,0,0} {20,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 629 {83,0,0} {21,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 630 {83,0,0} {22,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 631 {83,0,0} {23,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 632 {83,0,0} {24,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 633 {83,0,0} {25,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 634 {83,0,0} {26,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 635 {83,0,0} {27,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 636 {83,0,0} {28,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 637 {83,0,0} {29,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 638 {83,0,0} {30,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90
00d00274 1 adr ld s 83 639 {83,0,0} {31,19,0} _Z10GetPos2D_2PiPKcPcijjii+0003f8 c:\users…\gpusolver.cu:90

Summary of access violations:
c:\users…\gpusolver.cu(90): error MemoryChecker: #misaligned=0 #invalidAddress=32

Memory Checker detected 31 access violations.
error = access violation on load (shared memory)
gridid = 46
blockIdx = {83,0,0}
threadIdx = {1,19,0}
address = 0x00d00274
accessSize = 1

Any idea what might cause the failure or how I can find the cause.

how I can find the cause

gpusolver.cu:90

means the invalid address occurred while processing line 90 of that file. now lets parse some other items on the memory checker output:

00d00274 1 adr ld

Referring to nsight doc:

http://docs.nvidia.com/gameworks/content/developertools/desktop/nsight/use_memory_checker.htm

adr ld means the error occurred while doing a ld (read) operation, and the problem was an invalid address. The 1 indicates a memory read of size 1, so a char-type quantity.

Go to line 90 of that file, and find all the instances of where you are doing a char-type load. One of those has an invalid address associated with it. Perhaps line 90 is this one:

if (dict[d * wapL + i] != txt[t * wapL + i])

Now add some conditional test code, for each index, and test each index (before you use it in a read operation) to see if the index is within the expected range (e.g. for the size of your const char *dict, or char *txt arrays). If it is not in the valid range, print out its value and exit the kernel at that point (or just skip the load operation).

Then run your code and inspect the output. Based on your printout, you may see what the problem is. If not, continue to work backward in your code (either with a debugger or with additional code modification and printf statements in the kernel) to identify how the invalid index got created.

You can do something similar using the standalone (outside of Nsight VSE) cuda-memcheck tool:

https://stackoverflow.com/questions/27277365/unspecified-launch-failure-on-memcpy/27278218#27278218

Also, you can do something similar with a debugger:

http://docs.nvidia.com/nsight-visual-studio-edition/3.2/Content/Using_CUDA_Debugger.htm

The debugger will have a learning curve associated with it, and you will probably also want to learn how to use conditional breakpoints to debug this sort of problem.

Yes, that is line 90.
Thank you, txbob…again:-)
I check your links…

If that is line 90, then suppose that the size of dict is size_dict and the size of txt is size_txt. Now modify your kernel to pass those two quantities to the kernel code via kernel paramters:

__global__ void GetPos2D_2(int *pos, const char *dict, char *txt, const int wapL, const int nEx, const int nEy, const size_t size_dict, const size_t size_txt)

Then modify the for-loop that includes line 90 to look like this:

for (size_t i = 0; i < wapL; i++)
{ 
  if (((d*wapL+i) >= size_dict) || (d*wapL+i) < 0) {printf("dict index out of range: %ld\n", (long)(d*wapL+i)); same = false;}
  else if (((t*wapL + i) >= size_txt) || (t*wapL + i) < 0) {printf("txt index out of range: %ld\n", (long)(t*wapL+i)); same = false;}
  else if (dict[d * wapL + i] != txt[t * wapL + i])  same = false;
}

That is the basic idea. If the index is out of range, don’t let the read happen. You may also want to print out other variables like d or t, for example.

Be prepared for potentially a lot of printout. Since you are up to the “some billion” range, be on the lookout for overflow/underflow of int or 32-bit quantities.

Great, I’ll try that.
I launch my kernel with
nEx = sizeTx;
nEy = sizeDict;
so it shoul be right, but still it is not.
I test and return with the results…

After uncountable hours of searching, testing and rewriting code I finally found something. The variable i goes through the roof and suddenly takes values of well anything, like 3489 or 685214698. i should go from 0 to wapL which is 32. How the **** can that happen? And how can I prevent it from happening???

The next 2 lines from printf indicate that the value of t somehow spills over into i
2.) wapL = 32, d 0, t = 3789, i = 0, dict[0 * wapL + 0] = ‘g’ == txt[3789 * wapL + 0] = ‘g’
2.) wapL = 32, d = , t = 0, i = 3792, dict[0 * wapL + 0] = ’ ’ == txt[100 * wapL + 3792] = ’ ’

At one point I get:
d = 690894090, it should be max 559. But the code txbob suggested does not catch that.
if (((dwapL + i) >= nEywapL) || (d*wapL + i) < 0)

And in the following line i first equals 0, then jumps to 539569717 without warning and then goes back to 100:
2.) wapL = 32, d = 28, t = 2446, i = 0, dict[28 * wapL + 539569717] = ’ ’ != txt[1567906675 * wapL + 100] = ‘d’

My block is (32,32) and my grid (6471, 559)
All arrays are allocated with the correct sizes (dict is in fact bigger than used here) and even used and printed out with some initial values without problems.
What is going on? I’m totally at a loss here.

maybe your printf format specifiers are wrong
maybe you have some sort of integer underflow/overflow going on.
Also, your grid is fairly large. On windows, you probably want to make sure you are not running into a WDDM timeout.

The kernel you presented in your first comment in this thread is fairly simple. If you can make a short but complete code around that, which demonstrates the problem (out of bounds access), then someone may be able to help you pretty quickly without a lot of back-and-forth.

Good idea writing some short-code. I will do that…

Hello again!
I wrote a short version. What it does is ever so simple:

  1. Create a Dictionary of unique words.
  2. Creats a Text picked from that dictionnary. For simplicity copying the dictionary some times over.
  3. Then as the main attraction comparing every word from the text with every word from the dict. And if they are indeed identical save the number of the word from the dict as the PosT as where to find a word from the Text in the dict.

I have left the error checking stuff that txbob suggestest as well as all the printing out in there.

The variables wL, nooWinDict and nooWinText are very low now. If thing thing ever works they will be much higher (the goals in the comment). But already these low values do not work.

Nsight returns
CUDA context created : 0377b218
CUDA module loaded: 077e6f40 kernel.cu
CUDA grid launch failed: CUcontext: 58176024 CUmodule: 125726528 Function: _Z6GetPosPiPKcS1_ijj

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>
#include <stdio.h>
using namespace std;
#include <cmath>

__global__ void GetPos(int *pos, const char *dict, const char *txt, const int wL, const unsigned int nooT, const unsigned int nooD)
{
	int t = blockIdx.x * blockDim.x + threadIdx.x; //text
	int d = blockIdx.y * blockDim.y + threadIdx.y; //dict

	if (t < nooT && d < nooD)
	{
		bool same = true;
		for (size_t i = 0; i < wL; i++)
		{
			if (dict[d * wL + i] == txt[t * wL + i])
				printf("1.) wapL = %d, d = %d, t = %d, i = %d, dict[%d * wapL + %d] = '%c' == txt[%d * wapL + %d] = '%c'\n", wL, d, t, i, d, i, dict[d * wL + i], t, i, txt[t * wL + i]);
			else
				printf("2.) wapL = %d,  d = %d, t = %d, i = %d, dict[%d * wapL + %d] = '%c' != txt[%d * wapL + %d] = '%c'\n", wL, d, t, i, d, i, dict[d * wL + i], t, i, txt[t * wL + i]);


			if (((d*wL + i) >= nooD*wL) || (d*wL + i) < 0) {
				printf("dict index out of range: %ld\n", (long)(d*wL + i)); same = false; break;
			}
			else if (((t*wL + i) >= nooT*wL) || (t*wL + i) < 0) {
				printf("txt index out of range: %ld\n", (long)(t*wL + i)); same = false; break;
			}
			else if (dict[d * wL + i] != txt[t * wL + i]) {
				same = false;
				break;
			}
		}
		if (same)
		{
			pos[t] = d;
			printf("\npos[t]: %d d: %d,", pos[t], d);
		}
	}
}

void CreateDict(char * Dict, const char * Alph, const int wL, const int nooWinDict, const int nooLetters)
{
	for (size_t w = 0; w < nooWinDict; w++)
	{
		for (size_t l = 0; l < wL; l++)
		{
			int a = (int)((w*wL + l) /wL / pow(nooLetters, (int)l)) % nooLetters;
			Dict[w*wL + l] = Alph[a];
		}
	}
}

void CreateText(const char * Dict, char * Text, const int nooWinDict, const int nooWinText, const int wL)
{
	for (size_t t = 0; t < nooWinText; t++)
	{
		int d = t % nooWinDict;
		for (size_t l = 0; l < wL; l++)
		{
			Text[t * wL + l] = Dict[(d * wL + l)];
		}
	}
}

int main()
{
    const int nooLetters = 10;     //no of letters in Alphabet
	const int wL = 2;          //goal 32   //no of letters in Word
	const int nooWinDict = 100; // goal 50000 //no of words in Dictionary
	const int nooWinText = 1000; // goal 250000 //no of words in Text
	int sizeDict = wL * nooWinDict; //1D Array of unique words of same length
	int sizeText = wL * nooWinText; //1D Array of Words from Dict

	const char Alph[nooLetters] = { 'a','b','c','d','e','f','g','h','i','j'};
	char * Dict = new char; //Dictionary
	char * Text = new char; //Text
	int * PosT = new int[nooWinText]; //Position of TextWord in Dicionary, like 'a''b''c'... is the 3rd word in the Dict

	//Create a Dictionary
	CreateDict(Dict, Alph, wL, nooWinDict, nooLetters);
	
	cout << "Dict[" << nooWinDict << "]\n";

	for (size_t w = 0; w < nooWinDict; w++)
	{
		for (size_t l = 0; l < wL; l++)
		{
			cout << Dict[w*wL + l];
		}
		cout << "\n";
	}
	//Create a Text
	CreateText(Dict, Text, nooWinDict, nooWinText, wL);

	cout << "Text[" << nooWinText << "]\n";
	for (size_t t = 0; t < nooWinText; t++)
	{
		for (size_t l = 0; l < wL; l++)
		{
			cout << Text[t*wL + l];
		}
		cout << "\n";
	}

	char * dev_Dict = 0;
	char * dev_Text = 0;
	int * dev_PosT = 0;

	cudaMalloc((void**)&dev_Dict, sizeDict * sizeof(char));
	cudaMalloc((void**)&dev_Text, sizeText * sizeof(char));
	cudaMalloc((void**)&dev_PosT, nooWinText * sizeof(int));

	cudaMemcpy(dev_Dict, Dict, sizeDict * sizeof(char), cudaMemcpyHostToDevice);
	cudaMemcpy(dev_Text, Text, sizeText * sizeof(char), cudaMemcpyHostToDevice);

	int nEx = nooWinText;
	int nEy = nooWinDict;
	int Tx, Ty, Tz, Bx, By, Bz;
	if (nEx > 1024 || nEy > 1024 || nEx*nEy > 1024) { Tx = 32;	Ty = 32; Tz = 1; Bx = (nooWinText + Tx - 1) / Tx; By = (nooWinDict + Ty - 1) / Ty; Bz = 1; }
	else { Tx = nooWinText;	Ty = nooWinDict; Tz = 1; }
	dim3 grid(Bx, By, Bz);
	dim3 block(Tx, Ty, Tz);
	GetPos << <grid, block >> > (dev_PosT, dev_Dict, dev_Text, wL, nooWinText, nooWinDict);

	cudaMemcpy(PosT, dev_PosT, sizeText * sizeof(int), cudaMemcpyDeviceToHost);

	cudaFree(dev_Dict);
	cudaFree(dev_Text);
	cudaFree(dev_PosT);

	cout << "PosT[" << nooWinText << "]\n";
	for (size_t t = 0; t < nooWinText; t++)
	{
			cout << PosT[t];
	}
	cout << "\n";

    return 0;
}

I don’t see proper cuda error checking in this code. When I add it, I learn that your last cudaMemcpy operation is asking for an invalid transfer size. You are requesting a transfer size of sizeText * sizeof(int) but you have only allocated nooWinText*sizeof(int) for dev_Post. So that is broken.

Your kernel is printing out so much stuff that it’s impossible to tell what is going on, and I believe for sure you are overflowing the device printf buffer. Try to be more surgical or strategic, rather than printing everything out, for every thread, in every block.

Other than that, if I get rid of the above problems, your code runs without error for me.

You are on windows so I think its likely that you are hitting a WDDM timeout due in large part to all the printout. I suggest raising your timeout limit, or reducing the printout.

The following modification of your code runs without (CUDA runtime) error for me:

$ cat t408.cu
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>
#include <stdio.h>
using namespace std;
#include <cmath>

__global__ void GetPos(int *pos, const char *dict, const char *txt, const int wL, const unsigned int nooT, const unsigned int nooD)
{
        int t = blockIdx.x * blockDim.x + threadIdx.x; //text
        int d = blockIdx.y * blockDim.y + threadIdx.y; //dict

        if (t < nooT && d < nooD)
        {
                bool same = true;
                for (size_t i = 0; i < wL; i++)
                {
#if 0
                        if (dict[d * wL + i] == txt[t * wL + i])
                                printf("1.) wapL = %d, d = %d, t = %d, i = %d, dict[%d * wapL + %d] = '%c' == txt[%d * wapL + %d] = '%c'\n", wL, d, t, i, d, i, dict[d * wL + i], t, i, txt[t * wL + i]);
                        else
                                printf("2.) wapL = %d,  d = %d, t = %d, i = %d, dict[%d * wapL + %d] = '%c' != txt[%d * wapL + %d] = '%c'\n", wL, d, t, i, d, i, dict[d * wL + i], t, i, txt[t * wL + i]);
#endif

                        if (((d*wL + i) >= nooD*wL) || (d*wL + i) < 0) {
                                printf("dict index out of range: %ld\n", (long)(d*wL + i)); same = false; break;
                        }
                        else if (((t*wL + i) >= nooT*wL) || (t*wL + i) < 0) {
                                printf("txt index out of range: %ld\n", (long)(t*wL + i)); same = false; break;
                        }
                        else if (dict[d * wL + i] != txt[t * wL + i]) {
                                same = false;
                                break;
                        }
                }
                if (same)
                {
                        pos[t] = d;
                        //printf("\npos[t]: %d d: %d,", pos[t], d);
                }
        }
}

void CreateDict(char * Dict, const char * Alph, const int wL, const int nooWinDict, const int nooLetters)
{
        for (size_t w = 0; w < nooWinDict; w++)
        {
                for (size_t l = 0; l < wL; l++)
                {
                        int a = (int)((w*wL + l) /wL / pow(nooLetters, (int)l)) % nooLetters;
                        Dict[w*wL + l] = Alph[a];
                }
        }
}

void CreateText(const char * Dict, char * Text, const int nooWinDict, const int nooWinText, const int wL)
{
        for (size_t t = 0; t < nooWinText; t++)
        {
                int d = t % nooWinDict;
                for (size_t l = 0; l < wL; l++)
                {
                        Text[t * wL + l] = Dict[(d * wL + l)];
                }
        }
}

int main()
{
    const int nooLetters = 10;     //no of letters in Alphabet
        const int wL = 2;          //goal 32   //no of letters in Word
        const int nooWinDict = 100; // goal 50000 //no of words in Dictionary
        const int nooWinText = 1000; // goal 250000 //no of words in Text
        int sizeDict = wL * nooWinDict; //1D Array of unique words of same length
        int sizeText = wL * nooWinText; //1D Array of Words from Dict

        const char Alph[nooLetters] = { 'a','b','c','d','e','f','g','h','i','j'};
        char * Dict = new char; //Dictionary
        char * Text = new char; //Text
        int * PosT = new int[nooWinText]; //Position of TextWord in Dicionary, like 'a''b''c'... is the 3rd word in the Dict

        //Create a Dictionary
        CreateDict(Dict, Alph, wL, nooWinDict, nooLetters);

        cout << "Dict[" << nooWinDict << "]\n";

        for (size_t w = 0; w < nooWinDict; w++)
        {
                for (size_t l = 0; l < wL; l++)
                {
                        //cout << Dict[w*wL + l];
                }
//              cout << "\n";
        }
        //Create a Text
        CreateText(Dict, Text, nooWinDict, nooWinText, wL);

        cout << "Text[" << nooWinText << "]\n";
        for (size_t t = 0; t < nooWinText; t++)
        {
                for (size_t l = 0; l < wL; l++)
                {
                        //cout << Text[t*wL + l];
                }
//              cout << "\n";
        }

        char * dev_Dict = 0;
        char * dev_Text = 0;
        int * dev_PosT = 0;
        cudaError_t err;
        err = cudaMalloc((void**)&dev_Dict, sizeDict * sizeof(char));
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err)  << endl;
        err = cudaMalloc((void**)&dev_Text, sizeText * sizeof(char));
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err)  << endl;
        err = cudaMalloc((void**)&dev_PosT, nooWinText * sizeof(int));
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err)  << endl;

        err = cudaMemcpy(dev_Dict, Dict, sizeDict * sizeof(char), cudaMemcpyHostToDevice);
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err)  << endl;
        err = cudaMemcpy(dev_Text, Text, sizeText * sizeof(char), cudaMemcpyHostToDevice);
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err)  << endl;

        int nEx = nooWinText;
        int nEy = nooWinDict;
        int Tx, Ty, Tz, Bx, By, Bz;
        if (nEx > 1024 || nEy > 1024 || nEx*nEy > 1024) { Tx = 32;      Ty = 32; Tz = 1; Bx = (nooWinText + Tx - 1) / Tx; By = (nooWinDict + Ty - 1) / Ty; Bz = 1; }
        else { Tx = nooWinText; Ty = nooWinDict; Tz = 1; }
        dim3 grid(Bx, By, Bz);
        dim3 block(Tx, Ty, Tz);
        cout << "grid: " << grid.x << "," << grid.y << "," << grid.z << " block: " << block.x << "," << block.y << "," << block.z << endl;
        GetPos << <grid, block >> > (dev_PosT, dev_Dict, dev_Text, wL, nooWinText, nooWinDict);
        cudaDeviceSynchronize();
        err = cudaGetLastError();
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err)  << endl;
        if (sizeText > nooWinText) cout << "oops!!" << endl;
        else err = cudaMemcpy(PosT, dev_PosT, sizeText * sizeof(int), cudaMemcpyDeviceToHost);
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err)  << endl;

        cudaFree(dev_Dict);
        cudaFree(dev_Text);
        cudaFree(dev_PosT);

        cout << "PosT[" << nooWinText << "]\n";
        for (size_t t = 0; t < nooWinText; t++)
        {
                        //cout << PosT[t];
        }
        cout << "\n";

    return 0;
}
$ nvcc -arch=sm_61 -o t408 t408.cu
t408.cu(25): warning: pointless comparison of unsigned integer with zero

t408.cu(28): warning: pointless comparison of unsigned integer with zero

t408.cu(25): warning: pointless comparison of unsigned integer with zero

t408.cu(28): warning: pointless comparison of unsigned integer with zero

$ cuda-memcheck ./t408
========= CUDA-MEMCHECK
Dict[100]
Text[1000]
grid: 32,4,1 block: 32,32,1
oops!!
PosT[1000]

========= ERROR SUMMARY: 0 errors
$

Fantastic! A few more modifications and now it works up to
nooWinDict = 10000; nooWinText = 250000;
Then WDDM kicks in an ruins it all. THAT must have been the problem all along!
Thanks a lot txbob! Again! And again! And again!

I was a little to fast there. I managed to set TdrDelay to 20 sec, but still, while
nooWinDict = 10000; nooWinText = 250000; works fine
nooWinDict = 15000; nooWinText = 250000; does not.

Do I hit som other limit I do not know of.

Here is the modified code:

#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>
#include <stdio.h>
using namespace std;
#include <cmath>

__global__ void GetPos(int *pos, const char *dict, const char *txt, const int wL, const unsigned int nooT, const unsigned int nooD)
{
	int t = blockIdx.x * blockDim.x + threadIdx.x; //text
	int d = blockIdx.y * blockDim.y + threadIdx.y; //dict

	if (t < nooT && d < nooD)
	{
		bool same = true;
		for (size_t i = 0; i < wL; i++)
		{

			if (((d*wL + i) >= nooD*wL) || (d*wL + i) < 0) {
				printf("dict index out of range: %ld\n", (long)(d*wL + i)); same = false; break;
			}
			else if (((t*wL + i) >= nooT*wL) || (t*wL + i) < 0) {
				printf("txt index out of range: %ld\n", (long)(t*wL + i)); same = false; break;
			}
			else if (dict[d * wL + i] != txt[t * wL + i]) {
				same = false;
				break;
			}
		}
		if (same)
		{
			pos[t] = d;
			//printf("\npos[%d]: %d d: %d,",t, pos[t], d);
		}
	}
}

void CreateDict(char * Dict, const char * Alph, const int wL, const int nooWinDict, const int nooLetters)
{
	for (size_t w = 0; w < nooWinDict; w++)
	{
		for (size_t l = 0; l < wL; l++)
		{
			int a = (int)((w*wL + l) / wL / pow(nooLetters, (int)l)) % nooLetters;
			Dict[w*wL + l] = Alph[a];
		}
	}
}

void CreateText(const char * Dict, char * Text, const int nooWinDict, const int nooWinText, const int wL)
{
	for (size_t t = 0; t < nooWinText; t++)
	{
		int d = t % nooWinDict;
		for (size_t l = 0; l < wL; l++)
		{
			Text[t * wL + l] = Dict[(d * wL + l)];
		}
	}
}

int main()
{
	const int nooLetters = 10;     //no of letters in Alphabet
	const int wL = 32;          //goal 32   //no of letters in Word
	const int nooWinDict = 15000; // goal 50000 //no of words in Dictionary
	const int nooWinText = 250000; // goal 250000 //no of words in Text
	int sizeDict = wL * nooWinDict; //1D Array of unique words of same length
	int sizeText = wL * nooWinText; //1D Array of Words from Dict

	const char Alph[nooLetters] = { 'a','b','c','d','e','f','g','h','i','j' };
	char * Dict = new char; //Dictionary
	char * Text = new char; //Text
	int * PosT = new int[nooWinText]; //Position of TextWord in Dicionary, like 'a''b''c'... is the 3rd word in the Dict

									  //Create a Dictionary
	CreateDict(Dict, Alph, wL, nooWinDict, nooLetters);

	cout << "Dict[" << nooWinDict << "]\n";

	/*for (size_t w = 0; w < nooWinDict; w++)
	{
		for (size_t l = 0; l < wL; l++)
		{
			cout << Dict[w*wL + l];
		}
		              cout << "\n";
	}*/
	//Create a Text
	CreateText(Dict, Text, nooWinDict, nooWinText, wL);

	cout << "Text[" << nooWinText << "]\n";
	/*for (size_t t = 0; t < nooWinText; t++)
	{
		for (size_t l = 0; l < wL; l++)
		{
			cout << Text[t*wL + l];
		}
		              cout << "\n";
	}*/

	char * dev_Dict = 0;
	char * dev_Text = 0;
	int * dev_PosT = 0;
	cudaError_t err;
	err = cudaMalloc((void**)&dev_Dict, sizeDict * sizeof(char));
	if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;
	err = cudaMalloc((void**)&dev_Text, sizeText * sizeof(char));
	if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;
	err = cudaMalloc((void**)&dev_PosT, nooWinText * sizeof(int));
	if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;

	err = cudaMemcpy(dev_Dict, Dict, sizeDict * sizeof(char), cudaMemcpyHostToDevice);
	if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;
	err = cudaMemcpy(dev_Text, Text, sizeText * sizeof(char), cudaMemcpyHostToDevice);
	if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;

	int nEx = nooWinText;
	int nEy = nooWinDict;
	int Tx, Ty, Tz, Bx, By, Bz;
	if (nEx > 1024 || nEy > 1024 || nEx*nEy > 1024) { Tx = 32;      Ty = 32; Tz = 1; Bx = (nooWinText + Tx - 1) / Tx; By = (nooWinDict + Ty - 1) / Ty; Bz = 1; }
	else {
		Tx = nooWinText; Ty = nooWinDict; Tz = 1; Bx = 1; By = 1; Bz = 1;
	}
	dim3 grid(Bx, By, Bz);
	dim3 block(Tx, Ty, Tz);
	cout << "grid: " << grid.x << "," << grid.y << "," << grid.z << " block: " << block.x << "," << block.y << "," << block.z << endl;
	GetPos << <grid, block >> > (dev_PosT, dev_Dict, dev_Text, wL, nooWinText, nooWinDict);
	cudaDeviceSynchronize();
	err = cudaGetLastError();
	if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;

	err = cudaMemcpy(PosT, dev_PosT, nooWinText * sizeof(int), cudaMemcpyDeviceToHost);

	if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;

	cudaFree(dev_Dict);
	cudaFree(dev_Text);
	cudaFree(dev_PosT);

	cout << "PosT[" << nooWinText << "]\n";
	for (size_t t = 0; t < 1000; t++)
	{
		cout << PosT[t] << " ";
	}
	cout << "\n";

	return 0;
}

If you set nooWinDict to 10000 then the output from PosT are the numbers from 0 to 999 as they should. At 15000 output is rubbish.

when I run your code as-is from comment 12 above, I get the numbers from 0 to 999.

That is very strange. With 14525 * 250000 the code runs fine. With 14532 it does not. Inbetween it varies.
Have you tried to increase nooWinDict to f.i. 20000? Or even 50000?
I added TdrDelay (value 20) and TdrLevel (value 3) to Dator\HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\GraphicsDrivers. Was that not right?

This configuration gives me this:
Dict[18000]
Text[210000]
grid: 6563,563,1 block: 32,32,1
err: 131 unspecified launch failure
err: 135 unspecified launch failure

What GPU are you running on? Have you set your compilation parameters to build code for the architecture matching your GPU?

I modified your code to allow entry of nooWinDict on the command line, and also removed some pointless checking that the compiler was warning about (this was just get rid of the warnings, it should not matter functionally). When I run that code with a nooWinDict value of 25000, it seems to run as expected. This is on linux, with no watchdog timer. So my guess is that you are continuing to have watchdog timer issues. Anyway its not obvious to me there is anything wrong with your code.

$ cat t409.cu
#include <iostream>
#include <stdio.h>
using namespace std;
#include <cmath>

__global__ void GetPos(int *pos, const char *dict, const char *txt, const int wL, const unsigned int nooT, const unsigned int nooD)
{
        int t = blockIdx.x * blockDim.x + threadIdx.x; //text
        int d = blockIdx.y * blockDim.y + threadIdx.y; //dict

        if (t < nooT && d < nooD)
        {
                bool same = true;
                for (size_t i = 0; i < wL; i++)
                {

                        if (((d*wL + i) >= nooD*wL)) {
                                printf("dict index out of range: %ld\n", (long)(d*wL + i)); same = false; break;
                        }
                        else if (((t*wL + i) >= nooT*wL)) {
                                printf("txt index out of range: %ld\n", (long)(t*wL + i)); same = false; break;
                        }
                        else if (dict[d * wL + i] != txt[t * wL + i]) {
                                same = false;
                                break;
                        }
                }
                if (same)
                {
                        pos[t] = d;
                        //printf("\npos[%d]: %d d: %d,",t, pos[t], d);
                }
        }
}

void CreateDict(char * Dict, const char * Alph, const int wL, const int nooWinDict, const int nooLetters)
{
        for (size_t w = 0; w < nooWinDict; w++)
        {
                for (size_t l = 0; l < wL; l++)
                {
                        int a = (int)((w*wL + l) / wL / pow(nooLetters, (int)l)) % nooLetters;
                        Dict[w*wL + l] = Alph[a];
                }
        }
}

void CreateText(const char * Dict, char * Text, const int nooWinDict, const int nooWinText, const int wL)
{
        for (size_t t = 0; t < nooWinText; t++)
        {
                int d = t % nooWinDict;
                for (size_t l = 0; l < wL; l++)
                {
                        Text[t * wL + l] = Dict[(d * wL + l)];
                }
        }
}

int main(int argc, char *argv[])
{
        const int nooLetters = 10;     //no of letters in Alphabet
        const int wL = 32;          //goal 32   //no of letters in Word
        int nooWinDict = 15000; // goal 50000 //no of words in Dictionary
        if (argc > 1) nooWinDict = atoi(argv[1]);
        const int nooWinText = 250000; // goal 250000 //no of words in Text
        int sizeDict = wL * nooWinDict; //1D Array of unique words of same length
        int sizeText = wL * nooWinText; //1D Array of Words from Dict

        const char Alph[nooLetters] = { 'a','b','c','d','e','f','g','h','i','j' };
        char * Dict = new char; //Dictionary
        char * Text = new char; //Text
        int * PosT = new int[nooWinText]; //Position of TextWord in Dicionary, like 'a''b''c'... is the 3rd word in the Dict

                                                                          //Create a Dictionary
        CreateDict(Dict, Alph, wL, nooWinDict, nooLetters);

        cout << "Dict[" << nooWinDict << "]\n";

        /*for (size_t w = 0; w < nooWinDict; w++)
        {
                for (size_t l = 0; l < wL; l++)
                {
                        cout << Dict[w*wL + l];
                }
                              cout << "\n";
        }*/
        //Create a Text
        CreateText(Dict, Text, nooWinDict, nooWinText, wL);

        cout << "Text[" << nooWinText << "]\n";
        /*for (size_t t = 0; t < nooWinText; t++)
        {
                for (size_t l = 0; l < wL; l++)
                {
                        cout << Text[t*wL + l];
                }
                              cout << "\n";
        }*/

        char * dev_Dict = 0;
        char * dev_Text = 0;
        int * dev_PosT = 0;
        cudaError_t err;
        err = cudaMalloc((void**)&dev_Dict, sizeDict * sizeof(char));
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;
        err = cudaMalloc((void**)&dev_Text, sizeText * sizeof(char));
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;
        err = cudaMalloc((void**)&dev_PosT, nooWinText * sizeof(int));
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;

        err = cudaMemcpy(dev_Dict, Dict, sizeDict * sizeof(char), cudaMemcpyHostToDevice);
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;
        err = cudaMemcpy(dev_Text, Text, sizeText * sizeof(char), cudaMemcpyHostToDevice);
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;

        int nEx = nooWinText;
        int nEy = nooWinDict;
        int Tx, Ty, Tz, Bx, By, Bz;
        if (nEx > 1024 || nEy > 1024 || nEx*nEy > 1024) { Tx = 32;      Ty = 32; Tz = 1; Bx = (nooWinText + Tx - 1) / Tx; By = (nooWinDict + Ty - 1) / Ty; Bz = 1; }
        else {
                Tx = nooWinText; Ty = nooWinDict; Tz = 1; Bx = 1; By = 1; Bz = 1;
        }
        dim3 grid(Bx, By, Bz);
        dim3 block(Tx, Ty, Tz);
        cout << "grid: " << grid.x << "," << grid.y << "," << grid.z << " block: " << block.x << "," << block.y << "," << block.z << endl;
        GetPos << <grid, block >> > (dev_PosT, dev_Dict, dev_Text, wL, nooWinText, nooWinDict);
        cudaDeviceSynchronize();
        err = cudaGetLastError();
        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;

        err = cudaMemcpy(PosT, dev_PosT, nooWinText * sizeof(int), cudaMemcpyDeviceToHost);

        if (err != cudaSuccess) cout << "err: " << __LINE__ << " " << cudaGetErrorString(err) << endl;

        cudaFree(dev_Dict);
        cudaFree(dev_Text);
        cudaFree(dev_PosT);

        cout << "PosT[" << nooWinText << "]\n";
        for (size_t t = 0; t < 1000; t++)
        {
                cout << PosT[t] << " ";
        }
        cout << "\n";

        return 0;
}
$ nvcc -arch=sm_61 -o t409 t409.cu
$ ./t409 25000
Dict[25000]
Text[250000]
grid: 7813,782,1 block: 32,32,1
PosT[250000]
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999
$

I don’t know exactly how long the kernel is running on your machine. If I don’t have the memory checker turned on, it runs pretty quick on my machine. As a test, you might try and turn the memory checker off. That may make the kernel run a lot quicker for you.

I find windows development of long-running kernels under the WDDM watchdog timer regime tedious, so I generally try to avoid that. Even if your WDDM timeout is set to fully disabled, if you have a long running kernel that runs for ~30 sec or more on the GPU that is hosting the display, I find that occasionally windows does not like that, and the machine becomes unresponsive even after the kernel should have ended.

To avoid this, I generally try other approaches such as developing on a non-display GPU, or on linux, or both.

Thanks txbob, you are incredibly kind to put down so much time and effort to solve my problems. Just prior to your posting I realized, that the TDR settings had no effect. I updated my driver and restared my computer and now I can run
even
Dict[100000]
Text[2000000]
without problems. So, it was the watchdog TDR after all! I have a GTX-1080 and thanks to you I start to enjoy CUDA, even at the very basic level I’m on.