-
Notifications
You must be signed in to change notification settings - Fork 1
add compat feature for unsafe get_value_ptr #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Thanks for opening a PR, @JoshCu! I this is actually a bug in This problem is something i've been thinking about and just haven't had time / haven't settled on a solution yet on the rust side of things. My main concern is rust implementations are explicit about opting into exposing some or all variables over How this all works efficiently through the Im open to ideas and semantics that you have in mind! |
|
Perhaps a rust specific BMI adapter is warranted for ngen instead of trying to shoe horn it through the BMI C semantics. |
|
@hellkite500 I guess it boils down to requiring bmi-c modules to expose all output variables over |
|
BMI doesn't prescribe any requirement beyond returning/indicating success/failure. ngen, on the other hand, requires C models to expose pointers for efficiency. If you can't/shouldn't expose pointers, then using the C model semantics in ngen doesn't seem appropriate. Hence a specific adapter to map the pointer interface to the get value can, as is done with the fortran adapter, even though it uses the C compatibility layer. |
|
What i'm hearing is there is nothing stopping Are there any cases where |
|
I would have to double check to be sure, but I wouldn't depend on the answer either way, as it is subject to change. Values pointed to by BMI acquired pointers should generally be considered mutable. The pointer itself would be safe. If all that is needed is an override of get_value_pointer for the adapter it would be pretty trivial to derive the adapter from the existing C adapter and add a constructor hook. Providing an unsafe pointer from the ffi is reasonable too as long as the consequence is acceptable to general rust BMI implementations, which may be hard to speculate on right now. |
Here are the options on the rust side i've come up with so far. It's really just a matter of getting the return type right; either unsafe fn get_value_ptr(&mut self, name: &str) -> BmiResult<*mut T>;or unsafe fn get_value_ptr(&mut self, name: &str) -> BmiResult<*const T>;I am more and more convinced that int get_value_ptr(void* self, const char* name, void** dest_ptr);Aside, the |
another public and possibly wrong pr so others can learn from my mistakes
I updated the rust lstm to use the latest versions published in crates.io and was getting this error
land_surface_water__runoff_depthis one of the output variables set as the main_output_variable in ngen.I got it working again by modifying get_value_ptr but I'm not entirely sure it was the correct thing to do?
should I be overwriting that function in my lstm lib? do I need to change ngen to use get_value()?
I'd prefer to confine changes to the rust lstm code but I wasn't sure if that was possible