Skip to content

Commit fa39754

Browse files
SS-JIAfacebook-github-bot
authored andcommitted
[vulkan] Disable shader optimization to avoid Validation Errors (pytorch#69331)
Summary: Pull Request resolved: pytorch#69331 --- ## Context When the optimization flag is turned on, some SPIR-V modules produced from the Vulkan compute shaders were invalid. The Vulkan Validation layer raises the following error for these modules: ``` [ UNASSIGNED-CoreValidation-Shader-InconsistentSpirv ] Object: VK_NULL_HANDLE (Type = 0) | SPIR-V module not valid: Header block 52[%52] is contained in the loop construct headed by 44[%44], but it's merge block 47[%47] is not %52 = OpLabel ``` Turning off the optimization flag, the SPIR-V modules produced no longer reports these errors in the Validation layer. ## Changes Turns off optimization when generating SPIR-V modules to ensure correctness of the modules. **Note that disabling SPIR-V optimization did not regress inference latency for the several models I tested**. Test Plan: Imported from OSS Reviewed By: beback4u Differential Revision: D32840910 Pulled By: SS-JIA fbshipit-source-id: 7ccb5691fd0e2d11b9c8c28ad7b83906e8163699
1 parent bede33e commit fa39754

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

aten/src/ATen/gen_vulkan_spv.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def genCppH(hFilePath, cppFilePath, srcDirPath, glslcPath, tmpDirPath, env):
4343
print("spvPath {}".format(spvPath))
4444

4545
cmd = [
46-
glslcPath, "-fshader-stage=compute", "-Os",
46+
glslcPath, "-fshader-stage=compute",
4747
srcPath, "-o", spvPath,
4848
"--target-env=vulkan1.0",
4949
"-Werror"

aten/src/ATen/native/vulkan/api/Shader.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,8 @@ struct Shader::Factory::Compiler final {
7777
options.SetWarningsAsErrors();
7878
#ifdef DEBUG
7979
options.SetGenerateDebugInfo();
80-
options.SetOptimizationLevel(shaderc_optimization_level_zero);
81-
#else
82-
options.SetOptimizationLevel(shaderc_optimization_level_performance);
8380
#endif /* DEBUG */
81+
options.SetOptimizationLevel(shaderc_optimization_level_zero);
8482
}
8583

8684
std::vector<uint32_t> compile(const char* const source) const {

0 commit comments

Comments
 (0)