fix for #882.

Refactor the code that initializes the cuda mpm environment.