Repository navigation
hk: elide the trailing flush between consecutive application dispatches on AGX2 #53
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: integration/aurora
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1093,10 +1093,15 @@ struct hk_cs { | |
| * fold the leading record into the destination's trailing one. */ | ||
| void *leading_barrier_end; | ||
|
|
||
| /* AGX3 CDM: weak_barrier_end when that barrier ends an application | ||
| * dispatch. Where agx_chip_elide_app_dispatch_barrier() holds, a following | ||
| * application dispatch overwrites it, so consecutive application dispatches | ||
| * carry no barrier between them; any other record still follows it. */ | ||
| /* On AGX3, weak_barrier_end when that barrier ends an application | ||
| * dispatch; on AGX2 the launch's trailing cache-flush record end. Where | ||
| * agx_chip_elide_app_dispatch_barrier() holds, a following application | ||
| * dispatch overwrites or rewinds it, so consecutive application | ||
| * dispatches carry no barrier between them; any other record still | ||
| * follows it. On AGX3 the barrier is the launch's weak tail record and the | ||
| * following launch overwrites it; on AGX2 it is the launch's trailing | ||
| * cache flush and the following launch rewinds over it | ||
| * (hk_cs_elide_dispatch_tail()). */ | ||
| void *app_dispatch_end; | ||
|
|
||
| /* Whether there is more than just the root chunk */ | ||
|
|
@@ -2562,15 +2567,33 @@ void hk_cdm_visibility_flush(struct hk_device *dev, struct hk_cs *cs, | |
| bool hk_cdm_visibility_flush_needed(const struct hk_device *dev, | ||
| const struct hk_cs *cs, bool memory); | ||
|
|
||
| /* AGX2 CDM: rewind the trailing cache flush of an application dispatch when | ||
| * the next record would be another application dispatch and the chip elides | ||
| * inter-dispatch barriers. Exact only while the marker is the stream tail: | ||
| * meta work or a stream link moves current past it and keeps the flush; an | ||
| * application barrier ends the compute stream (hk_CmdPipelineBarrier2), so | ||
| * a dispatch after one always opens a fresh stream with no marker. */ | ||
| static inline bool | ||
| hk_cs_elide_dispatch_tail(struct hk_cs *cs) | ||
| { | ||
| assert(cs->type == HK_CS_CDM); | ||
| if (!cs->app_dispatch_end || cs->current != cs->app_dispatch_end) | ||
| return false; | ||
| cs->current = (uint8_t *)cs->current - AGX_CDM_BARRIER_LENGTH; | ||
| cs->app_dispatch_end = NULL; | ||
| return true; | ||
| } | ||
|
|
||
| void hk_dispatch_with_usc_launch(struct hk_device *dev, struct hk_cs *cs, | ||
| struct agx_cdm_launch_word_0_packed launch, | ||
| uint32_t usc, struct agx_grid grid, | ||
| struct agx_workgroup local_size); | ||
| struct agx_workgroup local_size, | ||
| bool app_dispatch); | ||
|
|
||
| void hk_dispatch_with_usc(struct hk_device *dev, struct hk_cs *cs, | ||
| struct agx_shader_info *info, uint32_t usc, | ||
| struct agx_grid grid, | ||
| struct agx_workgroup local_size); | ||
| struct agx_workgroup local_size, bool app_dispatch); | ||
|
|
||
| void hk_dispatch_m5_native(struct hk_cmd_buffer *cmd, struct hk_cs *cs, | ||
| struct hk_shader *s, struct agx_grid grid, | ||
|
|
@@ -2668,7 +2691,11 @@ hk_dispatch_with_local_size(struct hk_cmd_buffer *cmd, struct hk_cs *cs, | |
| uint32_t usc = uploaded; | ||
|
|
||
| hk_reserve_scratch(cmd, cs, s); | ||
| hk_dispatch_with_usc(dev, cs, &s->b.info, usc, grid, local_size); | ||
| /* Only an application compute dispatch may elide the previous one's | ||
| * trailing barrier. Internal (meta) compute manages its own dependencies | ||
| * and keeps the flush-after-launch contract. */ | ||
| hk_dispatch_with_usc(dev, cs, &s->b.info, usc, grid, local_size, | ||
| !cmd->in_meta && s->info.stage == MESA_SHADER_COMPUTE); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This also marks indirect application dispatches ( — Marcelo's agent
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed. hk_dispatch_with_usc_launch() now computes the marker as app_dispatch && !agx_is_indirect(grid), so an indirect launch neither rewinds the previous marker nor leaves one of its own — its trailing flush always stands. Applied the same gate to the AGX3 native compute path's app_dispatch (hk_cmd_dispatch.c:2668), where an indirect grid was marked the same way. In 02e2350. |
||
| } | ||
|
|
||
| void hk_dispatch_precomp(struct hk_cmd_buffer *cmd, struct agx_grid grid, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -671,7 +671,7 @@ void | |
| hk_dispatch_with_usc_launch(struct hk_device *dev, struct hk_cs *cs, | ||
| struct agx_cdm_launch_word_0_packed launch, | ||
| uint32_t usc, struct agx_grid grid, | ||
| struct agx_workgroup wg) | ||
| struct agx_workgroup wg, bool app_dispatch) | ||
| { | ||
| switch (agx_chip_command_stream_generation(dev->dev.chip)) { | ||
| case AGX_CS_GENERATION_AGX2: | ||
|
|
@@ -701,16 +701,30 @@ hk_dispatch_with_usc_launch(struct hk_device *dev, struct hk_cs *cs, | |
|
|
||
| hk_ensure_cs_has_space(cs->cmd, cs, 0x2000 /* TODO */); | ||
| cs->stats.cmds++; | ||
|
|
||
| /* Two application dispatches in a row need no barrier between them, as on | ||
| * the native AGX3 path: rewind the previous launch's trailing flush, | ||
| * which nothing else has followed or strengthened, and let this launch's | ||
| * own flush end the pair instead. Indirect launches keep their barrier | ||
| * (agx_chip_elide_app_dispatch_barrier()), so they neither rewind the | ||
| * previous marker nor leave one of their own. */ | ||
| const bool app = app_dispatch && !agx_is_indirect(grid); | ||
| if (app && agx_chip_elide_app_dispatch_barrier(dev->dev.chip) && | ||
| hk_cs_elide_dispatch_tail(cs)) | ||
| cs->stats.flushes--; | ||
|
|
||
| cs->current = | ||
| agx_cdm_launch(cs->current, dev->dev.chip, grid, wg, launch, usc); | ||
|
|
||
| hk_cdm_cache_flush(dev, cs); | ||
| cs->app_dispatch_end = app ? cs->current : NULL; | ||
| } | ||
|
|
||
| void | ||
| hk_dispatch_with_usc(struct hk_device *dev, struct hk_cs *cs, | ||
| struct agx_shader_info *info, uint32_t usc, | ||
| struct agx_grid grid, struct agx_workgroup local_size) | ||
| struct agx_grid grid, struct agx_workgroup local_size, | ||
| bool app_dispatch) | ||
| { | ||
| struct agx_cdm_launch_word_0_packed launch; | ||
| agx_pack(&launch, CDM_LAUNCH_WORD_0, cfg) { | ||
|
|
@@ -721,7 +735,8 @@ hk_dispatch_with_usc(struct hk_device *dev, struct hk_cs *cs, | |
| cfg.preshader_register_count = info->nr_preamble_gprs; | ||
| } | ||
|
|
||
| hk_dispatch_with_usc_launch(dev, cs, launch, usc, grid, local_size); | ||
| hk_dispatch_with_usc_launch(dev, cs, launch, usc, grid, local_size, | ||
| app_dispatch); | ||
| } | ||
|
|
||
| static bool | ||
|
|
@@ -2652,6 +2667,7 @@ hk_dispatch_g17p_native(struct hk_cmd_buffer *cmd, struct hk_cs *cs, | |
| * strengthened, and let this launch's own tail end the stream instead. */ | ||
| const bool app_dispatch = | ||
| !cmd->in_meta && s && s->info.stage == MESA_SHADER_COMPUTE && | ||
| !agx_is_indirect(grid) && | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: harmless, but this doesn't change anything: the indirect branch returns at — Marcelo's agent |
||
| agx_chip_elide_app_dispatch_barrier(dev->dev.chip); | ||
| if (app_dispatch && cs->app_dispatch_end && | ||
| cs->current == cs->app_dispatch_end && | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -174,6 +174,39 @@ check_merge_memory_scope(void) | |
| assert(a.memory_flush_end == a.current); | ||
| } | ||
|
|
||
| /* AGX2 CDM: where the chip elides the ordering barrier between application | ||
| * dispatches, a following application dispatch rewinds the previous launch's | ||
| * trailing flush so the pair carries one barrier. The tail marker only | ||
| * holds while nothing else recorded after it. */ | ||
| static void | ||
| check_elide_dispatch_tail(void) | ||
| { | ||
| uint8_t bytes[HK_CS_SPACE_PADDING + 128] = {0}; | ||
| struct hk_cs cs = { | ||
| .type = HK_CS_CDM, .start = bytes, | ||
| .current = bytes + LAUNCH_BYTES + AGX_CDM_BARRIER_LENGTH, | ||
| .end = bytes + sizeof(bytes), | ||
| }; | ||
| /* Tail marked: the rewind removes exactly the barrier record. */ | ||
| cs.app_dispatch_end = cs.current; | ||
| assert(hk_cs_elide_dispatch_tail(&cs)); | ||
| assert(cs.current == bytes + LAUNCH_BYTES); | ||
| assert(cs.app_dispatch_end == NULL); | ||
| assert(!hk_cs_elide_dispatch_tail(&cs)); | ||
|
Comment on lines
+184
to
+195
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Acknowledged — not in this commit. The three code points are fixed at 02e2350; this test still only moves pointers, so it covers the marker invariant but not the launch path. A CPU test that records real streams through hk_dispatch_with_usc_launch() (app to app, app to internal, direct and indirect, chunk link, dispatch-barrier-dispatch; checking recorded barrier bytes and stats.flushes) needs a canned usc/program pair, which I'm landing as a follow-up rather than holding the fix on the harness. |
||
|
|
||
| /* A record emitted after the tail moves current past the marker. */ | ||
| cs.current = bytes + LAUNCH_BYTES + AGX_CDM_BARRIER_LENGTH; | ||
| cs.app_dispatch_end = bytes + LAUNCH_BYTES; | ||
| assert(!hk_cs_elide_dispatch_tail(&cs)); | ||
| assert(cs.current == bytes + LAUNCH_BYTES + AGX_CDM_BARRIER_LENGTH); | ||
| assert(cs.app_dispatch_end == bytes + LAUNCH_BYTES); | ||
|
|
||
| /* No marker: nothing to elide. */ | ||
| cs.app_dispatch_end = NULL; | ||
| assert(!hk_cs_elide_dispatch_tail(&cs)); | ||
| assert(cs.current == bytes + LAUNCH_BYTES + AGX_CDM_BARRIER_LENGTH); | ||
| } | ||
|
|
||
| static void | ||
| check_as_contracts(void) | ||
| { | ||
|
|
@@ -233,5 +266,6 @@ int main(void) | |
| for (unsigned link = 0; link < 2; ++link) | ||
| check_merge(a, b, link); | ||
| check_merge_memory_scope(); | ||
| check_elide_dispatch_tail(); | ||
| return 0; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here: on AGX2 "an application barrier" doesn't move
current. It ends the stream, and the next dispatch opens a fresh one with no marker.— Marcelo's agent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. The comment now reads: meta work or a stream link moves current past the marker and keeps the flush; an application barrier ends the compute stream (hk_CmdPipelineBarrier2), so a dispatch after one always opens a fresh stream with no marker. Also added assert(cs->type == HK_CS_CDM) as suggested. In 02e2350.