mirror of
https://github.com/NVIDIA/nvbench.git
synced 2026-05-13 17:55:39 +00:00
cuda.bench.register(fn) continues returning Benchmark, and supports
legacy use.
New signature added:
cuda.bench.register():
Returns a decorator
```
@bench.register()
@bench.axis.float64("Duration (s)", [7e-5, 1e-4, 5e-4])
@bench.option.min_samples(120)
def single_float64_axis(state: bench.State):
...
```
58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
# Copyright 2025-2026 NVIDIA Corporation
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 with the LLVM exception
|
|
# (the "License"); you may not use this file except in compliance with
|
|
# the License.
|
|
#
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://llvm.org/foundation/relicensing/LICENSE.txt
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import sys
|
|
|
|
import cuda.bench as bench
|
|
import cupy as cp
|
|
|
|
|
|
def as_cp_ExternalStream(cs: bench.CudaStream):
|
|
return cp.cuda.Stream.from_external(cs)
|
|
|
|
|
|
@bench.register()
|
|
@bench.axis.int64("numCols", [1024, 2048, 4096, 2 * 4096])
|
|
@bench.axis.int64("numRows", [1024, 2048, 4096, 2 * 4096])
|
|
def cupy_extract_by_mask(state: bench.State):
|
|
n_cols = state.get_int64("numCols")
|
|
n_rows = state.get_int64("numRows")
|
|
|
|
cp_s = as_cp_ExternalStream(state.get_stream())
|
|
|
|
state.add_element_count(n_rows * n_cols, "# Elements")
|
|
int32_dt = cp.dtype(cp.int32)
|
|
bool_dt = cp.dtype(cp.bool_)
|
|
state.add_global_memory_reads(
|
|
n_rows * n_cols * (int32_dt.itemsize + bool_dt.itemsize)
|
|
)
|
|
state.add_global_memory_writes(n_rows * n_cols * (int32_dt.itemsize))
|
|
|
|
with cp_s:
|
|
X = cp.full((n_cols, n_rows), fill_value=3, dtype=int32_dt)
|
|
mask = cp.ones((n_cols, n_rows), dtype=bool_dt)
|
|
_ = X[mask]
|
|
|
|
def launcher(launch: bench.Launch):
|
|
with as_cp_ExternalStream(launch.get_stream()):
|
|
_ = X[mask]
|
|
|
|
state.exec(launcher, sync=True)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
bench.run_all_benchmarks(sys.argv)
|