From 6bf7514adb8c8a14bd9dd6865803743c73e5e824 Mon Sep 17 00:00:00 2001 From: jatang Date: Fri, 24 Mar 2023 11:58:29 -0400 Subject: [PATCH] SWDEV-373396 - OCLCreateBuffer: make the CPU checkResult() 4 times faster Change-Id: Ia6e614d76ea0532e7e6424bd33a5e81fbd49db9e --- .../ocltst/module/runtime/OCLCreateBuffer.cpp | 26 +++++++++---------- .../ocltst/module/runtime/OCLCreateBuffer.h | 8 +++--- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.cpp b/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.cpp index cd6ea46eb5..a9d96bcc20 100644 --- a/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.cpp +++ b/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.cpp @@ -72,7 +72,7 @@ void OCLCreateBuffer::open(unsigned int test, char *units, double &conversion, void OCLCreateBuffer::run(void) { CPerfCounter timer; - cl_uchar pattern = PATTERN; + cl_ulong pattern = PATTERN_20_64BIT; timer.Reset(); timer.Start(); error_ = /*_wrapper->*/ clEnqueueFillBuffer( @@ -90,22 +90,20 @@ void OCLCreateBuffer::run(void) { } #endif void *resultBuf = NULL; - ; + while ((resultBuf = malloc(maxSteps)) == NULL) { maxSteps /= 2; continue; } - checkResult(maxSteps, resultBuf, pattern); + checkResult(maxSteps, resultBuf, PATTERN_20_64BIT); - pattern += 1; - - memset(resultBuf, pattern, maxSteps); + memset(resultBuf, PATTERN_2A_08BIT, maxSteps); writeBuffer(maxSteps, resultBuf); memset(resultBuf, 0x00, maxSteps); - checkResult(maxSteps, resultBuf, pattern); + checkResult(maxSteps, resultBuf, PATTERN_2A_64BIT); free(resultBuf); @@ -127,7 +125,7 @@ void OCLCreateBuffer::run(void) { } void OCLCreateBuffer::checkResult(size_t maxSteps, void *resultBuf, - cl_uchar pattern) { + cl_ulong pattern) { size_t startPoint = 0; while ((startPoint) < maxSize_) { cl_event ee; @@ -140,14 +138,16 @@ void OCLCreateBuffer::checkResult(size_t maxSteps, void *resultBuf, resultBuf, 0, NULL, &ee); CHECK_RESULT((error_ != CL_SUCCESS), "clEnqueueReadBuffer() failed"); _wrapper->clFinish(cmdQueues_[_deviceId]); - size_t cnt = 0; - cl_uchar *cc = (cl_uchar *)resultBuf; - for (size_t i = 0; i < readSize; i++) { + + size_t err_cnt = 0, chk_cnt = readSize / sizeof(cl_ulong); + cl_ulong *cc = (cl_ulong *)resultBuf; + + for (size_t i = 0; i < chk_cnt; i++) { if (cc[i] != pattern) { - cnt++; + err_cnt++; } } - if (cnt != 0) { + if (err_cnt != 0) { error_ = -1; CHECK_RESULT((error_ != CL_SUCCESS), "checkResult() failed"); break; diff --git a/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.h b/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.h index d02117c5b8..2c63984096 100644 --- a/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.h +++ b/opencl/tests/ocltst/module/runtime/OCLCreateBuffer.h @@ -22,7 +22,10 @@ #define _OCL_CREATE_BUFFER_H_ #include "OCLTestImp.h" -#define PATTERN 0x20 +#define PATTERN_20_08BIT 0x20 +#define PATTERN_20_64BIT 0x2020202020202020 +#define PATTERN_2A_08BIT 0x2a +#define PATTERN_2A_64BIT 0x2a2a2a2a2a2a2a2a class OCLCreateBuffer : public OCLTestImp { public: @@ -34,8 +37,7 @@ class OCLCreateBuffer : public OCLTestImp { unsigned int deviceID); virtual void run(void); virtual void writeBuffer(size_t tmpMaxSize, void* dataBuf); - virtual void checkResult(size_t tmpMaxSize, void* resultBuf, - cl_uchar pattern); + virtual void checkResult(size_t tmpMaxSize, void* resultBuf, cl_ulong pattern); virtual unsigned int close(void); private: