Skip to content

Avoid building a static library for CPU target code #23

Open

Description

@ggeorgakoudis

Offloading with target on the CPU requires creating a self-contained shared library for the CPU code. Numba lowering inserts calls to NRT or helperlib functions, which are not exported through Numba-compiled shared libraries. Additionally, we need to init the NRT memory system (NRT_MemSys_Init) to make it usable from the standalone CPU target code.

Currently, we build a static library by pulling sources from the Numba installation, insert a constructor for initialization (the memory system), and link that static library with the shared library CPU target code. Packaging a wheel pulls those sources from the specific Numba version installed at build time. This works across Numba versions because those APIs and their implementations are fairly stable, but it's not ideal.

I can think of the following alternatives:

  1. PyOMP builds the static library at JIT time instead of packaging it, pulling sources from the Numba installation. PyOMP can cache that library to avoid rebuilding for another CPU target region
  2. Numba provides a static library (or LLVM bitcode library)1 that PyOMP links at JIT time

Footnotes

  1. bitcode library will require the user to have python development headers which is not ideal ↩

Activity

  1. ggeorgakoudis commented on Sep 10, 2025

    @ggeorgakoudis
    ContributorAuthor

    PR #21 partially fixes this by going with approach 1: building the static library at runtime creating trampolines to the absolute symbol addresses loaded as python extension modules by numba, roughly similar to how numba adds those symbols to the execution engine

    I will leave the issue open because I think the ideal solution is approach 2, but requires upstream Numba changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions