Skip to content

Commit

Permalink
Fix SVM if 64-bit atomic extensions are supported (#396)
Browse files Browse the repository at this point in the history
Need to enable 64-bit atomic extensions in kernel source.
Use InterlockedCompareExchange64 for 64-bit type.
  • Loading branch information
wenju-he authored and kpet committed Jul 24, 2019
1 parent 64dba66 commit 1d2e0ca
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion test_conformance/SVM/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ bool AtomicCompareExchangeStrongExplicit(volatile T *a, T *expected, T desired,
{
T tmp;
#if defined( _MSC_VER ) || (defined( __INTEL_COMPILER ) && defined(WIN32))
tmp = (T)InterlockedCompareExchange((volatile LONG *)a, (LONG)desired, *(LONG *)expected);
tmp = (sizeof(void*) == 8) ? (T)InterlockedCompareExchange64((volatile LONG64 *)a, (LONG64)desired, *(LONG64 *)expected) :
(T)InterlockedCompareExchange((volatile LONG*)a, (LONG)desired, *(LONG*)expected);
#elif defined(__GNUC__)
tmp = (T)__sync_val_compare_and_swap((volatile intptr_t*)a, (intptr_t)(*expected), (intptr_t)desired);
#else
Expand Down
16 changes: 12 additions & 4 deletions test_conformance/SVM/test_fine_grain_memory_consistency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
//
#include "common.h"

const char *hash_table_kernel[] = {
static char hash_table_kernel[] =
"#if 0\n"
"#pragma OPENCL EXTENSION cl_khr_int64_base_atomics : enable\n"
"#pragma OPENCL EXTENSION cl_khr_int64_extended_atomics : enable\n"
"#endif\n"
"typedef struct BinNode {\n"
" int value;\n"
" atomic_uintptr_t pNext;\n"
Expand All @@ -32,8 +36,7 @@ const char *hash_table_kernel[] = {
" {\n"
" atomic_store_explicit(&(pNew->pNext), next, memory_order_seq_cst, memory_scope_all_svm_devices);\n" // always inserting at head of list
" } while(!atomic_compare_exchange_strong_explicit(&(pNodes[b].pNext), &next, (uintptr_t)pNew, memory_order_seq_cst, memory_order_relaxed, memory_scope_all_svm_devices));\n"
"}\n"
};
"}\n";

typedef struct BinNode{
cl_uint value;
Expand Down Expand Up @@ -143,7 +146,12 @@ int test_svm_fine_grain_memory_consistency(cl_device_id deviceID, cl_context c,
return 0;
}

err = create_cl_objects(deviceID, &hash_table_kernel[0], &context, &program, &queues[0], &num_devices, CL_DEVICE_SVM_FINE_GRAIN_BUFFER | CL_DEVICE_SVM_ATOMICS);
// Make pragmas visible for 64-bit addresses
hash_table_kernel[4] = sizeof(void *) == 8 ? '1' : '0';

char *source[] = { hash_table_kernel };

err = create_cl_objects(deviceID, (const char**)source, &context, &program, &queues[0], &num_devices, CL_DEVICE_SVM_FINE_GRAIN_BUFFER | CL_DEVICE_SVM_ATOMICS);
if(err == 1) return 0; // no devices capable of requested SVM level, so don't execute but count test as passing.
if(err < 0) return -1; // fail test.

Expand Down

0 comments on commit 1d2e0ca

Please sign in to comment.