Flood Fill algorithm in CUDA

I got a task to do. I need to run a Flood Fill algorithm on CUDA. On CPU I have a non-recursive method with stack, but I dont have any idea how to do move this code to GPU. Can anybody help?

this is my CPU code, it’s simple

void cpuFloodFill(std::vector<std::vector<int>> *colorVector, int node)
	std::queue<int> q;

	int i,j;

		int k = q.front();

		k2ij(k, &i, &j);
		if((*colorVector)[i][j] == COLOR_TARGET)
			(*colorVector)[i][j] = COLOR_REPLACEMENT;			
			if(i - 1 >= 0)
				q.push(ij2k(i - 1, j));

			if(i + 1 < X)
				q.push(ij2k(i + 1, j));

			if(j - 1 >= 0)
				q.push(ij2k(i, j - 1));

			if(j + 1 < Y)
				q.push(ij2k(i, j + 1));

That is essentially a BFS type algorithm, and there has been some work in that area;


You cannot expect someone here to write the CUDA version for you, but those papers will get you on your way.

Google is your friend…

I didn’t expect full code, but a help with a general idea, like using BFS ;) thanks for that, hope it will help