I recently had an interview with the head of a lab where I was given a task to write a code, answer some questions and send it back. The code was difficult and I know I have failed that part but I could answer the questions well. It has been 2 weeks and I haven't heard back for a 2nd round. I know 99% it is a fail only because I could not code well but should I still ask for a feedback or move on ?
Ask for feedback especially when you feel you have not done well 
It never hurts to ask for a feedback. Generally speaking, you should almost always seek feedback after an interview. It puts you in a good light by showing your eagerness to improve and learn. Remember, not to be boastful if you feel you have done well.
You have nothing to lost. In fact you'll end up learning about your weak area and mistakes by seeking feedback. You can also use this opportunity to show your courteousness and professionalism. Just put it politely:
I appeared for an interview with your organization for so and so position on so and so date. I could really use some feedback on how I performed.
Your feedback will really help me in understanding my weak areas. I wish to improve upon my skills and re-apply if any relevant opportunities comes in the organization in future.
Thanks & Regards
: Courtesy of this fine comment