xcompact3d / x3d2

https://xcompact3d.github.io/x3d2
BSD 3-Clause "New" or "Revised" License
3 stars 4 forks source link

Potential misuse of `host_allocator` #97

Open semi-h opened 3 months ago

semi-h commented 3 months ago

89 introduced a host_allocator concept. It is a way to make sure that we can get a field that lives in host memory when we need. Currently, its used for setting the initial conditions, but I anticipate it'll soon be used for other purposes too.

The open matter on this is that one can accidentally mix and use get_block and release_block from backend%allocator and solver%host_allocator. In OpenMP backend this won't cause any immediate issues, because both allocators point to the same object, but this isn't the case in CUDA backend.

So lets discuss the best strategy to prevent such misuses if we can.

One thing I tried was having field pointers a type type(field_t) instead of class(field_t) so that a get_field from CUDA allocator will raise an error, it was okay with nvfortran but the gcc compiler didn't like this.

One thing I have in mind is implementing a get_host_field function in allocator, and using this instead with host_allocator. But this can still cause problems when we test things on OpenMP and try to run on CUDA. In the meeting we had a few recommendations but I'm not sure if I understand these, so could you explain here please?