From 0ee77457c8294c0706f6fda3de0a1a64097493b4 Mon Sep 17 00:00:00 2001 From: Kaushik Kulkarni Date: Thu, 11 Aug 2022 23:54:39 -0500 Subject: [PATCH 1/2] use importlib to get the pycuda location pkg_resources is returning incorrect location for pip==22.2 --- pycuda/compiler.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pycuda/compiler.py b/pycuda/compiler.py index b84a0716..369b6375 100644 --- a/pycuda/compiler.py +++ b/pycuda/compiler.py @@ -206,9 +206,12 @@ def _get_per_user_string(): def _find_pycuda_include_path(): - from pkg_resources import Requirement, resource_filename + import importlib.util + import os - return resource_filename(Requirement.parse("pycuda"), "pycuda/cuda") + return os.path.abspath( + os.path.join(importlib.util.find_spec("pycuda").origin, + os.path.join(os.path.pardir, "cuda"))) DEFAULT_NVCC_FLAGS = [ -- GitLab From 9dbc4894e88276bec48c9b327931a2b89040e8dc Mon Sep 17 00:00:00 2001 From: Mit Kotak Date: Tue, 16 Aug 2022 13:45:59 -0500 Subject: [PATCH 2/2] added scalar | numpy args to unary_func --- pycuda/compiler.py | 7 +++++-- pycuda/cumath.py | 14 ++++++++++++++ test/test_cumath.py | 2 ++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/pycuda/compiler.py b/pycuda/compiler.py index b84a0716..369b6375 100644 --- a/pycuda/compiler.py +++ b/pycuda/compiler.py @@ -206,9 +206,12 @@ def _get_per_user_string(): def _find_pycuda_include_path(): - from pkg_resources import Requirement, resource_filename + import importlib.util + import os - return resource_filename(Requirement.parse("pycuda"), "pycuda/cuda") + return os.path.abspath( + os.path.join(importlib.util.find_spec("pycuda").origin, + os.path.join(os.path.pardir, "cuda"))) DEFAULT_NVCC_FLAGS = [ diff --git a/pycuda/cumath.py b/pycuda/cumath.py index ab2b32c8..25c0541d 100644 --- a/pycuda/cumath.py +++ b/pycuda/cumath.py @@ -25,6 +25,14 @@ def _make_unary_array_func(name): if "stream" in kwargs: stream = kwargs["stream"] + if np.isscalar(array): + if out is None: + out = gpuarray.GPUArray(shape=(), dtype=np.dtype(type(array))) + out[...] = gpuarray.to_gpu(np.array(getattr(np, + numpy_func_names.get(name, name))(array))) + + return out + if array.dtype == np.float32: func_name = name + "f" else: @@ -57,6 +65,12 @@ def _make_unary_array_func(name): return f +numpy_func_names = { + "asin": "arcsin", + "acos": "arccos", + "atan": "arctan", +} + fabs = _make_unary_array_func("fabs") ceil = _make_unary_array_func("ceil") floor = _make_unary_array_func("floor") diff --git a/test/test_cumath.py b/test/test_cumath.py index 2db96d15..021a87f5 100644 --- a/test/test_cumath.py +++ b/test/test_cumath.py @@ -37,11 +37,13 @@ def make_unary_function_test(name, a=0, b=1, threshold=0, complex=False): A += (np.random.random(s) * (b - a) + a) * 1j args = gpuarray.to_gpu(A) + scalar = np.random.random() gpu_results = gpu_func(args).get() cpu_results = cpu_func(A) max_err = np.max(np.abs(cpu_results - gpu_results)) assert (max_err <= threshold).all(), (max_err, name, dtype) + np.testing.assert_array_equal(gpu_func(scalar), cpu_func(scalar)) gpu_results2 = gpuarray.empty_like(args) gr2 = gpu_func(args, out=gpu_results2) -- GitLab