Skip to content

Commit eac56d6

Browse files
committed
fix the cuda_bindings side
1 parent ece9727 commit eac56d6

34 files changed

+286
-243
lines changed

cuda_bindings/benchmarks/kernels.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# is strictly prohibited.
88
kernel_string = """\
99
#define ITEM_PARAM(x, T) T x
10-
#define REP1(x, T) , ITEM_PARAM(x, T)
10+
#define REP1(x, T) , ITEM_PARAM(x, T)
1111
#define REP2(x, T) REP1(x##0, T) REP1(x##1, T)
1212
#define REP4(x, T) REP2(x##0, T) REP2(x##1, T)
1313
#define REP8(x, T) REP4(x##0, T) REP4(x##1, T)

cuda_bindings/benchmarks/perf_test_utils.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@
55
# this software. Any use, reproduction, disclosure, or distribution of
66
# this software and related documentation outside the terms of the EULA
77
# is strictly prohibited.
8+
import numpy as np
89
import pytest
10+
911
from cuda import cuda, cudart, nvrtc
10-
import numpy as np
1112

1213

1314
def ASSERT_DRV(err):
1415
if isinstance(err, cuda.CUresult):
1516
if err != cuda.CUresult.CUDA_SUCCESS:
16-
raise RuntimeError("Cuda Error: {}".format(err))
17+
raise RuntimeError(f"Cuda Error: {err}")
1718
elif isinstance(err, cudart.cudaError_t):
1819
if err != cudart.cudaError_t.cudaSuccess:
19-
raise RuntimeError("Cudart Error: {}".format(err))
20+
raise RuntimeError(f"Cudart Error: {err}")
2021
elif isinstance(err, nvrtc.nvrtcResult):
2122
if err != nvrtc.nvrtcResult.NVRTC_SUCCESS:
22-
raise RuntimeError("Nvrtc Error: {}".format(err))
23+
raise RuntimeError(f"Nvrtc Error: {err}")
2324
else:
24-
raise RuntimeError("Unknown error type: {}".format(err))
25+
raise RuntimeError(f"Unknown error type: {err}")
2526

2627

2728
@pytest.fixture

cuda_bindings/benchmarks/test_cupy.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
# this software. Any use, reproduction, disclosure, or distribution of
66
# this software and related documentation outside the terms of the EULA
77
# is strictly prohibited.
8-
import pytest
98
import ctypes
109

10+
import pytest
11+
1112
# Always skip since cupy is not CTK 12.x yet
1213
skip_tests = True
1314
if not skip_tests:

cuda_bindings/benchmarks/test_launch_latency.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
# this software. Any use, reproduction, disclosure, or distribution of
66
# this software and related documentation outside the terms of the EULA
77
# is strictly prohibited.
8+
import ctypes
9+
810
import pytest
11+
912
from cuda import cuda
10-
import ctypes
1113

12-
from .perf_test_utils import ASSERT_DRV
1314
from .kernels import kernel_string
15+
from .perf_test_utils import ASSERT_DRV
1416

1517

1618
def launch(kernel, stream, args=(), arg_types=()):
@@ -310,7 +312,7 @@ def test_launch_latency_small_kernel_512_args_ctypes_with_packing(
310312
ASSERT_DRV(err)
311313

312314
vals = []
313-
for i in range(512):
315+
for _i in range(512):
314316
err, p = cuda.cuMemAlloc(ctypes.sizeof(ctypes.c_int))
315317
ASSERT_DRV(err)
316318
vals.append(p)

cuda_bindings/benchmarks/test_numba.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
# this software. Any use, reproduction, disclosure, or distribution of
66
# this software and related documentation outside the terms of the EULA
77
# is strictly prohibited.
8-
import pytest
98
import numpy as np
9+
import pytest
1010

1111
try:
1212
from numba import cuda

cuda_bindings/benchmarks/test_pointer_attributes.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
# this software. Any use, reproduction, disclosure, or distribution of
66
# this software and related documentation outside the terms of the EULA
77
# is strictly prohibited.
8+
import random
9+
810
import pytest
11+
912
from cuda import cuda
10-
import random
1113

1214
from .perf_test_utils import ASSERT_DRV
1315

cuda_bindings/cuda/bindings/_version.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
"""Git implementation of _version.py."""
1212

1313
import errno
14+
import functools
1415
import os
1516
import re
1617
import subprocess
1718
import sys
1819
from typing import Any, Callable, Dict, List, Optional, Tuple
19-
import functools
2020

2121

2222
def get_keywords() -> Dict[str, str]:
@@ -114,18 +114,18 @@ def run_command(
114114
if e.errno == errno.ENOENT:
115115
continue
116116
if verbose:
117-
print("unable to run %s" % dispcmd)
117+
print(f"unable to run {dispcmd}")
118118
print(e)
119119
return None, None
120120
else:
121121
if verbose:
122-
print("unable to find command, tried %s" % (commands,))
122+
print(f"unable to find command, tried {commands}")
123123
return None, None
124124
stdout = process.communicate()[0].strip().decode()
125125
if process.returncode != 0:
126126
if verbose:
127-
print("unable to run %s (error)" % dispcmd)
128-
print("stdout was %s" % stdout)
127+
print(f"unable to run {dispcmd} (error)")
128+
print(f"stdout was {stdout}")
129129
return None, process.returncode
130130
return stdout, process.returncode
131131

@@ -158,8 +158,7 @@ def versions_from_parentdir(
158158

159159
if verbose:
160160
print(
161-
"Tried directories %s but none started with prefix %s"
162-
% (str(rootdirs), parentdir_prefix)
161+
f"Tried directories {str(rootdirs)} but none started with prefix {parentdir_prefix}"
163162
)
164163
raise NotThisMethod("rootdir doesn't start with parentdir_prefix")
165164

@@ -173,7 +172,7 @@ def git_get_keywords(versionfile_abs: str) -> Dict[str, str]:
173172
# _version.py.
174173
keywords: Dict[str, str] = {}
175174
try:
176-
with open(versionfile_abs, "r") as fobj:
175+
with open(versionfile_abs) as fobj:
177176
for line in fobj:
178177
if line.strip().startswith("git_refnames ="):
179178
mo = re.search(r'=\s*"(.*)"', line)
@@ -234,9 +233,9 @@ def git_versions_from_keywords(
234233
# "stabilization", as well as "HEAD" and "master".
235234
tags = {r for r in refs if re.search(r"\d", r)}
236235
if verbose:
237-
print("discarding '%s', no digits" % ",".join(refs - tags))
236+
print("discarding '{}', no digits".format(",".join(refs - tags)))
238237
if verbose:
239-
print("likely tags: %s" % ",".join(sorted(tags)))
238+
print("likely tags: {}".format(",".join(sorted(tags))))
240239
for ref in sorted(tags):
241240
# sorting will prefer e.g. "2.0" over "2.0rc1"
242241
if ref.startswith(tag_prefix):
@@ -247,7 +246,7 @@ def git_versions_from_keywords(
247246
if not re.match(r"\d", r):
248247
continue
249248
if verbose:
250-
print("picking %s" % r)
249+
print(f"picking {r}")
251250
return {
252251
"version": r,
253252
"full-revisionid": keywords["full"].strip(),
@@ -291,7 +290,7 @@ def git_pieces_from_vcs(
291290
_, rc = runner(GITS, ["rev-parse", "--git-dir"], cwd=root, hide_stderr=not verbose)
292291
if rc != 0:
293292
if verbose:
294-
print("Directory %s not under git control" % root)
293+
print(f"Directory {root} not under git control")
295294
raise NotThisMethod("'git rev-parse --git-dir' returned error")
296295

297296
# if there is a tag matching tag_prefix, this yields TAG-NUM-gHEX[-dirty]
@@ -372,7 +371,7 @@ def git_pieces_from_vcs(
372371
mo = re.search(r"^(.+)-(\d+)-g([0-9a-f]+)$", git_describe)
373372
if not mo:
374373
# unparsable. Maybe git-describe is misbehaving?
375-
pieces["error"] = "unable to parse git-describe output: '%s'" % describe_out
374+
pieces["error"] = f"unable to parse git-describe output: '{describe_out}'"
376375
return pieces
377376

378377
# tag
@@ -381,10 +380,7 @@ def git_pieces_from_vcs(
381380
if verbose:
382381
fmt = "tag '%s' doesn't start with prefix '%s'"
383382
print(fmt % (full_tag, tag_prefix))
384-
pieces["error"] = "tag '%s' doesn't start with prefix '%s'" % (
385-
full_tag,
386-
tag_prefix,
387-
)
383+
pieces["error"] = f"tag '{full_tag}' doesn't start with prefix '{tag_prefix}'"
388384
return pieces
389385
pieces["closest-tag"] = full_tag[len(tag_prefix) :]
390386

@@ -521,13 +517,13 @@ def render_pep440_post(pieces: Dict[str, Any]) -> str:
521517
if pieces["dirty"]:
522518
rendered += ".dev0"
523519
rendered += plus_or_dot(pieces)
524-
rendered += "g%s" % pieces["short"]
520+
rendered += "g{}".format(pieces["short"])
525521
else:
526522
# exception #1
527523
rendered = "0.post%d" % pieces["distance"]
528524
if pieces["dirty"]:
529525
rendered += ".dev0"
530-
rendered += "+g%s" % pieces["short"]
526+
rendered += "+g{}".format(pieces["short"])
531527
return rendered
532528

533529

@@ -546,15 +542,15 @@ def render_pep440_post_branch(pieces: Dict[str, Any]) -> str:
546542
if pieces["branch"] != "master":
547543
rendered += ".dev0"
548544
rendered += plus_or_dot(pieces)
549-
rendered += "g%s" % pieces["short"]
545+
rendered += "g{}".format(pieces["short"])
550546
if pieces["dirty"]:
551547
rendered += ".dirty"
552548
else:
553549
# exception #1
554550
rendered = "0.post%d" % pieces["distance"]
555551
if pieces["branch"] != "master":
556552
rendered += ".dev0"
557-
rendered += "+g%s" % pieces["short"]
553+
rendered += "+g{}".format(pieces["short"])
558554
if pieces["dirty"]:
559555
rendered += ".dirty"
560556
return rendered
@@ -653,7 +649,7 @@ def render(pieces: Dict[str, Any], style: str) -> Dict[str, Any]:
653649
elif style == "git-describe-long":
654650
rendered = render_git_describe_long(pieces)
655651
else:
656-
raise ValueError("unknown style '%s'" % style)
652+
raise ValueError(f"unknown style '{style}'")
657653

658654
return {
659655
"version": rendered,

cuda_bindings/docs/source/conf.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# add these directories to sys.path here. If the directory is relative to the
1111
# documentation root, use os.path.abspath to make it absolute, like shown here.
1212
import os
13+
1314
# import sys
1415
# sys.path.insert(0, os.path.abspath('.'))
1516

cuda_bindings/examples/0_Introduction/clock_nvrtc_test.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66
# this software and related documentation outside the terms of the EULA
77
# is strictly prohibited.
88
import numpy as np
9-
from cuda import cuda
109
from common import common
1110
from common.helper_cuda import checkCudaErrors, findCudaDevice
1211

12+
from cuda import cuda
13+
1314
clock_nvrtc = """\
1415
extern "C" __global__ void timedReduction(const float *hinput, float *output, clock_t *timer)
1516
{
@@ -115,7 +116,7 @@ def main():
115116
avgElapsedClocks += timer[i + NUM_BLOCKS] - timer[i]
116117

117118
avgElapsedClocks = avgElapsedClocks / NUM_BLOCKS
118-
print("Average clocks/block = {}".format(avgElapsedClocks))
119+
print(f"Average clocks/block = {avgElapsedClocks}")
119120

120121

121122
if __name__ == "__main__":

cuda_bindings/examples/0_Introduction/simpleCubemapTexture_test.py

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,15 @@
77
# is strictly prohibited.
88
import ctypes
99
import math
10-
import numpy as np
1110
import sys
1211
import time
13-
from cuda import cuda, cudart
12+
13+
import numpy as np
1414
from common import common
1515
from common.helper_cuda import checkCudaErrors, findCudaDevice
1616

17+
from cuda import cuda, cudart
18+
1719
simpleCubemapTexture = """\
1820
extern "C"
1921
__global__ void transformKernel(float *g_odata, int width, cudaTextureObject_t tex)
@@ -90,18 +92,11 @@ def main():
9092
# Get number of SMs on this GPU
9193
deviceProps = checkCudaErrors(cudart.cudaGetDeviceProperties(devID))
9294
print(
93-
"CUDA device [{}] has {} Multi-Processors SM {}.{}".format(
94-
deviceProps.name,
95-
deviceProps.multiProcessorCount,
96-
deviceProps.major,
97-
deviceProps.minor,
98-
)
95+
f"CUDA device [{deviceProps.name}] has {deviceProps.multiProcessorCount} Multi-Processors SM {deviceProps.major}.{deviceProps.minor}"
9996
)
10097
if deviceProps.major < 2:
10198
print(
102-
"{} requires SM 2.0 or higher for support of Texture Arrays. Test will exit...".format(
103-
sSDKname
104-
)
99+
"Test requires SM 2.0 or higher for support of Texture Arrays. Test will exit..."
105100
)
106101
sys.exit()
107102

@@ -175,9 +170,7 @@ def main():
175170
dimGrid.z = 1
176171

177172
print(
178-
"Covering Cubemap data array of {}~3 x {}: Grid size is {} x {}, each block has 8 x 8 threads".format(
179-
width, num_layers, dimGrid.x, dimGrid.y
180-
)
173+
f"Covering Cubemap data array of {width}~3 x {num_layers}: Grid size is {dimGrid.x} x {dimGrid.y}, each block has 8 x 8 threads"
181174
)
182175

183176
kernelHelper = common.KernelHelper(simpleCubemapTexture, devID)
@@ -222,11 +215,9 @@ def main():
222215

223216
checkCudaErrors(cudart.cudaDeviceSynchronize())
224217
stop = time.time()
225-
print("Processing time: {:.3f} msec".format(stop - start))
218+
print(f"Processing time: {stop - start:.3f} msec")
226219
print(
227-
"{:.2f} Mtexlookups/sec".format(
228-
cubemap_size / ((stop - start + 1) / 1000.0) / 1e6
229-
)
220+
f"{cubemap_size / ((stop - start + 1) / 1000.0) / 1e6:.2f} Mtexlookups/sec"
230221
)
231222

232223
# Allocate mem for the result on host side

0 commit comments

Comments
 (0)