CUDA not working without X server

Tried to start CUDA programs on Ubuntu without x server. Disabled X with “sudo service lightdm stop”. Then started some CUDA programs and tried cuda-dbg. Every CUDA program caused weird glitches on screen and even stops execution with error on most runs. Attached photo with matrixMul example from CUDA samples.

External Media

Tried on Ubuntu 64-bit 13.04, 12.04 with CUDA Toolkit 5.5, 5 respectively
Nvidia driver 319.23

Tried to use script

if [ "$?" -eq 0 ]; then
# Count the number of NVIDIA controllers found.
N3D=`/sbin/lspci | grep -i NVIDIA | grep "3D controller" | wc -l`
NVGA=`/sbin/lspci | grep -i NVIDIA | grep "VGA compatible controller" | wc -l`

N=`expr $N3D + $NVGA - 1`
for i in `seq 0 $N`; do
mknod -m 660 /dev/nvidia$i c 195 $i
done

mknod -m 660 /dev/nvidiactl c 195 255
else
exit 1
fi

CUDA programs work fine when X server running.

Problem solved. After some experimentation found that glitch was caused by vesafb kernel module. Apparently it is not working with Nvidia display driver. I just disabled it with “vga=normal” added in grub configuration file and now CUDA programs work well without X.