<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/149284>149284</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[offload] Allow liboffload cuda plugin to accept PTX binaries as input
</td>
</tr>
<tr>
<th>Labels</th>
<td>
offload
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
RossBrunton
</td>
</tr>
</table>
<pre>
Currently users of liboffload have to manually build and link any input PTX files into CUBIN files. For example (from Unified Runtime):
```c++
ur_result_t ProgramCreateCudaWorkaround(ur_context_handle_t hContext,
const uint8_t *Binary, size_t Length,
ur_program_handle_t hProgram) {
uint8_t *RealBinary;
size_t RealLength;
CUlinkState State;
cuLinkCreate(0, nullptr, nullptr, &State);
cuLinkAddData(State, CU_JIT_INPUT_PTX, (char *)(Binary), Length, nullptr, 0,
nullptr, nullptr);
void *CuBin = nullptr;
size_t CuBinSize = 0;
cuLinkComplete(State, &CuBin, &CuBinSize);
RealBinary = (uint8_t *)CuBin;
RealLength = CuBinSize;
auto Res = olCreateProgram(hContext->Device->OffloadDevice, RealBinary,
RealLength, &hProgram->OffloadProgram);
// Program owns the linked module now
cuLinkDestroy(State);
return offloadResultToUR(Res);
}
```
It makes sense for this format to be detected, built and linked in liboffload itself to save users from having to duplicate this logic and link against libcudadrv.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJxsVN-P4jgM_mvCizWoDTBtH_oA5ZDmtNobsaDbtyo0ps1NmqD8YJb9609pCvRGN6qGKLY_21_sj1krWoVYktWGrLYz5l2nTbnX1m6MV06r2UnzW1l5Y1A5eQNv0VjQZ5DipM9nqRmHjl0RnIaeKc-kvMHJC8mBKQ5SqA9g6gZCXbyD98NPOAuJFoRyGqrj5u17vJjDThvAX6y_SARC87PRPRyVOAvksPfKiR4JLchiTZLhe03i1xC6CV-y9qY2aL10tYN3o1vD-sogc1h5zv7W5oMZ7RUnNPembrRy-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