Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Defer PTX file load to runtime #13690

Merged
merged 15 commits into from
Jan 17, 2024
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions python/cudf/cudf/core/udf/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Copyright (c) 2020-2024, NVIDIA CORPORATION.

import functools
import os
from typing import Any, Callable, Dict

Expand Down Expand Up @@ -60,10 +61,15 @@
precompiled: cachetools.LRUCache = cachetools.LRUCache(maxsize=32)
launch_arg_getters: Dict[Any, Any] = {}

_PTX_FILE = _get_ptx_file(
os.path.join(os.path.dirname(strings_udf.__file__), "..", "core", "udf"),
"shim_",
)
@functools.cache
vyasr marked this conversation as resolved.
Show resolved Hide resolved
def _ptx_file():
return _get_ptx_file(
os.path.join(
os.path.dirname(strings_udf.__file__),
"..", "core", "udf"
vyasr marked this conversation as resolved.
Show resolved Hide resolved
),
"shim_",
)


@_cudf_nvtx_annotate
Expand Down Expand Up @@ -286,7 +292,7 @@ def _get_kernel(kernel_string, globals_, sig, func):
exec(kernel_string, globals_)
_kernel = globals_["_kernel"]
kernel = cuda.jit(
sig, link=[_PTX_FILE], extensions=[str_view_arg_handler]
sig, link=[_ptx_file()], extensions=[str_view_arg_handler]
)(_kernel)

return kernel
Expand Down
16 changes: 16 additions & 0 deletions python/cudf/cudf/tests/test_no_device.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright (c) 2024, NVIDIA CORPORATION.
import os
import subprocess


def test_cudf_import_no_device():
env = os.environ.copy()
env["CUDA_VISIBLE_DEVICES"] = "-1"
output = subprocess.run(
["python", "-c", "import cudf"],
env=env,
capture_output=True,
text=True,
cwd="/",
)
assert output.returncode == 0
6 changes: 4 additions & 2 deletions python/cudf/cudf/tests/test_string_udfs.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2022-2023, NVIDIA CORPORATION.
# Copyright (c) 2022-2024, NVIDIA CORPORATION.

import numba
import numpy as np
Expand All @@ -20,10 +20,12 @@
string_view,
udf_string,
)
from cudf.core.udf.utils import _PTX_FILE, _get_extensionty_size
from cudf.core.udf.utils import _get_extensionty_size, _ptx_file
from cudf.testing._utils import assert_eq, sv_to_udf_str
from cudf.utils._numba import _CUDFNumbaConfig

_PTX_FILE = _ptx_file()


def get_kernels(func, dtype, size):
"""
Expand Down
Loading