mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-19 06:09:01 +00:00
Refactor setting of compilation mode and cache mode
This change refactors the setting of the compilation mode, so that instead of using a 'gOfflineCompiler' bool together with a 'gOfflineCompilerOutputType' enum, a single 'gCompilationMode' enum is used. The default value for gCompilationMode is 'kOnline', which is equivalent to the previous defaulting of gOfflineCompiler to false. In addition, it refactors the setting of the compilation cache mode, so that instead of the 'gForceSpirVCache' and 'gForceSpirVGenerate' bools, a single 'gCompilationCacheMode' enum is used. The default value for gCompilationCacheMode is 'kCacheModeCompileIfAbsent', which is equivalent to the previous defaulting of both booleans to false.
This commit is contained in:
committed by
Kévin Petit
parent
814dd8adc0
commit
9be570cdf0
@@ -20,7 +20,7 @@
|
||||
|
||||
#include "errorHelpers.h"
|
||||
|
||||
extern bool gOfflineCompiler;
|
||||
#include "parseParameters.h"
|
||||
|
||||
const char *IGetErrorString( int clErrorCode )
|
||||
{
|
||||
@@ -800,7 +800,7 @@ int check_opencl_version(cl_device_id device, cl_uint requestedMajorVersion, cl_
|
||||
|
||||
int check_functions_for_offline_compiler(const char *subtestname, cl_device_id device)
|
||||
{
|
||||
if(gOfflineCompiler)
|
||||
if (gCompilationMode != kOnline)
|
||||
{
|
||||
int nNotRequiredWithOfflineCompiler = sizeof(subtests_to_skip_with_offline_compiler)/sizeof(char *);
|
||||
size_t i;
|
||||
|
||||
@@ -233,11 +233,16 @@ static cl_int get_device_address_bits(cl_context context, cl_uint &device_addres
|
||||
return CL_SUCCESS;
|
||||
}
|
||||
|
||||
int create_single_kernel_helper_create_program(cl_context context, cl_program *outProgram, unsigned int numKernelLines, const char **kernelProgram, const char *buildOptions)
|
||||
static int create_single_kernel_helper_create_program(cl_context context,
|
||||
cl_program *outProgram,
|
||||
unsigned int numKernelLines,
|
||||
const char **kernelProgram,
|
||||
const char *buildOptions,
|
||||
CompilationMode compilationMode)
|
||||
{
|
||||
int error = CL_SUCCESS;
|
||||
|
||||
if (gOfflineCompiler)
|
||||
if (compilationMode != kOnline)
|
||||
{
|
||||
std::string kernel;
|
||||
|
||||
@@ -261,7 +266,7 @@ int create_single_kernel_helper_create_program(cl_context context, cl_program *o
|
||||
std::string size_t_width_str;
|
||||
|
||||
cl_uint device_address_space_size = 0;
|
||||
if (gOfflineCompilerOutputType == kSpir_v)
|
||||
if (compilationMode == kSpir_v)
|
||||
{
|
||||
cl_int error = get_device_address_bits(context, device_address_space_size);
|
||||
if (error != CL_SUCCESS)
|
||||
@@ -276,11 +281,12 @@ int create_single_kernel_helper_create_program(cl_context context, cl_program *o
|
||||
size_t_width_str = size_t_width_stream.str();
|
||||
}
|
||||
|
||||
// try to read cached output file when test is run with gForceSpirVGenerate = false
|
||||
// try to read cached output file when test is run with gCompilationCacheMode != kCacheModeOverwrite
|
||||
std::ifstream ifs(outputFilename.c_str(), std::ios::binary);
|
||||
if (!ifs.good() || gForceSpirVGenerate)
|
||||
|
||||
if (gCompilationCacheMode == kCacheModeOverwrite || !ifs.good())
|
||||
{
|
||||
if (gForceSpirVCache)
|
||||
if (gCompilationCacheMode == kCacheModeForceRead)
|
||||
{
|
||||
log_info("OfflineCompiler: can't open cached SpirV file: %s\n", outputFilename.c_str());
|
||||
return -1;
|
||||
@@ -288,7 +294,7 @@ int create_single_kernel_helper_create_program(cl_context context, cl_program *o
|
||||
|
||||
ifs.close();
|
||||
|
||||
if (!gForceSpirVGenerate)
|
||||
if (gCompilationCacheMode != kCacheModeOverwrite)
|
||||
log_info("OfflineCompiler: can't find cached SpirV file: %s\n", outputFilename.c_str());
|
||||
|
||||
std::ofstream ofs(sourceFilename.c_str(), std::ios::binary);
|
||||
@@ -305,7 +311,7 @@ int create_single_kernel_helper_create_program(cl_context context, cl_program *o
|
||||
// set output type and default script
|
||||
std::string outputTypeStr;
|
||||
std::string defaultScript;
|
||||
if (gOfflineCompilerOutputType == kBinary)
|
||||
if (compilationMode == kBinary)
|
||||
{
|
||||
outputTypeStr = "binary";
|
||||
#if defined(_WIN32)
|
||||
@@ -314,7 +320,7 @@ int create_single_kernel_helper_create_program(cl_context context, cl_program *o
|
||||
defaultScript = "../build_script_binary.py ";
|
||||
#endif
|
||||
}
|
||||
else if (gOfflineCompilerOutputType == kSpir_v)
|
||||
else if (compilationMode == kSpir_v)
|
||||
{
|
||||
outputTypeStr = "spir_v";
|
||||
#if defined(_WIN32)
|
||||
@@ -390,7 +396,7 @@ int create_single_kernel_helper_create_program(cl_context context, cl_program *o
|
||||
ifs.seekg(0, ifs.beg);
|
||||
|
||||
//treat modifiedProgram as input for clCreateProgramWithBinary
|
||||
if (gOfflineCompilerOutputType == kBinary)
|
||||
if (compilationMode == kBinary)
|
||||
{
|
||||
// read binary from file:
|
||||
std::vector<unsigned char> modifiedKernelBuf(length);
|
||||
@@ -417,7 +423,7 @@ int create_single_kernel_helper_create_program(cl_context context, cl_program *o
|
||||
}
|
||||
}
|
||||
//treat modifiedProgram as input for clCreateProgramWithIL
|
||||
else if (gOfflineCompilerOutputType == kSpir_v)
|
||||
else if (compilationMode == kSpir_v)
|
||||
{
|
||||
// read spir-v from file:
|
||||
std::vector<unsigned char> modifiedKernelBuf(length);
|
||||
@@ -436,7 +442,7 @@ int create_single_kernel_helper_create_program(cl_context context, cl_program *o
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
else // compilationMode == kOnline
|
||||
{
|
||||
/* Create the program object from source */
|
||||
*outProgram = clCreateProgramWithSource(context, numKernelLines, kernelProgram, NULL, &error);
|
||||
@@ -449,7 +455,23 @@ int create_single_kernel_helper_create_program(cl_context context, cl_program *o
|
||||
return 0;
|
||||
}
|
||||
|
||||
int create_single_kernel_helper_with_build_options(cl_context context, cl_program *outProgram, cl_kernel *outKernel, unsigned int numKernelLines, const char **kernelProgram, const char *kernelName, const char *buildOptions)
|
||||
int create_single_kernel_helper_create_program(cl_context context,
|
||||
cl_program *outProgram,
|
||||
unsigned int numKernelLines,
|
||||
const char **kernelProgram,
|
||||
const char *buildOptions)
|
||||
{
|
||||
return create_single_kernel_helper_create_program(context, outProgram, numKernelLines,
|
||||
kernelProgram, buildOptions, gCompilationMode);
|
||||
}
|
||||
|
||||
int create_single_kernel_helper_with_build_options(cl_context context,
|
||||
cl_program *outProgram,
|
||||
cl_kernel *outKernel,
|
||||
unsigned int numKernelLines,
|
||||
const char **kernelProgram,
|
||||
const char *kernelName,
|
||||
const char *buildOptions)
|
||||
{
|
||||
return create_single_kernel_helper(context, outProgram, outKernel, numKernelLines, kernelProgram, kernelName, buildOptions);
|
||||
}
|
||||
|
||||
@@ -27,11 +27,9 @@
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool gOfflineCompiler = false;
|
||||
bool gForceSpirVCache = false;
|
||||
bool gForceSpirVGenerate = false;
|
||||
std::string gSpirVPath = ".";
|
||||
OfflineCompilerOutputType gOfflineCompilerOutputType;
|
||||
CompilationMode gCompilationMode = kOnline;
|
||||
CompilationCacheMode gCompilationCacheMode = kCacheModeCompileIfAbsent;
|
||||
std::string gSpirVPath = ".";
|
||||
|
||||
void helpInfo ()
|
||||
{
|
||||
@@ -78,29 +76,27 @@ int parseCustomParam (int argc, const char *argv[], const char *ignore)
|
||||
delArg = 1;
|
||||
if ((i + 1) < argc)
|
||||
{
|
||||
gOfflineCompiler = true;
|
||||
|
||||
if (!strcmp(argv[i + 1], "binary"))
|
||||
{
|
||||
gOfflineCompilerOutputType = kBinary;
|
||||
gCompilationMode = kBinary;
|
||||
delArg++;
|
||||
}
|
||||
else if (!strcmp(argv[i + 1], "spir_v"))
|
||||
{
|
||||
gOfflineCompilerOutputType = kSpir_v;
|
||||
gCompilationMode = kSpir_v;
|
||||
delArg++;
|
||||
if ((i + 3) < argc)
|
||||
{
|
||||
if (!strcmp(argv[i + 2], "cache"))
|
||||
{
|
||||
gForceSpirVCache = true;
|
||||
gCompilationCacheMode = kCacheModeForceRead;
|
||||
gSpirVPath = argv[i + 3];
|
||||
log_info(" SpirV reading from cache enabled.\n");
|
||||
delArg += 2;
|
||||
}
|
||||
else if (!strcmp(argv[i + 2], "generate"))
|
||||
{
|
||||
gForceSpirVGenerate = true;
|
||||
gCompilationCacheMode = kCacheModeOverwrite;
|
||||
gSpirVPath = argv[i + 3];
|
||||
log_info(" SpirV force generate binaries enabled.\n");
|
||||
delArg += 2;
|
||||
|
||||
@@ -19,18 +19,23 @@
|
||||
#include "compat.h"
|
||||
#include <string>
|
||||
|
||||
extern bool gOfflineCompiler;
|
||||
extern bool gForceSpirVCache;
|
||||
extern bool gForceSpirVGenerate;
|
||||
extern std::string gSpirVPath;
|
||||
|
||||
enum OfflineCompilerOutputType
|
||||
enum CompilationMode
|
||||
{
|
||||
kBinary = 0,
|
||||
kOnline = 0,
|
||||
kBinary,
|
||||
kSpir_v
|
||||
};
|
||||
|
||||
extern OfflineCompilerOutputType gOfflineCompilerOutputType;
|
||||
enum CompilationCacheMode
|
||||
{
|
||||
kCacheModeCompileIfAbsent = 0,
|
||||
kCacheModeForceRead,
|
||||
kCacheModeOverwrite
|
||||
};
|
||||
|
||||
extern CompilationMode gCompilationMode;
|
||||
extern CompilationCacheMode gCompilationCacheMode;
|
||||
extern std::string gSpirVPath;
|
||||
|
||||
extern int parseCustomParam (int argc, const char *argv[], const char *ignore = 0 );
|
||||
|
||||
|
||||
@@ -423,7 +423,7 @@ int test_get_program_source(cl_device_id deviceID, cl_context context, cl_comman
|
||||
/* Try getting the length */
|
||||
error = clGetProgramInfo( program, CL_PROGRAM_SOURCE, NULL, NULL, &length );
|
||||
test_error( error, "Unable to get program source length" );
|
||||
if (length != strlen(sample_kernel_code_single_line[0]) + 1 && !gOfflineCompiler)
|
||||
if (length != strlen(sample_kernel_code_single_line[0]) + 1 && gCompilationMode == kOnline)
|
||||
{
|
||||
log_error( "ERROR: Length returned for program source is incorrect!\n" );
|
||||
return -1;
|
||||
@@ -432,7 +432,7 @@ int test_get_program_source(cl_device_id deviceID, cl_context context, cl_comman
|
||||
/* Try normal source */
|
||||
error = clGetProgramInfo( program, CL_PROGRAM_SOURCE, sizeof( buffer ), buffer, NULL );
|
||||
test_error( error, "Unable to get program source" );
|
||||
if (strlen(buffer) != strlen(sample_kernel_code_single_line[0]) && !gOfflineCompiler)
|
||||
if (strlen(buffer) != strlen(sample_kernel_code_single_line[0]) && gCompilationMode == kOnline)
|
||||
{
|
||||
log_error( "ERROR: Length of program source is incorrect!\n" );
|
||||
return -1;
|
||||
@@ -441,12 +441,12 @@ int test_get_program_source(cl_device_id deviceID, cl_context context, cl_comman
|
||||
/* Try both at once */
|
||||
error = clGetProgramInfo( program, CL_PROGRAM_SOURCE, sizeof( buffer ), buffer, &length );
|
||||
test_error( error, "Unable to get program source" );
|
||||
if (strlen(buffer) != strlen(sample_kernel_code_single_line[0]) && !gOfflineCompiler)
|
||||
if (strlen(buffer) != strlen(sample_kernel_code_single_line[0]) && gCompilationMode == kOnline)
|
||||
{
|
||||
log_error( "ERROR: Length of program source is incorrect!\n" );
|
||||
return -1;
|
||||
}
|
||||
if (length != strlen(sample_kernel_code_single_line[0]) + 1 && !gOfflineCompiler)
|
||||
if (length != strlen(sample_kernel_code_single_line[0]) + 1 && gCompilationMode == kOnline)
|
||||
{
|
||||
log_error( "ERROR: Returned length of program source is incorrect!\n" );
|
||||
return -1;
|
||||
|
||||
@@ -139,7 +139,7 @@ int get_program_with_il(clProgramWrapper &prog,
|
||||
const char *prog_name)
|
||||
{
|
||||
cl_int err = 0;
|
||||
if (gOfflineCompiler && gOfflineCompilerOutputType == kBinary) {
|
||||
if (gCompilationMode == kBinary) {
|
||||
return offline_get_program_with_il(prog, deviceID, context, prog_name);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user