Reduce scope of variables (#1228)

Make variables local to loops, with appropriate types. These variables
are not read after the loop without being reset first, so this patch
doesn't change behaviour.

These variables should now be used for one purpose only, making it
easier to reason about the code. This will make future refactoring
easier.

Signed-off-by: Marco Antognini <marco.antognini@arm.com>
This commit is contained in:
Marco Antognini
2021-04-28 09:30:51 +01:00
committed by GitHub
parent cba7a8a537
commit 01497c402e
26 changed files with 420 additions and 471 deletions

View File

@@ -157,7 +157,6 @@ int TestFunc_Float_Float(const Func *f, MTdata d, bool relaxedMode)
{
TestInfo test_info;
cl_int error;
size_t i, j;
float maxError = 0.0f;
double maxErrorVal = 0.0;
int skipTestingRelaxed = (relaxedMode && strcmp(f->name, "tan") == 0);
@@ -189,7 +188,7 @@ int TestFunc_Float_Float(const Func *f, MTdata d, bool relaxedMode)
test_info.relaxedMode = relaxedMode;
// cl_kernels aren't thread safe, so we make one for each vector size for
// every thread
for (i = gMinVectorSizeIndex; i < gMaxVectorSizeIndex; i++)
for (auto i = gMinVectorSizeIndex; i < gMaxVectorSizeIndex; i++)
{
size_t array_size = test_info.threadCount * sizeof(cl_kernel);
test_info.k[i] = (cl_kernel *)malloc(array_size);
@@ -212,7 +211,7 @@ int TestFunc_Float_Float(const Func *f, MTdata d, bool relaxedMode)
}
memset(test_info.tinfo, 0,
test_info.threadCount * sizeof(*test_info.tinfo));
for (i = 0; i < test_info.threadCount; i++)
for (cl_uint i = 0; i < test_info.threadCount; i++)
{
cl_buffer_region region = {
i * test_info.subBufferSize * sizeof(cl_float),
@@ -229,7 +228,7 @@ int TestFunc_Float_Float(const Func *f, MTdata d, bool relaxedMode)
goto exit;
}
for (j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
{
test_info.tinfo[i].outBuf[j] = clCreateSubBuffer(
gOutBuffer[j], CL_MEM_WRITE_ONLY, CL_BUFFER_CREATE_TYPE_REGION,
@@ -287,7 +286,7 @@ int TestFunc_Float_Float(const Func *f, MTdata d, bool relaxedMode)
error = ThreadPool_Do(Test, test_info.jobCount, &test_info);
// Accumulate the arithmetic errors
for (i = 0; i < test_info.threadCount; i++)
for (cl_uint i = 0; i < test_info.threadCount; i++)
{
if (test_info.tinfo[i].maxError > maxError)
{
@@ -316,12 +315,12 @@ int TestFunc_Float_Float(const Func *f, MTdata d, bool relaxedMode)
exit:
// Release
for (i = gMinVectorSizeIndex; i < gMaxVectorSizeIndex; i++)
for (auto i = gMinVectorSizeIndex; i < gMaxVectorSizeIndex; i++)
{
clReleaseProgram(test_info.programs[i]);
if (test_info.k[i])
{
for (j = 0; j < test_info.threadCount; j++)
for (cl_uint j = 0; j < test_info.threadCount; j++)
clReleaseKernel(test_info.k[i][j]);
free(test_info.k[i]);
@@ -329,10 +328,10 @@ exit:
}
if (test_info.tinfo)
{
for (i = 0; i < test_info.threadCount; i++)
for (cl_uint i = 0; i < test_info.threadCount; i++)
{
clReleaseMemObject(test_info.tinfo[i].inBuf);
for (j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(test_info.tinfo[i].outBuf[j]);
clReleaseCommandQueue(test_info.tinfo[i].tQueue);
}
@@ -360,7 +359,6 @@ static cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
func = job->f->rfunc;
}
cl_uint j, k;
cl_int error;
int isRangeLimited = job->isRangeLimited;
@@ -370,7 +368,7 @@ static 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 (j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
{
out[j] = (cl_uint *)clEnqueueMapBuffer(
tinfo->tQueue, tinfo->outBuf[j], CL_FALSE, CL_MAP_WRITE, 0,
@@ -388,7 +386,7 @@ static cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
// Write the new values to the input array
cl_uint *p = (cl_uint *)gIn + thread_id * buffer_elements;
for (j = 0; j < buffer_elements; j++)
for (size_t j = 0; j < buffer_elements; j++)
{
p[j] = base + j * scale;
if (relaxedMode)
@@ -421,7 +419,7 @@ static cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
return error;
}
for (j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
{
// Wait for the map to finish
if ((error = clWaitForEvents(1, e + j)))
@@ -482,11 +480,11 @@ static cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
// Calculate the correctly rounded reference result
float *r = (float *)gOut_Ref + thread_id * buffer_elements;
float *s = (float *)p;
for (j = 0; j < buffer_elements; j++) r[j] = (float)func.f_f(s[j]);
for (size_t j = 0; j < buffer_elements; j++) r[j] = (float)func.f_f(s[j]);
// Read the data back -- no need to wait for the first N-1 buffers but wait
// for the last buffer. This is an in order queue.
for (j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
{
cl_bool blocking = (j + 1 < gMaxVectorSizeIndex) ? CL_FALSE : CL_TRUE;
out[j] = (cl_uint *)clEnqueueMapBuffer(
@@ -502,9 +500,9 @@ static cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
// Verify data
uint32_t *t = (uint32_t *)r;
for (j = 0; j < buffer_elements; j++)
for (size_t j = 0; j < buffer_elements; j++)
{
for (k = gMinVectorSizeIndex; k < gMaxVectorSizeIndex; k++)
for (auto k = gMinVectorSizeIndex; k < gMaxVectorSizeIndex; k++)
{
uint32_t *q = out[k];
@@ -695,7 +693,7 @@ static cl_int Test(cl_uint job_id, cl_uint thread_id, void *data)
}
}
for (j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
{
if ((error = clEnqueueUnmapMemObject(tinfo->tQueue, tinfo->outBuf[j],
out[j], 0, NULL, NULL)))