CUDA improvements and fixes

- CUDA macros now support freevars
    - Useful for dynamic generating new cuda function by freezing freevars as constants
- Fixes a race condition in the pagelocked staging mechanism