Normalizing gpi_embed and GPI_EXTRA libraries
See original GitHub issueThis started with https://github.com/cocotb/cocotb/pull/1293#discussion_r381814190, where I considered getting rid of embed_sim_event
from the embed
interface and adding a register_sim_event_callback
to the GPI.
This got me think about what else we could move from the embed
interface to the GPI via register_*
functions. And the answer is everything (see edit). There really only needs to be an init or entry point function on the embed
interface, from there it can register event and cleanup callbacks with the GPI. Sidebar question: Is there some reason that embed_init_python
is a separate function and not included in embed_sim_init
?
With only an entry point function, the embed
interface can go away entirely, because it is essentially equivalent to what is done for GPI_EXTRA
. gpi_embed
can simply be one such library. The only change to that interface would require we pass argc
and argv
to those extra library calls, which should already be done anyways.
With all of these changes in place, GPI is a standalone product, and GPI_EXTRA
is a mechanism for custom extensions. We could conceivably reuse GPI for other language extensions. There was someone on the gitter a few weeks ago asking for a Java port. This would now be conceivable.
This issue is in place mostly to gather thoughts on the soundness of the idea before I go implement it.
EDIT
There are 4 functions on the embed interface (they can be found in embed.h
):
embed_init_python
: this would be merged into the entry function, currently calledembed_sim_init
.embed_sim_cleanup
: this would no longer be on the interface, but be registered with the GPI using a newregister_sim_cleanup_callback
function.embed_sim_init
: this would be the entry function, the name may change, but this will remain.embed_sim_event
: this would no longer be on the interface, but be registered with the GPI using a newregister_sim_event_callback
function.
Issue Analytics
- State:
- Created 4 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
My plan involves a pretty large refactor of the GPI:
embed_sim_init
call to getters in simulator module. The idea is to makeembed_sim_init
look more likemain
. This also lift responsibility out of C into Python (#1737).GPI_EXTRA
. This will allow multiple runtime-specified GPI users instead of a single hardcoded one. Allowing us to better support extensions (like #1217) and other non-Python GPI bindings.embed_sim_init
,main
like function to call at startup (after all users are loaded and elab has finished)embed_sim_event
embed_sim_end
, called when the simulation finishes.cocotb._sim_event
)Most of this work is already done sitting in a branch that needs to be rebased, cleaned up, tests added, and one bug (related to shutdown behavior) fixed. I’ll bring it in (in small pieces) after I finish Python 2 cleanup/concurrency work.
We’ll also want to change
gpi_logging
behavior to register a log handler (*_v
style). Thengpi_log
will pass log calls to handler and check the return value, falling back togpi_log_native_v
if the handler returns an error. I was working on this before @eric-wieser’sgpi_log
changes, which should make this much easier now.