diff --git a/docs/user-tutorial/benchmarks/micro-benchmarks.md b/docs/user-tutorial/benchmarks/micro-benchmarks.md index 4b385c10d..7ff3f769b 100644 --- a/docs/user-tutorial/benchmarks/micro-benchmarks.md +++ b/docs/user-tutorial/benchmarks/micro-benchmarks.md @@ -441,22 +441,44 @@ For measurements of peer-to-peer communication performance between AMD GPUs, GPU #### Introduction -Measure the memory bandwidth of GPU using the STREAM benchmark. The benchmark tests various memory operations including copy, scale, add, and triad for double and float datatypes. +Measures Copy, Scale, Add, and Triad memory bandwidth for one `data_type` (`float` or `double`, default `double`). Use a separate benchmark entry for each data type. -__Note__: When `--check_data` is enabled, each process allocates 6× `--size` bytes of host memory (data\_buf + check\_buf + 4 validation buffers, e.g. 24 GiB with the default 4 GiB `--size`). Under `default_local_mode` with 8 GPUs this totals ~192 GiB of host RAM. Recommend using a small `--size` such as `1048576` (1 MiB) when `--check_data` is enabled. +By default, each operation sweeps block sizes (128, 256, 512, 1024) and unroll factors (1, 2, 3, 4, 6, 8) and reports the best result. `kernel_configs` sets `block_size` and `unroll` per operation as inline JSON; unlisted operations still sweep. `size` is bytes per array (default 8 GiB). `check_data` validates output outside timing and needs 6x `size` in host memory, so use small size like 1048576. + +Native sweep: + +```yaml +gpu-stream:fp64: + <<: *default_local_mode + parameters: + data_type: double +``` + +Fixed launch configuration: + +```yaml +gpu-stream:fp64: + <<: *default_local_mode + parameters: + data_type: double + size: 4294967296 + kernel_configs: >- + '{ + "STREAM_COPY_double": {"block_size": 256, "unroll": 2}, + "STREAM_SCALE_double": {"block_size": 256, "unroll": 2}, + "STREAM_ADD_double": {"block_size": 256, "unroll": 2}, + "STREAM_TRIAD_double": {"block_size": 256, "unroll": 2} + }' +``` #### Metrics -| Metric Name | Unit | Description | -|------------------------------------------------------------|------------------|-----------------------------------------------------------------------------------------------------------------------------------------| -| STREAM\_COPY\_(double\|float)\_buffer\_[0-9]+\_block\_[0-9]+\_bw | bandwidth (GB/s) | The memory bandwidth of the GPU for the copy operation with the selected data type (double for fp64, float for fp32), for the specified buffer size and block size. | -| STREAM\_SCALE\_(double\|float)\_buffer\_[0-9]+\_block\_[0-9]+\_bw | bandwidth (GB/s) | The memory bandwidth of the GPU for the scale operation with the selected data type (double for fp64, float for fp32), for the specified buffer size and block size. | -| STREAM\_ADD\_(double\|float)\_buffer\_[0-9]+\_block\_[0-9]+\_bw | bandwidth (GB/s) | The memory bandwidth of the GPU for the add operation with the selected data type (double for fp64, float for fp32), for the specified buffer size and block size. | -| STREAM\_TRIAD\_(double\|float)\_buffer\_[0-9]+\_block\_[0-9]+\_bw | bandwidth (GB/s) | The memory bandwidth of the GPU for the triad operation with the selected data type (double for fp64, float for fp32), for the specified buffer size and block size. | -| STREAM\_COPY\_(double\|float)\_buffer\_[0-9]+\_block\_[0-9]+\_ratio | Efficiency (%) | The memory bandwidth efficiency of the GPU for the copy operation with the selected data type (double for fp64, float for fp32), for the specified buffer size and block size. | -| STREAM\_SCALE\_(double\|float)\_buffer\_[0-9]+\_block\_[0-9]+\_ratio | Efficiency (%) | The memory bandwidth efficiency of the GPU for the scale operation with the selected data type (double for fp64, float for fp32), for the specified buffer size and block size. | -| STREAM\_ADD\_(double\|float)\_buffer\_[0-9]+\_block\_[0-9]+\_ratio | Efficiency (%) | The memory bandwidth efficiency of the GPU for the add operation with the selected data type (double for fp64, float for fp32), for the specified buffer size and block size. | -| STREAM\_TRIAD\_(double\|float)\_buffer\_[0-9]+\_block\_[0-9]+\_ratio | Efficiency (%) | The memory bandwidth efficiency of the GPU for the triad operation with the selected data type (double for fp64, float for fp32), for the specified buffer size and block size. | +| Metric Name | Unit | Description | +|-------------|------|-------------| +| STREAM\_(COPY\|SCALE\|ADD\|TRIAD)\_(double\|float)\_bw | GB/s | Bandwidth with the configured launch, or the best bandwidth from the sweep. | +| STREAM\_(COPY\|SCALE\|ADD\|TRIAD)\_(double\|float)\_ratio | % | Bandwidth as a percentage of theoretical peak; -1 if peak is unavailable. | + +For example: `gpu-stream:fp64/STREAM_ADD_double_bw`. Selected launch parameters stay in raw output. ### `ib-loopback` diff --git a/examples/benchmarks/gpu_stream.py b/examples/benchmarks/gpu_stream.py index 1aa67b15d..7af708431 100644 --- a/examples/benchmarks/gpu_stream.py +++ b/examples/benchmarks/gpu_stream.py @@ -5,6 +5,9 @@ Commands to run: python3 examples/benchmarks/gpu_stream.py + +Omit kernel_configs to autotune; supply --kernel_configs with a quoted JSON +mapping of workload tags to block_size/unroll overrides to skip tuning. """ from superbench.benchmarks import BenchmarkRegistry, Platform @@ -12,12 +15,8 @@ if __name__ == '__main__': context = BenchmarkRegistry.create_benchmark_context( - 'gpu-stream', platform=Platform.CUDA, parameters='--num_warm_up 1 --num_loops 10 --data_type double' + 'gpu-stream', platform=Platform.CUDA, parameters='--num_warm_up 10 --num_loops 40 --data_type double' ) - # For ROCm environment, please specify the benchmark name and the platform as the following. - # context = BenchmarkRegistry.create_benchmark_context( - # 'gpu-stream', platform=Platform.ROCM, parameters='--num_warm_up 1 --num_loops 10' - # ) # To enable data checking, please add '--check_data'. benchmark = BenchmarkRegistry.launch_benchmark(context) diff --git a/superbench/benchmarks/micro_benchmarks/gpu_stream.py b/superbench/benchmarks/micro_benchmarks/gpu_stream.py index 142acb5a9..1f137d670 100644 --- a/superbench/benchmarks/micro_benchmarks/gpu_stream.py +++ b/superbench/benchmarks/micro_benchmarks/gpu_stream.py @@ -1,129 +1,170 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT license. -"""Module of the GPU Stream Performance benchmark.""" +"""GPU STREAM bandwidth with inline launch overrides and a fixed fallback sweep.""" +import json +import math import os +import re +import shlex from superbench.common.utils import logger from superbench.benchmarks import BenchmarkRegistry, Platform, ReturnCode from superbench.benchmarks.micro_benchmarks import MicroBenchmarkWithInvoke +_OPERATIONS = ['copy', 'scale', 'add', 'triad'] +_BLOCKS = [128, 256, 512, 1024] +_UNROLLS = [1, 2, 3, 4, 6, 8] +_DEFAULT_SIZE = 8 * 1024**3 +_TAG = re.compile(r'^STREAM_(COPY|SCALE|ADD|TRIAD)_(float|double)$') + class GpuStreamBenchmark(MicroBenchmarkWithInvoke): - """The GPU stream performance benchmark class.""" + """Report one bandwidth per operation and datatype.""" def __init__(self, name, parameters=''): - """Constructor. - - Args: - name (str): benchmark name. - parameters (str): benchmark parameters. - """ + """Initialize the native benchmark.""" super().__init__(name, parameters) - self._bin_name = 'gpu_stream' + self._command_targets = [] def add_parser_arguments(self): - """Add the specified arguments.""" + """Retain the normal benchmark arguments; search dimensions are fixed.""" super().add_parser_arguments() - self._parser.add_argument( - '--size', - type=int, - default=4096 * 1024**2, - required=False, - help='Size of data buffer in bytes.', - ) - - self._parser.add_argument( - '--num_warm_up', - type=int, - default=20, - required=False, - help='Number of warm up rounds', + '--kernel_configs', + type=str, + default=None, + help='JSON mapping of workload tags to block_size/unroll. Omit to autotune.' ) - self._parser.add_argument( - '--num_loops', + '--size', type=int, - default=100, - required=False, - help='Number of data buffer copies performed.', + default=_DEFAULT_SIZE, + help='Bytes per array, independent of launch overrides (default: 8 GiB).' ) - + self._parser.add_argument('--num_warm_up', type=int, default=20) + self._parser.add_argument('--num_loops', type=int, default=100) self._parser.add_argument( '--data_type', - type=str, - default='double', choices=['float', 'double'], - required=False, - help='Data type of the buffer elements.', + default='double', + help='Element type; use one benchmark entry per data type.' ) - self._parser.add_argument( '--check_data', action='store_true', - help='Enable data checking. Note: allocates 6x --size bytes of host memory per process ' - '(data_buf + check_buf + 4 validation buffers, e.g. 24 GiB with default 4 GiB --size). ' - 'Recommend using a small --size such as 1048576 (1 MiB) when this flag is enabled.', + help='Validate output. Requires 6x buffer size in host memory; use small sizes.' ) - def _preprocess(self): - """Preprocess/preparation operations before the benchmarking. + @staticmethod + def _check_config(tag, config): + """Check only the parameters needed to launch a workload.""" + match = _TAG.fullmatch(tag) + if match is None or not isinstance(config, dict): + raise ValueError('Invalid workload configuration key: {}'.format(tag)) + if set(config) != {'block_size', 'unroll'} or any(type(value) is not int for value in config.values()): + raise ValueError('{} needs integer block_size and unroll'.format(tag)) + if config['block_size'] not in _BLOCKS or config['unroll'] not in _UNROLLS: + raise ValueError('Unsupported block size/unroll for {}'.format(tag)) + + def _kernel_configs(self): + """Load explicit workload overrides for the selected data type only.""" + if self._args.kernel_configs is None: + return {} + configs = json.loads(self._args.kernel_configs) + if not isinstance(configs, dict): + raise ValueError('Expected a workload-tag to configuration mapping') + for tag, config in configs.items(): + self._check_config(tag, config) + if not tag.endswith('_' + self._args.data_type): + raise ValueError('{} does not match data_type {}'.format(tag, self._args.data_type)) + return configs + + def _command(self, dtype, operation, size, config=None): + """Use singleton native parameters for overrides, or the native fixed sweep.""" + parts = [ + shlex.quote(self.__bin_path), + '--size', + str(size), + '--data_type', + dtype, + '--operation', + operation, + '--num_warm_up', + str(self._args.num_warm_up), + '--num_loops', + str(self._args.num_loops), + ] + if config: + parts.extend(['--block_size', str(config['block_size']), '--unroll', str(config['unroll'])]) + if self._args.check_data: + parts.append('--check_data') + return ' '.join(parts) - Return: - True if _preprocess() succeed. - """ + def _preprocess(self): + """Resolve size once, independently of workload launch overrides.""" if not super()._preprocess(): return False - self.__bin_path = os.path.join(self._args.bin_dir, self._bin_name) - - args = '--size %d --num_warm_up %d --num_loops %d --data_type %s' % ( - self._args.size, self._args.num_warm_up, self._args.num_loops, self._args.data_type - ) - - if self._args.check_data: - args += ' --check_data' - - self._commands = ['%s %s' % (self.__bin_path, args)] - + self._commands, self._command_targets = [], [] + try: + if ( + self._args.num_warm_up < 0 or self._args.num_loops <= 0 + or self._args.num_warm_up + self._args.num_loops >= 2**64 + ): + raise ValueError('Invalid warm-up/loop counts') + width = 4 if self._args.data_type == 'float' else 8 + if not 0 < self._args.size < 2**64 or self._args.size % width: + raise ValueError('Size must be a positive multiple of {} bytes'.format(width)) + configs = self._kernel_configs() + size, dtype = self._args.size, self._args.data_type + commands, targets = [], [] + if not configs: + commands.append(self._command(dtype, 'all', size)) + targets.append({'STREAM_{}_{}'.format(op.upper(), dtype) for op in _OPERATIONS}) + else: + for operation in _OPERATIONS: + tag = 'STREAM_{}_{}'.format(operation.upper(), dtype) + commands.append(self._command(dtype, operation, size, configs.get(tag))) + targets.append({tag}) + self._commands, self._command_targets = commands, targets + except ValueError as error: + self._result.set_return_code(ReturnCode.INVALID_ARGUMENT) + logger.error('Invalid GPU STREAM configuration: {}.'.format(error)) + return False return True def _process_raw_result(self, cmd_idx, raw_output): - """Function to parse raw results and save the summarized results. - - self._result.add_raw_data() and self._result.add_result() need to be called to save the results. - - Args: - cmd_idx (int): the index of command corresponding with the raw_output. - raw_output (str): raw output string of the micro-benchmark. - - Return: - True if the raw output string is valid and result can be extracted. - """ + """Read only canonical native winners; launch details stay in raw output.""" self._result.add_raw_data('raw_output_' + str(cmd_idx), raw_output, self._args.log_raw_data) - try: - output_lines = [x.strip() for x in raw_output.strip().splitlines()] - count = 0 - for output_line in output_lines: - if output_line.startswith('STREAM_'): - count += 1 - tag, bw_str, ratio = output_line.split() - self._result.add_result(tag + '_bw', float(bw_str)) - self._result.add_result(tag + '_ratio', float(ratio)) - if count == 0: - raise BaseException('No valid results found.') - except BaseException as e: + if not 0 <= cmd_idx < len(self._commands): + raise ValueError('Unexpected command index') + results = {} + for line in raw_output.splitlines(): + if not line.startswith('STREAM_'): + continue + fields = line.split() + if len(fields) != 3 or _TAG.fullmatch(fields[0]) is None or fields[0] in results: + raise ValueError('Invalid or duplicate canonical result') + tag, bandwidth, ratio = fields + bandwidth, ratio = float(bandwidth), float(ratio) + if ( + not math.isfinite(bandwidth) or bandwidth <= 0 or not math.isfinite(ratio) + or (ratio < 0 and ratio != -1) + ): + raise ValueError('Invalid bandwidth/efficiency for {}'.format(tag)) + results[tag] = bandwidth, ratio + if set(results) != self._command_targets[cmd_idx]: + raise ValueError('Missing or unexpected workload results') + for tag, (bandwidth, ratio) in sorted(results.items()): + self._result.add_result(tag + '_bw', bandwidth) + self._result.add_result(tag + '_ratio', ratio) + except ValueError as error: self._result.set_return_code(ReturnCode.MICROBENCHMARK_RESULT_PARSING_FAILURE) - logger.error( - 'The result format is invalid - round: {}, benchmark: {}, raw output: {}, message: {}.'.format( - self._curr_run_index, self._name, raw_output, str(e) - ) - ) + logger.error('Invalid GPU STREAM output: {}.'.format(error)) return False - return True diff --git a/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream.cu b/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream.cu index 64964a3df..d81c3e1ad 100644 --- a/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream.cu +++ b/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream.cu @@ -8,11 +8,20 @@ #include "gpu_stream.hpp" #include +#include #include #include #include #include +namespace { +// grid_size counts blocks of the main kernel; each thread moves `unroll` 16-byte vectors. +void PrintConfiguration(const char *record, const std::string &tag, uint64_t size, const LaunchConfig &config) { + std::cout << record << "\t" << tag << "\tsize=" << size << "\tblock_size=" << config.block_size + << "\tunroll=" << config.unroll << "\tgrid_size=" << (size / 16) / (config.block_size * config.unroll); +} +} // namespace + /** * @brief Destroys the CUDA events used for benchmarking. * @@ -303,6 +312,15 @@ template int GpuStream::PrepareBufAndStream(std::unique_ptrcheck_data) { + stream_kernels::InitializeData<<gpu_device_prop.multiProcessorCount * 32, 256, 0, args->sub.stream>>>( + args->sub.gpu_buf_ptrs[0].get(), args->sub.gpu_buf_ptrs[1].get(), args->size / sizeof(T)); + cuda_err = cudaGetLastError(); + if (cuda_err != cudaSuccess) { + std::cerr << "PrepareBufAndStream::InitializeData error: " << cudaGetErrorString(cuda_err) << std::endl; + return -1; + } + } return 0; } @@ -438,39 +456,33 @@ template int GpuStream::DestroyBufAndStream(std::unique_ptr -int GpuStream::RunStreamKernel(std::unique_ptr> &args, Kernel kernel, int num_threads_per_block) { +int GpuStream::RunStreamKernel(std::unique_ptr> &args, Kernel kernel, const LaunchConfig &config, + float *elapsed_ms) { cudaError_t cuda_err = cudaSuccess; - uint64_t num_thread_blocks; - int size_factor = 2; - if (num_threads_per_block == 0) { - std::cerr << "RunStreamKernel::num_threads_per_block must be > 0" << std::endl; - return -1; - } - - // Validate data size - // Each thread processes one VecT element (128 bits / 16 bytes) for optimal memory bandwidth. - // Derived from VecT so any vector type change is caught at compile time. - constexpr uint64_t kBytesPerThread = sizeof(VecT); - static_assert(kBytesPerThread == 16, "Vector type must be 128-bit aligned for current PTX"); - uint64_t num_bytes_in_thread_block = num_threads_per_block * kBytesPerThread; - if (args->size % num_bytes_in_thread_block) { - std::cerr << "RunStreamKernel: Data size should be multiple of " << num_bytes_in_thread_block << std::endl; - return -1; - } - num_thread_blocks = args->size / num_bytes_in_thread_block; - - args->sub.times_in_ms.resize(static_cast(Kernel::kCount)); + const uint64_t count = args->size / sizeof(T); + T *output = args->sub.gpu_buf_ptrs[2].get(); + const T *first = args->sub.gpu_buf_ptrs[0].get(); + const T *second = args->sub.gpu_buf_ptrs[1].get(); + const int max_grid_x = args->gpu_device_prop.maxGridSize[0]; if (SetGpu(args->gpu_id)) { return -1; } + if (args->check_data) { + cuda_err = cudaMemsetAsync(output, 0xff, args->size, args->sub.stream); + if (cuda_err != cudaSuccess) { + std::cerr << "RunStreamKernel::cudaMemsetAsync error: " << cudaGetErrorString(cuda_err) << std::endl; + return -1; + } + } // Launch jobs and collect running time for (uint64_t i = 0; i < args->num_loops + args->num_warm_up; i++) { @@ -486,36 +498,33 @@ int GpuStream::RunStreamKernel(std::unique_ptr> &args, Kernel kerne switch (kernel) { case Kernel::kCopy: - CopyKernel<<sub.stream>>>( - reinterpret_cast *>(args->sub.gpu_buf_ptrs[2].get()), - reinterpret_cast *>(args->sub.gpu_buf_ptrs[0].get())); + cuda_err = stream_kernels::Launch(output, first, second, count, config, args->sub.stream, + max_grid_x); args->sub.kernel_name = "COPY"; break; case Kernel::kScale: - ScaleKernel<<sub.stream>>>( - reinterpret_cast *>(args->sub.gpu_buf_ptrs[2].get()), - reinterpret_cast *>(args->sub.gpu_buf_ptrs[0].get()), static_cast(scalar)); + cuda_err = stream_kernels::Launch(output, first, second, count, config, args->sub.stream, + max_grid_x); args->sub.kernel_name = "SCALE"; break; case Kernel::kAdd: - AddKernel<<sub.stream>>>( - reinterpret_cast *>(args->sub.gpu_buf_ptrs[2].get()), - reinterpret_cast *>(args->sub.gpu_buf_ptrs[0].get()), - reinterpret_cast *>(args->sub.gpu_buf_ptrs[1].get())); - size_factor = 3; + cuda_err = stream_kernels::Launch(output, first, second, count, config, args->sub.stream, + max_grid_x); args->sub.kernel_name = "ADD"; break; case Kernel::kTriad: - TriadKernel<<sub.stream>>>( - reinterpret_cast *>(args->sub.gpu_buf_ptrs[2].get()), - reinterpret_cast *>(args->sub.gpu_buf_ptrs[0].get()), - reinterpret_cast *>(args->sub.gpu_buf_ptrs[1].get()), static_cast(scalar)); - size_factor = 3; + cuda_err = stream_kernels::Launch(output, first, second, count, config, args->sub.stream, + max_grid_x); args->sub.kernel_name = "TRIAD"; break; default: std::cerr << "RunStreamKernel::Invalid kernel: " << std::endl; - break; + return -1; + } + if (cuda_err != cudaSuccess) { + std::cerr << "RunStreamKernel::launch " << args->sub.kernel_name + << " error: " << cudaGetErrorString(cuda_err) << std::endl; + return -1; } // Record end event at the end of iterations @@ -543,7 +552,11 @@ int GpuStream::RunStreamKernel(std::unique_ptr> &args, Kernel kerne return -1; } - args->sub.times_in_ms[static_cast(kernel)].push_back(time_in_ms / size_factor); + if (!std::isfinite(time_in_ms) || time_in_ms <= 0) { + std::cerr << "RunStreamKernel::Invalid CUDA event duration: " << time_in_ms << std::endl; + return -1; + } + *elapsed_ms = time_in_ms; return 0; } @@ -617,47 +630,74 @@ int GpuStream::RunStream(std::unique_ptr> &args, const std::string return -1; } - // benchmark over the kThreadsPerBlock array - for (const int num_threads_in_block : kThreadsPerBlock) { - // run the stream benchmark over the stream kernels - for (int i = 0; i < static_cast(Kernel::kCount); ++i) { - Kernel kernel = static_cast(i); - ret = RunStreamKernel(args, kernel, num_threads_in_block); - if (ret != 0) { - Destroy(args); - return ret; + struct BestResult { + double bandwidth = 0; + LaunchConfig config; + }; + std::array(Kernel::kCount)> best{}; + for (const Kernel kernel : opts_.operations) { + const auto index = static_cast(kernel); + const std::string tag = "STREAM_" + KernelToString(static_cast(kernel)) + "_" + data_type; + for (const int block : kThreadsPerBlock) { + if (opts_.block_size != 0 && opts_.block_size != block) { + continue; + } + if (block > args->gpu_device_prop.maxThreadsPerBlock) { + std::cerr << "Skipping unsupported block size " << block << " for " << tag << std::endl; + continue; } - if (args->check_data) { - ret = CheckBuf(args, i); + for (const int unroll : kUnrollFactors) { + if (opts_.unroll != 0 && opts_.unroll != unroll) { + continue; + } + const uint64_t tiles = (args->size / 16) / (block * unroll); + if (tiles > static_cast(args->gpu_device_prop.maxGridSize[0])) { + std::cerr << "Skipping grid exceeding the device limit for " << tag << std::endl; + continue; + } + const LaunchConfig config{block, unroll}; + float elapsed_ms = 0; + ret = RunStreamKernel(args, kernel, config, &elapsed_ms); + if (ret == 0 && args->check_data) { + ret = CheckBuf(args, static_cast(kernel)); + } if (ret != 0) { Destroy(args); return ret; } + const double bandwidth = + static_cast(args->size) * args->num_loops * kBufferBwMultipliers[index] / elapsed_ms / 1e6; + if (!std::isfinite(bandwidth) || bandwidth <= 0) { + std::cerr << "Invalid bandwidth for " << tag << std::endl; + Destroy(args); + return -1; + } + if (bandwidth > best[index].bandwidth) { + best[index] = {bandwidth, config}; + } } } - } - - // output formatted results to stdout - // Tags are of format: - // STREAM__datatype_buffer__block_ - for (size_t i = 0; i < args->sub.times_in_ms.size(); i++) { - std::string tag = "STREAM_" + KernelToString(i) + "_" + data_type + "_buffer_" + std::to_string(args->size); - for (size_t j = 0; j < args->sub.times_in_ms[i].size(); j++) { - // Calculate and display bandwidth - double bw = static_cast(args->size) * args->num_loops / args->sub.times_in_ms[i][j] / 1e6; - std::cout << tag << "_block_" << kThreadsPerBlock[j] << "\t" << bw << "\t"; - - if (peak_bw < 0) { // cannot get peak_bw -> prints -1 for efficiency - std::cout << "-1" << std::endl; - } else { - std::cout << std::fixed << std::setprecision(2) << bw / peak_bw * 100 << std::endl; - } + if (best[index].bandwidth == 0) { + std::cerr << "No supported launch configuration for " << tag << std::endl; + Destroy(args); + return -1; } } - // cleanup buffer and streams for the curr arg - Destroy(args); - return ret; + const uint64_t size = args->size; + ret = Destroy(args); + if (ret != 0) { + return ret; + } + for (const Kernel kernel : opts_.operations) { + const auto &winner = best[static_cast(kernel)]; + const std::string tag = "STREAM_" + KernelToString(static_cast(kernel)) + "_" + data_type; + PrintConfiguration("GPU_STREAM_CONFIG", tag, size, winner.config); + std::cout << "\n" + << tag << "\t" << std::defaultfloat << std::setprecision(9) << winner.bandwidth << "\t" + << (peak_bw > 0 ? winner.bandwidth / peak_bw * 100 : -1) << std::endl; + } + return 0; } /** @@ -711,19 +751,10 @@ int GpuStream::Run() { std::cerr << "Run::No GPU available" << std::endl; return -1; } - - // Run on CUDA device 0 (the visible GPU assigned by CUDA_VISIBLE_DEVICES). - if (opts_.data_type == "float") { - ret = CreateBenchArgs(); - } else if (opts_.data_type == "double") { - ret = CreateBenchArgs(); - } else { + if (opts_.data_type != "float" && opts_.data_type != "double") { std::cerr << "Run::Invalid data_type: " << opts_.data_type << std::endl; return -1; } - if (ret != 0) { - return ret; - } // Pin the thread to the GPU's NUMA node for optimal host↔device bandwidth. // Query GPU 0's preferred CPU NUMA node via NVML; fall back to the process's @@ -770,7 +801,10 @@ int GpuStream::Run() { return -1; } - // Run the benchmark for the configured data + ret = opts_.data_type == "float" ? CreateBenchArgs() : CreateBenchArgs(); + if (ret != 0) { + return ret; + } std::visit( [&](auto &curr_args) { // Get memory clock rate once for both bandwidth computation and display diff --git a/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream.hpp b/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream.hpp index 65502a243..34138092f 100644 --- a/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream.hpp +++ b/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream.hpp @@ -51,7 +51,7 @@ class GpuStream { template int Destroy(std::unique_ptr> &); // Benchmark functions - template int RunStreamKernel(std::unique_ptr> &, Kernel, int); + template int RunStreamKernel(std::unique_ptr> &, Kernel, const LaunchConfig &, float *); float GetActualMemoryClockRate(int gpu_id); template int RunStream(std::unique_ptr> &, const std::string &data_type, float peak_bw); diff --git a/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_kernels.cu b/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_kernels.cu index e40237b83..68e329b23 100644 --- a/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_kernels.cu +++ b/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_kernels.cu @@ -1,33 +1,5 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. -/** - * @file gpu_stream_kernels.cu - * @brief CUDA kernel compilation unit for GPU stream benchmark. - * - * All template kernel implementations (CopyKernel, ScaleKernel, AddKernel, TriadKernel) - * are defined in gpu_stream_kernels.hpp rather than here. This is required because: - * - * 1. **C++ Template Instantiation Model**: Templates are not compiled until they are - * instantiated with concrete types. The compiler needs to see the full template - * definition (not just declaration) at the point of instantiation. - * - * 2. **Separate Compilation Units**: When gpu_stream.cu calls `CopyKernel<<<...>>>`, - * nvcc needs the full kernel implementation visible in that translation unit. - * If implementations were only in this .cu file, gpu_stream.cu would only see - * declarations, causing "undefined reference" linker errors. - * - * 3. **CUDA-Specific Consideration**: Unlike regular C++ where explicit template - * instantiation in a .cpp file can work, CUDA kernel launches require the kernel - * code to be visible to nvcc when compiling the caller. This is because nvcc - * generates device code at compile time, not link time. - * - * 4. **Header Guards for Mixed Compilation**: The header uses `#ifdef __CUDACC__` to - * protect CUDA-specific code (blockIdx, threadIdx, __global__, etc.) from g++ - * when the header is indirectly included by .cpp files (e.g., via gpu_stream.hpp). - * - * This file remains as the compilation unit that ensures the header is processed - * by nvcc, and can host any future non-template helper functions if needed. - */ - -#include "gpu_stream_kernels.hpp" \ No newline at end of file +// Template kernels and launch helpers must be visible to the launching translation unit. +#include "gpu_stream_kernels.hpp" diff --git a/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_kernels.hpp b/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_kernels.hpp index 8702b1421..fdec61ff1 100644 --- a/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_kernels.hpp +++ b/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_kernels.hpp @@ -3,192 +3,172 @@ #pragma once +#include #include #include +#include #include #include "gpu_stream_utils.hpp" -/** - * @brief Type trait mapping scalar types to their 128-bit aligned vector types. - * - * @details For optimal memory bandwidth, we use 128-bit (16 byte) vector loads/stores: - * - double -> double2 (2 x 64-bit = 128-bit) - * - float -> float4 (4 x 32-bit = 128-bit) - */ template struct VectorType; template <> struct VectorType { using type = double2; }; template <> struct VectorType { using type = float4; }; - template using VecT = typename VectorType::type; -// Kernel declarations (visible to all compilers for function pointer usage) -template __global__ void CopyKernel(VecT *tgt, const VecT *src); -template __global__ void ScaleKernel(VecT *tgt, const VecT *src, const T scalar); -template __global__ void AddKernel(VecT *tgt, const VecT *src_a, const VecT *src_b); -template -__global__ void TriadKernel(VecT *tgt, const VecT *src_a, const VecT *src_b, const T scalar); - -// Implementation section - only compiled by nvcc #ifdef __CUDACC__ +namespace stream_kernels { +using stream_config::Kernel; +using stream_config::LaunchConfig; -/** - * @brief Fetches a value from source memory and writes it to a register. - * - * @details This inline device function fetches a value from the specified source memory - * location and writes it to the provided register. The implementation references the following: - * 1) NCCL: - * https://github.com/NVIDIA/nccl/blob/7e515921295adaab72adf56ea71a0fafb0ecb5f3/src/collectives/device/common_kernel.h#L483 - * 2) RCCL: - * https://github.com/ROCmSoftwarePlatform/rccl/blob/5c8380ff5b5925cae4bce00b1879a5f930226e8d/src/collectives/device/common_kernel.h#L268 - * - * @tparam T The type of the value to fetch. - * @param[out] v The register to write the fetched value to. - * @param[in] p The source memory location to fetch the value from. - */ -template inline __device__ void Fetch(T &v, const T *p) { -#if defined(__HIP_PLATFORM_HCC__) || defined(__HCC__) || defined(__HIPCC__) - v = *p; -#else - if constexpr (std::is_same::value) { - asm volatile("ld.volatile.global.v2.f64 {%0,%1}, [%2];" : "=d"(v.x), "=d"(v.y) : "l"(p) : "memory"); - } else if constexpr (std::is_same::value) { - asm volatile("ld.volatile.global.v4.f32 {%0,%1,%2,%3}, [%4];" - : "=f"(v.x), "=f"(v.y), "=f"(v.z), "=f"(v.w) - : "l"(p) - : "memory"); +template __device__ __forceinline__ T Transform(T a, T b) { + if constexpr (OP == Kernel::kCopy) { + return a; + } else if constexpr (OP == Kernel::kScale) { + return static_cast(stream_config::scalar) * a; + } else if constexpr (OP == Kernel::kAdd) { + return a + b; + } else { + static_assert(OP == Kernel::kTriad, "Unsupported STREAM operation"); + return b + static_cast(stream_config::scalar) * a; } -#endif } -/** - * @brief Stores a value from register and writes it to target memory. - * - * @details This inline device function stores a value from the provided register - * and writes it to the specified target memory location. The implementation references the following: - * 1) NCCL: - * https://github.com/NVIDIA/nccl/blob/7e515921295adaab72adf56ea71a0fafb0ecb5f3/src/collectives/device/common_kernel.h#L486 - * 2) RCCL: - * https://github.com/ROCmSoftwarePlatform/rccl/blob/5c8380ff5b5925cae4bce00b1879a5f930226e8d/src/collectives/device/common_kernel.h#L276 - * - * @tparam T The type of the value to store. - * @param[out] p The target memory location to write the value to. - * @param[in] v The register containing the value to be stored. - */ -template inline __device__ void Store(T *p, const T &v) { -#if defined(__HIP_PLATFORM_HCC__) || defined(__HCC__) || defined(__HIPCC__) - *p = v; -#else - if constexpr (std::is_same::value) { - asm volatile("st.volatile.global.v2.f64 [%0], {%1,%2};" ::"l"(p), "d"(v.x), "d"(v.y) : "memory"); - } else if constexpr (std::is_same::value) { - asm volatile("st.volatile.global.v4.f32 [%0], {%1,%2,%3,%4};" ::"l"(p), "f"(v.x), "f"(v.y), "f"(v.z), "f"(v.w) - : "memory"); +template __device__ __forceinline__ VecT TransformPacket(VecT a, VecT b) { + VecT result; + result.x = Transform(a.x, b.x); + result.y = Transform(a.y, b.y); + if constexpr (std::is_same::value) { + result.z = Transform(a.z, b.z); + result.w = Transform(a.w, b.w); + } + return result; +} + +// Bounds checks and scalar remainders stay out of the complete-tile kernel. +template +__global__ __launch_bounds__(BLOCK) void BulkKernel(VecT *__restrict__ output, const VecT *__restrict__ a, + const VecT *__restrict__ b) { + const Index base = static_cast(blockIdx.x) * (BLOCK * UNROLL) + threadIdx.x; + VecT first[UNROLL]; + VecT second[UNROLL]; +#pragma unroll + for (int u = 0; u < UNROLL; ++u) { + first[u] = a[base + u * BLOCK]; + if constexpr (OP == Kernel::kAdd || OP == Kernel::kTriad) { + second[u] = b[base + u * BLOCK]; + } + } +#pragma unroll + for (int u = 0; u < UNROLL; ++u) { + if constexpr (OP == Kernel::kCopy) { + output[base + u * BLOCK] = first[u]; + } else if constexpr (OP == Kernel::kScale) { + output[base + u * BLOCK] = TransformPacket(first[u], VecT{}); + } else { + output[base + u * BLOCK] = TransformPacket(first[u], second[u]); + } + } +} + +template +__global__ void TailKernel(T *__restrict__ output, const T *__restrict__ a, const T *__restrict__ b, uint64_t begin, + uint64_t count) { + const uint64_t i = begin + static_cast(blockIdx.x) * blockDim.x + threadIdx.x; + if (i < count) { + T right = 0; + if constexpr (OP == Kernel::kAdd || OP == Kernel::kTriad) { + right = b[i]; + } + output[i] = Transform(a[i], right); } -#endif } -/** - * @brief Performs COPY, a simple copy operation from source to target. b = a - * - * @details This CUDA kernel performs a simple copy operation, copying data from the source array - * to the target array. This is used to measure transfer rates without any arithmetic operations. - * - * @param[out] tgt The target array where data will be copied to (128-bit aligned). - * @param[in] src The source array from which data will be copied (128-bit aligned). - */ -template __global__ void CopyKernel(VecT *tgt, const VecT *src) { - uint64_t index = blockIdx.x * blockDim.x + threadIdx.x; - VecT val; - Fetch(val, src + index); - Store(tgt + index, val); +template __global__ void InitializeData(T *a, T *b, uint64_t count) { + for (uint64_t i = static_cast(blockIdx.x) * blockDim.x + threadIdx.x; i < count; + i += static_cast(gridDim.x) * blockDim.x) { + a[i] = static_cast(i % stream_config::kUInt8Mod); + b[i] = a[i]; + } } -/** - * @brief Performs SCALE, a scaling operation on the source data. b = x * a - * - * @details This CUDA kernel performs a simple arithmetic operation by scaling the source data - * with a given scalar value and storing the result in the target array. - * - * @param[out] tgt The target array where the scaled data will be stored (128-bit aligned). - * @param[in] src The source array containing the data to be scaled (128-bit aligned). - * @param[in] scalar The scalar value used to scale the source data. - */ -template __global__ void ScaleKernel(VecT *tgt, const VecT *src, const T scalar) { - uint64_t index = blockIdx.x * blockDim.x + threadIdx.x; - VecT val; - Fetch(val, src + index); - if constexpr (std::is_same::value) { - val.x *= scalar; - val.y *= scalar; - } else if constexpr (std::is_same::value) { - val.x *= scalar; - val.y *= scalar; - val.z *= scalar; - val.w *= scalar; +template +cudaError_t LaunchIndexed(T *output, const T *a, const T *b, uint64_t count, cudaStream_t stream, int max_grid_x) { + static_assert(sizeof(VecT) == 16 && alignof(VecT) == 16, "STREAM packets must be 128-bit aligned"); + static_assert(std::is_unsigned::value, "STREAM indices must be unsigned"); + static_assert(UNROLL > 0 && BLOCK > 0, "STREAM tiles must be nonempty"); + constexpr uint64_t lanes = sizeof(VecT) / sizeof(T); + constexpr uint64_t tile_elements = BLOCK * UNROLL * lanes; + const uint64_t blocks = count / tile_elements; + const uint64_t tail_begin = blocks * tile_elements; + if (count == 0 || count / lanes > std::numeric_limits::max()) { + return cudaErrorInvalidValue; + } + const uint64_t tail_blocks = (count - tail_begin + 255) / 256; + if (max_grid_x <= 0 || blocks > static_cast(max_grid_x) || + tail_blocks > static_cast(max_grid_x)) { + return cudaErrorInvalidConfiguration; + } + if (blocks != 0) { + BulkKernel<<(blocks), BLOCK, 0, stream>>>( + reinterpret_cast *>(output), reinterpret_cast *>(a), + reinterpret_cast *>(b)); + const cudaError_t error = cudaGetLastError(); + if (error != cudaSuccess) { + return error; + } } - Store(tgt + index, val); + if (tail_begin < count) { + TailKernel<<(tail_blocks), 256, 0, stream>>>(output, a, b, tail_begin, count); + return cudaGetLastError(); + } + return cudaSuccess; } -/** - * @brief Performs ADD, an addition operation on two source arrays. c = a + b - * - * @details This CUDA kernel adds corresponding elements from two source arrays and stores the result - * in the target array. This operation is used to measure transfer rates with a simple arithmetic addition. - * - * @param[out] tgt The target array where the result of the addition will be stored (128-bit aligned). - * @param[in] src_a The first source array containing the first set of operands (128-bit aligned). - * @param[in] src_b The second source array containing the second set of operands (128-bit aligned). - */ -template __global__ void AddKernel(VecT *tgt, const VecT *src_a, const VecT *src_b) { - uint64_t index = blockIdx.x * blockDim.x + threadIdx.x; - VecT val_a; - VecT val_b; - Fetch(val_a, src_a + index); - Fetch(val_b, src_b + index); - if constexpr (std::is_same::value) { - val_a.x += val_b.x; - val_a.y += val_b.y; - } else if constexpr (std::is_same::value) { - val_a.x += val_b.x; - val_a.y += val_b.y; - val_a.z += val_b.z; - val_a.w += val_b.w; +template +cudaError_t LaunchUnroll(T *output, const T *a, const T *b, uint64_t count, cudaStream_t stream, int max_grid_x) { + if (count / (sizeof(VecT) / sizeof(T)) <= std::numeric_limits::max()) { + return LaunchIndexed(output, a, b, count, stream, max_grid_x); } - Store(tgt + index, val_a); + return LaunchIndexed(output, a, b, count, stream, max_grid_x); } -/** - * @brief Performs TRIAD, fused multiply/add operations on source arrays. c = b + x * a - * - * @details This CUDA kernel performs a fused multiply/add operation by multiplying elements from - * the first source array with a scalar value, adding the result to corresponding elements from - * the second source array, and storing the result in the target array. - * - * @param[out] tgt The target array where the result of the fused multiply/add operation will be stored (128-bit - * aligned). - * @param[in] src_a The first source array containing the first set of operands to be multiplied by the scalar - * (128-bit aligned). - * @param[in] src_b The second source array containing the second set of operands (128-bit aligned). - * @param[in] scalar The scalar value used in the multiply/add operation. - */ -template -__global__ void TriadKernel(VecT *tgt, const VecT *src_a, const VecT *src_b, const T scalar) { - uint64_t index = blockIdx.x * blockDim.x + threadIdx.x; - VecT val_a; - VecT val_b; - Fetch(val_a, src_a + index); - Fetch(val_b, src_b + index); - if constexpr (std::is_same::value) { - val_b.x += (val_a.x * scalar); - val_b.y += (val_a.y * scalar); - } else if constexpr (std::is_same::value) { - val_b.x += (val_a.x * scalar); - val_b.y += (val_a.y * scalar); - val_b.z += (val_a.z * scalar); - val_b.w += (val_a.w * scalar); +template +cudaError_t LaunchBlock(T *output, const T *a, const T *b, uint64_t count, cudaStream_t stream, int max_grid_x, + const LaunchConfig &config) { + switch (config.unroll) { + case 1: + return LaunchUnroll(output, a, b, count, stream, max_grid_x); + case 2: + return LaunchUnroll(output, a, b, count, stream, max_grid_x); + case 3: + return LaunchUnroll(output, a, b, count, stream, max_grid_x); + case 4: + return LaunchUnroll(output, a, b, count, stream, max_grid_x); + case 6: + return LaunchUnroll(output, a, b, count, stream, max_grid_x); + case 8: + return LaunchUnroll(output, a, b, count, stream, max_grid_x); + default: + return cudaErrorInvalidConfiguration; } - Store(tgt + index, val_b); } -#endif // __CUDACC__ \ No newline at end of file +template +cudaError_t Launch(T *output, const T *a, const T *b, uint64_t count, const LaunchConfig &config, cudaStream_t stream, + int max_grid_x) { + switch (config.block_size) { + case 128: + return LaunchBlock(output, a, b, count, stream, max_grid_x, config); + case 256: + return LaunchBlock(output, a, b, count, stream, max_grid_x, config); + case 512: + return LaunchBlock(output, a, b, count, stream, max_grid_x, config); + case 1024: + return LaunchBlock(output, a, b, count, stream, max_grid_x, config); + default: + return cudaErrorInvalidConfiguration; + } +} +} // namespace stream_kernels +#endif diff --git a/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_utils.cpp b/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_utils.cpp index 668a1f0a1..a6a71de5e 100644 --- a/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_utils.cpp +++ b/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_utils.cpp @@ -1,166 +1,127 @@ - // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. #include "gpu_stream_utils.hpp" +#include +#include +#include +#include + +namespace { +bool ParseUnsigned(const char *text, uint64_t *value) { + const char *end = text + std::strlen(text); + const auto parsed = std::from_chars(text, end, *value); + return parsed.ec == std::errc{} && parsed.ptr == end; +} + +template bool ParseChoice(const char *text, const std::array &allowed, int *value) { + uint64_t parsed = 0; + if (!ParseUnsigned(text, &parsed) || parsed > static_cast(std::numeric_limits::max())) { + return false; + } + if (std::find(allowed.begin(), allowed.end(), static_cast(parsed)) == allowed.end()) { + return false; + } + *value = static_cast(parsed); + return true; +} +} // namespace + namespace stream_config { -/** - * @brief Converts a kernel index to its corresponding string representation. - * - * @details This function takes an integer representing a kernel index and returns the corresponding - * string representation of the kernel. The mapping between kernel indices and their string representations - * should be defined within the function. - * - * @param[in] kernel_idx The index of the kernel to be converted to a string. - * - * @return std::string The string representation of the kernel. - */ std::string KernelToString(int kernel_idx) { - switch (kernel_idx) { - case static_cast(Kernel::kCopy): - return "COPY"; - case static_cast(Kernel::kScale): - return "SCALE"; - case static_cast(Kernel::kAdd): - return "ADD"; - case static_cast(Kernel::kTriad): - return "TRIAD"; - default: - return "UNKNOWN"; - } + const std::array names = {"COPY", "SCALE", "ADD", "TRIAD"}; + return kernel_idx >= 0 && kernel_idx < static_cast(names.size()) ? names[kernel_idx] : "UNKNOWN"; } -/** - * @brief Print the usage of this program. - * - * @details Thus function prints the usage of this program. - * - * @return void. - * */ void PrintUsage() { - std::cout << "Usage: gpu_stream " - << "--size " - << "--num_warm_up " - << "--num_loops " - << "[--data_type ] " - << "[--check_data]" << std::endl; + std::cout << "Usage: gpu_stream [--size ] [--num_warm_up ] [--num_loops ]\n" + << " [--data_type ] [--check_data]\n" + << " [--operation ] [--block_size ] [--unroll ]\n"; } -/** - * @brief Print the user provided inputs info. - * - * @details Thus function prints the parsed user provided inputs of this program.. - * - * @param[in] opts The Opts struct that stores the parsed values. - * - * @return void - * */ void PrintInputInfo(Opts &opts) { - std::cout << "STREAM Benchmark" << std::endl; - std::cout << "Buffer size(bytes): " << opts.size << std::endl; - std::cout << "Number of warm up runs: " << opts.num_warm_up << std::endl; - std::cout << "Number of loops: " << opts.num_loops << std::endl; - std::cout << "Data type: " << opts.data_type << std::endl; - std::cout << "Check data: " << (opts.check_data ? "Yes" : "No") << std::endl; + std::cout << "STREAM Benchmark\nBuffer size(bytes): " << opts.size + << "\nNumber of warm up runs: " << opts.num_warm_up << "\nNumber of loops: " << opts.num_loops + << "\nData type: " << opts.data_type << "\nCheck data: " << (opts.check_data ? "Yes" : "No") << std::endl; } -/** - * @brief Parse the command line options. - * - * @details Thus function parses the command line options and stores the values in the Opts struct. - * - * @param[in] argc The number of command line options. - * @param[in] argv The command line options. - * @param[out] opts The Opts struct to store the parsed values. - * - * @return int The status code. - * */ int ParseOpts(int argc, char **argv, Opts *opts) { - enum class OptIdx { kSize, kNumWarmUp, kNumLoops, kEnableCheckData, kDataType }; - const struct option options[] = {{"size", required_argument, nullptr, static_cast(OptIdx::kSize)}, - {"num_warm_up", required_argument, nullptr, static_cast(OptIdx::kNumWarmUp)}, - {"num_loops", required_argument, nullptr, static_cast(OptIdx::kNumLoops)}, - {"check_data", no_argument, nullptr, static_cast(OptIdx::kEnableCheckData)}, - {"data_type", required_argument, nullptr, static_cast(OptIdx::kDataType)}}; - int getopt_ret = 0; - int opt_idx = 0; - bool size_specified = false; - bool num_warm_up_specified = false; - bool num_loops_specified = false; - - bool parse_err = false; - while (true) { - getopt_ret = getopt_long(argc, argv, "", options, &opt_idx); - if (getopt_ret == -1) { - if (!size_specified || !num_warm_up_specified || !num_loops_specified) { - parse_err = true; - } - break; - } else if (getopt_ret == '?') { - parse_err = true; - break; - } - switch (opt_idx) { - case static_cast(OptIdx::kSize): - if (1 != sscanf(optarg, "%lu", &(opts->size))) { - std::cerr << "Invalid size: " << optarg << std::endl; - parse_err = true; - } else { - size_specified = true; - } + enum OptIdx { kSize, kWarmup, kLoops, kCheck, kType, kBlock, kUnroll, kOperation }; + const option options[] = { + {"size", required_argument, nullptr, kSize}, + {"num_warm_up", required_argument, nullptr, kWarmup}, + {"num_loops", required_argument, nullptr, kLoops}, + {"check_data", no_argument, nullptr, kCheck}, + {"data_type", required_argument, nullptr, kType}, + {"block_size", required_argument, nullptr, kBlock}, + {"unroll", required_argument, nullptr, kUnroll}, + {"operation", required_argument, nullptr, kOperation}, + {nullptr, 0, nullptr, 0}, + }; + int option_index = 0; + int token = 0; + while ((token = getopt_long(argc, argv, "", options, &option_index)) != -1) { + bool valid = true; + switch (token) { + case kSize: + valid = ParseUnsigned(optarg, &opts->size); break; - case static_cast(OptIdx::kNumWarmUp): - if (1 != sscanf(optarg, "%lu", &(opts->num_warm_up))) { - std::cerr << "Invalid num_warm_up: " << optarg << std::endl; - parse_err = true; - } else { - num_warm_up_specified = true; - } + case kWarmup: + valid = ParseUnsigned(optarg, &opts->num_warm_up); break; - case static_cast(OptIdx::kNumLoops): - if (1 != sscanf(optarg, "%lu", &(opts->num_loops))) { - std::cerr << "Invalid num_loops: " << optarg << std::endl; - parse_err = true; - } else { - num_loops_specified = true; - } + case kLoops: + valid = ParseUnsigned(optarg, &opts->num_loops); break; - case static_cast(OptIdx::kEnableCheckData): + case kCheck: opts->check_data = true; break; - case static_cast(OptIdx::kDataType): + case kType: opts->data_type = optarg; - if (opts->data_type != "float" && opts->data_type != "double") { - std::cerr << "Invalid data_type: " << optarg << ". Must be 'float' or 'double'." << std::endl; - parse_err = true; + valid = opts->data_type == "float" || opts->data_type == "double"; + break; + case kBlock: + valid = ParseChoice(optarg, kThreadsPerBlock, &opts->block_size); + break; + case kUnroll: + valid = ParseChoice(optarg, kUnrollFactors, &opts->unroll); + break; + case kOperation: { + const std::array names = {"copy", "scale", "add", "triad"}; + const auto found = std::find_if(names.begin(), names.end(), + [&](const char *name) { return std::strcmp(name, optarg) == 0; }); + valid = found != names.end() || std::strcmp(optarg, "all") == 0; + if (found != names.end()) { + opts->operations = {static_cast(found - names.begin())}; + } else if (valid) { + opts->operations = {Kernel::kCopy, Kernel::kScale, Kernel::kAdd, Kernel::kTriad}; } break; + } default: - parse_err = true; + PrintUsage(); + return -1; } - if (parse_err) { - break; + if (!valid) { + std::cerr << "Invalid value for --" << options[option_index].name << ": " << optarg << std::endl; + return -1; } } - if (parse_err) { - PrintUsage(); + const uint64_t element_size = opts->data_type == "float" ? sizeof(float) : sizeof(double); + if (optind != argc || opts->size == 0 || opts->size % element_size != 0) { + std::cerr << "Size must be a positive multiple of " << element_size + << " bytes; positional arguments are invalid" << std::endl; + return -1; + } + if (opts->num_loops == 0 || opts->num_warm_up > std::numeric_limits::max() - opts->num_loops) { + std::cerr << "num_loops must be positive and num_warm_up + num_loops must not overflow" << std::endl; return -1; } return 0; } - } // namespace stream_config unsigned long long getCurrentTimestampInMicroseconds() { - // Get the current time point - auto now = std::chrono::system_clock::now(); - - // Convert to time since epoch - auto duration = now.time_since_epoch(); - - // Convert to microseconds - auto microseconds = std::chrono::duration_cast(duration).count(); - - return static_cast(microseconds); + const auto duration = std::chrono::system_clock::now().time_since_epoch(); + return static_cast(std::chrono::duration_cast(duration).count()); } diff --git a/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_utils.hpp b/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_utils.hpp index 20f6a5654..3ab713d45 100644 --- a/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_utils.hpp +++ b/superbench/benchmarks/micro_benchmarks/gpu_stream/gpu_stream_utils.hpp @@ -29,9 +29,10 @@ struct GpuBufferDeleter { unsigned long long getCurrentTimestampInMicroseconds(); namespace stream_config { -constexpr std::array kThreadsPerBlock = {128, 256, 512, 1024}; // Threads per block -constexpr uint64_t kDefaultBufferSizeInBytes = 4294967296; // Default buffer size 4GB -constexpr int kNumBuffers = 3; // Number of buffers for triad, add kernel +constexpr std::array kThreadsPerBlock = {128, 256, 512, 1024}; +constexpr std::array kUnrollFactors = {1, 2, 3, 4, 6, 8}; +constexpr uint64_t kDefaultBufferSizeInBytes = 8589934592; // 8 GiB per array +constexpr int kNumBuffers = 3; // Number of buffers for triad, add kernel constexpr int kNumValidationBuffers = 4; // Number of validation buffers, one for each kernel constexpr int kUInt8Mod = 256; // Modulo for unsigned long data type constexpr std::array kBufferBwMultipliers = {2, 2, 3, 3}; // Buffer multiplier for triad, add kernel @@ -46,6 +47,11 @@ enum class Kernel { kCount // Add a count to keep track of the number of enums. Helpful for iterating over enums. }; +struct LaunchConfig { + int block_size = 0; + int unroll = 0; +}; + // Arguments for each sub benchmark run. template struct SubBenchArgs { // Unique pointer for GPU buffers @@ -72,9 +78,6 @@ template struct SubBenchArgs { // CUDA event to record end time. cudaEvent_t end_event = nullptr; - // CUDA event to record end time. - std::vector> times_in_ms; - // Stream Kernel name. std::string kernel_name; }; @@ -92,7 +95,7 @@ template struct BenchArgs { uint64_t size = kDefaultBufferSizeInBytes; // Number of warm up rounds to run. - uint64_t num_warm_up = 0; + uint64_t num_warm_up = 10; // Number of loops to run. uint64_t num_loops = 1; @@ -110,16 +113,18 @@ struct Opts { uint64_t size = kDefaultBufferSizeInBytes; // Number of warm up rounds to run. - uint64_t num_warm_up = 0; + uint64_t num_warm_up = 10; // Number of loops to run. - uint64_t num_loops = 0; + uint64_t num_loops = 40; // Whether check data after copy. bool check_data = false; - // Data type for the benchmark ("float" or "double"). std::string data_type = "double"; + int block_size = 0; + int unroll = 0; + std::vector operations{Kernel::kCopy, Kernel::kScale, Kernel::kAdd, Kernel::kTriad}; }; std::string KernelToString(int); // Function to convert enum to string diff --git a/tests/benchmarks/micro_benchmarks/test_gpu_stream.py b/tests/benchmarks/micro_benchmarks/test_gpu_stream.py index d9d836a92..006899d36 100644 --- a/tests/benchmarks/micro_benchmarks/test_gpu_stream.py +++ b/tests/benchmarks/micro_benchmarks/test_gpu_stream.py @@ -1,162 +1,150 @@ # Copyright (c) Microsoft Corporation. # Licensed under the MIT License. -"""Tests for gpu_stream benchmark.""" +"""Tests for gpu-stream benchmark.""" -import numbers +import json +from pathlib import Path +import shlex import unittest +from omegaconf import OmegaConf + from tests.helper import decorator from tests.helper.testcase import BenchmarkTestCase -from superbench.benchmarks import BenchmarkRegistry, BenchmarkType, ReturnCode, Platform +from superbench.benchmarks import BenchmarkRegistry, Platform, ReturnCode +from superbench.executor import SuperBenchExecutor + +_TAGS = ['STREAM_COPY_double', 'STREAM_SCALE_double', 'STREAM_ADD_double', 'STREAM_TRIAD_double'] +@decorator.cuda_test class GpuStreamBenchmarkTest(BenchmarkTestCase, unittest.TestCase): - """Test class for gpu_stream benchmark.""" + """Test command generation and result parsing with synthetic data.""" @classmethod def setUpClass(cls): - """Hook method for setting up class fixture before running tests in the class.""" + """Create mock binary environment.""" super().setUpClass() cls.createMockEnvs(cls) cls.createMockFiles(cls, ['bin/gpu_stream']) - def _test_gpu_stream_command_generation(self, platform, data_type='double'): - """Test gpu-stream benchmark command generation.""" - benchmark_name = 'gpu-stream' - (benchmark_class, - predefine_params) = BenchmarkRegistry._BenchmarkRegistry__select_benchmark(benchmark_name, platform) - assert (benchmark_class) - - num_warm_up = 5 - num_loops = 10 - size = 25769803776 - - parameters = '--num_warm_up %d --num_loops %d --size %d --data_type %s ' \ - '--check_data' % \ - (num_warm_up, num_loops, size, data_type) - benchmark = benchmark_class(benchmark_name, parameters=parameters) - - # Check basic information - assert (benchmark) - ret = benchmark._preprocess() - assert (ret is True) - assert (benchmark.return_code == ReturnCode.SUCCESS) - assert (benchmark.name == benchmark_name) - assert (benchmark.type == BenchmarkType.MICRO) - - # Check parameters specified in BenchmarkContext. - assert (benchmark._args.size == size) - assert (benchmark._args.num_warm_up == num_warm_up) - assert (benchmark._args.num_loops == num_loops) - assert (benchmark._args.check_data) - assert (benchmark._args.data_type == data_type) - - # Check command - assert (1 == len(benchmark._commands)) - assert (benchmark._commands[0].startswith(benchmark._GpuStreamBenchmark__bin_path)) - assert ('--size %d' % size in benchmark._commands[0]) - assert ('--num_warm_up %d' % num_warm_up in benchmark._commands[0]) - assert ('--num_loops %d' % num_loops in benchmark._commands[0]) - assert ('--data_type %s' % data_type in benchmark._commands[0]) - assert ('--check_data' in benchmark._commands[0]) - - @decorator.cuda_test - def test_gpu_stream_command_generation_cuda(self): - """Test gpu-stream benchmark command generation, CUDA case.""" - self._test_gpu_stream_command_generation(Platform.CUDA) - - @decorator.cuda_test - def test_gpu_stream_command_generation_cuda_float(self): - """Test gpu-stream benchmark command generation with float, CUDA case.""" - self._test_gpu_stream_command_generation(Platform.CUDA, data_type='float') - - @decorator.load_data('tests/data/gpu_stream.log') - def _test_gpu_stream_result_parsing(self, platform, test_raw_output): - """Test gpu-stream benchmark result parsing.""" - benchmark_name = 'gpu-stream' - (benchmark_class, - predefine_params) = BenchmarkRegistry._BenchmarkRegistry__select_benchmark(benchmark_name, platform) - assert (benchmark_class) - benchmark = benchmark_class(benchmark_name, parameters='') - assert (benchmark) - ret = benchmark._preprocess() - assert (ret is True) - assert (benchmark.return_code == ReturnCode.SUCCESS) - assert (benchmark.name == 'gpu-stream') - assert (benchmark.type == BenchmarkType.MICRO) - - # Positive case - valid raw output. - assert (benchmark._process_raw_result(0, test_raw_output)) - assert (benchmark.return_code == ReturnCode.SUCCESS) - - assert (1 == len(benchmark.raw_data)) - # print(test_raw_output.splitlines()) - test_raw_output_dict = { - x.split()[0]: [float(x.split()[1]), float(x.split()[2])] - for x in test_raw_output.strip().splitlines() if x.startswith('STREAM_') - } - assert (len(test_raw_output_dict) * 2 + benchmark.default_metric_count == len(benchmark.result)) - for output_key in benchmark.result: - if output_key == 'return_code': - assert (benchmark.result[output_key] == [0]) - else: - assert (len(benchmark.result[output_key]) == 1) - assert (isinstance(benchmark.result[output_key][0], numbers.Number)) - if output_key.endswith('_bw'): - assert (output_key[:-3] in test_raw_output_dict) - assert (test_raw_output_dict[output_key[:-3]][0] == benchmark.result[output_key][0]) - else: - assert (output_key.endswith('_ratio')) - assert (output_key[:-6] in test_raw_output_dict) - assert (test_raw_output_dict[output_key[:-6]][1] == benchmark.result[output_key][0]) - - # Negative case - invalid raw output. - assert (benchmark._process_raw_result(1, 'Invalid raw output') is False) - assert (benchmark.return_code == ReturnCode.MICROBENCHMARK_RESULT_PARSING_FAILURE) - - @decorator.cuda_test - def test_gpu_stream_result_parsing_cuda(self): - """Test gpu-stream benchmark result parsing, CUDA case.""" - self._test_gpu_stream_result_parsing(Platform.CUDA) - - @decorator.load_data('tests/data/gpu_stream_float.log') - def _test_gpu_stream_result_parsing_float(self, platform, test_raw_output): - """Test gpu-stream benchmark result parsing for float data type.""" - benchmark_name = 'gpu-stream' - (benchmark_class, - predefine_params) = BenchmarkRegistry._BenchmarkRegistry__select_benchmark(benchmark_name, platform) - assert (benchmark_class) - benchmark = benchmark_class(benchmark_name, parameters='--data_type float') - assert (benchmark) - ret = benchmark._preprocess() - assert (ret is True) - assert (benchmark.return_code == ReturnCode.SUCCESS) - - # Positive case - valid raw output with float tags. - assert (benchmark._process_raw_result(0, test_raw_output)) - assert (benchmark.return_code == ReturnCode.SUCCESS) - - assert (1 == len(benchmark.raw_data)) - test_raw_output_dict = { - x.split()[0]: [float(x.split()[1]), float(x.split()[2])] - for x in test_raw_output.strip().splitlines() if x.startswith('STREAM_') + def create(self, parameters='', configs=None): + """Create a benchmark and run preprocess.""" + if configs is not None: + parameters += ' --kernel_configs {}'.format(shlex.quote(json.dumps(configs))) + benchmark_class, _ = BenchmarkRegistry._BenchmarkRegistry__select_benchmark('gpu-stream', Platform.CUDA) + benchmark = benchmark_class('gpu-stream', parameters=parameters) + return benchmark, benchmark._preprocess() + + @staticmethod + def output(tags, bandwidth=100): + """Build synthetic native output.""" + return '\n'.join(['STREAM Benchmark'] + ['{}\t{}\t25'.format(tag, bandwidth) for tag in sorted(tags)]) + + def test_native_sweep(self): + """Without kernel_configs, one native command sweeps all operations.""" + benchmark, ret = self.create('--size 1048576 --num_warm_up 5 --num_loops 10 --check_data') + self.assertTrue(ret) + self.assertEqual(len(benchmark._commands), 1) + for value in [ + '--size 1048576', '--data_type double', '--operation all', '--num_warm_up 5', '--num_loops 10', + '--check_data' + ]: + self.assertIn(value, benchmark._commands[0]) + self.assertNotIn('--block_size', benchmark._commands[0]) + self.assertEqual(benchmark._command_targets, [set(_TAGS)]) + + def test_kernel_configs(self): + """Listed workloads use their launch config; unlisted workloads sweep.""" + configs = { + 'STREAM_COPY_double': { + 'block_size': 256, + 'unroll': 2 + }, + 'STREAM_TRIAD_double': { + 'block_size': 512, + 'unroll': 4 + } } - assert (len(test_raw_output_dict) * 2 + benchmark.default_metric_count == len(benchmark.result)) - for output_key in benchmark.result: - if output_key == 'return_code': - assert (benchmark.result[output_key] == [0]) + benchmark, ret = self.create('--size 1048576', configs) + self.assertTrue(ret) + self.assertEqual(benchmark._command_targets, [{tag} for tag in _TAGS]) + for command, tag in zip(benchmark._commands, _TAGS): + self.assertIn('--size 1048576', command) + self.assertIn('--operation {}'.format(tag.split('_')[1].lower()), command) + if tag in configs: + self.assertIn('--block_size {block_size} --unroll {unroll}'.format(**configs[tag]), command) else: - assert (len(benchmark.result[output_key]) == 1) - assert (isinstance(benchmark.result[output_key][0], numbers.Number)) - if output_key.endswith('_bw'): - assert (output_key[:-3] in test_raw_output_dict) - assert (test_raw_output_dict[output_key[:-3]][0] == benchmark.result[output_key][0]) - else: - assert (output_key.endswith('_ratio')) - assert (output_key[:-6] in test_raw_output_dict) - assert (test_raw_output_dict[output_key[:-6]][1] == benchmark.result[output_key][0]) - - @decorator.cuda_test - def test_gpu_stream_result_parsing_cuda_float(self): - """Test gpu-stream benchmark result parsing for float, CUDA case.""" - self._test_gpu_stream_result_parsing_float(Platform.CUDA) + self.assertNotIn('--block_size', command) + + def test_kernel_configs_from_yaml(self): + """Inline JSON in YAML survives executor argument conversion.""" + config = OmegaConf.create( + """ +parameters: + data_type: double + kernel_configs: >- + '{ + "STREAM_COPY_double": {"block_size": 256, "unroll": 2}, + "STREAM_SCALE_double": {"block_size": 256, "unroll": 2}, + "STREAM_ADD_double": {"block_size": 256, "unroll": 2}, + "STREAM_TRIAD_double": {"block_size": 256, "unroll": 2} + }' +""" + ) + executor = SuperBenchExecutor.__new__(SuperBenchExecutor) + benchmark, ret = self.create(executor._SuperBenchExecutor__get_arguments(config.parameters)) + self.assertTrue(ret) + self.assertEqual(len(benchmark._commands), 4) + self.assertTrue(all('--block_size 256 --unroll 2' in command for command in benchmark._commands)) + + def test_invalid_arguments(self): + """Invalid sizes, loops, and kernel_configs are rejected.""" + cases = ['--size 0', '--size 12', '--num_loops 0', '--num_warm_up -1'] + for value in [ + '{', + '[]', + '{"STREAM_COPY_half": {"block_size": 256, "unroll": 2}}', + '{"STREAM_COPY_float": {"block_size": 256, "unroll": 2}}', + '{"STREAM_COPY_double": {"block_size": 256}}', + '{"STREAM_COPY_double": {"block_size": 64, "unroll": 2}}', + '{"STREAM_COPY_double": {"block_size": 256, "unroll": 5}}', + '{"STREAM_COPY_double": {"block_size": true, "unroll": 2}}', + ]: + cases.append('--kernel_configs {}'.format(shlex.quote(value))) + for parameters in cases: + with self.subTest(parameters=parameters): + benchmark, ret = self.create(parameters) + self.assertFalse(ret) + self.assertEqual(benchmark.return_code, ReturnCode.INVALID_ARGUMENT) + self.assertEqual(benchmark._commands, []) + + def test_result_parsing(self): + """Metrics come from canonical rows; launch details stay in raw output.""" + for dtype, filename in [('float', 'gpu_stream_float.log'), ('double', 'gpu_stream.log')]: + with self.subTest(dtype=dtype): + benchmark, ret = self.create('--data_type {}'.format(dtype)) + self.assertTrue(ret) + output = (Path(__file__).parents[2] / 'data' / filename).read_text() + self.assertTrue(benchmark._process_raw_result(0, output)) + rows = [line.split() for line in output.splitlines() if line.startswith('STREAM_')] + self.assertEqual(len(rows), 4) + for tag, bandwidth, ratio in rows: + self.assertEqual(benchmark.result[tag + '_bw'], [float(bandwidth)]) + self.assertEqual(benchmark.result[tag + '_ratio'], [float(ratio)]) + self.assertEqual(len(benchmark.result), benchmark.default_metric_count + 8) + + def test_invalid_result(self): + """Missing, duplicate, and non-finite rows fail parsing.""" + valid = self.output(_TAGS) + for output in [ + '', + valid + '\nSTREAM_COPY_double\t300\t25', + valid.replace('\t100\t25', '\tnan\t25'), + valid.replace('\t100\t25', '\t-1\t25'), + ]: + with self.subTest(output=output): + benchmark, _ = self.create() + self.assertFalse(benchmark._process_raw_result(0, output)) + self.assertEqual(benchmark.return_code, ReturnCode.MICROBENCHMARK_RESULT_PARSING_FAILURE) + self.assertNotIn('STREAM_COPY_double_bw', benchmark.result) diff --git a/tests/data/gpu_stream.log b/tests/data/gpu_stream.log index a3dcf2b01..28e380ec9 100644 --- a/tests/data/gpu_stream.log +++ b/tests/data/gpu_stream.log @@ -1,24 +1,17 @@ STREAM Benchmark +Synthetic fixture; not hardware measurements. Buffer size(bytes): 4294967296 Number of warm up runs: 10 Number of loops: 40 Data type: double Check data: No -Device 0: "NVIDIA Graphics Device" 152 SMs(10.0) Memory: 4000MHz x 8192-bit = 8192 GB/s PEAK ECC is ON -STREAM_COPY_double_buffer_4294967296_block_128 6711.67 81.93 -STREAM_COPY_double_buffer_4294967296_block_256 6549.50 79.95 -STREAM_COPY_double_buffer_4294967296_block_512 6195.43 75.63 -STREAM_COPY_double_buffer_4294967296_block_1024 5721.52 69.84 -STREAM_SCALE_double_buffer_4294967296_block_128 6680.42 81.55 -STREAM_SCALE_double_buffer_4294967296_block_256 6515.51 79.54 -STREAM_SCALE_double_buffer_4294967296_block_512 6106.69 74.54 -STREAM_SCALE_double_buffer_4294967296_block_1024 5626.68 68.69 -STREAM_ADD_double_buffer_4294967296_block_128 7379.25 90.08 -STREAM_ADD_double_buffer_4294967296_block_256 7407.27 90.42 -STREAM_ADD_double_buffer_4294967296_block_512 7309.59 89.23 -STREAM_ADD_double_buffer_4294967296_block_1024 6788.64 82.87 -STREAM_TRIAD_double_buffer_4294967296_block_128 7378.19 90.07 -STREAM_TRIAD_double_buffer_4294967296_block_256 7414.01 90.50 -STREAM_TRIAD_double_buffer_4294967296_block_512 7295.50 89.06 -STREAM_TRIAD_double_buffer_4294967296_block_1024 6730.42 82.16 \ No newline at end of file +Device 0: "Synthetic test GPU" +GPU_STREAM_CONFIG STREAM_COPY_double size=4294967296 block_size=256 unroll=2 grid_size=524288 +STREAM_COPY_double 80 20 +GPU_STREAM_CONFIG STREAM_SCALE_double size=4294967296 block_size=256 unroll=2 grid_size=524288 +STREAM_SCALE_double 100 25 +GPU_STREAM_CONFIG STREAM_ADD_double size=4294967296 block_size=256 unroll=2 grid_size=524288 +STREAM_ADD_double 120 30 +GPU_STREAM_CONFIG STREAM_TRIAD_double size=4294967296 block_size=256 unroll=2 grid_size=524288 +STREAM_TRIAD_double 140 35 \ No newline at end of file diff --git a/tests/data/gpu_stream_float.log b/tests/data/gpu_stream_float.log index d1ab3ad1e..76058e7bd 100644 --- a/tests/data/gpu_stream_float.log +++ b/tests/data/gpu_stream_float.log @@ -1,24 +1,17 @@ STREAM Benchmark +Synthetic fixture; not hardware measurements. Buffer size(bytes): 4294967296 Number of warm up runs: 10 Number of loops: 40 Data type: float Check data: No -Device 0: "NVIDIA Graphics Device" 152 SMs(10.0) Memory: 4000MHz x 8192-bit = 8192 GB/s PEAK ECC is ON -STREAM_COPY_float_buffer_4294967296_block_128 6823.45 83.30 -STREAM_COPY_float_buffer_4294967296_block_256 6650.12 81.18 -STREAM_COPY_float_buffer_4294967296_block_512 6301.88 76.93 -STREAM_COPY_float_buffer_4294967296_block_1024 5812.34 70.95 -STREAM_SCALE_float_buffer_4294967296_block_128 6790.11 82.89 -STREAM_SCALE_float_buffer_4294967296_block_256 6620.33 80.81 -STREAM_SCALE_float_buffer_4294967296_block_512 6210.45 75.81 -STREAM_SCALE_float_buffer_4294967296_block_1024 5718.90 69.81 -STREAM_ADD_float_buffer_4294967296_block_128 7490.22 91.43 -STREAM_ADD_float_buffer_4294967296_block_256 7512.10 91.70 -STREAM_ADD_float_buffer_4294967296_block_512 7405.67 90.40 -STREAM_ADD_float_buffer_4294967296_block_1024 6890.33 84.11 -STREAM_TRIAD_float_buffer_4294967296_block_128 7485.55 91.38 -STREAM_TRIAD_float_buffer_4294967296_block_256 7520.88 91.81 -STREAM_TRIAD_float_buffer_4294967296_block_512 7390.12 90.21 -STREAM_TRIAD_float_buffer_4294967296_block_1024 6825.11 83.32 +Device 0: "Synthetic test GPU" +GPU_STREAM_CONFIG STREAM_COPY_float size=4294967296 block_size=256 unroll=2 grid_size=524288 +STREAM_COPY_float 100 25 +GPU_STREAM_CONFIG STREAM_SCALE_float size=4294967296 block_size=256 unroll=2 grid_size=524288 +STREAM_SCALE_float 120 30 +GPU_STREAM_CONFIG STREAM_ADD_float size=4294967296 block_size=256 unroll=2 grid_size=524288 +STREAM_ADD_float 140 35 +GPU_STREAM_CONFIG STREAM_TRIAD_float size=4294967296 block_size=256 unroll=2 grid_size=524288 +STREAM_TRIAD_float 160 40