Improve the parallism of min function, fix some mem bugs,
and parameterize the gpu cpu version selection