From 50a7bcbac92afc472f381f4dde694a613f411daf Mon Sep 17 00:00:00 2001 From: Aaron Watry Date: Thu, 5 Sep 2013 16:04:01 +0000 Subject: [PATCH] Add atomic_inc and atomic_add builtins Reviewed-by: Aaron Watry llvm-svn: 190058 --- libclc/generic/include/clc/atomic/atomic_add.h | 3 +++ libclc/generic/include/clc/atomic/atomic_decl.inc | 10 ++++++++++ libclc/generic/include/clc/atomic/atomic_inc.h | 1 + libclc/generic/include/clc/clc.h | 4 ++++ libclc/generic/lib/SOURCES | 1 + libclc/generic/lib/atomic/atomic_impl.ll | 11 +++++++++++ libclc/r600/lib/SOURCES | 1 + libclc/r600/lib/atomic/atomic.cl | 20 ++++++++++++++++++++ 8 files changed, 51 insertions(+) create mode 100644 libclc/generic/include/clc/atomic/atomic_add.h create mode 100644 libclc/generic/include/clc/atomic/atomic_decl.inc create mode 100644 libclc/generic/include/clc/atomic/atomic_inc.h create mode 100644 libclc/generic/lib/atomic/atomic_impl.ll create mode 100644 libclc/r600/lib/atomic/atomic.cl diff --git a/libclc/generic/include/clc/atomic/atomic_add.h b/libclc/generic/include/clc/atomic/atomic_add.h new file mode 100644 index 0000000..66d8978 --- /dev/null +++ b/libclc/generic/include/clc/atomic/atomic_add.h @@ -0,0 +1,3 @@ +#define __CLC_FUNCTION atomic_add +#include +#undef __CLC_FUNCTION diff --git a/libclc/generic/include/clc/atomic/atomic_decl.inc b/libclc/generic/include/clc/atomic/atomic_decl.inc new file mode 100644 index 0000000..03d01aa --- /dev/null +++ b/libclc/generic/include/clc/atomic/atomic_decl.inc @@ -0,0 +1,10 @@ + +#define __CLC_DECLARE_ATOMIC(ADDRSPACE, TYPE) \ + _CLC_OVERLOAD _CLC_DECL TYPE __CLC_FUNCTION (volatile ADDRSPACE TYPE *, TYPE); + +#define __CLC_DECLARE_ATOMIC_ADDRSPACE(TYPE) \ + __CLC_DECLARE_ATOMIC(global, TYPE); \ + __CLC_DECLARE_ATOMIC(local, TYPE); + +__CLC_DECLARE_ATOMIC_ADDRSPACE(int); +__CLC_DECLARE_ATOMIC_ADDRSPACE(uint); diff --git a/libclc/generic/include/clc/atomic/atomic_inc.h b/libclc/generic/include/clc/atomic/atomic_inc.h new file mode 100644 index 0000000..2137391 --- /dev/null +++ b/libclc/generic/include/clc/atomic/atomic_inc.h @@ -0,0 +1 @@ +#define atomic_inc(p) atomic_add(p, 1); diff --git a/libclc/generic/include/clc/clc.h b/libclc/generic/include/clc/clc.h index 305f058..105180e 100644 --- a/libclc/generic/include/clc/clc.h +++ b/libclc/generic/include/clc/clc.h @@ -99,4 +99,8 @@ #include #include +/* 6.11.11 Atomic Functins */ +#include +#include + #pragma OPENCL EXTENSION all : disable diff --git a/libclc/generic/lib/SOURCES b/libclc/generic/lib/SOURCES index d6e2d8c..16db9bc 100644 --- a/libclc/generic/lib/SOURCES +++ b/libclc/generic/lib/SOURCES @@ -1,3 +1,4 @@ +atomic/atomic_impl.ll convert.cl geometric/cross.cl geometric/dot.cl diff --git a/libclc/generic/lib/atomic/atomic_impl.ll b/libclc/generic/lib/atomic/atomic_impl.ll new file mode 100644 index 0000000..c11383b --- /dev/null +++ b/libclc/generic/lib/atomic/atomic_impl.ll @@ -0,0 +1,11 @@ +define i32 @__clc_atomic_add_addr1(i32 addrspace(1)* nocapture %ptr, i32 %value) nounwind alwaysinline { +entry: + %0 = atomicrmw volatile add i32 addrspace(1)* %ptr, i32 %value seq_cst + ret i32 %0 +} + +define i32 @__clc_atomic_add_addr3(i32 addrspace(3)* nocapture %ptr, i32 %value) nounwind alwaysinline { +entry: + %0 = atomicrmw volatile add i32 addrspace(3)* %ptr, i32 %value seq_cst + ret i32 %0 +} diff --git a/libclc/r600/lib/SOURCES b/libclc/r600/lib/SOURCES index 38919ab..de30f6e 100644 --- a/libclc/r600/lib/SOURCES +++ b/libclc/r600/lib/SOURCES @@ -1,3 +1,4 @@ +atomic/atomic.cl workitem/get_num_groups.ll workitem/get_group_id.ll workitem/get_local_size.ll diff --git a/libclc/r600/lib/atomic/atomic.cl b/libclc/r600/lib/atomic/atomic.cl new file mode 100644 index 0000000..e80180c --- /dev/null +++ b/libclc/r600/lib/atomic/atomic.cl @@ -0,0 +1,20 @@ +#include + +#define ATOMIC_FUNC_TYPE(SIGN, TYPE, FUNCTION, CL_ADDRSPACE, LLVM_ADDRSPACE) \ +_CLC_OVERLOAD _CLC_DEF SIGN TYPE FUNCTION (volatile CL_ADDRSPACE SIGN TYPE *p, SIGN TYPE val) { \ + return (SIGN TYPE)__clc_##FUNCTION##_addr##LLVM_ADDRSPACE((volatile CL_ADDRSPACE signed TYPE*)p, (signed TYPE)val); \ +} + +#define ATOMIC_FUNC_SIGN(TYPE, FUNCTION, CL_ADDRSPACE, LLVM_ADDRSPACE) \ + _CLC_DECL signed TYPE __clc_##FUNCTION##_addr##LLVM_ADDRSPACE(volatile CL_ADDRSPACE signed TYPE*, signed TYPE); \ + ATOMIC_FUNC_TYPE(signed, TYPE, FUNCTION, CL_ADDRSPACE, LLVM_ADDRSPACE) \ + ATOMIC_FUNC_TYPE(unsigned, TYPE, FUNCTION, CL_ADDRSPACE, LLVM_ADDRSPACE) + +#define ATOMIC_FUNC_ADDRSPACE(TYPE, FUNCTION) \ + ATOMIC_FUNC_SIGN(TYPE, FUNCTION, global, 1) \ + ATOMIC_FUNC_SIGN(TYPE, FUNCTION, local, 3) + +#define ATOMIC_FUNC(FUNCTION) \ + ATOMIC_FUNC_ADDRSPACE(int, FUNCTION) + +ATOMIC_FUNC(atomic_add) -- 2.7.4