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 7 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
10 changes: 7 additions & 3 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-2023, NVIDIA CORPORATION.
# Copyright (c) 2020-2024, NVIDIA CORPORATION.

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

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

_PTX_FILE = _get_ptx_file(os.path.dirname(__file__), "shim_")

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


@_cudf_nvtx_annotate
Expand Down Expand Up @@ -286,7 +290,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
14 changes: 13 additions & 1 deletion python/cudf/cudf/tests/test_no_cuinit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2023, NVIDIA CORPORATION.
# Copyright (c) 2023-2024, NVIDIA CORPORATION.

import os
import subprocess
Expand Down Expand Up @@ -109,3 +109,15 @@ def test_cudf_create_series_cuinit(cuda_gdb):
print(output.stderr)
assert output.returncode == 0
assert cuInit_called >= 0


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,
)
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