|
| 1 | +# Copyright (C) 2024 Intel Corporation |
| 2 | +# Part of the Unified-Runtime Project, under the Apache License v2.0 with LLVM Exceptions. |
| 3 | +# See LICENSE.TXT |
| 4 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 5 | + |
| 6 | +import os |
| 7 | +import csv |
| 8 | +import io |
| 9 | +from utils.utils import run, git_clone, create_build_path |
| 10 | +from .base import Benchmark |
| 11 | +from .result import Result |
| 12 | +from .options import options |
| 13 | + |
| 14 | +class ComputeBench: |
| 15 | + def __init__(self, directory): |
| 16 | + self.directory = directory |
| 17 | + self.built = False |
| 18 | + return |
| 19 | + |
| 20 | + def setup(self): |
| 21 | + if self.built: |
| 22 | + return |
| 23 | + |
| 24 | + repo_path = git_clone(self.directory, "compute-benchmarks-repo", "https://github.com/intel/compute-benchmarks.git", "0f758021dce9ba32341a503739b69db057433c59") |
| 25 | + build_path = create_build_path(self.directory, 'compute-benchmarks-build') |
| 26 | + |
| 27 | + configure_command = [ |
| 28 | + "cmake", |
| 29 | + f"-B {build_path}", |
| 30 | + f"-S {repo_path}", |
| 31 | + f"-DCMAKE_BUILD_TYPE=Release", |
| 32 | + f"-DBUILD_SYCL=ON", |
| 33 | + f"-DSYCL_COMPILER_ROOT={options.sycl}", |
| 34 | + f"-DALLOW_WARNINGS=ON" |
| 35 | + ] |
| 36 | + run(configure_command, add_sycl=True) |
| 37 | + |
| 38 | + run(f"cmake --build {build_path} -j", add_sycl=True) |
| 39 | + |
| 40 | + self.built = True |
| 41 | + self.bins = os.path.join(build_path, 'bin') |
| 42 | + |
| 43 | +class ComputeBenchmark(Benchmark): |
| 44 | + def __init__(self, bench, name, test): |
| 45 | + self.bench = bench |
| 46 | + self.bench_name = name |
| 47 | + self.test = test |
| 48 | + super().__init__(bench.directory) |
| 49 | + |
| 50 | + def bin_args(self) -> list[str]: |
| 51 | + return [] |
| 52 | + |
| 53 | + def extra_env_vars(self) -> dict: |
| 54 | + return {} |
| 55 | + |
| 56 | + def unit(self): |
| 57 | + return "μs" |
| 58 | + |
| 59 | + def setup(self): |
| 60 | + self.bench.setup() |
| 61 | + self.benchmark_bin = os.path.join(self.bench.bins, self.bench_name) |
| 62 | + |
| 63 | + def run(self, env_vars) -> Result: |
| 64 | + command = [ |
| 65 | + f"{self.benchmark_bin}", |
| 66 | + f"--test={self.test}", |
| 67 | + "--csv", |
| 68 | + "--noHeaders" |
| 69 | + ] |
| 70 | + |
| 71 | + command += self.bin_args() |
| 72 | + env_vars.update(self.extra_env_vars()) |
| 73 | + |
| 74 | + result = self.run_bench(command, env_vars) |
| 75 | + (label, mean) = self.parse_output(result) |
| 76 | + return Result(label=label, value=mean, command=command, env=env_vars, stdout=result) |
| 77 | + |
| 78 | + def parse_output(self, output): |
| 79 | + csv_file = io.StringIO(output) |
| 80 | + reader = csv.reader(csv_file) |
| 81 | + next(reader, None) |
| 82 | + data_row = next(reader, None) |
| 83 | + if data_row is None: |
| 84 | + raise ValueError("Benchmark output does not contain data.") |
| 85 | + try: |
| 86 | + label = data_row[0] |
| 87 | + mean = float(data_row[1]) |
| 88 | + return (label, mean) |
| 89 | + except (ValueError, IndexError) as e: |
| 90 | + raise ValueError(f"Error parsing output: {e}") |
| 91 | + |
| 92 | + def teardown(self): |
| 93 | + return |
| 94 | + |
| 95 | +class SubmitKernelSYCL(ComputeBenchmark): |
| 96 | + def __init__(self, bench, ioq): |
| 97 | + self.ioq = ioq |
| 98 | + super().__init__(bench, "api_overhead_benchmark_sycl", "SubmitKernel") |
| 99 | + |
| 100 | + def name(self): |
| 101 | + order = "in order" if self.ioq else "out of order" |
| 102 | + return f"api_overhead_benchmark_sycl SubmitKernel {order}" |
| 103 | + |
| 104 | + def bin_args(self) -> list[str]: |
| 105 | + return [ |
| 106 | + f"--Ioq={self.ioq}", |
| 107 | + "--DiscardEvents=0", |
| 108 | + "--MeasureCompletion=0", |
| 109 | + "--iterations=100000", |
| 110 | + "--Profiling=0", |
| 111 | + "--NumKernels=10", |
| 112 | + "--KernelExecTime=1" |
| 113 | + ] |
| 114 | + |
| 115 | +class ExecImmediateCopyQueue(ComputeBenchmark): |
| 116 | + def __init__(self, bench, ioq, isCopyOnly, source, destination, size): |
| 117 | + self.ioq = ioq |
| 118 | + self.isCopyOnly = isCopyOnly |
| 119 | + self.source = source |
| 120 | + self.destination = destination |
| 121 | + self.size = size |
| 122 | + super().__init__(bench, "api_overhead_benchmark_sycl", "ExecImmediateCopyQueue") |
| 123 | + |
| 124 | + def name(self): |
| 125 | + order = "in order" if self.ioq else "out of order" |
| 126 | + return f"api_overhead_benchmark_sycl ExecImmediateCopyQueue {order} from {self.source} to {self.destination}, size {self.size}" |
| 127 | + |
| 128 | + def bin_args(self) -> list[str]: |
| 129 | + return [ |
| 130 | + "--iterations=100000", |
| 131 | + f"--ioq={self.ioq}", |
| 132 | + f"--IsCopyOnly={self.isCopyOnly}", |
| 133 | + "--MeasureCompletionTime=0", |
| 134 | + f"--src={self.destination}", |
| 135 | + f"--dst={self.destination}", |
| 136 | + f"--size={self.size}" |
| 137 | + ] |
| 138 | + |
| 139 | +class QueueInOrderMemcpy(ComputeBenchmark): |
| 140 | + def __init__(self, bench, isCopyOnly, source, destination, size): |
| 141 | + self.isCopyOnly = isCopyOnly |
| 142 | + self.source = source |
| 143 | + self.destination = destination |
| 144 | + self.size = size |
| 145 | + super().__init__(bench, "memory_benchmark_sycl", "QueueInOrderMemcpy") |
| 146 | + |
| 147 | + def name(self): |
| 148 | + return f"memory_benchmark_sycl QueueInOrderMemcpy from {self.source} to {self.destination}, size {self.size}" |
| 149 | + |
| 150 | + def bin_args(self) -> list[str]: |
| 151 | + return [ |
| 152 | + "--iterations=10000", |
| 153 | + f"--IsCopyOnly={self.isCopyOnly}", |
| 154 | + f"--sourcePlacement={self.source}", |
| 155 | + f"--destinationPlacement={self.destination}", |
| 156 | + f"--size={self.size}", |
| 157 | + "--count=100" |
| 158 | + ] |
| 159 | + |
| 160 | +class QueueMemcpy(ComputeBenchmark): |
| 161 | + def __init__(self, bench, source, destination, size): |
| 162 | + self.source = source |
| 163 | + self.destination = destination |
| 164 | + self.size = size |
| 165 | + super().__init__(bench, "memory_benchmark_sycl", "QueueMemcpy") |
| 166 | + |
| 167 | + def name(self): |
| 168 | + return f"memory_benchmark_sycl QueueMemcpy from {self.source} to {self.destination}, size {self.size}" |
| 169 | + |
| 170 | + def bin_args(self) -> list[str]: |
| 171 | + return [ |
| 172 | + "--iterations=10000", |
| 173 | + f"--sourcePlacement={self.source}", |
| 174 | + f"--destinationPlacement={self.destination}", |
| 175 | + f"--size={self.size}", |
| 176 | + ] |
| 177 | + |
| 178 | +class StreamMemory(ComputeBenchmark): |
| 179 | + def __init__(self, bench, type, size, placement): |
| 180 | + self.type = type |
| 181 | + self.size = size |
| 182 | + self.placement = placement |
| 183 | + super().__init__(bench, "memory_benchmark_sycl", "StreamMemory") |
| 184 | + |
| 185 | + def name(self): |
| 186 | + return f"memory_benchmark_sycl StreamMemory, placement {self.placement}, type {self.type}, size {self.size}" |
| 187 | + |
| 188 | + def bin_args(self) -> list[str]: |
| 189 | + return [ |
| 190 | + "--iterations=10000", |
| 191 | + f"--type={self.type}", |
| 192 | + f"--size={self.size}", |
| 193 | + f"--memoryPlacement={self.placement}", |
| 194 | + "--useEvents=0", |
| 195 | + "--contents=Zeros", |
| 196 | + ] |
| 197 | + |
| 198 | +class VectorSum(ComputeBenchmark): |
| 199 | + def __init__(self, bench): |
| 200 | + super().__init__(bench, "miscellaneous_benchmark_sycl", "VectorSum") |
| 201 | + |
| 202 | + def name(self): |
| 203 | + return f"miscellaneous_benchmark_sycl VectorSum" |
| 204 | + |
| 205 | + def bin_args(self) -> list[str]: |
| 206 | + return [ |
| 207 | + "--iterations=1000", |
| 208 | + "--numberOfElementsX=512", |
| 209 | + "--numberOfElementsY=256", |
| 210 | + "--numberOfElementsZ=256", |
| 211 | + ] |
| 212 | + |
0 commit comments