Skip to content

Commit

Permalink
make atomic tests in prog var testing optional
Browse files Browse the repository at this point in the history
This is helpful for testing progvars on implementations not implementing
all the optional atomic features.
  • Loading branch information
karolherbst committed Oct 3, 2023
1 parent e3c8de8 commit 8213e37
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions test_conformance/basic/test_progvar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include <sys/stat.h>
#include "harness/typeWrappers.h"
#include "harness/errorHelpers.h"
#include "harness/featureHelpers.h"
#include "harness/mt19937.h"
#include "procs.h"

Expand All @@ -57,6 +58,7 @@
static int l_has_double = 0;
static int l_has_half = 0;
static int l_64bit_device = 0;
static int l_has_atomics = 1;
static int l_has_int64_atomics = 0;
static int l_has_intptr_atomics = 0;
static int l_has_cles_int64 = 0;
Expand Down Expand Up @@ -398,7 +400,7 @@ class StringTable {
////////////////////
// File scope function declarations

static void l_load_abilities(cl_device_id device);
static int l_load_abilities(cl_device_id device);
static const char* l_get_fp64_pragma(void);
static const char* l_get_cles_int64_pragma(void);
static int l_build_type_table(cl_device_id device);
Expand Down Expand Up @@ -547,12 +549,26 @@ static cl_int print_build_log(cl_program program, cl_uint num_devices,
return error;
}

static void l_load_abilities(cl_device_id device)
static int l_load_abilities(cl_device_id device)
{
l_has_half = is_extension_available(device, "cl_khr_fp16");
l_has_double = is_extension_available(device, "cl_khr_fp64");
l_has_cles_int64 = is_extension_available(device, "cles_khr_int64");

if (get_device_cl_version(device) >= Version(3, 0))
{
OpenCLCFeatures features;
int ret = get_device_cl_c_features(device, features);
if (ret)
{
log_error("Couldn't query OpenCL C features for the device!\n");
return ret;
}

l_has_atomics = features.supports__opencl_c_atomic_order_seq_cst
&& features.supports__opencl_c_atomic_scope_device;
}

l_has_int64_atomics =
is_extension_available(device, "cl_khr_int64_base_atomics")
&& is_extension_available(device, "cl_khr_int64_extended_atomics");
Expand All @@ -566,7 +582,8 @@ static void l_load_abilities(cl_device_id device)
}

// 32-bit devices always have intptr atomics.
l_has_intptr_atomics = !l_64bit_device || l_has_int64_atomics;
l_has_intptr_atomics =
l_has_atomics && (!l_64bit_device || l_has_int64_atomics);

union {
char c[4];
Expand Down Expand Up @@ -608,6 +625,8 @@ static void l_load_abilities(cl_device_id device)
"CL_DEVICE_LINKER_AVAILABLE failed."))
return;
}

return TEST_PASS;
}


Expand Down Expand Up @@ -649,7 +668,9 @@ static int l_build_type_table(cl_device_id device)
const char* intptr_atomics[] = { "atomic_intptr_t", "atomic_uintptr_t",
"atomic_size_t", "atomic_ptrdiff_t" };

l_load_abilities(device);
int ret = l_load_abilities(device);
if (ret) return CL_INVALID_DEVICE;

num_type_info = 0;

// Boolean.
Expand Down Expand Up @@ -688,6 +709,7 @@ static int l_build_type_table(cl_device_id device)
// Atomic types.
for (iscalar = 0; iscalar < sizeof(atomics) / sizeof(atomics[0]); ++iscalar)
{
if (!l_has_atomics) continue;
if (!l_has_int64_atomics && strstr(atomics[iscalar], "long")) continue;
if (!(l_has_int64_atomics && l_has_double)
&& strstr(atomics[iscalar], "double"))
Expand Down

0 comments on commit 8213e37

Please sign in to comment.