[Libclc-dev] [PATCH 1/1] Implement cl_khr_int64_base_atomics builtins

Jan Vesely via Libclc-dev libclc-dev at lists.llvm.org
Mon Sep 18 14:34:26 PDT 2017


Passes newly posted piglit tests on carrizo/iceland (after modding
clover to expose the extension)

Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
---
I'm not sure if seq_cst is the ordering we are looking for, but the
cl1.x specs don't say how atomics relate to memory ops.

 generic/include/clc/cl_khr_int64_base_atomics/atom_add.h |  4 ++++
 .../include/clc/cl_khr_int64_base_atomics/atom_cmpxchg.h |  4 ++++
 generic/include/clc/cl_khr_int64_base_atomics/atom_dec.h |  4 ++++
 generic/include/clc/cl_khr_int64_base_atomics/atom_inc.h |  4 ++++
 generic/include/clc/cl_khr_int64_base_atomics/atom_sub.h |  4 ++++
 .../include/clc/cl_khr_int64_base_atomics/atom_xchg.h    |  4 ++++
 generic/include/clc/clc.h                                | 10 ++++++++++
 generic/lib/SOURCES                                      |  6 ++++++
 generic/lib/cl_khr_int64_base_atomics/atom_add.cl        | 16 ++++++++++++++++
 generic/lib/cl_khr_int64_base_atomics/atom_cmpxchg.cl    | 16 ++++++++++++++++
 generic/lib/cl_khr_int64_base_atomics/atom_dec.cl        | 16 ++++++++++++++++
 generic/lib/cl_khr_int64_base_atomics/atom_inc.cl        | 16 ++++++++++++++++
 generic/lib/cl_khr_int64_base_atomics/atom_sub.cl        | 16 ++++++++++++++++
 generic/lib/cl_khr_int64_base_atomics/atom_xchg.cl       | 16 ++++++++++++++++
 14 files changed, 136 insertions(+)
 create mode 100644 generic/include/clc/cl_khr_int64_base_atomics/atom_add.h
 create mode 100644 generic/include/clc/cl_khr_int64_base_atomics/atom_cmpxchg.h
 create mode 100644 generic/include/clc/cl_khr_int64_base_atomics/atom_dec.h
 create mode 100644 generic/include/clc/cl_khr_int64_base_atomics/atom_inc.h
 create mode 100644 generic/include/clc/cl_khr_int64_base_atomics/atom_sub.h
 create mode 100644 generic/include/clc/cl_khr_int64_base_atomics/atom_xchg.h
 create mode 100644 generic/lib/cl_khr_int64_base_atomics/atom_add.cl
 create mode 100644 generic/lib/cl_khr_int64_base_atomics/atom_cmpxchg.cl
 create mode 100644 generic/lib/cl_khr_int64_base_atomics/atom_dec.cl
 create mode 100644 generic/lib/cl_khr_int64_base_atomics/atom_inc.cl
 create mode 100644 generic/lib/cl_khr_int64_base_atomics/atom_sub.cl
 create mode 100644 generic/lib/cl_khr_int64_base_atomics/atom_xchg.cl

diff --git a/generic/include/clc/cl_khr_int64_base_atomics/atom_add.h b/generic/include/clc/cl_khr_int64_base_atomics/atom_add.h
new file mode 100644
index 0000000..5addc13
--- /dev/null
+++ b/generic/include/clc/cl_khr_int64_base_atomics/atom_add.h
@@ -0,0 +1,4 @@
+_CLC_OVERLOAD _CLC_DECL long atom_add(volatile global long *p, long val);
+_CLC_OVERLOAD _CLC_DECL unsigned long atom_add(volatile global unsigned long *p, unsigned long val);
+_CLC_OVERLOAD _CLC_DECL long atom_add(volatile local long *p, long val);
+_CLC_OVERLOAD _CLC_DECL unsigned long atom_add(volatile local unsigned long *p, unsigned long val);
diff --git a/generic/include/clc/cl_khr_int64_base_atomics/atom_cmpxchg.h b/generic/include/clc/cl_khr_int64_base_atomics/atom_cmpxchg.h
new file mode 100644
index 0000000..ce3f9f9
--- /dev/null
+++ b/generic/include/clc/cl_khr_int64_base_atomics/atom_cmpxchg.h
@@ -0,0 +1,4 @@
+_CLC_OVERLOAD _CLC_DECL long atom_cmpxchg(volatile global long *p, long cmp, long val);
+_CLC_OVERLOAD _CLC_DECL unsigned long atom_cmpxchg(volatile global unsigned long *p, unsigned long cmp, unsigned long val);
+_CLC_OVERLOAD _CLC_DECL long atom_cmpxchg(volatile local long *p, long cmp, long val);
+_CLC_OVERLOAD _CLC_DECL unsigned long atom_cmpxchg(volatile local unsigned long *p, unsigned long cmp, unsigned long val);
diff --git a/generic/include/clc/cl_khr_int64_base_atomics/atom_dec.h b/generic/include/clc/cl_khr_int64_base_atomics/atom_dec.h
new file mode 100644
index 0000000..e2e3756
--- /dev/null
+++ b/generic/include/clc/cl_khr_int64_base_atomics/atom_dec.h
@@ -0,0 +1,4 @@
+_CLC_OVERLOAD _CLC_DECL long atom_dec(volatile global long *p);
+_CLC_OVERLOAD _CLC_DECL unsigned long atom_dec(volatile global unsigned long *p);
+_CLC_OVERLOAD _CLC_DECL long atom_dec(volatile local long *p);
+_CLC_OVERLOAD _CLC_DECL unsigned long atom_dec(volatile local unsigned long *p);
diff --git a/generic/include/clc/cl_khr_int64_base_atomics/atom_inc.h b/generic/include/clc/cl_khr_int64_base_atomics/atom_inc.h
new file mode 100644
index 0000000..1bb91e2
--- /dev/null
+++ b/generic/include/clc/cl_khr_int64_base_atomics/atom_inc.h
@@ -0,0 +1,4 @@
+_CLC_OVERLOAD _CLC_DECL long atom_inc(volatile global long *p);
+_CLC_OVERLOAD _CLC_DECL unsigned long atom_inc(volatile global unsigned long *p);
+_CLC_OVERLOAD _CLC_DECL long atom_inc(volatile local long *p);
+_CLC_OVERLOAD _CLC_DECL unsigned long atom_inc(volatile local unsigned long *p);
diff --git a/generic/include/clc/cl_khr_int64_base_atomics/atom_sub.h b/generic/include/clc/cl_khr_int64_base_atomics/atom_sub.h
new file mode 100644
index 0000000..2186ec9
--- /dev/null
+++ b/generic/include/clc/cl_khr_int64_base_atomics/atom_sub.h
@@ -0,0 +1,4 @@
+_CLC_OVERLOAD _CLC_DECL long atom_sub(volatile global long *p, long val);
+_CLC_OVERLOAD _CLC_DECL unsigned long atom_sub(volatile global unsigned long *p, unsigned long val);
+_CLC_OVERLOAD _CLC_DECL long atom_sub(volatile local long *p, long val);
+_CLC_OVERLOAD _CLC_DECL unsigned long atom_sub(volatile local unsigned long *p, unsigned long val);
diff --git a/generic/include/clc/cl_khr_int64_base_atomics/atom_xchg.h b/generic/include/clc/cl_khr_int64_base_atomics/atom_xchg.h
new file mode 100644
index 0000000..3627af1
--- /dev/null
+++ b/generic/include/clc/cl_khr_int64_base_atomics/atom_xchg.h
@@ -0,0 +1,4 @@
+_CLC_OVERLOAD _CLC_DECL long atom_xchg(volatile global long *p, long val);
+_CLC_OVERLOAD _CLC_DECL unsigned long atom_xchg(volatile global unsigned long *p, unsigned long val);
+_CLC_OVERLOAD _CLC_DECL long atom_xchg(volatile local long *p, long val);
+_CLC_OVERLOAD _CLC_DECL unsigned long atom_xchg(volatile local unsigned long *p, unsigned long val);
diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index 9c0e00c..863a73d 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -237,6 +237,16 @@
 #include <clc/cl_khr_local_int32_extended_atomics/atom_or.h>
 #include <clc/cl_khr_local_int32_extended_atomics/atom_xor.h>
 
+/* cl_khr_int64_base_atomics Extension Functions */
+#ifdef cl_khr_int64_base_atomics
+#include <clc/cl_khr_int64_base_atomics/atom_add.h>
+#include <clc/cl_khr_int64_base_atomics/atom_cmpxchg.h>
+#include <clc/cl_khr_int64_base_atomics/atom_dec.h>
+#include <clc/cl_khr_int64_base_atomics/atom_inc.h>
+#include <clc/cl_khr_int64_base_atomics/atom_sub.h>
+#include <clc/cl_khr_int64_base_atomics/atom_xchg.h>
+#endif
+
 /* 6.12.12 Miscellaneous Vector Functions */
 #include <clc/misc/shuffle.h>
 #include <clc/misc/shuffle2.h>
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index f665ce2..7df8683 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -28,6 +28,12 @@ cl_khr_local_int32_extended_atomics/atom_max.cl
 cl_khr_local_int32_extended_atomics/atom_min.cl
 cl_khr_local_int32_extended_atomics/atom_or.cl
 cl_khr_local_int32_extended_atomics/atom_xor.cl
+cl_khr_int64_base_atomics/atom_add.cl
+cl_khr_int64_base_atomics/atom_cmpxchg.cl
+cl_khr_int64_base_atomics/atom_dec.cl
+cl_khr_int64_base_atomics/atom_inc.cl
+cl_khr_int64_base_atomics/atom_sub.cl
+cl_khr_int64_base_atomics/atom_xchg.cl
 convert.cl
 common/degrees.cl
 common/mix.cl
diff --git a/generic/lib/cl_khr_int64_base_atomics/atom_add.cl b/generic/lib/cl_khr_int64_base_atomics/atom_add.cl
new file mode 100644
index 0000000..9ef8a1b
--- /dev/null
+++ b/generic/lib/cl_khr_int64_base_atomics/atom_add.cl
@@ -0,0 +1,16 @@
+#include <clc/clc.h>
+
+#ifdef cl_khr_int64_base_atomics
+
+#define IMPL(AS, TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_add(volatile AS TYPE *p, TYPE val) { \
+  return __sync_fetch_and_add_8(p, val); \
+}
+
+IMPL(global, long)
+IMPL(global, unsigned long)
+IMPL(local, long)
+IMPL(local, unsigned long)
+#undef IMPL
+
+#endif
diff --git a/generic/lib/cl_khr_int64_base_atomics/atom_cmpxchg.cl b/generic/lib/cl_khr_int64_base_atomics/atom_cmpxchg.cl
new file mode 100644
index 0000000..74e3e31
--- /dev/null
+++ b/generic/lib/cl_khr_int64_base_atomics/atom_cmpxchg.cl
@@ -0,0 +1,16 @@
+#include <clc/clc.h>
+
+#ifdef cl_khr_int64_base_atomics
+
+#define IMPL(AS, TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_cmpxchg(volatile AS TYPE *p, TYPE cmp, TYPE val) { \
+  return __sync_val_compare_and_swap_8(p, cmp, val); \
+}
+
+IMPL(global, long)
+IMPL(global, unsigned long)
+IMPL(local, long)
+IMPL(local, unsigned long)
+#undef IMPL
+
+#endif
diff --git a/generic/lib/cl_khr_int64_base_atomics/atom_dec.cl b/generic/lib/cl_khr_int64_base_atomics/atom_dec.cl
new file mode 100644
index 0000000..cc2d8e3
--- /dev/null
+++ b/generic/lib/cl_khr_int64_base_atomics/atom_dec.cl
@@ -0,0 +1,16 @@
+#include <clc/clc.h>
+
+#ifdef cl_khr_int64_base_atomics
+
+#define IMPL(AS, TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_dec(volatile AS TYPE *p) { \
+  return atom_sub(p, (TYPE)1); \
+}
+
+IMPL(global, long)
+IMPL(global, unsigned long)
+IMPL(local, long)
+IMPL(local, unsigned long)
+#undef IMPL
+
+#endif
diff --git a/generic/lib/cl_khr_int64_base_atomics/atom_inc.cl b/generic/lib/cl_khr_int64_base_atomics/atom_inc.cl
new file mode 100644
index 0000000..5541e27
--- /dev/null
+++ b/generic/lib/cl_khr_int64_base_atomics/atom_inc.cl
@@ -0,0 +1,16 @@
+#include <clc/clc.h>
+
+#ifdef cl_khr_int64_base_atomics
+
+#define IMPL(AS, TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_inc(volatile AS TYPE *p) { \
+  return atom_add(p, (TYPE)1); \
+}
+
+IMPL(global, long)
+IMPL(global, unsigned long)
+IMPL(local, long)
+IMPL(local, unsigned long)
+#undef IMPL
+
+#endif
diff --git a/generic/lib/cl_khr_int64_base_atomics/atom_sub.cl b/generic/lib/cl_khr_int64_base_atomics/atom_sub.cl
new file mode 100644
index 0000000..c1b9272
--- /dev/null
+++ b/generic/lib/cl_khr_int64_base_atomics/atom_sub.cl
@@ -0,0 +1,16 @@
+#include <clc/clc.h>
+
+#ifdef cl_khr_int64_base_atomics
+
+#define IMPL(AS, TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_sub(volatile AS TYPE *p, TYPE val) { \
+  return __sync_fetch_and_sub_8(p, val); \
+}
+
+IMPL(global, long)
+IMPL(global, unsigned long)
+IMPL(local, long)
+IMPL(local, unsigned long)
+#undef IMPL
+
+#endif
diff --git a/generic/lib/cl_khr_int64_base_atomics/atom_xchg.cl b/generic/lib/cl_khr_int64_base_atomics/atom_xchg.cl
new file mode 100644
index 0000000..f6560db
--- /dev/null
+++ b/generic/lib/cl_khr_int64_base_atomics/atom_xchg.cl
@@ -0,0 +1,16 @@
+#include <clc/clc.h>
+
+#ifdef cl_khr_int64_base_atomics
+
+#define IMPL(AS, TYPE) \
+_CLC_OVERLOAD _CLC_DEF TYPE atom_xchg(volatile AS TYPE *p, TYPE val) { \
+  return __sync_swap_8(p, val); \
+}
+
+IMPL(global, long)
+IMPL(global, unsigned long)
+IMPL(local, long)
+IMPL(local, unsigned long)
+#undef IMPL
+
+#endif
-- 
2.13.5



More information about the Libclc-dev mailing list