Use high quality, fine cornmeal for a smoother texture and ensure you're using enough liquid. Continuously stir the mixture if boiling or lower the heat. If it is still grainy, it may need to cook for longer.