Here are some patches that I would like reviewed before pushing. In particular, the cuda patch should work elsewhere but I don't have other non-mac gpu machines to test it on. I've kept these patches simple to help show how nice smaller chunks are to review :-)