Use barrier rather than mem fence to wait until block histogram computation is complete.  Mem fence only requires that memory be in consistent state, ie that write through cache has been flushed.  It does not guarantee that all threads have reached the mem fence!