<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/74127>74127</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Rip out all non-trivial uses of HSA from libc
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            libc
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
            JonChesterfield,
            jhuber6
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          JonChesterfield
      </td>
    </tr>
</table>

<pre>
    Libc has an implementation of a loader for amdgpu code objects implemented on HSA. We are currently struggling to get an implementation that runs consistently on the various HSA/kernel combinations and this makes using libc as a development platform excessively difficult.

I propose that we stop doing things the proper HSA way, with pinned memory and calls to hsa_memcpy_async etc, and instead go with the absolute bare minimum of calls we can get away with. Personally I'd rather we linked against ROCT directly to cut debugging through HSA out of the puzzle when things go wrong but I'm not sure we're there yet.

Specifically, the RPC machinery involves one pointer to fine grain memory and one global struct in the gpu image that we need to initialise. Instead of HSA memcpy to initialise that, lets write it from the host.

1/ find the dynamic symbol table in the code object
2/ find the address of the global from that
3/ memcpy over that part of the code object
4/ finally pass the code object to hsa to "load" onto the gpu

This will remove the pinning and all but one memory allocation done currently and hopefully retrieve a green buildbot as well as a more stable system going forward.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJxsVEuP2zYQ_jXyZRDDpu3aPviQbmA0RYEGSYAeA4ocSZMlOQIfVpVfXwxld3fTXixYmpnvMQ-dEvUB8dIcfm2U-p3D04ApY-wInW2UatRTo9T3obQYf5H_hw8rXfLA8fJT8KplO1_-oNbAoBPoAORHhx5D1pk4AHegwbG2GKHjCNrbfixg2CJw-x1NTi8paIED_Pbl_Rr-QtARwZQYMWQ3Q8qx9L2j0ENm6DH_D1gedIZYQgLDIVHKS2r9gnDTkbgkqd-o6zPGgA4M-5ZCTRf6FvJACbx-xgQlCZoTcaINLN7Q8Sh4MDqdO44e8G-DKdEN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