High performance direct gravitational N-body simulations on graphics processing units II: An implementation in CUDA