celeritas icon indicating copy to clipboard operation
celeritas copied to clipboard

Improve device initialization for eventual CMSSW use

Open sethrj opened this issue 2 years ago • 3 comments

We've never had a completely satisfactory way of handling device initialization:

  • celeritas::device is a global variable that's allowed to be initialized exactly once
  • The CUDA runtime API device context is stored with threadlocal
  • Disabling the device (basically) has to be done with an environment variable

Important features we want to retain from the current implementation:

  • Manage a "stream" abstraction (so that the state's stream ID can be converted to a CUDA/HIP stream pointer without requiring CUDA API inclusion from host code)
  • Let params objects determine whether to allocate on device or not
  • Save diagnostic data about the device being used

It's really unclear to me how in practice we'd want a single process to share multiple GPUs.

sethrj avatar Nov 28 '23 19:11 sethrj

I think the option to enable/disable device use is also required to cleanly implement https://github.com/drbenmorgan/celer-adept/issues/10. I don't know how tightly coupled this is to the other items here, but perhaps we could split it out into a subitem? At least in terms of the celer-adept use case it probably only needs a parameter in SetupOptions and some way to pass that other than an env var into Device?

drbenmorgan avatar Jul 17 '24 12:07 drbenmorgan

Yeah, we can split it into a separate option. For what it's worth, it is possible to set Celeritas "environment variables" programmatically—celeritas::environment().insert({"CELER_DISABLE_DEVICE", "1"}). But there should be a better way than that to disable the device when integrating externally.

The biggest problem is that lots of the code assumes this setting is set exactly once. If we allow it to change then it could result in an inconsistent state. The best option I can think of is to define a more general Config class (perhaps a wrapper to std::map<std::string, std::any>), pass it into the highest level classes (perhaps sharing it with a global config as a default?) and replace static data with class data.

sethrj avatar Jul 19 '24 13:07 sethrj