High performance digitally programmable CNN chip with discrete templates