Skip to content

Commit

Permalink
attempt to fix some thread issues
Browse files Browse the repository at this point in the history
  • Loading branch information
franz committed Nov 3, 2023
1 parent db1af99 commit bbc25e7
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
5 changes: 4 additions & 1 deletion test_common/harness/mt19937.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@
#include "mingw_compat.h"
#include "harness/alloc.h"

#ifdef __SSE2__
#include <mutex>
#ifdef __SSE2__
#include <emmintrin.h>
#endif

Expand All @@ -62,6 +62,8 @@
#define UPPER_MASK (cl_uint)0x80000000UL /* most significant w-r bits */
#define LOWER_MASK (cl_uint)0x7fffffffUL /* least significant r bits */

static std::mutex Mt19937Mtx;

typedef struct _MTdata
{
cl_uint mt[N];
Expand Down Expand Up @@ -105,6 +107,7 @@ void free_mtdata(MTdata d)
/* generates a random number on [0,0xffffffff]-interval */
cl_uint genrand_int32(MTdata d)
{
std::lock_guard<std::mutex> LockGuard(Mt19937Mtx);
/* mag01[x] = x * MATRIX_A for x=0,1 */
static const cl_uint mag01[2] = { 0x0UL, MATRIX_A };
#ifdef __SSE2__
Expand Down
23 changes: 9 additions & 14 deletions test_conformance/math_brute_force/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ static int doTest(const char *name)
{
if (get_device_cl_version(gDevice) > Version(1, 2))
{
gTestCount++;
vlog("%3d: ", gTestCount);
int TestCount = __atomic_add_fetch(&gTestCount, 1, __ATOMIC_ACQ_REL);
vlog("%3d: ", TestCount);
// Test with relaxed requirements here.
if (func_data->vtbl_ptr->TestFunc(func_data, gMTdata,
true /* relaxed mode */))
Expand All @@ -202,13 +202,13 @@ static int doTest(const char *name)

if (gTestFloat)
{
gTestCount++;
vlog("%3d: ", gTestCount);
int TestCount = __atomic_add_fetch(&gTestCount, 1, __ATOMIC_ACQ_REL);
vlog("%3d: ", TestCount);
// Don't test with relaxed requirements.
if (func_data->vtbl_ptr->TestFunc(func_data, gMTdata,
false /* relaxed mode */))
{
gFailCount++;
__atomic_add_fetch(&gFailCount, 1, __ATOMIC_ACQ_REL);
error++;
if (gStopOnError)
{
Expand All @@ -221,13 +221,13 @@ static int doTest(const char *name)
if (gHasDouble && NULL != func_data->vtbl_ptr->DoubleTestFunc
&& NULL != func_data->dfunc.p)
{
gTestCount++;
vlog("%3d: ", gTestCount);
int TestCount = __atomic_add_fetch(&gTestCount, 1, __ATOMIC_ACQ_REL);
vlog("%3d: ", TestCount);
// Don't test with relaxed requirements.
if (func_data->vtbl_ptr->DoubleTestFunc(func_data, gMTdata,
false /* relaxed mode*/))
{
gFailCount++;
__atomic_add_fetch(&gFailCount, 1, __ATOMIC_ACQ_REL);
error++;
if (gStopOnError)
{
Expand Down Expand Up @@ -701,12 +701,7 @@ test_status InitCL(cl_device_id device)
if (NULL == gOut2[i]) return TEST_FAIL;
}

cl_mem_flags device_flags = CL_MEM_READ_ONLY;
// save a copy on the host device to make this go faster
if (CL_DEVICE_TYPE_CPU == device_type)
device_flags |= CL_MEM_USE_HOST_PTR;
else
device_flags |= CL_MEM_COPY_HOST_PTR;
cl_mem_flags device_flags = CL_MEM_READ_ONLY | CL_MEM_COPY_HOST_PTR;

// setup input buffers
gInBuffer =
Expand Down

0 comments on commit bbc25e7

Please sign in to comment.