mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-22 15:19:02 +00:00
add test for cl_khr_spirv_linkonce_odr (#1226)
* initial version of the test with placeholders for linkonce_odr linkage * add OpExtension SPV_KHR_linkonce_odr extension * add check for extension * switch to actual LinkOnceODR linkage * fix formatting * add a test case to ensure a function with linkonce_odr is exported * add back the extension check * fix formatting * undo compiler optimization and actually add the call to function a
This commit is contained in:
@@ -144,3 +144,96 @@ TEST_SPIRV_FUNC(linkage_import_function_link)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int test_linkonce_odr_helper(cl_device_id deviceID, cl_context context,
|
||||
cl_command_queue queue,
|
||||
const char *main_module_filename)
|
||||
{
|
||||
cl_int err = 0;
|
||||
|
||||
clProgramWrapper prog_obj;
|
||||
err = test_linkage_compile(deviceID, context, queue,
|
||||
"linkage_linkonce_odr_obj", prog_obj);
|
||||
SPIRV_CHECK_ERROR(err, "Failed to compile export program");
|
||||
|
||||
clProgramWrapper prog_main;
|
||||
err = test_linkage_compile(deviceID, context, queue, main_module_filename,
|
||||
prog_main);
|
||||
SPIRV_CHECK_ERROR(err, "Failed to compile import program");
|
||||
|
||||
cl_program progs[] = { prog_obj, prog_main };
|
||||
|
||||
clProgramWrapper prog =
|
||||
clLinkProgram(context, 1, &deviceID, NULL, 2, progs, NULL, NULL, &err);
|
||||
SPIRV_CHECK_ERROR(err, "Failed to link programs");
|
||||
|
||||
clKernelWrapper kernel = clCreateKernel(prog, "test_linkonce_odr", &err);
|
||||
SPIRV_CHECK_ERROR(err, "Failed to create spv kernel");
|
||||
|
||||
const int num = 256;
|
||||
std::vector<cl_int> h_in(num);
|
||||
RandomSeed seed(gRandomSeed);
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
h_in[i] = genrand<cl_int>(seed) % 2048;
|
||||
}
|
||||
|
||||
size_t bytes = sizeof(cl_int) * num;
|
||||
clMemWrapper in =
|
||||
clCreateBuffer(context, CL_MEM_READ_WRITE, bytes, NULL, &err);
|
||||
SPIRV_CHECK_ERROR(err, "Failed to create in buffer");
|
||||
|
||||
err = clEnqueueWriteBuffer(queue, in, CL_TRUE, 0, bytes, &h_in[0], 0, NULL,
|
||||
NULL);
|
||||
SPIRV_CHECK_ERROR(err, "Failed to copy to in buffer");
|
||||
|
||||
err = clSetKernelArg(kernel, 0, sizeof(cl_mem), &in);
|
||||
SPIRV_CHECK_ERROR(err, "Failed to set arg 1");
|
||||
|
||||
size_t global = num;
|
||||
err = clEnqueueNDRangeKernel(queue, kernel, 1, NULL, &global, NULL, 0, NULL,
|
||||
NULL);
|
||||
SPIRV_CHECK_ERROR(err, "Failed to enqueue cl kernel");
|
||||
|
||||
std::vector<cl_int> h_out(num);
|
||||
err = clEnqueueReadBuffer(queue, in, CL_TRUE, 0, bytes, &h_out[0], 0, NULL,
|
||||
NULL);
|
||||
SPIRV_CHECK_ERROR(err, "Failed to read to output");
|
||||
|
||||
for (int i = 0; i < num; i++)
|
||||
{
|
||||
if (h_out[i] != 5)
|
||||
{
|
||||
log_error("Incorrect values at location %d\n", i);
|
||||
return TEST_FAIL;
|
||||
}
|
||||
}
|
||||
|
||||
return TEST_PASS;
|
||||
}
|
||||
|
||||
TEST_SPIRV_FUNC(linkage_linkonce_odr)
|
||||
{
|
||||
if (!is_extension_available(deviceID, "cl_khr_spirv_linkonce_odr"))
|
||||
{
|
||||
log_info("Extension cl_khr_spirv_linkonce_odr not supported; skipping "
|
||||
"tests.\n");
|
||||
return TEST_SKIPPED_ITSELF;
|
||||
}
|
||||
|
||||
int result = TEST_PASS;
|
||||
|
||||
// For this test, use the default main module, which has an "a" function
|
||||
// with the linkonce_odr linkage type. This ensures that having two "a"
|
||||
// functions with linkonce_odr works properly.
|
||||
result |= test_linkonce_odr_helper(deviceID, context, queue,
|
||||
"linkage_linkonce_odr_main");
|
||||
|
||||
// For this test, use a main module without the "a" function. This ensures
|
||||
// that the "a" function is properly exported with the linkonce_odr linkage
|
||||
// type.
|
||||
result |= test_linkonce_odr_helper(deviceID, context, queue,
|
||||
"linkage_linkonce_odr_noa_main");
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user