Skip to content

[offload] Allow liboffload cuda plugin to accept PTX binaries as input #149284

@RossBrunton

Description

@RossBrunton

Currently users of liboffload have to manually build and link any input PTX files into CUBIN files. For example (from Unified Runtime):

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions