switch SVM tests to the new test registration framework (#2168)

Switches the SVM tests to the new test registration framework.

The first commit is the best to review and contains the actual changes.
The second commit purely has formatting changes.

Note that several of these changes were a bit more than mechanical
because many of the SVM tests create a new context vs. using the context
provided by the harness and passed to each test function. The previous
code named the context provided by the harness differently, and hence
could use the name "context" in each test function, but with the new
test registration framework this is no longer possible. Instead, I am
creating the new context using the name "contextWrapper" and then
assigning it to the "context" passed to the test function, which seems
like the best way to avoid using the wrong context unintentionally. I am
open to suggestions to do this differently.

I have verified that the same calls are made before and after these
changes, and specifically that there are no context leaks.
This commit is contained in:
Ben Ashbaugh
2024-12-03 14:51:23 -08:00
committed by GitHub
parent e361b387d9
commit d99b302f90
16 changed files with 1066 additions and 854 deletions

View File

@@ -41,71 +41,83 @@ const char* flag_set_names[] = {
};
int test_svm_allocate_shared_buffer(cl_device_id deviceID, cl_context context2, cl_command_queue queue, int num_elements)
REGISTER_TEST(svm_allocate_shared_buffer)
{
clContextWrapper context = NULL;
clProgramWrapper program = NULL;
cl_uint num_devices = 0;
cl_int err = CL_SUCCESS;
clCommandQueueWrapper queues[MAXQ];
clContextWrapper contextWrapper = NULL;
clProgramWrapper program = NULL;
cl_uint num_devices = 0;
cl_int err = CL_SUCCESS;
clCommandQueueWrapper queues[MAXQ];
cl_device_svm_capabilities caps;
err = clGetDeviceInfo(deviceID, CL_DEVICE_SVM_CAPABILITIES, sizeof(cl_device_svm_capabilities), &caps, NULL);
test_error(err,"clGetDeviceInfo failed for CL_DEVICE_SVM_CAPABILITIES");
cl_device_svm_capabilities caps;
err = clGetDeviceInfo(deviceID, CL_DEVICE_SVM_CAPABILITIES,
sizeof(cl_device_svm_capabilities), &caps, NULL);
test_error(err, "clGetDeviceInfo failed for CL_DEVICE_SVM_CAPABILITIES");
// under construction...
err = create_cl_objects(deviceID, NULL, &context, &program, &queues[0], &num_devices, CL_DEVICE_SVM_COARSE_GRAIN_BUFFER);
if(err) return -1;
// under construction...
err =
create_cl_objects(deviceID, NULL, &contextWrapper, &program, &queues[0],
&num_devices, CL_DEVICE_SVM_COARSE_GRAIN_BUFFER);
context = contextWrapper;
if (err) return -1;
size_t size = 1024;
size_t size = 1024;
// iteration over flag combos
int num_flags = sizeof(flag_set)/sizeof(cl_mem_flags);
for(int i = 0; i < num_flags; i++)
{
if (((flag_set[i] & CL_MEM_SVM_FINE_GRAIN_BUFFER) != 0 && (caps & CL_DEVICE_SVM_FINE_GRAIN_BUFFER) == 0)
|| ((flag_set[i] & CL_MEM_SVM_ATOMICS) != 0 && (caps & CL_DEVICE_SVM_ATOMICS) == 0))
// iteration over flag combos
int num_flags = sizeof(flag_set) / sizeof(cl_mem_flags);
for (int i = 0; i < num_flags; i++)
{
log_info("Skipping clSVMalloc with flags: %s\n", flag_set_names[i]);
continue;
}
log_info("Testing clSVMalloc with flags: %s\n", flag_set_names[i]);
cl_char *pBufData1 = (cl_char*) clSVMAlloc(context, flag_set[i], size, 0);
if(pBufData1 == NULL)
{
log_error("SVMalloc returned NULL");
return -1;
}
{
clMemWrapper buf = clCreateBuffer(context, CL_MEM_USE_HOST_PTR, size, pBufData1, &err);
test_error(err,"clCreateBuffer failed");
cl_char *pBufData2 = NULL;
cl_uint flags = CL_MAP_READ | CL_MAP_READ;
if(flag_set[i] & CL_MEM_HOST_READ_ONLY) flags ^= CL_MAP_WRITE;
if(flag_set[i] & CL_MEM_HOST_WRITE_ONLY) flags ^= CL_MAP_READ;
if(!(flag_set[i] & CL_MEM_HOST_NO_ACCESS))
{
pBufData2 = (cl_char*) clEnqueueMapBuffer(queues[0], buf, CL_TRUE, flags, 0, size, 0, NULL,NULL, &err);
test_error(err, "clEnqueueMapBuffer failed");
if(pBufData2 != pBufData1 || NULL == pBufData1)
if (((flag_set[i] & CL_MEM_SVM_FINE_GRAIN_BUFFER) != 0
&& (caps & CL_DEVICE_SVM_FINE_GRAIN_BUFFER) == 0)
|| ((flag_set[i] & CL_MEM_SVM_ATOMICS) != 0
&& (caps & CL_DEVICE_SVM_ATOMICS) == 0))
{
log_error("SVM pointer returned by clEnqueueMapBuffer doesn't match pointer returned by clSVMalloc");
return -1;
log_info("Skipping clSVMalloc with flags: %s\n", flag_set_names[i]);
continue;
}
err = clEnqueueUnmapMemObject(queues[0], buf, pBufData2, 0, NULL, NULL);
test_error(err, "clEnqueueUnmapMemObject failed");
err = clFinish(queues[0]);
test_error(err, "clFinish failed");
}
log_info("Testing clSVMalloc with flags: %s\n", flag_set_names[i]);
cl_char *pBufData1 =
(cl_char *)clSVMAlloc(context, flag_set[i], size, 0);
if (pBufData1 == NULL)
{
log_error("SVMalloc returned NULL");
return -1;
}
{
clMemWrapper buf = clCreateBuffer(context, CL_MEM_USE_HOST_PTR,
size, pBufData1, &err);
test_error(err, "clCreateBuffer failed");
cl_char *pBufData2 = NULL;
cl_uint flags = CL_MAP_READ | CL_MAP_READ;
if (flag_set[i] & CL_MEM_HOST_READ_ONLY) flags ^= CL_MAP_WRITE;
if (flag_set[i] & CL_MEM_HOST_WRITE_ONLY) flags ^= CL_MAP_READ;
if (!(flag_set[i] & CL_MEM_HOST_NO_ACCESS))
{
pBufData2 = (cl_char *)clEnqueueMapBuffer(
queues[0], buf, CL_TRUE, flags, 0, size, 0, NULL, NULL,
&err);
test_error(err, "clEnqueueMapBuffer failed");
if (pBufData2 != pBufData1 || NULL == pBufData1)
{
log_error("SVM pointer returned by clEnqueueMapBuffer "
"doesn't match pointer returned by clSVMalloc");
return -1;
}
err = clEnqueueUnmapMemObject(queues[0], buf, pBufData2, 0,
NULL, NULL);
test_error(err, "clEnqueueUnmapMemObject failed");
err = clFinish(queues[0]);
test_error(err, "clFinish failed");
}
}
clSVMFree(context, pBufData1);
}
clSVMFree(context, pBufData1);
}
return 0;
return 0;
}