[Beignet] [PATCH 13/22 V2] Add the common module into the libocl as template

junyan.he at inbox.com junyan.he at inbox.com
Sun Aug 31 19:12:42 PDT 2014


From: Junyan He <junyan.he at linux.intel.com>

Signed-off-by: Junyan He <junyan.he at linux.intel.com>
---
 backend/src/libocl/script/ocl_common.def   |   22 +++++++++++++
 backend/src/libocl/tmpl/ocl_common.tmpl.cl |   49 ++++++++++++++++++++++++++++
 backend/src/libocl/tmpl/ocl_common.tmpl.h  |   21 ++++++++++++
 3 files changed, 92 insertions(+)
 create mode 100644 backend/src/libocl/script/ocl_common.def
 create mode 100644 backend/src/libocl/tmpl/ocl_common.tmpl.cl
 create mode 100644 backend/src/libocl/tmpl/ocl_common.tmpl.h

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..0096b48
--- /dev/null
+++ b/backend/src/libocl/tmpl/ocl_common.tmpl.cl
@@ -0,0 +1,49 @@
+#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..9001a6f
--- /dev/null
+++ b/backend/src/libocl/tmpl/ocl_common.tmpl.h
@@ -0,0 +1,21 @@
+#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);
+
+
-- 
1.7.9.5





More information about the Beignet mailing list