Enqueue fill buffer (#1561)

* grab latest from upstream OpenCL

* Use clEnqueueFillBuffer rather than memset4 in all test files

* Cleanup leftover code from memset_pattern4

* Remove unnecessary map, unmap, writeBuffer from math_brute_force tests

* Remove extraneous build system change

* Appease clang-format

* Add option to perform buffer fills on the host

Co-authored-by: Taeten Prettyman <taeten.j@gmail.com>
Co-authored-by: taetenp <taet@holochip.com>
Co-authored-by: Chip Davis <chip@holochip.com>
This commit is contained in:
Steven Winston
2023-01-24 08:51:00 -08:00
committed by GitHub
parent 77e4fe5588
commit 4759159a50
29 changed files with 1027 additions and 506 deletions

View File

@@ -227,24 +227,27 @@ cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
}
}
// start the map of the output arrays
cl_event e[VECTOR_SIZE_COUNT];
cl_uint *out[VECTOR_SIZE_COUNT];
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
if (gHostFill)
{
out[j] = (cl_uint *)clEnqueueMapBuffer(
tinfo->tQueue, tinfo->outBuf[j], CL_FALSE, CL_MAP_WRITE, 0,
buffer_size, 0, NULL, e + j, &error);
if (error || NULL == out[j])
// start the map of the output arrays
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
{
vlog_error("Error: clEnqueueMapBuffer %d failed! err: %d\n", j,
error);
return error;
out[j] = (cl_uint *)clEnqueueMapBuffer(
tinfo->tQueue, tinfo->outBuf[j], CL_FALSE, CL_MAP_WRITE, 0,
buffer_size, 0, NULL, e + j, &error);
if (error || NULL == out[j])
{
vlog_error("Error: clEnqueueMapBuffer %d failed! err: %d\n", j,
error);
return error;
}
}
}
// Get that moving
if ((error = clFlush(tinfo->tQueue))) vlog("clFlush failed\n");
// Get that moving
if ((error = clFlush(tinfo->tQueue))) vlog("clFlush failed\n");
}
// Init input array
cl_uint *p = (cl_uint *)gIn + thread_id * buffer_elements;
@@ -253,8 +256,9 @@ cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
int totalSpecialValueCount = specialValuesCount * specialValuesCount;
int lastSpecialJobIndex = (totalSpecialValueCount - 1) / buffer_elements;
// Test edge cases
if (job_id <= (cl_uint)lastSpecialJobIndex)
{ // test edge cases
{
float *fp = (float *)p;
float *fp2 = (float *)p2;
uint32_t x, y;
@@ -276,7 +280,7 @@ cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
}
}
// Init any remaining values.
// Init any remaining values
for (; idx < buffer_elements; idx++)
{
p[idx] = genrand_int32(d);
@@ -299,31 +303,48 @@ cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
{
// Wait for the map to finish
if ((error = clWaitForEvents(1, e + j)))
if (gHostFill)
{
vlog_error("Error: clWaitForEvents failed! err: %d\n", error);
goto exit;
}
if ((error = clReleaseEvent(e[j])))
{
vlog_error("Error: clReleaseEvent failed! err: %d\n", error);
goto exit;
// Wait for the map to finish
if ((error = clWaitForEvents(1, e + j)))
{
vlog_error("Error: clWaitForEvents failed! err: %d\n", error);
goto exit;
}
if ((error = clReleaseEvent(e[j])))
{
vlog_error("Error: clReleaseEvent failed! err: %d\n", error);
goto exit;
}
}
// Fill the result buffer with garbage, so that old results don't carry
// over
uint32_t pattern = 0xffffdead;
memset_pattern4(out[j], &pattern, buffer_size);
if ((error = clEnqueueUnmapMemObject(tinfo->tQueue, tinfo->outBuf[j],
out[j], 0, NULL, NULL)))
if (gHostFill)
{
vlog_error("Error: clEnqueueUnmapMemObject failed! err: %d\n",
error);
goto exit;
memset_pattern4(out[j], &pattern, buffer_size);
if ((error = clEnqueueUnmapMemObject(
tinfo->tQueue, tinfo->outBuf[j], out[j], 0, NULL, NULL)))
{
vlog_error("Error: clEnqueueUnmapMemObject failed! err: %d\n",
error);
goto exit;
}
}
else
{
if ((error = clEnqueueFillBuffer(tinfo->tQueue, tinfo->outBuf[j],
&pattern, sizeof(pattern), 0,
buffer_size, 0, NULL, NULL)))
{
vlog_error("Error: clEnqueueFillBuffer failed! err: %d\n",
error);
return error;
}
}
// run the kernel
// Run the kernel
size_t vectorCount =
(buffer_elements + sizeValues[j] - 1) / sizeValues[j];
cl_kernel kernel = job->k[j][thread_id]; // each worker thread has its