Make variables and functions local to translation unit (#1216)

* Make variables and functions local to translation unit

Make some global variables local to function, or remove them when
actually dead.

Signed-off-by: Marco Antognini <marco.antognini@arm.com>

* Address comments

Remove unused code.
Reduce scope of gDoubleCapabilities.

Signed-off-by: Marco Antognini <marco.antognini@arm.com>
This commit is contained in:
Marco Antognini
2021-04-15 18:19:09 +01:00
committed by GitHub
parent b7e7a3eb65
commit 7286e06a94
2 changed files with 26 additions and 38 deletions

View File

@@ -51,21 +51,21 @@
(CL_FP_FMA | CL_FP_ROUND_TO_NEAREST | CL_FP_ROUND_TO_ZERO \ (CL_FP_FMA | CL_FP_ROUND_TO_NEAREST | CL_FP_ROUND_TO_ZERO \
| CL_FP_ROUND_TO_INF | CL_FP_INF_NAN | CL_FP_DENORM) | CL_FP_ROUND_TO_INF | CL_FP_INF_NAN | CL_FP_DENORM)
const char **gTestNames = NULL; static const char **gTestNames = NULL;
unsigned int gTestNameCount = 0; static unsigned int gTestNameCount = 0;
char appName[MAXPATHLEN] = ""; static char appName[MAXPATHLEN] = "";
cl_device_id gDevice = NULL; cl_device_id gDevice = NULL;
cl_context gContext = NULL; cl_context gContext = NULL;
cl_command_queue gQueue = NULL; cl_command_queue gQueue = NULL;
static int32_t gStartTestNumber = -1; static int32_t gStartTestNumber = -1;
static int32_t gEndTestNumber = -1; static int32_t gEndTestNumber = -1;
int gSkipCorrectnessTesting = 0; int gSkipCorrectnessTesting = 0;
int gStopOnError = 0; static int gStopOnError = 0;
static bool gSkipRestOfTests; static bool gSkipRestOfTests;
int gForceFTZ = 0; int gForceFTZ = 0;
int gWimpyMode = 0; int gWimpyMode = 0;
int gHasDouble = 0; static int gHasDouble = 0;
int gTestFloat = 1; static int gTestFloat = 1;
// This flag should be 'ON' by default and it can be changed through the command // This flag should be 'ON' by default and it can be changed through the command
// line arguments. // line arguments.
static int gTestFastRelaxed = 1; static int gTestFastRelaxed = 1;
@@ -78,7 +78,7 @@ static int gTestFastRelaxed = 1;
OpenCL 2.0 spec then it has to be changed through a command line argument. OpenCL 2.0 spec then it has to be changed through a command line argument.
*/ */
int gFastRelaxedDerived = 1; int gFastRelaxedDerived = 1;
int gToggleCorrectlyRoundedDivideSqrt = 0; static int gToggleCorrectlyRoundedDivideSqrt = 0;
int gDeviceILogb0 = 1; int gDeviceILogb0 = 1;
int gDeviceILogbNaN = 1; int gDeviceILogbNaN = 1;
int gCheckTininessBeforeRounding = 1; int gCheckTininessBeforeRounding = 1;
@@ -97,12 +97,8 @@ cl_mem gInBuffer2 = NULL;
cl_mem gInBuffer3 = NULL; cl_mem gInBuffer3 = NULL;
cl_mem gOutBuffer[VECTOR_SIZE_COUNT] = { NULL, NULL, NULL, NULL, NULL, NULL }; cl_mem gOutBuffer[VECTOR_SIZE_COUNT] = { NULL, NULL, NULL, NULL, NULL, NULL };
cl_mem gOutBuffer2[VECTOR_SIZE_COUNT] = { NULL, NULL, NULL, NULL, NULL, NULL }; cl_mem gOutBuffer2[VECTOR_SIZE_COUNT] = { NULL, NULL, NULL, NULL, NULL, NULL };
uint32_t gComputeDevices = 0;
uint32_t gSimdSize = 1;
uint32_t gDeviceFrequency = 0;
static MTdata gMTdata; static MTdata gMTdata;
cl_device_fp_config gFloatCapabilities = 0; cl_device_fp_config gFloatCapabilities = 0;
cl_device_fp_config gDoubleCapabilities = 0;
int gWimpyReductionFactor = 32; int gWimpyReductionFactor = 32;
int gWimpyBufferSize = BUFFER_SIZE; int gWimpyBufferSize = BUFFER_SIZE;
int gVerboseBruteForce = 0; int gVerboseBruteForce = 0;
@@ -110,15 +106,14 @@ int gVerboseBruteForce = 0;
static int ParseArgs(int argc, const char **argv); static int ParseArgs(int argc, const char **argv);
static void PrintUsage(void); static void PrintUsage(void);
static void PrintFunctions(void); static void PrintFunctions(void);
test_status InitCL(cl_device_id device); static test_status InitCL(cl_device_id device);
static void ReleaseCL(void); static void ReleaseCL(void);
static int InitILogbConstants(void); static int InitILogbConstants(void);
static int IsTininessDetectedBeforeRounding(void); static int IsTininessDetectedBeforeRounding(void);
static int static int
IsInRTZMode(void); // expensive. Please check gIsInRTZMode global instead. IsInRTZMode(void); // expensive. Please check gIsInRTZMode global instead.
static int doTest(const char *name)
int doTest(const char *name)
{ {
if (gSkipRestOfTests) if (gSkipRestOfTests)
{ {
@@ -747,7 +742,7 @@ int test_not(cl_device_id deviceID, cl_context context, cl_command_queue queue,
return doTest("not"); return doTest("not");
} }
test_definition test_list[] = { static test_definition test_list[] = {
ADD_TEST(acos), ADD_TEST(acosh), ADD_TEST(acospi), ADD_TEST(acos), ADD_TEST(acosh), ADD_TEST(acospi),
ADD_TEST(asin), ADD_TEST(asinh), ADD_TEST(asinpi), ADD_TEST(asin), ADD_TEST(asinh), ADD_TEST(asinpi),
ADD_TEST(atan), ADD_TEST(atanh), ADD_TEST(atanpi), ADD_TEST(atan), ADD_TEST(atanh), ADD_TEST(atanpi),
@@ -784,7 +779,7 @@ test_definition test_list[] = {
ADD_TEST(not), ADD_TEST(not),
}; };
const int test_num = ARRAY_SIZE(test_list); static const int test_num = ARRAY_SIZE(test_list);
#pragma mark - #pragma mark -
@@ -1080,7 +1075,6 @@ test_status InitCL(cl_device_id device)
{ {
int error; int error;
uint32_t i; uint32_t i;
size_t configSize = sizeof(gComputeDevices);
cl_device_type device_type; cl_device_type device_type;
error = clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(device_type), error = clGetDeviceInfo(device, CL_DEVICE_TYPE, sizeof(device_type),
@@ -1092,18 +1086,16 @@ test_status InitCL(cl_device_id device)
} }
gDevice = device; gDevice = device;
if ((error = clGetDeviceInfo(gDevice, CL_DEVICE_MAX_COMPUTE_UNITS,
configSize, &gComputeDevices, NULL)))
gComputeDevices = 1;
// Check extensions // Check extensions
if (is_extension_available(gDevice, "cl_khr_fp64")) if (is_extension_available(gDevice, "cl_khr_fp64"))
{ {
gHasDouble ^= 1; gHasDouble ^= 1;
#if defined(CL_DEVICE_DOUBLE_FP_CONFIG) #if defined(CL_DEVICE_DOUBLE_FP_CONFIG)
cl_device_fp_config doubleCapabilities = 0;
if ((error = clGetDeviceInfo(gDevice, CL_DEVICE_DOUBLE_FP_CONFIG, if ((error = clGetDeviceInfo(gDevice, CL_DEVICE_DOUBLE_FP_CONFIG,
sizeof(gDoubleCapabilities), sizeof(doubleCapabilities),
&gDoubleCapabilities, NULL))) &doubleCapabilities, NULL)))
{ {
vlog_error("ERROR: Unable to get device " vlog_error("ERROR: Unable to get device "
"CL_DEVICE_DOUBLE_FP_CONFIG. (%d)\n", "CL_DEVICE_DOUBLE_FP_CONFIG. (%d)\n",
@@ -1112,19 +1104,19 @@ test_status InitCL(cl_device_id device)
} }
if (DOUBLE_REQUIRED_FEATURES if (DOUBLE_REQUIRED_FEATURES
!= (gDoubleCapabilities & DOUBLE_REQUIRED_FEATURES)) != (doubleCapabilities & DOUBLE_REQUIRED_FEATURES))
{ {
std::string list; std::string list;
if (0 == (gDoubleCapabilities & CL_FP_FMA)) list += "CL_FP_FMA, "; if (0 == (doubleCapabilities & CL_FP_FMA)) list += "CL_FP_FMA, ";
if (0 == (gDoubleCapabilities & CL_FP_ROUND_TO_NEAREST)) if (0 == (doubleCapabilities & CL_FP_ROUND_TO_NEAREST))
list += "CL_FP_ROUND_TO_NEAREST, "; list += "CL_FP_ROUND_TO_NEAREST, ";
if (0 == (gDoubleCapabilities & CL_FP_ROUND_TO_ZERO)) if (0 == (doubleCapabilities & CL_FP_ROUND_TO_ZERO))
list += "CL_FP_ROUND_TO_ZERO, "; list += "CL_FP_ROUND_TO_ZERO, ";
if (0 == (gDoubleCapabilities & CL_FP_ROUND_TO_INF)) if (0 == (doubleCapabilities & CL_FP_ROUND_TO_INF))
list += "CL_FP_ROUND_TO_INF, "; list += "CL_FP_ROUND_TO_INF, ";
if (0 == (gDoubleCapabilities & CL_FP_INF_NAN)) if (0 == (doubleCapabilities & CL_FP_INF_NAN))
list += "CL_FP_INF_NAN, "; list += "CL_FP_INF_NAN, ";
if (0 == (gDoubleCapabilities & CL_FP_DENORM)) if (0 == (doubleCapabilities & CL_FP_DENORM))
list += "CL_FP_DENORM, "; list += "CL_FP_DENORM, ";
vlog_error("ERROR: required double features are missing: %s\n", vlog_error("ERROR: required double features are missing: %s\n",
list.c_str()); list.c_str());
@@ -1138,10 +1130,11 @@ test_status InitCL(cl_device_id device)
#endif #endif
} }
configSize = sizeof(gDeviceFrequency); uint32_t deviceFrequency = 0;
size_t configSize = sizeof(deviceFrequency);
if ((error = clGetDeviceInfo(gDevice, CL_DEVICE_MAX_CLOCK_FREQUENCY, if ((error = clGetDeviceInfo(gDevice, CL_DEVICE_MAX_CLOCK_FREQUENCY,
configSize, &gDeviceFrequency, NULL))) configSize, &deviceFrequency, NULL)))
gDeviceFrequency = 0; deviceFrequency = 0;
if ((error = clGetDeviceInfo(gDevice, CL_DEVICE_SINGLE_FP_CONFIG, if ((error = clGetDeviceInfo(gDevice, CL_DEVICE_SINGLE_FP_CONFIG,
sizeof(gFloatCapabilities), sizeof(gFloatCapabilities),
@@ -1288,7 +1281,7 @@ test_status InitCL(cl_device_id device)
vlog("\tCL C Version: %s\n", c); vlog("\tCL C Version: %s\n", c);
clGetDeviceInfo(gDevice, CL_DRIVER_VERSION, sizeof(c), &c, NULL); clGetDeviceInfo(gDevice, CL_DRIVER_VERSION, sizeof(c), &c, NULL);
vlog("\tDriver Version: %s\n", c); vlog("\tDriver Version: %s\n", c);
vlog("\tDevice Frequency: %d MHz\n", gDeviceFrequency); vlog("\tDevice Frequency: %d MHz\n", deviceFrequency);
vlog("\tSubnormal values supported for floats? %s\n", vlog("\tSubnormal values supported for floats? %s\n",
no_yes[0 != (CL_FP_DENORM & gFloatCapabilities)]); no_yes[0 != (CL_FP_DENORM & gFloatCapabilities)]);
vlog("\tCorrectly rounded divide and sqrt supported for floats? %s\n", vlog("\tCorrectly rounded divide and sqrt supported for floats? %s\n",

View File

@@ -56,22 +56,17 @@ extern cl_mem gInBuffer2;
extern cl_mem gInBuffer3; extern cl_mem gInBuffer3;
extern cl_mem gOutBuffer[VECTOR_SIZE_COUNT]; extern cl_mem gOutBuffer[VECTOR_SIZE_COUNT];
extern cl_mem gOutBuffer2[VECTOR_SIZE_COUNT]; extern cl_mem gOutBuffer2[VECTOR_SIZE_COUNT];
extern uint32_t gComputeDevices;
extern uint32_t gSimdSize;
extern int gSkipCorrectnessTesting; extern int gSkipCorrectnessTesting;
extern int gForceFTZ; extern int gForceFTZ;
extern int gFastRelaxedDerived; extern int gFastRelaxedDerived;
extern int gWimpyMode; extern int gWimpyMode;
extern int gHasDouble;
extern int gIsInRTZMode; extern int gIsInRTZMode;
extern int gInfNanSupport; extern int gInfNanSupport;
extern int gIsEmbedded; extern int gIsEmbedded;
extern int gVerboseBruteForce; extern int gVerboseBruteForce;
extern uint32_t gMaxVectorSizeIndex; extern uint32_t gMaxVectorSizeIndex;
extern uint32_t gMinVectorSizeIndex; extern uint32_t gMinVectorSizeIndex;
extern uint32_t gDeviceFrequency;
extern cl_device_fp_config gFloatCapabilities; extern cl_device_fp_config gFloatCapabilities;
extern cl_device_fp_config gDoubleCapabilities;
#define LOWER_IS_BETTER 0 #define LOWER_IS_BETTER 0
#define HIGHER_IS_BETTER 1 #define HIGHER_IS_BETTER 1