From e20d2b72c8f274291bc23eadfde037f1e3ec7802 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Wed, 12 Jul 2023 07:09:31 -0700 Subject: [PATCH 1/6] cache ptx file retrieval and defer to runtime --- python/cudf/cudf/core/udf/utils.py | 8 ++++++-- python/cudf/cudf/tests/test_string_udfs.py | 4 +++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/python/cudf/cudf/core/udf/utils.py b/python/cudf/cudf/core/udf/utils.py index 35a3f6c1ffd..ff961dbca33 100644 --- a/python/cudf/cudf/core/udf/utils.py +++ b/python/cudf/cudf/core/udf/utils.py @@ -1,5 +1,6 @@ # Copyright (c) 2020-2023, NVIDIA CORPORATION. +import functools import os from typing import Any, Callable, Dict @@ -62,7 +63,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(): + return _get_ptx_file(os.path.dirname(__file__), "shim_") @_cudf_nvtx_annotate @@ -284,7 +288,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 diff --git a/python/cudf/cudf/tests/test_string_udfs.py b/python/cudf/cudf/tests/test_string_udfs.py index 88c73ccf964..822b3719ef5 100644 --- a/python/cudf/cudf/tests/test_string_udfs.py +++ b/python/cudf/cudf/tests/test_string_udfs.py @@ -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): """ From 1e55edf9d275191268a66ae1d918f5426a168e52 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Wed, 12 Jul 2023 07:17:04 -0700 Subject: [PATCH 2/6] Add a basic test --- python/cudf/cudf/tests/test_no_cuinit.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/python/cudf/cudf/tests/test_no_cuinit.py b/python/cudf/cudf/tests/test_no_cuinit.py index 3731f9b5fd4..9eacdd8fa3c 100644 --- a/python/cudf/cudf/tests/test_no_cuinit.py +++ b/python/cudf/cudf/tests/test_no_cuinit.py @@ -107,3 +107,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 From cd98f38aa5352f1b2eea58adb0ef43c91885d174 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Fri, 5 Jan 2024 07:20:01 -0800 Subject: [PATCH 3/6] copyrights --- python/cudf/cudf/core/udf/utils.py | 2 +- python/cudf/cudf/tests/test_no_cuinit.py | 2 +- python/cudf/cudf/tests/test_string_udfs.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/python/cudf/cudf/core/udf/utils.py b/python/cudf/cudf/core/udf/utils.py index 8c5e7a3be8e..a2449b6e412 100644 --- a/python/cudf/cudf/core/udf/utils.py +++ b/python/cudf/cudf/core/udf/utils.py @@ -1,4 +1,4 @@ -# Copyright (c) 2020-2023, NVIDIA CORPORATION. +# Copyright (c) 2020-2024, NVIDIA CORPORATION. import functools import os diff --git a/python/cudf/cudf/tests/test_no_cuinit.py b/python/cudf/cudf/tests/test_no_cuinit.py index 1075c49ad26..d752c3b25de 100644 --- a/python/cudf/cudf/tests/test_no_cuinit.py +++ b/python/cudf/cudf/tests/test_no_cuinit.py @@ -1,4 +1,4 @@ -# Copyright (c) 2023, NVIDIA CORPORATION. +# Copyright (c) 2023-2024, NVIDIA CORPORATION. import os import subprocess diff --git a/python/cudf/cudf/tests/test_string_udfs.py b/python/cudf/cudf/tests/test_string_udfs.py index 822b3719ef5..5dbb86fe27d 100644 --- a/python/cudf/cudf/tests/test_string_udfs.py +++ b/python/cudf/cudf/tests/test_string_udfs.py @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2023, NVIDIA CORPORATION. +# Copyright (c) 2022-2024, NVIDIA CORPORATION. import numba import numpy as np From 99268151feb4f2e86ea497e361b059ee549fad6e Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Mon, 8 Jan 2024 09:28:23 -0800 Subject: [PATCH 4/6] add cwd --- python/cudf/cudf/tests/test_no_cuinit.py | 1 + 1 file changed, 1 insertion(+) diff --git a/python/cudf/cudf/tests/test_no_cuinit.py b/python/cudf/cudf/tests/test_no_cuinit.py index d752c3b25de..c4d6ce5ce3b 100644 --- a/python/cudf/cudf/tests/test_no_cuinit.py +++ b/python/cudf/cudf/tests/test_no_cuinit.py @@ -119,5 +119,6 @@ def test_cudf_import_no_device(): env=env, capture_output=True, text=True, + cwd="/", ) assert output.returncode == 0 From 67abb2c2e501317d43bad89ac61452e0f86570b9 Mon Sep 17 00:00:00 2001 From: brandon-b-miller Date: Tue, 16 Jan 2024 08:58:51 -0800 Subject: [PATCH 5/6] break test off into its own file --- python/cudf/cudf/tests/test_no_cuinit.py | 15 +-------------- python/cudf/cudf/tests/test_no_device.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 14 deletions(-) create mode 100644 python/cudf/cudf/tests/test_no_device.py diff --git a/python/cudf/cudf/tests/test_no_cuinit.py b/python/cudf/cudf/tests/test_no_cuinit.py index c4d6ce5ce3b..45d812fe9a2 100644 --- a/python/cudf/cudf/tests/test_no_cuinit.py +++ b/python/cudf/cudf/tests/test_no_cuinit.py @@ -1,4 +1,4 @@ -# Copyright (c) 2023-2024, NVIDIA CORPORATION. +# Copyright (c) 2023, NVIDIA CORPORATION. import os import subprocess @@ -109,16 +109,3 @@ 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, - cwd="/", - ) - assert output.returncode == 0 diff --git a/python/cudf/cudf/tests/test_no_device.py b/python/cudf/cudf/tests/test_no_device.py new file mode 100644 index 00000000000..722762b2d0c --- /dev/null +++ b/python/cudf/cudf/tests/test_no_device.py @@ -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 From 89f8d17b7969ea430616c6beb051be36fedb613c Mon Sep 17 00:00:00 2001 From: Vyas Ramasubramani Date: Wed, 17 Jan 2024 11:21:01 -0500 Subject: [PATCH 6/6] Apply suggestions from code review --- python/cudf/cudf/core/udf/utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/cudf/cudf/core/udf/utils.py b/python/cudf/cudf/core/udf/utils.py index e1744021c31..12baf1ea6d1 100644 --- a/python/cudf/cudf/core/udf/utils.py +++ b/python/cudf/cudf/core/udf/utils.py @@ -61,12 +61,12 @@ precompiled: cachetools.LRUCache = cachetools.LRUCache(maxsize=32) launch_arg_getters: Dict[Any, Any] = {} + @functools.cache def _ptx_file(): return _get_ptx_file( os.path.join( - os.path.dirname(strings_udf.__file__), - "..", "core", "udf" + os.path.dirname(strings_udf.__file__), "..", "core", "udf" ), "shim_", )