Run spirv-val for SPIR-V offline compilation (#1108)

The common --disable-spirv-validation option has been added to disable
this functionality.

Signed-off-by: Stuart Brady <stuart.brady@arm.com>
This commit is contained in:
Stuart Brady
2021-06-11 09:42:20 +01:00
committed by GitHub
parent 76ace61314
commit 277d029608
3 changed files with 54 additions and 2 deletions

View File

@@ -530,7 +530,7 @@ static int get_offline_compiler_output(
sourceFilename, outputFilename);
if (error != CL_SUCCESS) return error;
// read output file
// open output file for reading
ifs.open(outputFilename.c_str(), std::ios::binary);
if (!ifs.good())
{
@@ -540,6 +540,26 @@ static int get_offline_compiler_output(
}
}
}
if (compilationMode == kSpir_v && !gDisableSPIRVValidation)
{
std::string runString = gSPIRVValidator + " " + outputFilename;
int returnCode = system(runString.c_str());
if (returnCode == -1)
{
log_error("Error: failed to invoke SPIR-V validator\n");
return CL_COMPILE_PROGRAM_FAILURE;
}
else if (returnCode != 0)
{
log_error(
"Failed to validate SPIR-V file %s: system() returned 0x%x\n",
outputFilename.c_str(), returnCode);
return CL_COMPILE_PROGRAM_FAILURE;
}
}
return CL_SUCCESS;
}