mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-25 16:29:03 +00:00
Allow device ID to be specified for offline compilation
Signed-off-by: Stuart Brady <stuart.brady@arm.com>
This commit is contained in:
committed by
Kévin Petit
parent
76fd344e64
commit
245e11ec67
@@ -353,7 +353,7 @@ static std::string get_offline_compilation_command(const cl_uint device_address_
|
|||||||
return scriptToRunString;
|
return scriptToRunString;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int invoke_offline_compiler(cl_context context,
|
static int invoke_offline_compiler(const cl_device_id device,
|
||||||
const cl_uint device_address_space_size,
|
const cl_uint device_address_space_size,
|
||||||
const CompilationMode compilationMode,
|
const CompilationMode compilationMode,
|
||||||
const std::string &bOptions,
|
const std::string &bOptions,
|
||||||
@@ -411,16 +411,9 @@ static cl_int get_first_device_id(const cl_context context, cl_device_id &device
|
|||||||
return CL_SUCCESS;
|
return CL_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static cl_int get_first_device_address_bits(const cl_context context, cl_uint &device_address_space_size)
|
static cl_int get_device_address_bits(const cl_device_id device, cl_uint &device_address_space_size)
|
||||||
{
|
{
|
||||||
cl_device_id device;
|
cl_int error = clGetDeviceInfo(device, CL_DEVICE_ADDRESS_BITS, sizeof(cl_uint), &device_address_space_size, NULL);
|
||||||
cl_int error = get_first_device_id(context, device);
|
|
||||||
if (error != CL_SUCCESS)
|
|
||||||
{
|
|
||||||
return error;
|
|
||||||
}
|
|
||||||
|
|
||||||
error = clGetDeviceInfo(device, CL_DEVICE_ADDRESS_BITS, sizeof(cl_uint), &device_address_space_size, NULL);
|
|
||||||
test_error(error, "Unable to obtain device address bits");
|
test_error(error, "Unable to obtain device address bits");
|
||||||
|
|
||||||
if (device_address_space_size != 32 && device_address_space_size != 64)
|
if (device_address_space_size != 32 && device_address_space_size != 64)
|
||||||
@@ -434,6 +427,7 @@ static cl_int get_first_device_address_bits(const cl_context context, cl_uint &d
|
|||||||
|
|
||||||
static int get_offline_compiler_output(std::ifstream &ifs,
|
static int get_offline_compiler_output(std::ifstream &ifs,
|
||||||
cl_context context,
|
cl_context context,
|
||||||
|
cl_device_id device,
|
||||||
const std::string &kernel,
|
const std::string &kernel,
|
||||||
const bool openclCXX,
|
const bool openclCXX,
|
||||||
const CompilationMode compilationMode,
|
const CompilationMode compilationMode,
|
||||||
@@ -444,7 +438,7 @@ static int get_offline_compiler_output(std::ifstream &ifs,
|
|||||||
|
|
||||||
// Get device CL_DEVICE_ADDRESS_BITS
|
// Get device CL_DEVICE_ADDRESS_BITS
|
||||||
cl_uint device_address_space_size = 0;
|
cl_uint device_address_space_size = 0;
|
||||||
int error = get_first_device_address_bits(context, device_address_space_size);
|
int error = get_device_address_bits(device, device_address_space_size);
|
||||||
if (error != CL_SUCCESS)
|
if (error != CL_SUCCESS)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
@@ -487,7 +481,7 @@ static int get_offline_compiler_output(std::ifstream &ifs,
|
|||||||
ofs.write(kernel.c_str(), kernel.size());
|
ofs.write(kernel.c_str(), kernel.size());
|
||||||
ofs.close();
|
ofs.close();
|
||||||
|
|
||||||
error = invoke_offline_compiler(context, device_address_space_size, compilationMode,
|
error = invoke_offline_compiler(device, device_address_space_size, compilationMode,
|
||||||
bOptions, sourceFilename, outputFilename, openclCXX);
|
bOptions, sourceFilename, outputFilename, openclCXX);
|
||||||
if (error != CL_SUCCESS)
|
if (error != CL_SUCCESS)
|
||||||
return error;
|
return error;
|
||||||
@@ -506,6 +500,7 @@ static int get_offline_compiler_output(std::ifstream &ifs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int create_single_kernel_helper_create_program_offline(cl_context context,
|
static int create_single_kernel_helper_create_program_offline(cl_context context,
|
||||||
|
cl_device_id device,
|
||||||
cl_program *outProgram,
|
cl_program *outProgram,
|
||||||
unsigned int numKernelLines,
|
unsigned int numKernelLines,
|
||||||
const char *const *kernelProgram,
|
const char *const *kernelProgram,
|
||||||
@@ -523,8 +518,14 @@ static int create_single_kernel_helper_create_program_offline(cl_context context
|
|||||||
|
|
||||||
kernelName = add_build_options(kernelName, buildOptions);
|
kernelName = add_build_options(kernelName, buildOptions);
|
||||||
|
|
||||||
|
if (device == NULL)
|
||||||
|
{
|
||||||
|
error = get_first_device_id(context, device);
|
||||||
|
test_error(error, "Failed to get device ID for first device");
|
||||||
|
}
|
||||||
|
|
||||||
std::ifstream ifs;
|
std::ifstream ifs;
|
||||||
error = get_offline_compiler_output(ifs, context, kernel, openclCXX, compilationMode, bOptions, kernelName);
|
error = get_offline_compiler_output(ifs, context, device, kernel, openclCXX, compilationMode, bOptions, kernelName);
|
||||||
if (error != CL_SUCCESS)
|
if (error != CL_SUCCESS)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
@@ -552,10 +553,6 @@ static int create_single_kernel_helper_create_program_offline(cl_context context
|
|||||||
ifs.read((char *)&modifiedKernelBuf[0], length);
|
ifs.read((char *)&modifiedKernelBuf[0], length);
|
||||||
ifs.close();
|
ifs.close();
|
||||||
|
|
||||||
cl_device_id device;
|
|
||||||
error = get_first_device_id(context, device);
|
|
||||||
test_error(error, "Failed to get device ID");
|
|
||||||
|
|
||||||
size_t lengths = modifiedKernelBuf.size();
|
size_t lengths = modifiedKernelBuf.size();
|
||||||
const unsigned char *binaries = { &modifiedKernelBuf[0] };
|
const unsigned char *binaries = { &modifiedKernelBuf[0] };
|
||||||
log_info("offlineCompiler: clCreateProgramWithSource replaced with clCreateProgramWithBinary\n");
|
log_info("offlineCompiler: clCreateProgramWithSource replaced with clCreateProgramWithBinary\n");
|
||||||
@@ -590,6 +587,7 @@ static int create_single_kernel_helper_create_program_offline(cl_context context
|
|||||||
}
|
}
|
||||||
|
|
||||||
static int create_single_kernel_helper_create_program(cl_context context,
|
static int create_single_kernel_helper_create_program(cl_context context,
|
||||||
|
cl_device_id device,
|
||||||
cl_program *outProgram,
|
cl_program *outProgram,
|
||||||
unsigned int numKernelLines,
|
unsigned int numKernelLines,
|
||||||
const char **kernelProgram,
|
const char **kernelProgram,
|
||||||
@@ -612,9 +610,10 @@ static int create_single_kernel_helper_create_program(cl_context context,
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return create_single_kernel_helper_create_program_offline(context, outProgram, numKernelLines,
|
return create_single_kernel_helper_create_program_offline(context, device, outProgram,
|
||||||
kernelProgram, buildOptions,
|
numKernelLines, kernelProgram,
|
||||||
openclCXX, compilationMode);
|
buildOptions, openclCXX,
|
||||||
|
compilationMode);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -625,9 +624,24 @@ int create_single_kernel_helper_create_program(cl_context context,
|
|||||||
const char *buildOptions,
|
const char *buildOptions,
|
||||||
const bool openclCXX)
|
const bool openclCXX)
|
||||||
{
|
{
|
||||||
return create_single_kernel_helper_create_program(context, outProgram, numKernelLines,
|
return create_single_kernel_helper_create_program(context, NULL, outProgram,
|
||||||
kernelProgram, buildOptions,
|
numKernelLines, kernelProgram,
|
||||||
openclCXX, gCompilationMode);
|
buildOptions, openclCXX,
|
||||||
|
gCompilationMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
int create_single_kernel_helper_create_program_for_device(cl_context context,
|
||||||
|
cl_device_id device,
|
||||||
|
cl_program *outProgram,
|
||||||
|
unsigned int numKernelLines,
|
||||||
|
const char **kernelProgram,
|
||||||
|
const char *buildOptions,
|
||||||
|
const bool openclCXX)
|
||||||
|
{
|
||||||
|
return create_single_kernel_helper_create_program(context, device, outProgram,
|
||||||
|
numKernelLines, kernelProgram,
|
||||||
|
buildOptions, openclCXX,
|
||||||
|
gCompilationMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
int create_single_kernel_helper_with_build_options(cl_context context,
|
int create_single_kernel_helper_with_build_options(cl_context context,
|
||||||
@@ -728,7 +742,7 @@ int create_openclcpp_program(cl_context context,
|
|||||||
{
|
{
|
||||||
// Create program
|
// Create program
|
||||||
return create_single_kernel_helper_create_program(
|
return create_single_kernel_helper_create_program(
|
||||||
context, outProgram, numKernelLines, kernelProgram, buildOptions, true, kSpir_v
|
context, NULL, outProgram, numKernelLines, kernelProgram, buildOptions, true, kSpir_v
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -89,6 +89,14 @@ extern int create_single_kernel_helper_create_program(cl_context context,
|
|||||||
const char *buildOptions = NULL,
|
const char *buildOptions = NULL,
|
||||||
const bool openclCXX = false);
|
const bool openclCXX = false);
|
||||||
|
|
||||||
|
extern int create_single_kernel_helper_create_program_for_device(cl_context context,
|
||||||
|
cl_device_id device,
|
||||||
|
cl_program *outProgram,
|
||||||
|
unsigned int numKernelLines,
|
||||||
|
const char **kernelProgram,
|
||||||
|
const char *buildOptions = NULL,
|
||||||
|
const bool openclCXX = false);
|
||||||
|
|
||||||
/* Creates OpenCL C++ program. This one must be used for creating OpenCL C++ program. */
|
/* Creates OpenCL C++ program. This one must be used for creating OpenCL C++ program. */
|
||||||
extern int create_openclcpp_program(cl_context context,
|
extern int create_openclcpp_program(cl_context context,
|
||||||
cl_program *outProgram,
|
cl_program *outProgram,
|
||||||
|
|||||||
Reference in New Issue
Block a user