Skip to content

Commit 95e8d54

Browse files
Fix type annotations in cuda.nvbench, and in examples
1 parent b56d37a commit 95e8d54

File tree

6 files changed

+52
-43
lines changed

6 files changed

+52
-43
lines changed

python/cuda/nvbench/__init__.pyi

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,27 @@ class Benchmark:
4343
Use `~register` function to create Benchmark and register
4444
it with NVBench.
4545
"""
46-
def getName(self) -> str:
46+
def get_name(self) -> str:
4747
"Get benchmark name"
4848
...
49-
def addInt64Axis(self, name: str, values: Sequence[int]) -> Self:
49+
def add_int64_axis(self, name: str, values: Sequence[int]) -> Self:
5050
"Add integral type parameter axis with given name and values to sweep over"
5151
...
52-
def addFloat64Axis(self, name: str, values: Sequence[float]) -> Self:
52+
def add_float64_axis(self, name: str, values: Sequence[float]) -> Self:
5353
"Add floating-point type parameter axis with given name and values to sweep over"
5454
...
55-
def addStringAxis(sef, name: str, values: Sequence[str]) -> Self:
55+
def add_string_axis(sef, name: str, values: Sequence[str]) -> Self:
5656
"Add string type parameter axis with given name and values to sweep over"
5757
...
58+
def set_name(self, name: str) -> Self:
59+
""
60+
...
61+
def set_is_cpu_only(self, is_cpu_only: bool) -> Self:
62+
"Set whether this benchmark only executes on CPU"
63+
...
64+
def set_run_once(self, v: bool) -> Self:
65+
"Set whether all benchmark configurations are executed only once"
66+
...
5867

5968
class Launch:
6069
"""Configuration object for function launch.
@@ -63,7 +72,7 @@ class Launch:
6372
----
6473
The class is not user-constructible.
6574
"""
66-
def getStream(self) -> CudaStream:
75+
def get_stream(self) -> CudaStream:
6776
"Get CUDA stream of this configuration"
6877
...
6978

@@ -74,92 +83,91 @@ class State:
7483
----
7584
The class is not user-constructible.
7685
"""
77-
def hasDevice(self) -> bool:
86+
def has_device(self) -> bool:
7887
"True if configuration has a device"
7988
...
80-
def hasPrinters(self) -> bool:
89+
def has_printers(self) -> bool:
8190
"True if configuration has a printer"
8291
...
83-
def getDevice(self) -> Union[int, None]:
92+
def get_device(self) -> Union[int, None]:
8493
"Get device_id of the device from this configuration"
8594
...
86-
def getStream(self) -> CudaStream:
95+
def get_stream(self) -> CudaStream:
8796
"CudaStream object from this configuration"
8897
...
89-
def getInt64(self, name: str, default_value: Optional[int] = None) -> int:
98+
def get_int64(self, name: str, default_value: Optional[int] = None) -> int:
9099
"Get value for given Int64 axis from this configuration"
91100
...
92-
def getFloat64(self, name: str, default_value: Optional[float] = None) -> float:
101+
def get_float64(self, name: str, default_value: Optional[float] = None) -> float:
93102
"Get value for given Float64 axis from this configuration"
94103
...
95-
def getString(self, name: str, default_value: Optional[str] = None) -> str:
104+
def get_string(self, name: str, default_value: Optional[str] = None) -> str:
96105
"Get value for given String axis from this configuration"
97106
...
98-
def addElementCount(self, count: int, column_name: Optional[str] = None) -> None:
107+
def add_element_count(self, count: int, column_name: Optional[str] = None) -> None:
99108
"Add element count"
100109
...
101-
def setElementCount(self, count: int) -> None:
110+
def set_element_count(self, count: int) -> None:
102111
"Set element count"
103112
...
104-
def getElementCount(self) -> int:
113+
def get_element_count(self) -> int:
105114
"Get element count"
106115
...
107116
def skip(self, reason: str) -> None:
108117
"Skip this configuration"
109118
...
110-
def isSkipped(self) -> bool:
119+
def is_skipped(self) -> bool:
111120
"Has this configuration been skipped"
112121
...
113-
def getSkipReason(self) -> str:
122+
def get_skip_reason(self) -> str:
114123
"Get reason provided for skipping this configuration"
115124
...
116-
def addGlobalMemoryReads(self, nbytes: int) -> None:
125+
def add_global_memory_reads(self, nbytes: int, /, column_name: str = "") -> None:
117126
"Inform NVBench that given amount of bytes is being read by the benchmark from global memory"
118127
...
119-
def addGlobalMemoryWrites(self, nbytes: int) -> None:
128+
def add_global_memory_writes(self, nbytes: int, /, column_name: str = "") -> None:
120129
"Inform NVBench that given amount of bytes is being written by the benchmark into global memory"
121130
...
122-
def getBenchmark(self) -> Benchmark:
131+
def get_benchmark(self) -> Benchmark:
123132
"Get Benchmark this configuration is a part of"
124133
...
125-
def getThrottleThreshold(self) -> float:
134+
def get_throttle_threshold(self) -> float:
126135
"Get throttle threshold value"
127136
...
128-
def getMinSamples(self) -> int:
137+
def get_min_samples(self) -> int:
129138
"Get the number of benchmark timings NVBench performs before stopping criterion begins being used"
130139
...
131-
def setMinSamples(self, count: int) -> None:
140+
def set_min_samples(self, count: int) -> None:
132141
"Set the number of benchmark timings for NVBench to perform before stopping criterion begins being used"
133142
...
134-
def getDisableBlockingKernel(self) -> bool:
143+
def get_disable_blocking_kernel(self) -> bool:
135144
"True if use of blocking kernel by NVBench is disabled, False otherwise"
136145
...
137-
def setDisableBlockingKernel(self, flag: bool) -> None:
146+
def set_disable_blocking_kernel(self, flag: bool) -> None:
138147
"Use flag = True to disable use of blocking kernel by NVBench"
139148
...
140-
def getRunOnce(self) -> bool:
149+
def get_run_once(self) -> bool:
141150
"Boolean flag whether configuration should only run once"
142151
...
143-
144-
def setRunOnce(self, flag: bool) -> None:
152+
def set_run_once(self, flag: bool) -> None:
145153
"Set run-once flag for this configuration"
146154
...
147-
def getTimeout(self) -> float:
155+
def get_timeout(self) -> float:
148156
"Get time-out value for benchmark execution of this configuration"
149157
...
150-
def setTimeout(self, duration: float) -> None:
158+
def set_timeout(self, duration: float) -> None:
151159
"Set time-out value for benchmark execution of this configuration"
152160
...
153-
def getBlockingKernelTimeout(self) -> float:
161+
def get_blocking_kernel_timeout(self) -> float:
154162
"Get time-out value for execution of blocking kernel"
155163
...
156-
def setBlockingKernelTimeout(self, duration: float) -> None:
164+
def set_blocking_kernel_timeout(self, duration: float) -> None:
157165
"Set time-out value for execution of blocking kernel"
158166
...
159-
def collectCUPTIMetrics(self) -> None:
167+
def collect_cupti_metrics(self) -> None:
160168
"Request NVBench to record CUPTI metrics while running benchmark for this configuration"
161169
...
162-
def isCUPTIRequired(self) -> bool:
170+
def is_cupti_required(self) -> bool:
163171
"True if (some) CUPTI metrics are being collected"
164172
...
165173
def exec(
@@ -187,6 +195,9 @@ class State:
187195
Default: `False`.
188196
"""
189197
...
198+
def get_short_description(self) -> str:
199+
"Get short description for this configuration"
200+
...
190201
def add_summary(self, column_name: str, value: Union[int, float, str]) -> None:
191202
"Add summary column with a value"
192203
...

python/examples/auto_throughput.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# limitations under the License.
1616

1717
import sys
18-
from collections.abc import Callable
1918

2019
import cuda.nvbench as nvbench
2120
import numpy as np
@@ -26,7 +25,7 @@ def as_cuda_Stream(cs: nvbench.CudaStream) -> cuda.cudadrv.driver.Stream:
2625
return cuda.external_stream(cs.addressof())
2726

2827

29-
def make_kernel(items_per_thread: int) -> Callable:
28+
def make_kernel(items_per_thread: int) -> cuda.compiler.AutoJitCUDAKernel:
3029
@cuda.jit
3130
def kernel(stride: np.uintp, elements: np.uintp, in_arr, out_arr):
3231
tid = cuda.grid(1)

python/examples/axes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ctypes
22
import sys
3-
from typing import Optional
3+
from typing import Dict, Optional, Tuple
44

55
import cuda.cccl.headers as headers
66
import cuda.core.experimental as core
@@ -134,7 +134,7 @@ def launcher(launch: nvbench.Launch):
134134
def copy_type_sweep(state: nvbench.State):
135135
type_id = state.get_int64("TypeID")
136136

137-
types_map = {
137+
types_map: Dict[int, Tuple[type, str]] = {
138138
0: (ctypes.c_uint8, "cuda::std::uint8_t"),
139139
1: (ctypes.c_uint16, "cuda::std::uint16_t"),
140140
2: (ctypes.c_uint32, "cuda::std::uint32_t"),
@@ -148,7 +148,7 @@ def copy_type_sweep(state: nvbench.State):
148148

149149
# Number of elements in 256MiB
150150
nbytes = 256 * 1024 * 1024
151-
num_values = nbytes // ctypes.sizeof(value_ctype(0))
151+
num_values = nbytes // ctypes.sizeof(value_ctype)
152152

153153
state.add_element_count(num_values)
154154
state.add_global_memory_reads(nbytes)

python/examples/cccl_parallel_segmented_reduce.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def as_cccl_Stream(cs: nvbench.CudaStream) -> CCCLStream:
2727

2828

2929
def as_cp_ExternalStream(
30-
cs: nvbench.CudaStream, dev_id: int = -1
30+
cs: nvbench.CudaStream, dev_id: int | None = -1
3131
) -> cp.cuda.ExternalStream:
3232
h = cs.addressof()
3333
return cp.cuda.ExternalStream(h, dev_id)

python/examples/cupy_extract.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66

77
def as_cp_ExternalStream(
8-
cs: nvbench.CudaStream, dev_id: int = -1
8+
cs: nvbench.CudaStream, dev_id: int | None = -1
99
) -> cp.cuda.ExternalStream:
1010
h = cs.addressof()
1111
return cp.cuda.ExternalStream(h, dev_id)

python/examples/throughput.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
# limitations under the License.
1616

1717
import sys
18-
from collections.abc import Callable
1918

2019
import cuda.nvbench as nvbench
2120
import numpy as np
@@ -26,7 +25,7 @@ def as_cuda_Stream(cs: nvbench.CudaStream) -> cuda.cudadrv.driver.Stream:
2625
return cuda.external_stream(cs.addressof())
2726

2827

29-
def make_kernel(items_per_thread: int) -> Callable:
28+
def make_kernel(items_per_thread: int) -> cuda.compiler.AutoJitCUDAKernel:
3029
@cuda.jit
3130
def kernel(stride: np.uintp, elements: np.uintp, in_arr, out_arr):
3231
tid = cuda.grid(1)

0 commit comments

Comments
 (0)