Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 81 additions & 6 deletions src/asahi/compiler/test/test-g17p-mod3-ra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,25 +274,29 @@ TEST(G17PMod3RA, NonG17PAndPreambleGating)
{
/* Verify mod-3 tie-breaking, loop_phi_targets, and rmw_web stay strictly
* gated on AGX_CAP_MOD3_REG_BANK_RA and non-preamble shaders: disabled on
* M5/AGX3C (G17G), on non-capable AGX3B chips (G16G), and on G17P
* preambles. Use the same k/pad0/pad1/m loop that G17P resolves to 0
* AGX3D (G18G), on non-capable AGX3B chips (G16G), and on G17P/M5
* preambles. Use the same k/pad0/pad1/m loop that G17P and M5 resolve to 0
* conflicts and confirm it stays untouched (k=r1, m=r4) when gated off. */
for (unsigned mode = 0; mode < 3; ++mode) {
for (unsigned mode = 0; mode < 4; ++mode) {
nir_builder nb = make_compute_shader("g17p-mod3-gating");
void *mem = ralloc_context(NULL);
agx_builder *b = agx_test_builder(mem);
agx_shader_key key = {};
struct agx_shader_info out = {};
if (mode == 0) {
key.dev.chip = AGX_CHIP_G17G;
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
key.dev.chip = AGX_CHIP_G18G;
key.dev.encoding = AGX_ISA_ENCODING_AGX3D;
} else if (mode == 1) {
key.dev.chip = AGX_CHIP_G16G;
key.dev.encoding = AGX_ISA_ENCODING_AGX3B;
} else {
} else if (mode == 2) {
key.dev.chip = AGX_CHIP_G17P;
key.dev.encoding = AGX_ISA_ENCODING_AGX3B;
b->shader->is_preamble = true;
} else {
key.dev.chip = AGX_CHIP_G17C;
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
b->shader->is_preamble = true;
}
b->shader->key = &key;
b->shader->out = &out;
Expand Down Expand Up @@ -347,6 +351,77 @@ TEST(G17PMod3RA, NonG17PAndPreambleGating)
}
}

TEST(G17PMod3RA, M5ResolvesMod3Conflicts)
{
/* Verify M5 (G17G, G17S, G17C) carries AGX_CAP_MOD3_REG_BANK_RA and
* resolves the same co-read loop to zero mod-3 bank conflicts without
* spilling. */
const enum agx_chip m5_chips[] = {
AGX_CHIP_G17G,
AGX_CHIP_G17S,
AGX_CHIP_G17C,
};
for (unsigned i = 0; i < ARRAY_SIZE(m5_chips); ++i) {
nir_builder nb = make_compute_shader("m5-mod3-loop");
void *mem = ralloc_context(NULL);
agx_builder *b = agx_test_builder(mem);
agx_shader_key key = {};
struct agx_shader_info out = {};
key.dev.chip = m5_chips[i];
key.dev.encoding = AGX_ISA_ENCODING_AGX3C;
b->shader->key = &key;
b->shader->out = &out;
b->shader->nir = nb.shader;
b->shader->stage = MESA_SHADER_COMPUTE;

agx_block *entry = agx_start_block(b->shader);
agx_block *loop = agx_test_block(b->shader);
agx_block *latch = agx_test_block(b->shader);
agx_block *exit = agx_test_block(b->shader);
loop->loop_header = true;
agx_block_add_successor(entry, loop);
agx_block_add_successor(loop, latch);
agx_block_add_successor(latch, loop);
agx_block_add_successor(loop, exit);

b->cursor = agx_after_block(entry);
agx_index k = agx_mov_imm(b, 32, 0x3f800000);
agx_index pad0 = agx_mov_imm(b, 32, 0x40000000);
agx_index pad1 = agx_mov_imm(b, 32, 0x40400000);
agx_index m = agx_mov_imm(b, 32, 0x40800000);

b->cursor = agx_after_block(loop);
agx_index x0 = agx_ffma(b, k, m, pad0);
agx_index x1 = agx_ffma(b, k, m, pad1);
agx_index x2 = agx_ffma(b, k, m, x0);
agx_index x3 = agx_ffma(b, k, m, x1);

b->cursor = agx_after_block(exit);
agx_unit_test(b, x2);
agx_unit_test(b, x3);

agx_compute_liveness(b->shader);
agx_ra(b->shader);

unsigned mod3_conflicts = 0;
agx_foreach_instr_in_block(loop, I) {
if (I->op != AGX_OPCODE_FFMA)
continue;
if (I->src[0].type == AGX_INDEX_REGISTER &&
I->src[1].type == AGX_INDEX_REGISTER) {
unsigned r0 = I->src[0].value >> 1;
unsigned r1 = I->src[1].value >> 1;
if (r0 != r1 && (r0 % 3u) == (r1 % 3u))
mod3_conflicts++;
}
}
EXPECT_EQ(mod3_conflicts, 0u);
EXPECT_EQ(b->shader->scratch_size_B, 0u);
ralloc_free(mem);
ralloc_free(nb.shader);
}
}

TEST(G17PMod3RA, SsaZeroAndDeadPartnerDoNotCausePhantomConflicts)
{
/* Case 1: SSA 0 is a co-read partner of `v` that has NOT been visited yet
Expand Down
11 changes: 6 additions & 5 deletions src/asahi/lib/agx_chip_caps.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ enum agx_chip_cap {

/* Register allocation tie-breaks co-read GPR pairs across the three 32-bit
* register banks ((reg / 2) % 3) and coalesces single-use loop RMW
* accumulator chains on non-preamble shaders. Enabled on G17P (HAL200); off
* on M5 (G17G/G17S/G17C), G15, G16, G18G, and AGX2 until per-generation
* hardware A/B and CTS rows are collected. */
* accumulator chains on non-preamble shaders. Measured and qualified on
* G17P (HAL200) and M5 (G17G/G17S/G17C, HAL300); off on G15, G16, G18G,
* and AGX2 until per-generation hardware A/B and CTS rows are collected. */
AGX_CAP_MOD3_REG_BANK_RA = 1u << 13,

/* Private Gen10 colour and depth compression. In Gallium: single-level,
Expand Down Expand Up @@ -193,8 +193,9 @@ enum agx_chip_cap {
AGX_CAP_HW_TXF_BOUNDS | AGX_CAP_COOPERATIVE_MATRIX | \
AGX_CAP_SPARSE_BINDING | AGX_CAP_DESCRIPTOR_BUFFER | \
AGX_CAP_COALESCE_PURE_GLOBAL_WORKGROUPS | AGX_CAP_CDM_WAR_WEAK_BARRIER | \
AGX_CAP_GEN10_2D_COMPRESSION | AGX_CAP_SIGNED_ZERO_MINMAX_SELECT | \
AGX_CAP_CDM_OVERLAP_SPLIT | AGX_CAP_CACHED_CMD_MEMORY)
AGX_CAP_GEN10_2D_COMPRESSION | AGX_CAP_MOD3_REG_BANK_RA | \
AGX_CAP_SIGNED_ZERO_MINMAX_SELECT | AGX_CAP_CDM_OVERLAP_SPLIT | \
AGX_CAP_CACHED_CMD_MEMORY)

/*
* One row per chip of AGX_CHIPS, in the same order: chip, capabilities.
Expand Down
11 changes: 6 additions & 5 deletions src/asahi/lib/tests/test-chip-caps.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,16 +140,17 @@ test_cdm_war_weak_barrier(void)
}
}

/* AGX_CAP_MOD3_REG_BANK_RA is enabled only on G17P until per-generation
* hardware A/B benchmarks and CTS rows qualify other parts. */
/* AGX_CAP_MOD3_REG_BANK_RA is qualified on G17P and M5 (G17G/G17S/G17C);
* G15, G16, G18G, and AGX2 stay off until per-generation hardware A/B
* benchmarks and CTS rows qualify them. */
static void
test_mod3_reg_bank_ra(void)
{
for (unsigned i = 0; i <= AGX_CHIP_UNKNOWN; ++i) {
const enum agx_chip c = (enum agx_chip)i;
CHECK_CHIP(agx_chip_has_cap(c, AGX_CAP_MOD3_REG_BANK_RA) ==
(c == AGX_CHIP_G17P),
c);
const bool expected = c == AGX_CHIP_G17P || c == AGX_CHIP_G17G ||
c == AGX_CHIP_G17S || c == AGX_CHIP_G17C;
CHECK_CHIP(agx_chip_has_cap(c, AGX_CAP_MOD3_REG_BANK_RA) == expected, c);
}
}

Expand Down