On 05/05/2026 14:14, Arsen Arsenović wrote:
So far, the GCN plugin has used a kernel_dispatch struct instance it
calls "shadow" to keep effectively a copy of part of the HSA dispatch
packet before populating said packet.  It also allocated it on the heap.

This, at first glance, seems useless: why double up the data in a shadow
when it's already in packet?

But, it serves a purpose.  The packet is owned by the HSA runtime.
After dispatch, its contents are to be considered no longer accessible
by the dispatcher (i.e. run_kernel).  So, we can't read back from it the
addresses or handles of resources we allocated, and so, we can't clean
them up.

However, this allocation doesn't need to happen on the heap.  It's of a
known fixed size, and its lifetime is the same as the lifetime of an
automatic variable.

This patch demotes the heap allocation into an automatic variable, and
adds commentary to make it clear what the purpose of this "shadow" is.
In the end, the result of this patch is that the run_kernel hot path has
one fewer allocation.

I've also taken the opportunity to do some very minor code cleanup.

libgomp/ChangeLog:

        * plugin/plugin-gcn.c (struct kernel_dispatch): Store
        hsa_signal_t, rather than a uint64_t, so that we don't rely on
        knowledge of the contents of hsa_signal_t.
        (create_kernel_dispatch): Rename...
        (prepare_kernel_dispatch): ... to this, as it no longer creates
        a kernel dispatch.  The allocation that would've created it is
        hoisted...
        (run_kernel): ... here, as an automatic variable.  Move logic
        that copies the fields of kernel_dispatch...
        (populate_packet_from_dispatch): ... into this standalone
        function, to make it clearer.
        (release_kernel_dispatch): Rename....
        (cleanup_kernel_dispatch): ... to this, don't free 'shadow'.

OK.

Andrew

Reply via email to