mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -28,11 +28,14 @@
|
||||
using namespace std;
|
||||
|
||||
#define DEFAULT_COMPILATION_PROGRAM "cl_offline_compiler"
|
||||
#define DEFAULT_SPIRV_VALIDATOR "spirv-val"
|
||||
|
||||
CompilationMode gCompilationMode = kOnline;
|
||||
CompilationCacheMode gCompilationCacheMode = kCacheModeCompileIfAbsent;
|
||||
std::string gCompilationCachePath = ".";
|
||||
std::string gCompilationProgram = DEFAULT_COMPILATION_PROGRAM;
|
||||
bool gDisableSPIRVValidation = false;
|
||||
std::string gSPIRVValidator = DEFAULT_SPIRV_VALIDATOR;
|
||||
|
||||
void helpInfo()
|
||||
{
|
||||
@@ -62,7 +65,14 @@ For offline compilation (binary and spir-v modes) only:
|
||||
Path for offline compiler output and CL source
|
||||
--compilation-program <prog>
|
||||
Program to use for offline compilation, defaults to:
|
||||
)" DEFAULT_COMPILATION_PROGRAM "\n\n");
|
||||
)" DEFAULT_COMPILATION_PROGRAM R"(
|
||||
|
||||
For spir-v mode only:
|
||||
--disable-spirv-validation
|
||||
Disable validation of SPIR-V using the SPIR-V validator
|
||||
--spirv-validator
|
||||
Path for SPIR-V validator, defaults to )" DEFAULT_SPIRV_VALIDATOR "\n"
|
||||
"\n");
|
||||
}
|
||||
|
||||
int parseCustomParam(int argc, const char *argv[], const char *ignore)
|
||||
@@ -198,6 +208,26 @@ int parseCustomParam(int argc, const char *argv[], const char *ignore)
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
else if (!strcmp(argv[i], "--disable-spirv-validation"))
|
||||
{
|
||||
delArg++;
|
||||
gDisableSPIRVValidation = true;
|
||||
}
|
||||
else if (!strcmp(argv[i], "--spirv-validator"))
|
||||
{
|
||||
delArg++;
|
||||
if ((i + 1) < argc)
|
||||
{
|
||||
delArg++;
|
||||
gSPIRVValidator = argv[i + 1];
|
||||
}
|
||||
else
|
||||
{
|
||||
log_error("Program argument for --spirv-validator was not "
|
||||
"specified.\n");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// cleaning parameters from argv tab
|
||||
for (int j = i; j < argc - delArg; j++) argv[j] = argv[j + delArg];
|
||||
|
||||
@@ -38,6 +38,8 @@ extern CompilationMode gCompilationMode;
|
||||
extern CompilationCacheMode gCompilationCacheMode;
|
||||
extern std::string gCompilationCachePath;
|
||||
extern std::string gCompilationProgram;
|
||||
extern bool gDisableSPIRVValidation;
|
||||
extern std::string gSPIRVValidator;
|
||||
|
||||
extern int parseCustomParam(int argc, const char *argv[],
|
||||
const char *ignore = 0);
|
||||
|
||||
Reference in New Issue
Block a user