summaryrefslogtreecommitdiff
path: root/backend
diff options
context:
space:
mode:
authorJunyan He <junyan.he@linux.intel.com>2014-09-01 10:12:42 +0800
committerZhigang Gong <zhigang.gong@intel.com>2014-09-04 12:09:43 +0800
commit9f8e2cdce9b0548021eee6243ee9ae41ebd35b45 (patch)
tree8574c9e92aa3b3a1df2e900f7d538ae82f8062a0 /backend
parent9cbe604a1919bcac84f9c2140e6fefc8af7fef84 (diff)
Add the common module into the libocl as template
Signed-off-by: Junyan He <junyan.he@linux.intel.com> Reviewed-by: Zhigang Gong <zhigang.gong@intel.com>
Diffstat (limited to 'backend')
-rw-r--r--backend/src/libocl/script/ocl_common.def22
-rw-r--r--backend/src/libocl/tmpl/ocl_common.tmpl.cl48
-rw-r--r--backend/src/libocl/tmpl/ocl_common.tmpl.h19
3 files changed, 89 insertions, 0 deletions
diff --git a/backend/src/libocl/script/ocl_common.def b/backend/src/libocl/script/ocl_common.def
new file mode 100644
index 0000000..fac5ef5
--- /dev/null
+++ b/backend/src/libocl/script/ocl_common.def
@@ -0,0 +1,22 @@
+##common
+gentype clamp (gentype x, gentype minval, gentype maxval)
+gentypef clamp (gentypef x, float minval, float maxval)
+gentyped clamp (gentyped x, double minval, double maxval)
+gentype degrees (gentype radians)
+gentype max (gentype x, gentype y)
+gentypef max (gentypef x, float y)
+gentyped max (gentyped x, double y)
+gentype min (gentype x, gentype y)
+gentypef min (gentypef x, float y)
+gentyped min (gentyped x, double y)
+gentype mix (gentype x, gentype y, gentype a)
+gentypef mix (gentypef x, gentypef y, float a)
+gentyped mix (gentyped x, gentyped y, double a)
+gentype radians (gentype degrees)
+gentype step (gentype edge, gentype x)
+gentypef step (float edge, gentypef x)
+gentyped step (double edge, gentyped x)
+gentype smoothstep (gentype edge0, gentype edge1, gentype x)
+gentypef smoothstep (float edge0, float edge1, gentypef x)
+gentyped smoothstep (double edge0, double edge1, gentyped x)
+gentype sign (gentype x)
diff --git a/backend/src/libocl/tmpl/ocl_common.tmpl.cl b/backend/src/libocl/tmpl/ocl_common.tmpl.cl
new file mode 100644
index 0000000..92341bc
--- /dev/null
+++ b/backend/src/libocl/tmpl/ocl_common.tmpl.cl
@@ -0,0 +1,48 @@
+#include "ocl_common.h"
+#include "ocl_float.h"
+
+/////////////////////////////////////////////////////////////////////////////
+// Common Functions
+/////////////////////////////////////////////////////////////////////////////
+PURE CONST float __gen_ocl_fmax(float a, float b);
+PURE CONST float __gen_ocl_fmin(float a, float b);
+
+OVERLOADABLE float step(float edge, float x) {
+ return x < edge ? 0.0 : 1.0;
+}
+
+OVERLOADABLE float max(float a, float b) {
+ return __gen_ocl_fmax(a, b);
+}
+OVERLOADABLE float min(float a, float b) {
+ return __gen_ocl_fmin(a, b);
+}
+OVERLOADABLE float mix(float x, float y, float a) {
+ return x + (y-x)*a;
+}
+OVERLOADABLE float clamp(float v, float l, float u) {
+ return max(min(v, u), l);
+}
+
+
+OVERLOADABLE float degrees(float radians) {
+ return (180 / M_PI_F) * radians;
+}
+OVERLOADABLE float radians(float degrees) {
+ return (M_PI_F / 180) * degrees;
+}
+
+OVERLOADABLE float smoothstep(float e0, float e1, float x) {
+ x = clamp((x - e0) / (e1 - e0), 0.f, 1.f);
+ return x * x * (3 - 2 * x);
+}
+
+OVERLOADABLE float sign(float x) {
+ if(x > 0)
+ return 1;
+ if(x < 0)
+ return -1;
+ if(x == -0.f)
+ return -0.f;
+ return 0.f;
+}
diff --git a/backend/src/libocl/tmpl/ocl_common.tmpl.h b/backend/src/libocl/tmpl/ocl_common.tmpl.h
new file mode 100644
index 0000000..cbe6c4f
--- /dev/null
+++ b/backend/src/libocl/tmpl/ocl_common.tmpl.h
@@ -0,0 +1,19 @@
+#ifndef __OCL_COMMON_H__
+#define __OCL_COMMON_H__
+
+#include "ocl_types.h"
+
+/////////////////////////////////////////////////////////////////////////////
+// Common Functions
+/////////////////////////////////////////////////////////////////////////////
+OVERLOADABLE float step(float edge, float x);
+OVERLOADABLE float max(float a, float b);
+OVERLOADABLE float min(float a, float b);
+OVERLOADABLE float mix(float x, float y, float a);
+OVERLOADABLE float clamp(float v, float l, float u);
+
+OVERLOADABLE float degrees(float radians);
+OVERLOADABLE float radians(float degrees);
+OVERLOADABLE float smoothstep(float e0, float e1, float x);
+
+OVERLOADABLE float sign(float x);