Add support for cl_khr_il_program extension

This commit is contained in:
Grzegorz Wawiorko
2020-03-30 17:31:55 +02:00
committed by Alastair Murray
parent 3730bce4e8
commit adec8f9412
4 changed files with 55 additions and 9 deletions

View File

@@ -665,11 +665,32 @@ static int create_single_kernel_helper_create_program_offline(cl_context context
size_t length = modifiedKernelBuf.size();
log_info("offlineCompiler: clCreateProgramWithSource replaced with clCreateProgramWithIL\n");
if (gCoreILProgram) {
*outProgram = clCreateProgramWithIL(context, &modifiedKernelBuf[0], length, &error);
}
else {
cl_platform_id platform;
error = clGetDeviceInfo(device, CL_DEVICE_PLATFORM, sizeof(cl_platform_id), &platform, NULL);
print_error(error, "clGetDeviceInfo for CL_DEVICE_PLATFORM failed");
clCreateProgramWithILKHR_fn clCreateProgramWithILKHR = NULL;
clCreateProgramWithILKHR = (clCreateProgramWithILKHR_fn)clGetExtensionFunctionAddressForPlatform(platform, "clCreateProgramWithILKHR");
if (clCreateProgramWithILKHR == NULL)
{
log_error("ERROR: clGetExtensionFunctionAddressForPlatform failed\n");
return -1;
}
*outProgram = clCreateProgramWithILKHR(context, &modifiedKernelBuf[0], length, &error);
}
*outProgram = clCreateProgramWithIL(context, &modifiedKernelBuf[0], length, &error);
if (*outProgram == NULL || error != CL_SUCCESS)
{
print_error(error, "clCreateProgramWithIL failed");
if (gCoreILProgram) {
print_error(error, "clCreateProgramWithIL failed");
}
else {
print_error(error, "clCreateProgramWithILKHR failed");
}
return error;
}
}

View File

@@ -57,6 +57,7 @@ int gIsEmbedded = 0;
int gIsOpenCL_C_1_0_Device = 0;
int gIsOpenCL_1_0_Device = 0;
int gHasLong = 1;
bool gCoreILProgram = true;
#define DEFAULT_NUM_ELEMENTS 0x4000
@@ -911,7 +912,7 @@ bool check_device_spirv_il_support(cl_device_id device) {
return false;
} else {
Version spirv_version = get_device_spirv_il_version(device);
log_info("This device supports SPIR-V offline compilation. SPIR-V version is %s\n", spirv_version.to_string());
log_info("This device supports SPIR-V offline compilation. SPIR-V version is %s\n", spirv_version.to_string().c_str());
}
return true;
}
@@ -949,21 +950,27 @@ test_status check_spirv_compilation_readiness(cl_device_id device, bool force)
auto ocl_expected_min_version = Version(2, 1);
if (ocl_version < ocl_expected_min_version) {
version_expected_info("Test", "OpenCL", ocl_expected_min_version.to_string().c_str(), ocl_version.to_string().c_str());
return TEST_SKIP;
if (is_extension_available(device, "cl_khr_il_program")) {
gCoreILProgram = false;
log_info("SPIR-V intermediate language supported in OpenCL %s by extension cl_khr_il_program.\n", ocl_version.to_string().c_str());
}
else {
version_expected_info("Test", "OpenCL", ocl_expected_min_version.to_string().c_str(), ocl_version.to_string().c_str());
return TEST_SKIP;
}
}
bool spirv_supported = check_device_spirv_il_support(device);
if (ocl_version >= ocl_expected_min_version && ocl_version <= Version(2, 2)) {
if (spirv_supported == false) {
log_error("SPIR-V intermediate language not supported !!! OpenCL %s requires support.\n", ocl_version.to_string());
log_error("SPIR-V intermediate language not supported !!! OpenCL %s requires support.\n", ocl_version.to_string().c_str());
return TEST_FAIL;
}
}
if (ocl_version > Version(2, 2)) {
if (spirv_supported == false) {
log_info("SPIR-V intermediate language not supported in OpenCL %s. Test skipped.\n", ocl_version.to_string());
log_info("SPIR-V intermediate language not supported in OpenCL %s. Test skipped.\n", ocl_version.to_string().c_str());
return TEST_SKIP;
}
}

View File

@@ -146,6 +146,7 @@ extern int gInfNanSupport; // This is set to 1 if the device suppor
extern int gIsEmbedded; // This is set to 1 if the device is an embedded device
extern int gHasLong; // This is set to 1 if the device suppots long and ulong types in OpenCL C.
extern int gIsOpenCL_C_1_0_Device; // This is set to 1 if the device supports only OpenCL C 1.0.
extern bool gCoreILProgram;
#if ! defined( __APPLE__ )
void memset_pattern4(void *, const void *, size_t);

View File

@@ -154,8 +154,25 @@ int get_program_with_il(clProgramWrapper &prog,
}
unsigned char *buffer = &buffer_vec[0];
prog = clCreateProgramWithIL(context, buffer, file_bytes, &err);
SPIRV_CHECK_ERROR(err, "Failed to create program with clCreateProgramWithIL");
if (gCoreILProgram) {
prog = clCreateProgramWithIL(context, buffer, file_bytes, &err);
SPIRV_CHECK_ERROR(err, "Failed to create program with clCreateProgramWithIL");
}
else {
cl_platform_id platform;
err = clGetDeviceInfo(deviceID, CL_DEVICE_PLATFORM, sizeof(cl_platform_id), &platform, NULL);
print_error(err, "clGetDeviceInfo for CL_DEVICE_PLATFORM failed");
clCreateProgramWithILKHR_fn clCreateProgramWithILKHR = NULL;
clCreateProgramWithILKHR = (clCreateProgramWithILKHR_fn)clGetExtensionFunctionAddressForPlatform(platform, "clCreateProgramWithILKHR");
if (clCreateProgramWithILKHR == NULL)
{
log_error("ERROR: clGetExtensionFunctionAddressForPlatform failed\n");
return -1;
}
prog = clCreateProgramWithILKHR(context, buffer, file_bytes, &err);
SPIRV_CHECK_ERROR(err, "Failed to create program with clCreateProgramWithILKHR");
}
err = clBuildProgram(prog, 1, &deviceID, NULL, NULL, NULL);
SPIRV_CHECK_ERROR(err, "Failed to build program");