Use clMemWrapper in math_brute_force (#1476)

Simplify code by avoiding manual resource management.

Original patch by Marco Antognini.

Signed-off-by: Marco Antognini <marco.antognini@arm.com>
Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>

Signed-off-by: Marco Antognini <marco.antognini@arm.com>
Signed-off-by: Sven van Haastregt <sven.vanhaastregt@arm.com>
This commit is contained in:
Sven van Haastregt
2022-09-01 06:43:43 +01:00
committed by GitHub
parent 8f5a2f0ae8
commit f94c135755
13 changed files with 57 additions and 92 deletions

View File

@@ -124,9 +124,11 @@ cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
// Thread specific data for a worker thread // Thread specific data for a worker thread
struct ThreadInfo struct ThreadInfo
{ {
cl_mem inBuf; // input buffer for the thread // Input and output buffers for the thread
cl_mem inBuf2; // input buffer for the thread clMemWrapper inBuf;
cl_mem outBuf[VECTOR_SIZE_COUNT]; // output buffers for the thread clMemWrapper inBuf2;
Buffers outBuf;
float maxError; // max error value. Init to 0. float maxError; // max error value. Init to 0.
double double
maxErrorValue; // position of the max error value (param 1). Init to 0. maxErrorValue; // position of the max error value (param 1). Init to 0.
@@ -793,10 +795,6 @@ exit:
for (auto &threadInfo : test_info.tinfo) for (auto &threadInfo : test_info.tinfo)
{ {
free_mtdata(threadInfo.d); free_mtdata(threadInfo.d);
clReleaseMemObject(threadInfo.inBuf);
clReleaseMemObject(threadInfo.inBuf2);
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(threadInfo.outBuf[j]);
} }
return error; return error;

View File

@@ -122,9 +122,11 @@ cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
// Thread specific data for a worker thread // Thread specific data for a worker thread
struct ThreadInfo struct ThreadInfo
{ {
cl_mem inBuf; // input buffer for the thread // Input and output buffers for the thread
cl_mem inBuf2; // input buffer for the thread clMemWrapper inBuf;
cl_mem outBuf[VECTOR_SIZE_COUNT]; // output buffers for the thread clMemWrapper inBuf2;
Buffers outBuf;
float maxError; // max error value. Init to 0. float maxError; // max error value. Init to 0.
double double
maxErrorValue; // position of the max error value (param 1). Init to 0. maxErrorValue; // position of the max error value (param 1). Init to 0.
@@ -950,10 +952,6 @@ exit:
for (auto &threadInfo : test_info.tinfo) for (auto &threadInfo : test_info.tinfo)
{ {
free_mtdata(threadInfo.d); free_mtdata(threadInfo.d);
clReleaseMemObject(threadInfo.inBuf);
clReleaseMemObject(threadInfo.inBuf2);
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(threadInfo.outBuf[j]);
} }
return error; return error;

View File

@@ -123,9 +123,11 @@ cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
// Thread specific data for a worker thread // Thread specific data for a worker thread
struct ThreadInfo struct ThreadInfo
{ {
cl_mem inBuf; // input buffer for the thread // Input and output buffers for the thread
cl_mem inBuf2; // input buffer for the thread clMemWrapper inBuf;
cl_mem outBuf[VECTOR_SIZE_COUNT]; // output buffers for the thread clMemWrapper inBuf2;
Buffers outBuf;
float maxError; // max error value. Init to 0. float maxError; // max error value. Init to 0.
double double
maxErrorValue; // position of the max error value (param 1). Init to 0. maxErrorValue; // position of the max error value (param 1). Init to 0.
@@ -715,10 +717,6 @@ exit:
for (auto &threadInfo : test_info.tinfo) for (auto &threadInfo : test_info.tinfo)
{ {
free_mtdata(threadInfo.d); free_mtdata(threadInfo.d);
clReleaseMemObject(threadInfo.inBuf);
clReleaseMemObject(threadInfo.inBuf2);
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(threadInfo.outBuf[j]);
} }
return error; return error;

View File

@@ -121,9 +121,11 @@ cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
// Thread specific data for a worker thread // Thread specific data for a worker thread
struct ThreadInfo struct ThreadInfo
{ {
cl_mem inBuf; // input buffer for the thread // Input and output buffers for the thread
cl_mem inBuf2; // input buffer for the thread clMemWrapper inBuf;
cl_mem outBuf[VECTOR_SIZE_COUNT]; // output buffers for the thread clMemWrapper inBuf2;
Buffers outBuf;
float maxError; // max error value. Init to 0. float maxError; // max error value. Init to 0.
double double
maxErrorValue; // position of the max error value (param 1). Init to 0. maxErrorValue; // position of the max error value (param 1). Init to 0.
@@ -708,10 +710,6 @@ exit:
for (auto &threadInfo : test_info.tinfo) for (auto &threadInfo : test_info.tinfo)
{ {
free_mtdata(threadInfo.d); free_mtdata(threadInfo.d);
clReleaseMemObject(threadInfo.inBuf);
clReleaseMemObject(threadInfo.inBuf2);
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(threadInfo.outBuf[j]);
} }
return error; return error;

View File

@@ -123,9 +123,11 @@ cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
// Thread specific data for a worker thread // Thread specific data for a worker thread
struct ThreadInfo struct ThreadInfo
{ {
cl_mem inBuf; // input buffer for the thread // Input and output buffers for the thread
cl_mem inBuf2; // input buffer for the thread clMemWrapper inBuf;
cl_mem outBuf[VECTOR_SIZE_COUNT]; // output buffers for the thread clMemWrapper inBuf2;
Buffers outBuf;
float maxError; // max error value. Init to 0. float maxError; // max error value. Init to 0.
double double
maxErrorValue; // position of the max error value (param 1). Init to 0. maxErrorValue; // position of the max error value (param 1). Init to 0.
@@ -760,10 +762,6 @@ exit:
for (auto &threadInfo : test_info.tinfo) for (auto &threadInfo : test_info.tinfo)
{ {
free_mtdata(threadInfo.d); free_mtdata(threadInfo.d);
clReleaseMemObject(threadInfo.inBuf);
clReleaseMemObject(threadInfo.inBuf2);
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(threadInfo.outBuf[j]);
} }
return error; return error;

View File

@@ -121,9 +121,11 @@ cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
// Thread specific data for a worker thread // Thread specific data for a worker thread
struct ThreadInfo struct ThreadInfo
{ {
cl_mem inBuf; // input buffer for the thread // Input and output buffers for the thread
cl_mem inBuf2; // input buffer for the thread clMemWrapper inBuf;
cl_mem outBuf[VECTOR_SIZE_COUNT]; // output buffers for the thread clMemWrapper inBuf2;
Buffers outBuf;
float maxError; // max error value. Init to 0. float maxError; // max error value. Init to 0.
double double
maxErrorValue; // position of the max error value (param 1). Init to 0. maxErrorValue; // position of the max error value (param 1). Init to 0.
@@ -887,10 +889,6 @@ exit:
for (auto &threadInfo : test_info.tinfo) for (auto &threadInfo : test_info.tinfo)
{ {
free_mtdata(threadInfo.d); free_mtdata(threadInfo.d);
clReleaseMemObject(threadInfo.inBuf);
clReleaseMemObject(threadInfo.inBuf2);
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(threadInfo.outBuf[j]);
} }
return error; return error;

View File

@@ -28,6 +28,9 @@ using KernelMatrix = std::array<std::vector<cl_kernel>, VECTOR_SIZE_COUNT>;
// Array of programs for each vector size. // Array of programs for each vector size.
using Programs = std::array<clProgramWrapper, VECTOR_SIZE_COUNT>; using Programs = std::array<clProgramWrapper, VECTOR_SIZE_COUNT>;
// Array of buffers for each vector size.
using Buffers = std::array<clMemWrapper, VECTOR_SIZE_COUNT>;
// Information to generate OpenCL kernels. // Information to generate OpenCL kernels.
struct BuildKernelInfo struct BuildKernelInfo
{ {

View File

@@ -122,9 +122,11 @@ cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
// Thread specific data for a worker thread // Thread specific data for a worker thread
struct ThreadInfo struct ThreadInfo
{ {
cl_mem inBuf; // input buffer for the thread // Input and output buffers for the thread
cl_mem inBuf2; // input buffer for the thread clMemWrapper inBuf;
cl_mem outBuf[VECTOR_SIZE_COUNT]; // output buffers for the thread clMemWrapper inBuf2;
Buffers outBuf;
MTdata d; MTdata d;
// Per thread command queue to improve performance // Per thread command queue to improve performance
@@ -705,10 +707,6 @@ exit:
for (auto &threadInfo : test_info.tinfo) for (auto &threadInfo : test_info.tinfo)
{ {
free_mtdata(threadInfo.d); free_mtdata(threadInfo.d);
clReleaseMemObject(threadInfo.inBuf);
clReleaseMemObject(threadInfo.inBuf2);
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(threadInfo.outBuf[j]);
} }
return error; return error;

View File

@@ -120,9 +120,11 @@ cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
// Thread specific data for a worker thread // Thread specific data for a worker thread
struct ThreadInfo struct ThreadInfo
{ {
cl_mem inBuf; // input buffer for the thread // Input and output buffers for the thread
cl_mem inBuf2; // input buffer for the thread clMemWrapper inBuf;
cl_mem outBuf[VECTOR_SIZE_COUNT]; // output buffers for the thread clMemWrapper inBuf2;
Buffers outBuf;
MTdata d; MTdata d;
// Per thread command queue to improve performance // Per thread command queue to improve performance
@@ -694,10 +696,6 @@ exit:
for (auto &threadInfo : test_info.tinfo) for (auto &threadInfo : test_info.tinfo)
{ {
free_mtdata(threadInfo.d); free_mtdata(threadInfo.d);
clReleaseMemObject(threadInfo.inBuf);
clReleaseMemObject(threadInfo.inBuf2);
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(threadInfo.outBuf[j]);
} }
return error; return error;

View File

@@ -116,8 +116,9 @@ cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
// Thread specific data for a worker thread // Thread specific data for a worker thread
struct ThreadInfo struct ThreadInfo
{ {
cl_mem inBuf; // input buffer for the thread // Input and output buffers for the thread
cl_mem outBuf[VECTOR_SIZE_COUNT]; // output buffers for the thread clMemWrapper inBuf;
Buffers outBuf;
// Per thread command queue to improve performance // Per thread command queue to improve performance
clCommandQueueWrapper tQueue; clCommandQueueWrapper tQueue;
@@ -475,12 +476,5 @@ exit:
} }
} }
for (auto &threadInfo : test_info.tinfo)
{
clReleaseMemObject(threadInfo.inBuf);
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(threadInfo.outBuf[j]);
}
return error; return error;
} }

View File

@@ -115,8 +115,9 @@ cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
// Thread specific data for a worker thread // Thread specific data for a worker thread
struct ThreadInfo struct ThreadInfo
{ {
cl_mem inBuf; // input buffer for the thread // Input and output buffers for the thread
cl_mem outBuf[VECTOR_SIZE_COUNT]; // output buffers for the thread clMemWrapper inBuf;
Buffers outBuf;
// Per thread command queue to improve performance // Per thread command queue to improve performance
clCommandQueueWrapper tQueue; clCommandQueueWrapper tQueue;
@@ -489,12 +490,5 @@ exit:
} }
} }
for (auto &threadInfo : test_info.tinfo)
{
clReleaseMemObject(threadInfo.inBuf);
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(threadInfo.outBuf[j]);
}
return error; return error;
} }

View File

@@ -116,8 +116,10 @@ cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
// Thread specific data for a worker thread // Thread specific data for a worker thread
struct ThreadInfo struct ThreadInfo
{ {
cl_mem inBuf; // input buffer for the thread // Input and output buffers for the thread
cl_mem outBuf[VECTOR_SIZE_COUNT]; // output buffers for the thread clMemWrapper inBuf;
Buffers outBuf;
float maxError; // max error value. Init to 0. float maxError; // max error value. Init to 0.
double maxErrorValue; // position of the max error value. Init to 0. double maxErrorValue; // position of the max error value. Init to 0.
@@ -513,12 +515,5 @@ exit:
} }
} }
for (auto &threadInfo : test_info.tinfo)
{
clReleaseMemObject(threadInfo.inBuf);
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(threadInfo.outBuf[j]);
}
return error; return error;
} }

View File

@@ -114,8 +114,10 @@ cl_int BuildKernelFn(cl_uint job_id, cl_uint thread_id UNUSED, void *p)
// Thread specific data for a worker thread // Thread specific data for a worker thread
struct ThreadInfo struct ThreadInfo
{ {
cl_mem inBuf; // input buffer for the thread // Input and output buffers for the thread
cl_mem outBuf[VECTOR_SIZE_COUNT]; // output buffers for the thread clMemWrapper inBuf;
Buffers outBuf;
float maxError; // max error value. Init to 0. float maxError; // max error value. Init to 0.
double maxErrorValue; // position of the max error value. Init to 0. double maxErrorValue; // position of the max error value. Init to 0.
@@ -690,12 +692,5 @@ exit:
} }
} }
for (auto &threadInfo : test_info.tinfo)
{
clReleaseMemObject(threadInfo.inBuf);
for (auto j = gMinVectorSizeIndex; j < gMaxVectorSizeIndex; j++)
clReleaseMemObject(threadInfo.outBuf[j]);
}
return error; return error;
} }