[Libclc-dev] [PATCH 1/1] Implement cl_khr_int64_extended_atomics builtins
Aaron Watry via Libclc-dev
libclc-dev at lists.llvm.org
Wed Sep 20 13:31:20 PDT 2017
Reviewed-by: Aaron Watry <awatry at gmail.com>
Tested-by: Aaron Watry <awatry at gmail.com>
I've tested this using the CL 1.2 CTS on PITCAIRN (GCN 1.0) after
exposing the extension in clover.
--Aaron
On Wed, Sep 20, 2017 at 1:46 AM, Jan Vesely via Libclc-dev
<libclc-dev at lists.llvm.org> wrote:
> Pass newly posted piglits on carrizo/iceland
>
> Signed-off-by: Jan Vesely <jan.vesely at rutgers.edu>
> ---
> The helpers are necessary because clang's atomic min/max are only
> available for int32.
> They'll be moved to llvm-4/5 compatibility sources when 64bit clang builtins are added.
>
> amdgcn/lib/SOURCES | 1 +
> .../minmax_helpers.ll | 47 ++++++++++++++++++++++
> .../clc/cl_khr_int64_extended_atomics/atom_and.h | 4 ++
> .../clc/cl_khr_int64_extended_atomics/atom_max.h | 4 ++
> .../clc/cl_khr_int64_extended_atomics/atom_min.h | 4 ++
> .../clc/cl_khr_int64_extended_atomics/atom_or.h | 4 ++
> .../clc/cl_khr_int64_extended_atomics/atom_xor.h | 4 ++
> generic/include/clc/clc.h | 9 +++++
> generic/lib/SOURCES | 5 +++
> .../lib/cl_khr_int64_extended_atomics/atom_and.cl | 16 ++++++++
> .../lib/cl_khr_int64_extended_atomics/atom_max.cl | 21 ++++++++++
> .../lib/cl_khr_int64_extended_atomics/atom_min.cl | 21 ++++++++++
> .../lib/cl_khr_int64_extended_atomics/atom_or.cl | 16 ++++++++
> .../lib/cl_khr_int64_extended_atomics/atom_xor.cl | 16 ++++++++
> 14 files changed, 172 insertions(+)
> create mode 100644 amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll
> create mode 100644 generic/include/clc/cl_khr_int64_extended_atomics/atom_and.h
> create mode 100644 generic/include/clc/cl_khr_int64_extended_atomics/atom_max.h
> create mode 100644 generic/include/clc/cl_khr_int64_extended_atomics/atom_min.h
> create mode 100644 generic/include/clc/cl_khr_int64_extended_atomics/atom_or.h
> create mode 100644 generic/include/clc/cl_khr_int64_extended_atomics/atom_xor.h
> create mode 100644 generic/lib/cl_khr_int64_extended_atomics/atom_and.cl
> create mode 100644 generic/lib/cl_khr_int64_extended_atomics/atom_max.cl
> create mode 100644 generic/lib/cl_khr_int64_extended_atomics/atom_min.cl
> create mode 100644 generic/lib/cl_khr_int64_extended_atomics/atom_or.cl
> create mode 100644 generic/lib/cl_khr_int64_extended_atomics/atom_xor.cl
>
> diff --git a/amdgcn/lib/SOURCES b/amdgcn/lib/SOURCES
> index a1f9483..8c177bd 100644
> --- a/amdgcn/lib/SOURCES
> +++ b/amdgcn/lib/SOURCES
> @@ -1,3 +1,4 @@
> +cl_khr_int64_extended_atomics/minmax_helpers.ll
> math/ldexp.cl
> mem_fence/fence.cl
> mem_fence/waitcnt.ll
> diff --git a/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll b/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll
> new file mode 100644
> index 0000000..7f12556
> --- /dev/null
> +++ b/amdgcn/lib/cl_khr_int64_extended_atomics/minmax_helpers.ll
> @@ -0,0 +1,47 @@
> +define i64 @__clc__sync_fetch_and_min_global_8(i64 addrspace(1)* nocapture %ptr, i64 %value) nounwind alwaysinline {
> +entry:
> + %0 = atomicrmw volatile min i64 addrspace(1)* %ptr, i64 %value seq_cst
> + ret i64 %0
> +}
> +
> +define i64 @__clc__sync_fetch_and_umin_global_8(i64 addrspace(1)* nocapture %ptr, i64 %value) nounwind alwaysinline {
> +entry:
> + %0 = atomicrmw volatile umin i64 addrspace(1)* %ptr, i64 %value seq_cst
> + ret i64 %0
> +}
> +
> +define i64 @__clc__sync_fetch_and_min_local_8(i64 addrspace(3)* nocapture %ptr, i64 %value) nounwind alwaysinline {
> +entry:
> + %0 = atomicrmw volatile min i64 addrspace(3)* %ptr, i64 %value seq_cst
> + ret i64 %0
> +}
> +
> +define i64 @__clc__sync_fetch_and_umin_local_8(i64 addrspace(3)* nocapture %ptr, i64 %value) nounwind alwaysinline {
> +entry:
> + %0 = atomicrmw volatile umin i64 addrspace(3)* %ptr, i64 %value seq_cst
> + ret i64 %0
> +}
> +
> +define i64 @__clc__sync_fetch_and_max_global_8(i64 addrspace(1)* nocapture %ptr, i64 %value) nounwind alwaysinline {
> +entry:
> + %0 = atomicrmw volatile max i64 addrspace(1)* %ptr, i64 %value seq_cst
> + ret i64 %0
> +}
> +
> +define i64 @__clc__sync_fetch_and_umax_global_8(i64 addrspace(1)* nocapture %ptr, i64 %value) nounwind alwaysinline {
> +entry:
> + %0 = atomicrmw volatile umax i64 addrspace(1)* %ptr, i64 %value seq_cst
> + ret i64 %0
> +}
> +
> +define i64 @__clc__sync_fetch_and_max_local_8(i64 addrspace(3)* nocapture %ptr, i64 %value) nounwind alwaysinline {
> +entry:
> + %0 = atomicrmw volatile max i64 addrspace(3)* %ptr, i64 %value seq_cst
> + ret i64 %0
> +}
> +
> +define i64 @__clc__sync_fetch_and_umax_local_8(i64 addrspace(3)* nocapture %ptr, i64 %value) nounwind alwaysinline {
> +entry:
> + %0 = atomicrmw volatile umax i64 addrspace(3)* %ptr, i64 %value seq_cst
> + ret i64 %0
> +}
> diff --git a/generic/include/clc/cl_khr_int64_extended_atomics/atom_and.h b/generic/include/clc/cl_khr_int64_extended_atomics/atom_and.h
> new file mode 100644
> index 0000000..388df1d
> --- /dev/null
> +++ b/generic/include/clc/cl_khr_int64_extended_atomics/atom_and.h
> @@ -0,0 +1,4 @@
> +_CLC_OVERLOAD _CLC_DECL long atom_and(volatile global long *p, long val);
> +_CLC_OVERLOAD _CLC_DECL unsigned long atom_and(volatile global unsigned long *p, unsigned long val);
> +_CLC_OVERLOAD _CLC_DECL long atom_and(volatile local long *p, long val);
> +_CLC_OVERLOAD _CLC_DECL unsigned long atom_and(volatile local unsigned long *p, unsigned long val);
> diff --git a/generic/include/clc/cl_khr_int64_extended_atomics/atom_max.h b/generic/include/clc/cl_khr_int64_extended_atomics/atom_max.h
> new file mode 100644
> index 0000000..b84b5a0
> --- /dev/null
> +++ b/generic/include/clc/cl_khr_int64_extended_atomics/atom_max.h
> @@ -0,0 +1,4 @@
> +_CLC_OVERLOAD _CLC_DECL long atom_max(volatile global long *p, long val);
> +_CLC_OVERLOAD _CLC_DECL unsigned long atom_max(volatile global unsigned long *p, unsigned long val);
> +_CLC_OVERLOAD _CLC_DECL long atom_max(volatile local long *p, long val);
> +_CLC_OVERLOAD _CLC_DECL unsigned long atom_max(volatile local unsigned long *p, unsigned long val);
> diff --git a/generic/include/clc/cl_khr_int64_extended_atomics/atom_min.h b/generic/include/clc/cl_khr_int64_extended_atomics/atom_min.h
> new file mode 100644
> index 0000000..bd70b0b
> --- /dev/null
> +++ b/generic/include/clc/cl_khr_int64_extended_atomics/atom_min.h
> @@ -0,0 +1,4 @@
> +_CLC_OVERLOAD _CLC_DECL long atom_min(volatile global long *p, long val);
> +_CLC_OVERLOAD _CLC_DECL unsigned long atom_min(volatile global unsigned long *p, unsigned long val);
> +_CLC_OVERLOAD _CLC_DECL long atom_min(volatile local long *p, long val);
> +_CLC_OVERLOAD _CLC_DECL unsigned long atom_min(volatile local unsigned long *p, unsigned long val);
> diff --git a/generic/include/clc/cl_khr_int64_extended_atomics/atom_or.h b/generic/include/clc/cl_khr_int64_extended_atomics/atom_or.h
> new file mode 100644
> index 0000000..e307822
> --- /dev/null
> +++ b/generic/include/clc/cl_khr_int64_extended_atomics/atom_or.h
> @@ -0,0 +1,4 @@
> +_CLC_OVERLOAD _CLC_DECL long atom_or(volatile global long *p, long val);
> +_CLC_OVERLOAD _CLC_DECL unsigned long atom_or(volatile global unsigned long *p, unsigned long val);
> +_CLC_OVERLOAD _CLC_DECL long atom_or(volatile local long *p, long val);
> +_CLC_OVERLOAD _CLC_DECL unsigned long atom_or(volatile local unsigned long *p, unsigned long val);
> diff --git a/generic/include/clc/cl_khr_int64_extended_atomics/atom_xor.h b/generic/include/clc/cl_khr_int64_extended_atomics/atom_xor.h
> new file mode 100644
> index 0000000..54eb492
> --- /dev/null
> +++ b/generic/include/clc/cl_khr_int64_extended_atomics/atom_xor.h
> @@ -0,0 +1,4 @@
> +_CLC_OVERLOAD _CLC_DECL long atom_xor(volatile global long *p, long val);
> +_CLC_OVERLOAD _CLC_DECL unsigned long atom_xor(volatile global unsigned long *p, unsigned long val);
> +_CLC_OVERLOAD _CLC_DECL long atom_xor(volatile local long *p, long val);
> +_CLC_OVERLOAD _CLC_DECL unsigned long atom_xor(volatile local unsigned long *p, unsigned long val);
> diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
> index 863a73d..adaab90 100644
> --- a/generic/include/clc/clc.h
> +++ b/generic/include/clc/clc.h
> @@ -247,6 +247,15 @@
> #include <clc/cl_khr_int64_base_atomics/atom_xchg.h>
> #endif
>
> +/* cl_khr_int64_extended_atomics Extension Functions */
> +#ifdef cl_khr_int64_base_atomics
> +#include <clc/cl_khr_int64_extended_atomics/atom_and.h>
> +#include <clc/cl_khr_int64_extended_atomics/atom_max.h>
> +#include <clc/cl_khr_int64_extended_atomics/atom_min.h>
> +#include <clc/cl_khr_int64_extended_atomics/atom_or.h>
> +#include <clc/cl_khr_int64_extended_atomics/atom_xor.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 7df8683..23905c4 100644
> --- a/generic/lib/SOURCES
> +++ b/generic/lib/SOURCES
> @@ -34,6 +34,11 @@ 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
> +cl_khr_int64_extended_atomics/atom_and.cl
> +cl_khr_int64_extended_atomics/atom_max.cl
> +cl_khr_int64_extended_atomics/atom_min.cl
> +cl_khr_int64_extended_atomics/atom_or.cl
> +cl_khr_int64_extended_atomics/atom_xor.cl
> convert.cl
> common/degrees.cl
> common/mix.cl
> diff --git a/generic/lib/cl_khr_int64_extended_atomics/atom_and.cl b/generic/lib/cl_khr_int64_extended_atomics/atom_and.cl
> new file mode 100644
> index 0000000..55e5f6e
> --- /dev/null
> +++ b/generic/lib/cl_khr_int64_extended_atomics/atom_and.cl
> @@ -0,0 +1,16 @@
> +#include <clc/clc.h>
> +
> +#ifdef cl_khr_int64_extended_atomics
> +
> +#define IMPL(AS, TYPE) \
> +_CLC_OVERLOAD _CLC_DEF TYPE atom_and(volatile AS TYPE *p, TYPE val) { \
> + return __sync_fetch_and_and_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_extended_atomics/atom_max.cl b/generic/lib/cl_khr_int64_extended_atomics/atom_max.cl
> new file mode 100644
> index 0000000..357acf3
> --- /dev/null
> +++ b/generic/lib/cl_khr_int64_extended_atomics/atom_max.cl
> @@ -0,0 +1,21 @@
> +#include <clc/clc.h>
> +
> +#ifdef cl_khr_int64_extended_atomics
> +
> +unsigned long __clc__sync_fetch_and_max_local_8(volatile local long *, long);
> +unsigned long __clc__sync_fetch_and_max_global_8(volatile global long *, long);
> +unsigned long __clc__sync_fetch_and_umax_local_8(volatile local unsigned long *, unsigned long);
> +unsigned long __clc__sync_fetch_and_umax_global_8(volatile global unsigned long *, unsigned long);
> +
> +#define IMPL(AS, TYPE, OP) \
> +_CLC_OVERLOAD _CLC_DEF TYPE atom_max(volatile AS TYPE *p, TYPE val) { \
> + return __clc__sync_fetch_and_##OP##_##AS##_8(p, val); \
> +}
> +
> +IMPL(global, long, max)
> +IMPL(global, unsigned long, umax)
> +IMPL(local, long, max)
> +IMPL(local, unsigned long, umax)
> +#undef IMPL
> +
> +#endif
> diff --git a/generic/lib/cl_khr_int64_extended_atomics/atom_min.cl b/generic/lib/cl_khr_int64_extended_atomics/atom_min.cl
> new file mode 100644
> index 0000000..6a1b13a
> --- /dev/null
> +++ b/generic/lib/cl_khr_int64_extended_atomics/atom_min.cl
> @@ -0,0 +1,21 @@
> +#include <clc/clc.h>
> +
> +#ifdef cl_khr_int64_extended_atomics
> +
> +unsigned long __clc__sync_fetch_and_min_local_8(volatile local long *, long);
> +unsigned long __clc__sync_fetch_and_min_global_8(volatile global long *, long);
> +unsigned long __clc__sync_fetch_and_umin_local_8(volatile local unsigned long *, unsigned long);
> +unsigned long __clc__sync_fetch_and_umin_global_8(volatile global unsigned long *, unsigned long);
> +
> +#define IMPL(AS, TYPE, OP) \
> +_CLC_OVERLOAD _CLC_DEF TYPE atom_min(volatile AS TYPE *p, TYPE val) { \
> + return __clc__sync_fetch_and_##OP##_##AS##_8(p, val); \
> +}
> +
> +IMPL(global, long, min)
> +IMPL(global, unsigned long, umin)
> +IMPL(local, long, min)
> +IMPL(local, unsigned long, umin)
> +#undef IMPL
> +
> +#endif
> diff --git a/generic/lib/cl_khr_int64_extended_atomics/atom_or.cl b/generic/lib/cl_khr_int64_extended_atomics/atom_or.cl
> new file mode 100644
> index 0000000..660b718
> --- /dev/null
> +++ b/generic/lib/cl_khr_int64_extended_atomics/atom_or.cl
> @@ -0,0 +1,16 @@
> +#include <clc/clc.h>
> +
> +#ifdef cl_khr_int64_extended_atomics
> +
> +#define IMPL(AS, TYPE) \
> +_CLC_OVERLOAD _CLC_DEF TYPE atom_or(volatile AS TYPE *p, TYPE val) { \
> + return __sync_fetch_and_or_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_extended_atomics/atom_xor.cl b/generic/lib/cl_khr_int64_extended_atomics/atom_xor.cl
> new file mode 100644
> index 0000000..21e878c
> --- /dev/null
> +++ b/generic/lib/cl_khr_int64_extended_atomics/atom_xor.cl
> @@ -0,0 +1,16 @@
> +#include <clc/clc.h>
> +
> +#ifdef cl_khr_int64_extended_atomics
> +
> +#define IMPL(AS, TYPE) \
> +_CLC_OVERLOAD _CLC_DEF TYPE atom_xor(volatile AS TYPE *p, TYPE val) { \
> + return __sync_fetch_and_xor_8(p, val); \
> +}
> +
> +IMPL(global, long)
> +IMPL(global, unsigned long)
> +IMPL(local, long)
> +IMPL(local, unsigned long)
> +#undef IMPL
> +
> +#endif
> --
> 2.13.5
>
> _______________________________________________
> Libclc-dev mailing list
> Libclc-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/libclc-dev
More information about the Libclc-dev
mailing list