Skip to content

Commit

Permalink
Hack out cudf's import time GPU initialisation
Browse files Browse the repository at this point in the history
We don't rely on this part of cudf at all, so until we just depend on
a separate pylibcudf package, stub the bad submodules out.

This technically means that if you import cudf_polars and want to use
cudf in the same process, you can't use numba functionality. But I
really don't want the warnings that numba gives on old drivers to
appear.
  • Loading branch information
wence- committed Jul 26, 2024
1 parent a1f12a4 commit 000ef52
Showing 1 changed file with 25 additions and 3 deletions.
28 changes: 25 additions & 3 deletions python/cudf_polars/cudf_polars/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,31 @@

from __future__ import annotations

from cudf_polars._version import __git_commit__, __version__
from cudf_polars.callback import execute_with_cudf
from cudf_polars.dsl.translate import translate_ir

# We want to avoid initialising the GPU on import. Unfortunately,
# while we still depend on cudf, the default mode is to check things.
# This ugly hack patches away the import-time calls in cudf that
# require initialising the GPU.
# TODO: Remove this when we only depend on a pylibcudf package.
def _patch_away_import_gpu_init():
import sys
import types

fake_mod = types.ModuleType("_numba")
fake_mod.__dict__["_setup_numba"] = lambda: None
fake_mod.__dict__["_CUDFNumbaConfig"] = lambda: None
fake_mod.__dict__["_get_ptx_file"] = lambda: None
fake_mod.__dict__["validate_setup"] = lambda: None
sys.modules["cudf.utils._numba"] = fake_mod
sys.modules["cudf.utils.gpu_utils"] = fake_mod


_patch_away_import_gpu_init()
del _patch_away_import_gpu_init

from cudf_polars._version import __git_commit__, __version__ # noqa: E402
from cudf_polars.callback import execute_with_cudf # noqa: E402
from cudf_polars.dsl.translate import translate_ir # noqa: E402

__all__: list[str] = [
"execute_with_cudf",
Expand Down

0 comments on commit 000ef52

Please sign in to comment.