Gol comments

Marked open questions in the comments with "???"" for easy search.
One additional question: why does the guard appear uniform black instead of being initialized with the neighbor's borders when dumping the buffer to a png after "bufdif->deviceToHost();" (without using the gather function)