-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.py
124 lines (97 loc) · 4 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
import random
from dataclasses import dataclass
from dataclasses import field
from typing import Literal
from typing import Optional
from src.optimiser_fuzzer import fuzz_optimiser
from src.utils import get_spirvsmith_version
rng = random.SystemRandom()
@dataclass
class BoundedInt:
min: int
max: int
def __iter__(self):
return iter((self.min, self.max))
@dataclass
class BinariesConfig:
ASSEMBLER_PATH: str = "bin/spirv-as"
VALIDATOR_PATH: str = "bin/spirv-val"
OPTIMISER_PATH: str = "bin/spirv-opt"
CROSS_PATH: str = "bin/spirv-cross"
AMBER_PATH: str = "bin/amber"
@dataclass
class MutationsConfig:
# Constants
w_composite_constant: BoundedInt = BoundedInt(1, 3)
w_scalar_constant: BoundedInt = BoundedInt(2, 4)
@dataclass
class LimitsConfig:
# How many types should the fuzzer aim to generate.
n_types: int = 20
# How many constants should the fuzzer aim to generate.
n_constants: int = 50
# How many functions should the fuzzer aim to generate.
n_functions: int = 1
# How deep can the shader go when generating shaders (in terms of control flow).
# e.g. with a depth of 2, the fuzzer will never generate a triply-nested loop.
max_depth: int = 3
# How many shaders should the fuzzer generate. If None, the fuzzer will generate indefinitely.
max_shaders: Optional[int] = 100
@dataclass
class FuzzingStrategyConfig:
mutations_config: MutationsConfig = MutationsConfig()
# If True, SPIRVSmith will include instructions from
# the GLSL extension in generated shaders
enable_ext_glsl_std_450: bool = True
type_exclusion_set: list[str] = field(default_factory=list)
gp_policy: str = "gaussian"
rbp_policy: str = "beta_binomial"
# The following parameters are used to determine
# what constants will be generated by SPIRVSmith
#
# They are similarly interpreted as weight rather than probabilities.
#
# Classification of types:
# scalar_constant -> OpConstant with underlying type OpTypeInt, OpTypeFloat, OpTypeBool
# composite_constant -> OpConstantComposite with underlying type OpTypeVector, OpTypeMatrix etc.
w_composite_constant: int = rng.randint(*mutations_config.w_composite_constant)
w_scalar_constant: int = rng.randint(*mutations_config.w_scalar_constant)
# The following parameter is used to determine how much the fuzzer should
# favour statements rather than constants when looking for operands.
#
# When SPIRVSmith has to pick operands for an operation (say an OpIAdd),
# it has the choice between:
# - Constants -> a global OpConstant or OpConstantComposite
# - Statements -> the result of a previous operation in scope
#
# Setting a higher probability will favour statements over constants.
p_picking_statement_operand: float = 0.8
# The following parameter is used to determine how often a GP re-parameterisation
# should be triggered.
#
# This is only useful in practice in the context of looking for bugs in
# consumers of SPIR-V since it increases variance.
p_mutation: float = 0.0
# SPIRVSmith will try to generate shaders with `shader_target_size` lines.
# No strong guarantees until we figure out how to properly count.
shader_target_size: int = 1500
@dataclass
class MiscConfig:
out_folder: str = "out"
fuzz_optimiser: bool = False
version: str = get_spirvsmith_version()
# The following parameters are only useful when running SPIRVSmith in
# a distributed fashion. Enabling these will almost definitely crash SPIRVSmith
# unless you have deployed the associated infrastructure and have a credentials file.
broadcast_generated_shaders: bool = False
upload_logs: bool = True
@dataclass
class SPIRVSmithConfig:
# Binaries
binaries: BinariesConfig = BinariesConfig()
# Limits
limits: LimitsConfig = LimitsConfig()
# Fuzzing strategy
strategy: FuzzingStrategyConfig = FuzzingStrategyConfig()
# Misc
misc: MiscConfig = MiscConfig()