mirror of
https://github.com/KhronosGroup/OpenCL-CTS.git
synced 2026-03-25 16:29:03 +00:00
Test SVM: Fix - do not use unmapped pointer. (#661)
* Fix - do not use unmapped pointer. * Exchanging variable names to more readable.
This commit is contained in:
committed by
GitHub
parent
5ec04da102
commit
8a00f4eced
@@ -50,13 +50,13 @@ int test_svm_pointer_passing(cl_device_id deviceID, cl_context context2, cl_comm
|
|||||||
test_error(error,"clCreateKernel failed");
|
test_error(error,"clCreateKernel failed");
|
||||||
|
|
||||||
size_t bufSize = 256;
|
size_t bufSize = 256;
|
||||||
char *pbuf = (char*) clSVMAlloc(context, CL_MEM_READ_WRITE, sizeof(cl_uchar)*bufSize, 0);
|
cl_uchar *pbuf_svm_alloc = (cl_uchar*) clSVMAlloc(context, CL_MEM_READ_WRITE, sizeof(cl_uchar)*bufSize, 0);
|
||||||
|
|
||||||
cl_int *pNumCorrect = NULL;
|
cl_int *pNumCorrect = NULL;
|
||||||
pNumCorrect = (cl_int*) clSVMAlloc(context, CL_MEM_READ_WRITE, sizeof(cl_int), 0);
|
pNumCorrect = (cl_int*) clSVMAlloc(context, CL_MEM_READ_WRITE, sizeof(cl_int), 0);
|
||||||
|
|
||||||
{
|
{
|
||||||
clMemWrapper buf = clCreateBuffer(context, CL_MEM_USE_HOST_PTR, sizeof(cl_uchar)*bufSize, pbuf, &error);
|
clMemWrapper buf = clCreateBuffer(context, CL_MEM_USE_HOST_PTR, sizeof(cl_uchar)*bufSize, pbuf_svm_alloc, &error);
|
||||||
test_error(error, "clCreateBuffer failed.");
|
test_error(error, "clCreateBuffer failed.");
|
||||||
|
|
||||||
clMemWrapper num_correct = clCreateBuffer(context, CL_MEM_USE_HOST_PTR, sizeof(cl_int), pNumCorrect, &error);
|
clMemWrapper num_correct = clCreateBuffer(context, CL_MEM_USE_HOST_PTR, sizeof(cl_int), pNumCorrect, &error);
|
||||||
@@ -67,13 +67,13 @@ int test_svm_pointer_passing(cl_device_id deviceID, cl_context context2, cl_comm
|
|||||||
|
|
||||||
// put values into buf so that we can expect to see these values in the kernel when we pass a pointer to them.
|
// put values into buf so that we can expect to see these values in the kernel when we pass a pointer to them.
|
||||||
cl_command_queue cmdq = queues[0];
|
cl_command_queue cmdq = queues[0];
|
||||||
cl_uchar* pBuf = (cl_uchar*) clEnqueueMapBuffer(cmdq, buf, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, sizeof(cl_uchar)*bufSize, 0, NULL,NULL, &error);
|
cl_uchar* pbuf_map_buffer = (cl_uchar*) clEnqueueMapBuffer(cmdq, buf, CL_TRUE, CL_MAP_READ | CL_MAP_WRITE, 0, sizeof(cl_uchar)*bufSize, 0, NULL,NULL, &error);
|
||||||
test_error2(error, pBuf, "clEnqueueMapBuffer failed");
|
test_error2(error, pbuf_map_buffer, "clEnqueueMapBuffer failed");
|
||||||
for(int i = 0; i<(int)bufSize; i++)
|
for(int i = 0; i<(int)bufSize; i++)
|
||||||
{
|
{
|
||||||
pBuf[i]= (cl_uchar)i;
|
pbuf_map_buffer[i]= (cl_uchar)i;
|
||||||
}
|
}
|
||||||
error = clEnqueueUnmapMemObject(cmdq, buf, pBuf, 0,NULL,NULL);
|
error = clEnqueueUnmapMemObject(cmdq, buf, pbuf_map_buffer, 0,NULL,NULL);
|
||||||
test_error(error, "clEnqueueUnmapMemObject failed.");
|
test_error(error, "clEnqueueUnmapMemObject failed.");
|
||||||
|
|
||||||
for (cl_uint ii = 0; ii<num_devices; ++ii) // iterate over all devices in the platform.
|
for (cl_uint ii = 0; ii<num_devices; ++ii) // iterate over all devices in the platform.
|
||||||
@@ -81,7 +81,7 @@ int test_svm_pointer_passing(cl_device_id deviceID, cl_context context2, cl_comm
|
|||||||
cmdq = queues[ii];
|
cmdq = queues[ii];
|
||||||
for(int i = 0; i<(int)bufSize; i++)
|
for(int i = 0; i<(int)bufSize; i++)
|
||||||
{
|
{
|
||||||
cl_uchar* pChar = &pBuf[i];
|
cl_uchar* pChar = &pbuf_svm_alloc[i];
|
||||||
error = clSetKernelArgSVMPointer(kernel_verify_char, 0, pChar); // pass a pointer to a location within the buffer
|
error = clSetKernelArgSVMPointer(kernel_verify_char, 0, pChar); // pass a pointer to a location within the buffer
|
||||||
test_error(error, "clSetKernelArg failed");
|
test_error(error, "clSetKernelArg failed");
|
||||||
error = clSetKernelArg(kernel_verify_char, 2, sizeof(cl_uchar), (void *) &i ); // pass the expected value at the above location.
|
error = clSetKernelArg(kernel_verify_char, 2, sizeof(cl_uchar), (void *) &i ); // pass the expected value at the above location.
|
||||||
@@ -108,7 +108,7 @@ int test_svm_pointer_passing(cl_device_id deviceID, cl_context context2, cl_comm
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
clSVMFree(context, pbuf);
|
clSVMFree(context, pbuf_svm_alloc);
|
||||||
clSVMFree(context, pNumCorrect);
|
clSVMFree(context, pNumCorrect);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user