diff --git a/aksetup_helper.py b/aksetup_helper.py index 32f80cde..311be305 100644 --- a/aksetup_helper.py +++ b/aksetup_helper.py @@ -25,7 +25,7 @@ def count_down_delay(delay): sys.stdout.flush() delay -= 1 sleep(1) - print("") + print() DASH_SEPARATOR = 75 * "-" @@ -297,7 +297,6 @@ def get_default_config(self): return dict((opt.name, opt.default) for opt in self.options) def read_config_from_pyfile(self, filename): - result = {} filevars = {} infile = open(filename) try: @@ -307,11 +306,7 @@ def read_config_from_pyfile(self, filename): exec(compile(contents, filename, "exec"), filevars) - for key, value in filevars.items(): - if key in self.optdict: - result[key] = value - - return result + return {key: value for key, value in filevars.items() if key in self.optdict} def update_conf_file(self, filename, config): result = {} @@ -324,16 +319,13 @@ def update_conf_file(self, filename, config): filevars.pop("__builtins__", None) - for key, value in config.items(): - if value is not None: - filevars[key] = value + filevars.update({key: value for key, value in config.items() if value is not None}) keys = list(filevars.keys()) keys.sort() outf = open(filename, "w") - for key in keys: - outf.write("%s = %s\n" % (key, repr(filevars[key]))) + outf.writelines("%s = %s\n" % (key, repr(filevars[key])) for key in keys) outf.close() return result @@ -520,8 +512,7 @@ def take_from_configparser(self, options): import re sep = re.compile(r"(? capability: - from warnings import warn - warn( "trying to compile for a compute capability " "higher than selected GPU", stacklevel=2 ) - except Exception: - pass + except Exception as e: + warn(f"failed to check compute capability for module: {e!s}", stacklevel=1) def _bind_module(self): self.get_global = self.module.get_global @@ -411,7 +404,7 @@ def __init__( include_dirs = [] compute_capability = Context.get_device().compute_capability() if compute_capability < (3, 5): - raise Exception( + raise RuntimeError( "Minimum compute capability for dynamic parallelism is 3.5 (found: %u.%u)!" % (compute_capability[0], compute_capability[1]) ) diff --git a/pycuda/compyte b/pycuda/compyte index f1010ef6..80ed45de 160000 --- a/pycuda/compyte +++ b/pycuda/compyte @@ -1 +1 @@ -Subproject commit f1010ef64b5d4559ca4bb7690d4b3394091477b6 +Subproject commit 80ed45de98b5432341763b9fa52a00fdac870b89 diff --git a/pycuda/cumath.py b/pycuda/cumath.py index 4ac71d58..5110105c 100644 --- a/pycuda/cumath.py +++ b/pycuda/cumath.py @@ -4,8 +4,7 @@ import numpy as np -import pycuda.elementwise as elementwise -import pycuda.gpuarray as gpuarray +from pycuda import elementwise, gpuarray from pycuda.driver import Stream diff --git a/pycuda/curandom.py b/pycuda/curandom.py index 4382b888..f31ac220 100644 --- a/pycuda/curandom.py +++ b/pycuda/curandom.py @@ -1015,8 +1015,7 @@ def _kernels(self): def generate_direction_vectors(count, direction=None): if get_curand_version() >= (4, 0, 0): if ( - direction == direction_vector_set.VECTOR_64 - or direction == direction_vector_set.SCRAMBLED_VECTOR_64 + direction in (direction_vector_set.VECTOR_64, direction_vector_set.SCRAMBLED_VECTOR_64) ): result = np.empty((count, 64), dtype=np.uint64) else: diff --git a/pycuda/debug.py b/pycuda/debug.py index f2973b08..5ed22d65 100644 --- a/pycuda/debug.py +++ b/pycuda/debug.py @@ -27,4 +27,4 @@ sys.argv = args with open(mainpyfile) as mainpy: - exec(compile(mainpy.read(), mainpyfile, "exec")) + exec(compile(mainpy.read(), mainpyfile, "exec")) # noqa: S102 diff --git a/pycuda/gpuarray.py b/pycuda/gpuarray.py index f208a286..41afeca0 100644 --- a/pycuda/gpuarray.py +++ b/pycuda/gpuarray.py @@ -15,7 +15,7 @@ from pytools import memoize, memoize_method import pycuda.driver as drv -import pycuda.elementwise as elementwise +from pycuda import elementwise from pycuda.characterize import has_double_support from pycuda.compyte.array import ( ArrayFlags as _ArrayFlags, @@ -1345,10 +1345,9 @@ def _array_like_helper(other_ary, dtype, order): def empty_like(other_ary, dtype=None, order="K"): dtype, order, strides = _array_like_helper(other_ary, dtype, order) - result = GPUArray( + return GPUArray( other_ary.shape, dtype, other_ary.allocator, order=order, strides=strides ) - return result def zeros_like(other_ary, dtype=None, order="K"): diff --git a/pycuda/scan.py b/pycuda/scan.py index 65a9b0d6..48c3dc45 100644 --- a/pycuda/scan.py +++ b/pycuda/scan.py @@ -28,8 +28,7 @@ import numpy as np import pycuda._mymako as mako -import pycuda.driver as driver -import pycuda.gpuarray as gpuarray +from pycuda import driver, gpuarray from pycuda._cluda import CLUDA_PREAMBLE from pycuda.compiler import SourceModule from pycuda.tools import dtype_to_ctype diff --git a/pycuda/sparse/cg.py b/pycuda/sparse/cg.py index 4079c1fa..fbf341a6 100644 --- a/pycuda/sparse/cg.py +++ b/pycuda/sparse/cg.py @@ -5,7 +5,7 @@ from pytools import memoize_method import pycuda.driver as drv -import pycuda.gpuarray as gpuarray +from pycuda import gpuarray from pycuda.sparse.inner import AsyncInnerProduct diff --git a/pycuda/sparse/coordinate.py b/pycuda/sparse/coordinate.py index 13191a86..4b7e0a19 100644 --- a/pycuda/sparse/coordinate.py +++ b/pycuda/sparse/coordinate.py @@ -5,7 +5,7 @@ from pytools import memoize_method import pycuda.driver as drv -import pycuda.gpuarray as gpuarray +from pycuda import gpuarray from pycuda.compiler import SourceModule diff --git a/pycuda/sparse/inner.py b/pycuda/sparse/inner.py index 7e61498f..4400b0c8 100644 --- a/pycuda/sparse/inner.py +++ b/pycuda/sparse/inner.py @@ -3,7 +3,7 @@ import atexit import pycuda.driver as drv -import pycuda.gpuarray as gpuarray +from pycuda import gpuarray STREAM_POOL = [] diff --git a/pycuda/sparse/packeted.py b/pycuda/sparse/packeted.py index c06ae322..bbbb397d 100644 --- a/pycuda/sparse/packeted.py +++ b/pycuda/sparse/packeted.py @@ -4,7 +4,7 @@ from pytools import memoize_method -import pycuda.gpuarray as gpuarray +from pycuda import gpuarray from pycuda.compiler import SourceModule diff --git a/pycuda/sparse/pkt_build.py b/pycuda/sparse/pkt_build.py index 235e1a0f..1746d187 100644 --- a/pycuda/sparse/pkt_build.py +++ b/pycuda/sparse/pkt_build.py @@ -2,7 +2,7 @@ import numpy as np -import pycuda.gpuarray as gpuarray +from pycuda import gpuarray def build_pkt_data_structure( diff --git a/pycuda/tools.py b/pycuda/tools.py index e37e616f..d30b1d35 100644 --- a/pycuda/tools.py +++ b/pycuda/tools.py @@ -1,4 +1,4 @@ -"""Miscallenous helper functionality.""" +"""Miscellaneous helper functionality.""" from __future__ import annotations @@ -198,7 +198,7 @@ def ctx_maker(dev): assert homedir is not None with open(os.path.join(homedir, ".cuda_device")) as devrc: devn = devrc.read().strip() - except Exception: + except Exception: # noqa: S110 pass # If either CUDA_DEVICE or $HOME/.cuda_device is set, try to use it @@ -314,7 +314,7 @@ def align_words(self, word_size): def align_bytes(self, word_size=4): if word_size == 4: return 64 - elif word_size == 8 or word_size == 16: + elif word_size in {8, 16}: return 128 else: raise ValueError("no alignment possible for fetches of size %d" % word_size) diff --git a/pyproject.toml b/pyproject.toml index 394b9f68..6c5c5fa3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -45,6 +45,7 @@ extend-ignore = [ "SIM108", # ternary instead of if-then-else "RUF067", # no code in __init__ *shrug* "RUF069", # unreliable FP comparison + "BLE001", ] [tool.ruff.lint.flake8-quotes] @@ -67,12 +68,15 @@ required-imports = ["from __future__ import annotations"] extend-ignore-names = ["update_for_*"] [tool.ruff.lint.per-file-ignores] +"doc/conf.py" = ["S102"] "test/test_*.py" = [ "N806", # upper case locals + "S102", ] "setup.py" = [ "N806", # upper case locals "SIM115", # context manager for files + "S102", ] "pycuda/sparse/coordinate.py" = [ "E501", # line length @@ -85,7 +89,7 @@ extend-ignore-names = ["update_for_*"] "E501", # line length ] "examples/from-wiki/*.py" = [ - "F", "E", "N", "B" + "F", "E", "N", "B", "EXE001", "PLW", ] "examples/demo_cdpSimplePrint.py" = [ "E501", # line length @@ -93,6 +97,6 @@ extend-ignore-names = ["update_for_*"] ] "aksetup_helper.py" = [ # effectively unmaintained, will go away - "UP", "C", "E501", "B", "SIM", "RUF", + "UP", "C", "E501", "B", "SIM", "RUF", "S102", "S110", "TRY" ] "test/undistributed/*.py" = ["B"] diff --git a/setup.py b/setup.py index a15ef2b8..bf3c1c51 100644 --- a/setup.py +++ b/setup.py @@ -1,4 +1,3 @@ -#!/usr/bin/env python from __future__ import annotations from os.path import dirname, join, normpath diff --git a/test/test_cumath.py b/test/test_cumath.py index 4267e120..7951963a 100644 --- a/test/test_cumath.py +++ b/test/test_cumath.py @@ -4,9 +4,8 @@ import numpy as np -import pycuda.cumath as cumath import pycuda.driver as drv # noqa -import pycuda.gpuarray as gpuarray +from pycuda import cumath, gpuarray from pycuda.tools import mark_cuda_test diff --git a/test/test_driver.py b/test/test_driver.py index 5e9befe7..cf9ca89e 100644 --- a/test/test_driver.py +++ b/test/test_driver.py @@ -11,7 +11,7 @@ import pytest import pycuda.driver as drv -import pycuda.gpuarray as gpuarray +from pycuda import gpuarray from pycuda.compiler import SourceModule from pycuda.tools import dtype_to_ctype, mark_cuda_test @@ -141,7 +141,7 @@ def test_streamed_kernel(self): def test_gpuarray(self): a = np.arange(200000, dtype=np.float32) b = a + 17 - import pycuda.gpuarray as gpuarray + from pycuda import gpuarray a_g = gpuarray.to_gpu(a) b_g = gpuarray.to_gpu(b) @@ -172,7 +172,7 @@ def test_gpuarray_cai(self): def donottest_cublas_mixing(self): self.test_streamed_kernel() - import pycuda.blas as blas + from pycuda import blas shape = (10,) a = blas.ones(shape, dtype=np.float32) @@ -675,7 +675,7 @@ def test_large_smem(self): kernel = mod.get_function("kernel") - import pycuda.gpuarray as gpuarray + from pycuda import gpuarray arg = gpuarray.zeros((n,), dtype=np.float32) diff --git a/test/test_gpuarray.py b/test/test_gpuarray.py index 18516a46..630bedce 100644 --- a/test/test_gpuarray.py +++ b/test/test_gpuarray.py @@ -1,4 +1,3 @@ -#! /usr/bin/env python from __future__ import annotations import operator @@ -9,7 +8,7 @@ import pytest import pycuda.driver as drv -import pycuda.gpuarray as gpuarray +from pycuda import gpuarray from pycuda.characterize import has_double_support from pycuda.compiler import SourceModule from pycuda.tools import init_cuda_context_fixture @@ -765,7 +764,7 @@ def test_reverse(self): b = a_cpu.get() - for i in range(0, 10): + for i in range(10): assert a[len(a) - 1 - i] == b[i] def test_sum(self): @@ -996,7 +995,7 @@ def test_2d_slice_c(self): assert la.norm(a_gpu_slice.get() - a_slice) == 0 def test_2d_slice_f(self): - import pycuda.gpuarray as gpuarray + from pycuda import gpuarray from pycuda.curandom import rand as curand n = 1000 @@ -1023,7 +1022,7 @@ def test_where(self): b = np.array([2, 2, 2]) c = np.array([3, 3, 3]) - import pycuda.gpuarray as gpuarray + from pycuda import gpuarray a_gpu = gpuarray.to_gpu(a) b_gpu = gpuarray.to_gpu(b) @@ -1043,7 +1042,7 @@ def test_if_positive(self): a = a_gpu.get() b = b_gpu.get() - import pycuda.gpuarray as gpuarray + from pycuda import gpuarray max_a_b_gpu = gpuarray.maximum(a_gpu, b_gpu) min_a_b_gpu = gpuarray.minimum(a_gpu, b_gpu) @@ -1479,7 +1478,7 @@ def test_minimum_maximum_scalar(self): a_gpu = curand((sz,)) a = a_gpu.get() - import pycuda.gpuarray as gpuarray + from pycuda import gpuarray max_a0_gpu = gpuarray.maximum(a_gpu, 0) min_a0_gpu = gpuarray.minimum(0, a_gpu) @@ -1546,7 +1545,7 @@ def test_copy(self): ) def test_get_set(self): - import pycuda.gpuarray as gpuarray + from pycuda import gpuarray a = np.random.normal(0.0, 1.0, (4, 4)) a_gpu = gpuarray.to_gpu(a) diff --git a/test/undistributed/elwise-perf.py b/test/undistributed/elwise-perf.py index 960c275b..de2270a4 100644 --- a/test/undistributed/elwise-perf.py +++ b/test/undistributed/elwise-perf.py @@ -9,7 +9,7 @@ def main(): tbl = Table() tbl.add_row(("size [MiB]", "time [s]", "mem.bw [GB/s]")) - import pycuda.gpuarray as gpuarray + from pycuda import gpuarray # they're floats, i.e. 4 bytes each for power in range(10, 28): diff --git a/test/undistributed/measure_gpuarray_speed.py b/test/undistributed/measure_gpuarray_speed.py index 4e441fde..1edb4dc2 100755 --- a/test/undistributed/measure_gpuarray_speed.py +++ b/test/undistributed/measure_gpuarray_speed.py @@ -7,7 +7,7 @@ def main(): - import pycuda.gpuarray as gpuarray + from pycuda import gpuarray sizes = [] times_gpu = []