Skip to content

Commit c698791

Browse files
Esteban Padilla Cerdiofacebook-github-bot
authored andcommitted
Enable RANGE definition in shader YAML for repetitive shader generation (#4196)
Summary: Pull Request resolved: #4196 GPUInfo requires the compilation of a ton of shaders with small variations to emulate OpenCL's kernel compilation on runtime with strings. This diff enables a RANGE implementation to generate these shaders dynamically without typing each value out. The format is - RANGE: [start, end] // Inclusive SUFFIX: string // Optional If a suffix is selected, the shaders will be called `name_suffix_K ` for each value K from the range. If no suffix is selected, the shaders will be simply called `name_K ` Reviewed By: SS-JIA Differential Revision: D59588223 fbshipit-source-id: 67394c6b860c09e324baa45ccf7f5b7d6d555ed2
1 parent e3e6744 commit c698791

File tree

2 files changed

+24
-514
lines changed

2 files changed

+24
-514
lines changed

backends/vulkan/runtime/gen_vulkan_spv.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -525,8 +525,29 @@ def generateVariantCombinations(
525525
if param_name not in exclude_params:
526526
param_values = []
527527
for value in value_list:
528-
suffix = value.get("SUFFIX", value["VALUE"])
529-
param_values.append((param_name, suffix, value["VALUE"]))
528+
if "RANGE" in value:
529+
value_range = value["RANGE"]
530+
suffix = value.get("SUFFIX", "")
531+
if isinstance(value_range, list) and len(value_range) == 2:
532+
for i in range(value_range[0], value_range[1] + 1):
533+
curr_suffix = (
534+
suffix + "_" + str(i) if suffix else str(i)
535+
)
536+
param_values.append((param_name, curr_suffix, str(i)))
537+
else:
538+
raise ValueError(
539+
f"{value['RANGE']} is not a valid range. Must be in format [start, end] (inclusive)."
540+
)
541+
542+
elif "VALUE" in value:
543+
suffix = value.get("SUFFIX", value["VALUE"])
544+
param_values.append((param_name, suffix, value["VALUE"]))
545+
546+
else:
547+
raise KeyError(
548+
"Parameter must be 'VALUE: string' or 'RANGE: [a, b]'"
549+
)
550+
530551
all_iterated_params.append(param_values)
531552

532553
return list(product(*all_iterated_params))

0 commit comments

Comments
 (0)