<!DOCTYPE html><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  </head>
  <body>
    It could be that the automated testing tools will run amok on that.<br>
    <br>
    I need to ask Felix for details but I think the code for the CWSR
    trap handlers were converted to C style comments as well because of
    that.<br>
    <br>
    Christian.<br>
    <br>
    <div class="moz-cite-prefix">Am 04.09.24 um 12:52 schrieb Deucher,
      Alexander:<br>
    </div>
    <blockquote type="cite" cite="mid:BL1PR12MB51440CA6B867F66075BD50ADF79C2@BL1PR12MB5144.namprd12.prod.outlook.com">
      
      <style type="text/css" style="display:none;">P {margin-top:0;margin-bottom:0;}</style>
      <p style="font-family:Calibri;font-size:10pt;color:#0000FF;margin:5pt;font-style:normal;font-weight:normal;text-decoration:none;" align="Left">
        [AMD Official Use Only - AMD Internal Distribution Only]<br>
      </p>
      <br>
      <div>
        <div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
          I think you can drop this patch.  This code is not compiled,
          it's just for reference, and changing all of the comments will
          just make it harder to keep in sync with the internal version.</div>
        <div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
          <br>
        </div>
        <div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
          Alex</div>
        <div class="elementToProof" style="font-family: Aptos, Aptos_EmbeddedFont, Aptos_MSFontService, Calibri, Helvetica, sans-serif; font-size: 12pt; color: rgb(0, 0, 0);">
          <br>
        </div>
        <hr style="display:inline-block;width:98%" tabindex="-1">
        <div id="divRplyFwdMsg" dir="ltr"><font style="font-size:11pt" face="Calibri, sans-serif" color="#000000"><b>From:</b>
            SHANMUGAM, SRINIVASAN <a class="moz-txt-link-rfc2396E" href="mailto:SRINIVASAN.SHANMUGAM@amd.com"><SRINIVASAN.SHANMUGAM@amd.com></a><br>
            <b>Sent:</b> Wednesday, September 4, 2024 5:51 AM<br>
            <b>To:</b> Koenig, Christian
            <a class="moz-txt-link-rfc2396E" href="mailto:Christian.Koenig@amd.com"><Christian.Koenig@amd.com></a>; Deucher, Alexander
            <a class="moz-txt-link-rfc2396E" href="mailto:Alexander.Deucher@amd.com"><Alexander.Deucher@amd.com></a><br>
            <b>Cc:</b> <a class="moz-txt-link-abbreviated" href="mailto:amd-gfx@lists.freedesktop.org">amd-gfx@lists.freedesktop.org</a>
            <a class="moz-txt-link-rfc2396E" href="mailto:amd-gfx@lists.freedesktop.org"><amd-gfx@lists.freedesktop.org></a>; SHANMUGAM, SRINIVASAN
            <a class="moz-txt-link-rfc2396E" href="mailto:SRINIVASAN.SHANMUGAM@amd.com"><SRINIVASAN.SHANMUGAM@amd.com></a><br>
            <b>Subject:</b> [PATCH v2] drm/amdgpu/gfx9: Convert `//` to
            `/* ... */` in cleaner shader code</font>
          <div> </div>
        </div>
        <div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
              <div class="PlainText">This commit updates the comment
                style in the cleaner shader code from<br>
                `//` to `/* ... */` to adhere to the Linux kernel coding
                style.<br>
                <br>
                The comments describe the operation of the cleaner
                shader, which is used<br>
                to clean LDS, SGPRs, and VGPRs. The shader uses two
                kernels launched<br>
                separately to clean VGPRs, LDS, and lower SGPRs, and to
                clean remaining<br>
                SGPRs.<br>
                <br>
                Fixes: 3b721dfb2c95 ("drm/amdgpu/gfx9: Add cleaner
                shader for GFX9.4.3")<br>
                Cc: Christian König <a class="moz-txt-link-rfc2396E" href="mailto:christian.koenig@amd.com"><christian.koenig@amd.com></a><br>
                Cc: Alex Deucher <a class="moz-txt-link-rfc2396E" href="mailto:alexander.deucher@amd.com"><alexander.deucher@amd.com></a><br>
                Signed-off-by: Srinivasan Shanmugam
                <a class="moz-txt-link-rfc2396E" href="mailto:srinivasan.shanmugam@amd.com"><srinivasan.shanmugam@amd.com></a><br>
                ---<br>
                v2:<br>
                 - Corrected typo for iteraions<br>
                 - Added fixes tag<br>
                <br>
                 .../amd/amdgpu/gfx_v9_4_3_cleaner_shader.asm  | 139
                +++++++++---------<br>
                 1 file changed, 72 insertions(+), 67 deletions(-)<br>
                <br>
                diff --git
                a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3_cleaner_shader.asm
b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3_cleaner_shader.asm<br>
                index d5325ef80ab0..8951b5a87ae1 100644<br>
                ---
                a/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3_cleaner_shader.asm<br>
                +++
                b/drivers/gpu/drm/amd/amdgpu/gfx_v9_4_3_cleaner_shader.asm<br>
                @@ -21,47 +21,52 @@<br>
                  * OTHER DEALINGS IN THE SOFTWARE.<br>
                  */<br>
                 <br>
                -// This shader is to clean LDS, SGPRs and VGPRs. It is 
                first 64 Dwords or 256 bytes of 192 Dwords cleaner
                shader.<br>
                -//To turn this shader program on for complitaion change
                this to main and lower shader main to main_1<br>
                - <br>
                -// MI300 : Clear SGPRs, VGPRs and LDS<br>
                -//   Uses two kernels launched separately:<br>
                -//   1. Clean VGPRs, LDS, and lower SGPRs<br>
                -//        Launches one workgroup per CU, each workgroup
                with 4x wave64 per SIMD in the CU<br>
                -//        Waves are "wave64" and have 128 VGPRs each,
                which uses all 512 VGPRs per SIMD<br>
                -//        Waves in the workgroup share the 64KB of LDS<br>
                -//        Each wave clears SGPRs 0 - 95. Because there
                are 4 waves/SIMD, this is physical SGPRs 0-383<br>
                -//        Each wave clears 128 VGPRs, so all 512 in the
                SIMD<br>
                -//        The first wave of the workgroup clears its
                64KB of LDS<br>
                -//        The shader starts with "S_BARRIER" to ensure
                SPI has launched all waves of the workgroup<br>
                -//          before any wave in the workgroup could
                end.  Without this, it is possible not all SGPRs get
                cleared.<br>
                -//    2. Clean remaining SGPRs<br>
                -//        Launches a workgroup with 24 waves per
                workgroup, yielding 6 waves per SIMD in each CU<br>
                -//        Waves are allocating 96 SGPRs<br>
                -//          CP sets up SPI_RESOURCE_RESERVE_* registers
                to prevent these waves from allocating SGPRs 0-223.<br>
                -//          As such, these 6 waves per SIMD are
                allocated physical SGPRs 224-799<br>
                -//        Barriers do not work for >16 waves per
                workgroup, so we cannot start with S_BARRIER<br>
                -//          Instead, the shader starts with an
                S_SETHALT 1. Once all waves are launched CP will send
                unhalt command<br>
                -//        The shader then clears all SGPRs allocated to
                it, cleaning out physical SGPRs 224-799<br>
                +/*<br>
                + * This shader is to clean LDS, SGPRs and VGPRs. It is 
                first 64 Dwords or 256 bytes of 192 Dwords cleaner
                shader.<br>
                + * To turn this shader program on for complitaion
                change this to main and lower shader main to main_1<br>
                + *<br>
                + * MI300 : Clear SGPRs, VGPRs and LDS<br>
                + *   Uses two kernels launched separately:<br>
                + *   1. Clean VGPRs, LDS, and lower SGPRs<br>
                + *        Launches one workgroup per CU, each workgroup
                with 4x wave64 per SIMD in the CU<br>
                + *        Waves are "wave64" and have 128 VGPRs each,
                which uses all 512 VGPRs per SIMD<br>
                + *        Waves in the workgroup share the 64KB of LDS<br>
                + *        Each wave clears SGPRs 0 - 95. Because there
                are 4 waves/SIMD, this is physical SGPRs 0-383<br>
                + *        Each wave clears 128 VGPRs, so all 512 in the
                SIMD<br>
                + *        The first wave of the workgroup clears its
                64KB of LDS<br>
                + *        The shader starts with "S_BARRIER" to ensure
                SPI has launched all waves of the workgroup<br>
                + *          before any wave in the workgroup could
                end.  Without this, it is possible not all SGPRs get
                cleared.<br>
                + *    2. Clean remaining SGPRs<br>
                + *        Launches a workgroup with 24 waves per
                workgroup, yielding 6 waves per SIMD in each CU<br>
                + *        Waves are allocating 96 SGPRs<br>
                + *          CP sets up SPI_RESOURCE_RESERVE_* registers
                to prevent these waves from allocating SGPRs 0-223.<br>
                + *          As such, these 6 waves per SIMD are
                allocated physical SGPRs 224-799<br>
                + *       Barriers do not work for >16 waves per
                workgroup, so we cannot start with S_BARRIER<br>
                + *       Instead, the shader starts with an S_SETHALT
                1. Once all waves are launched CP will send unhalt
                command<br>
                + *       The shader then clears all SGPRs allocated to
                it, cleaning out physical SGPRs 224-799<br>
                + */<br>
                  <br>
                 shader main<br>
                   asic(MI300)<br>
                   type(CS)<br>
                   wave_size(64)<br>
                -// Note: original source code from SQ team<br>
                 <br>
                -//   (theorhetical fastest = ~512clks vgpr + 1536 lds +
                ~128 sgpr  = 2176 clks)<br>
                +/*<br>
                + * Note: original source code from SQ team<br>
                + *<br>
                + * (theorhetical fastest = ~512clks vgpr + 1536 lds +
                ~128 sgpr  = 2176 clks)<br>
                + */<br>
                 <br>
                -  s_cmp_eq_u32 s0, 1                                //
                Bit0 is set, sgpr0 is set then clear VGPRS and LDS as FW
                set COMPUTE_USER_DATA_3<br>
                -  s_cbranch_scc0  label_0023                        //
                Clean VGPRs and LDS if sgpr0 of wave is set, scc = (s3
                == 1)<br>
                +  s_cmp_eq_u32 s0, 1                                /*
                Bit0 is set, sgpr0 is set then clear VGPRS and LDS as FW
                set COMPUTE_USER_DATA_3 */<br>
                +  s_cbranch_scc0  label_0023                        /*
                Clean VGPRs and LDS if sgpr0 of wave is set, scc = (s3
                == 1) */<br>
                   S_BARRIER<br>
                 <br>
                   s_movk_i32    m0, 0x0000<br>
                -  s_mov_b32     s2, 0x00000078  // Loop 128/8=16 times 
                (loop unrolled for performance)<br>
                -  //<br>
                -  // CLEAR VGPRs<br>
                -  //<br>
                -  s_set_gpr_idx_on  s2, 0x8    // enable Dest VGPR
                indexing<br>
                +  s_mov_b32     s2, 0x00000078  /* Loop 128/8=16 times 
                (loop unrolled for performance) */<br>
                +/*<br>
                + * CLEAR VGPRs<br>
                + */<br>
                +  s_set_gpr_idx_on  s2, 0x8    /* enable Dest VGPR
                indexing */<br>
                 label_0005:<br>
                   v_mov_b32     v0, 0<br>
                   v_mov_b32     v1, 0<br>
                @@ -75,24 +80,24 @@ label_0005:<br>
                   s_set_gpr_idx_idx  s2<br>
                   s_cbranch_scc0  label_0005<br>
                   s_set_gpr_idx_off<br>
                - <br>
                -  //<br>
                -  //<br>
                - <br>
                -  s_mov_b32     s2, 0x80000000                      //
                Bit31 is first_wave<br>
                -  s_and_b32     s2, s2, s1                          //
                sgpr0 has tg_size (first_wave) term as in ucode only
                COMPUTE_PGM_RSRC2.tg_size_en is set<br>
                -  s_cbranch_scc0  label_clean_sgpr_1                //
                Clean LDS if its first wave of ThreadGroup/WorkGroup<br>
                -  // CLEAR LDS<br>
                -  //<br>
                +<br>
                +  s_mov_b32     s2, 0x80000000                      /*
                Bit31 is first_wave */<br>
                +  s_and_b32     s2, s2, s1                          /*
                sgpr0 has tg_size (first_wave) term as in ucode only
                COMPUTE_PGM_RSRC2.tg_size_en is set */<br>
                +  s_cbranch_scc0  label_clean_sgpr_1                /*
                Clean LDS if its first wave of ThreadGroup/WorkGroup */<br>
                +/*<br>
                + * CLEAR LDS<br>
                + */<br>
                   s_mov_b32 exec_lo, 0xffffffff<br>
                   s_mov_b32 exec_hi, 0xffffffff<br>
                -  v_mbcnt_lo_u32_b32  v1, exec_hi, 0          // Set V1
                to thread-ID (0..63)<br>
                -  v_mbcnt_hi_u32_b32  v1, exec_lo, v1         // Set V1
                to thread-ID (0..63)<br>
                -  v_mul_u32_u24  v1, 0x00000008, v1           // * 8,
                so each thread is a double-dword address (8byte)<br>
                -  s_mov_b32     s2, 0x00000003f               // 64
                loop iteraions<br>
                +  v_mbcnt_lo_u32_b32  v1, exec_hi, 0          /* Set V1
                to thread-ID (0..63) */<br>
                +  v_mbcnt_hi_u32_b32  v1, exec_lo, v1         /* Set V1
                to thread-ID (0..63) */<br>
                +  v_mul_u32_u24  v1, 0x00000008, v1           /* * 8,
                so each thread is a double-dword address (8byte) */<br>
                +  s_mov_b32     s2, 0x00000003f               /* 64
                loop iterations */<br>
                   s_mov_b32     m0, 0xffffffff<br>
                -  // Clear all of LDS space<br>
                -  // Each FirstWave of WorkGroup clears 64kbyte block<br>
                +/*<br>
                + * Clear all of LDS space<br>
                + * Each FirstWave of WorkGroup clears 64kbyte block<br>
                + */<br>
                  <br>
                 label_001F:<br>
                   ds_write2_b64  v1, v[2:3], v[2:3] offset1:32<br>
                @@ -100,11 +105,11 @@ label_001F:<br>
                   v_add_co_u32     v1, vcc, 0x00000400, v1<br>
                   s_sub_u32     s2, s2, 1<br>
                   s_cbranch_scc0  label_001F<br>
                -  //<br>
                -  // CLEAR SGPRs<br>
                -  //<br>
                +/*<br>
                + * CLEAR SGPRs<br>
                + */<br>
                 label_clean_sgpr_1:<br>
                -  s_mov_b32     m0, 0x0000005c   // Loop 96/4=24 times 
                (loop unrolled for performance)<br>
                +  s_mov_b32     m0, 0x0000005c   /* Loop 96/4=24 times 
                (loop unrolled for performance) */<br>
                   s_nop 0<br>
                 label_sgpr_loop:<br>
                   s_movreld_b32     s0, 0<br>
                @@ -114,25 +119,25 @@ label_sgpr_loop:<br>
                   s_sub_u32         m0, m0, 4<br>
                   s_cbranch_scc0  label_sgpr_loop<br>
                  <br>
                -  //clear vcc, flat scratch<br>
                -  s_mov_b32 flat_scratch_lo, 0   //clear  flat scratch
                lo SGPR <br>
                -  s_mov_b32 flat_scratch_hi, 0   //clear  flat scratch
                hi SGPR <br>
                -  s_mov_b64 vcc, 0               //clear vcc<br>
                -  s_mov_b64 ttmp0, 0             //Clear ttmp0 and
                ttmp1 <br>
                -  s_mov_b64 ttmp2, 0             //Clear ttmp2 and
                ttmp3 <br>
                -  s_mov_b64 ttmp4, 0             //Clear ttmp4 and
                ttmp5 <br>
                -  s_mov_b64 ttmp6, 0             //Clear ttmp6 and
                ttmp7 <br>
                -  s_mov_b64 ttmp8, 0             //Clear ttmp8 and
                ttmp9 <br>
                -  s_mov_b64 ttmp10, 0            //Clear ttmp10 and
                ttmp11 <br>
                -  s_mov_b64 ttmp12, 0            //Clear ttmp12 and
                ttmp13 <br>
                -  s_mov_b64 ttmp14, 0            //Clear ttmp14 and
                ttmp15 <br>
                +  /* clear vcc, flat scratch */<br>
                +  s_mov_b32 flat_scratch_lo, 0   /* clear flat scratch
                lo SGPR */<br>
                +  s_mov_b32 flat_scratch_hi, 0   /* clear flat scratch
                hi SGPR */<br>
                +  s_mov_b64 vcc, 0               /* clear vcc */<br>
                +  s_mov_b64 ttmp0, 0             /* Clear ttmp0 and
                ttmp1 */<br>
                +  s_mov_b64 ttmp2, 0             /* Clear ttmp2 and
                ttmp3 */<br>
                +  s_mov_b64 ttmp4, 0             /* Clear ttmp4 and
                ttmp5 */<br>
                +  s_mov_b64 ttmp6, 0             /* Clear ttmp6 and
                ttmp7 */<br>
                +  s_mov_b64 ttmp8, 0             /* Clear ttmp8 and
                ttmp9 */<br>
                +  s_mov_b64 ttmp10, 0            /* Clear ttmp10 and
                ttmp11 */<br>
                +  s_mov_b64 ttmp12, 0            /* Clear ttmp12 and
                ttmp13 */<br>
                +  s_mov_b64 ttmp14, 0            /* Clear ttmp14 and
                ttmp15 */<br>
                 s_endpgm<br>
                 <br>
                 label_0023:<br>
                 <br>
                   s_sethalt 1<br>
                 <br>
                -  s_mov_b32     m0, 0x0000005c   // Loop 96/4=24 times 
                (loop unrolled for performance)<br>
                +  s_mov_b32     m0, 0x0000005c   /* Loop 128/8=16
                times  (loop unrolled for performance) */<br>
                   s_nop 0<br>
                 label_sgpr_loop1:<br>
                 <br>
                @@ -143,10 +148,10 @@ label_sgpr_loop1:<br>
                   s_sub_u32         m0, m0, 4<br>
                   s_cbranch_scc0  label_sgpr_loop1<br>
                  <br>
                -  //clear vcc, flat scratch<br>
                -  s_mov_b32 flat_scratch_lo, 0   //clear  flat scratch
                lo SGPR <br>
                -  s_mov_b32 flat_scratch_hi, 0   //clear  flat scratch
                hi SGPR <br>
                -  s_mov_b64 vcc, 0xee            //clear vcc<br>
                +  /* clear vcc, flat scratch */<br>
                +  s_mov_b32 flat_scratch_lo, 0   /* clear  flat scratch
                lo SGPR */<br>
                +  s_mov_b32 flat_scratch_hi, 0   /* clear  flat scratch
                hi SGPR */<br>
                +  s_mov_b64 vcc, 0xee            /* clear vcc */<br>
                 <br>
                 s_endpgm<br>
                 end  <br>
                -- <br>
                2.34.1<br>
                <br>
              </div>
            </span></font></div>
      </div>
    </blockquote>
    <br>
  </body>
</html>