[Beignet] [VER_2 2/5] test cospi, cbrt, tan

Homer Hsing homer.xing at intel.com
Wed May 8 20:20:37 PDT 2013


in test file, not use internal function name

Signed-off-by: Homer Hsing <homer.xing at intel.com>
---
 kernels/compiler_math.cl | 24 ++++++++++++++----------
 utests/compiler_math.cpp | 26 +++++++++++++++-----------
 2 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/kernels/compiler_math.cl b/kernels/compiler_math.cl
index 0659840..de2cda3 100644
--- a/kernels/compiler_math.cl
+++ b/kernels/compiler_math.cl
@@ -1,14 +1,18 @@
 __kernel void compiler_math(__global float *dst, __global float *src) {
-  const float x = src[get_global_id(0)];
-  switch (get_global_id(0)) {
-    case 0: dst[get_global_id(0)] = native_cos(x); break;
-    case 1: dst[get_global_id(0)] = native_sin(x); break;
-    case 2: dst[get_global_id(0)] = native_log2(x); break;
-    case 3: dst[get_global_id(0)] = native_sqrt(x); break;
-    case 4: dst[get_global_id(0)] = native_rsqrt(x); break;
-    case 5: dst[get_global_id(0)] = native_recip(x); break;
-    case 6: dst[get_global_id(0)] = native_tan(x); break;
-    default: dst[get_global_id(0)] = 1.f; break;
+  int i = get_global_id(0);
+  const float x = src[i];
+  switch (i) {
+    case 0: dst[i] = cos(x); break;
+    case 1: dst[i] = sin(x); break;
+    case 2: dst[i] = log2(x); break;
+    case 3: dst[i] = sqrt(x); break;
+    case 4: dst[i] = rsqrt(x); break;
+    case 5: dst[i] = native_recip(x); break;
+    case 6: dst[i] = tan(x); break;
+    case 7: dst[i] = cbrt(x); break;
+    case 8: dst[i] = ceil(x); break;
+    case 9: dst[i] = cospi(x); break;
+    default: dst[i] = 1.f; break;
   };
 }
 
diff --git a/utests/compiler_math.cpp b/utests/compiler_math.cpp
index 7303dd5..4915469 100644
--- a/utests/compiler_math.cpp
+++ b/utests/compiler_math.cpp
@@ -2,18 +2,22 @@
 #include <cmath>
 #include <algorithm>
 
-static void cpu_compiler_math(float *dst, float *src, int get_global_id0)
+static void cpu_compiler_math(float *dst, float *src, int i)
 {
-  const float x = src[get_global_id0];
-  switch (get_global_id0) {
-    case 0: dst[get_global_id0] = cosf(x); break;
-    case 1: dst[get_global_id0] = sinf(x); break;
-    case 2: dst[get_global_id0] = log2f(x); break;
-    case 3: dst[get_global_id0] = sqrtf(x); break;
-    case 4: dst[get_global_id0] = 1.f/ sqrtf(x); break;
-    case 5: dst[get_global_id0] = 1.f / x; break;
-    case 6: dst[get_global_id0] = tanf(x); break;
-    default: dst[get_global_id0] = 1.f; break;
+  const float x = src[i];
+  const float PI = 3.141592653589793f;
+  switch (i) {
+    case 0: dst[i] = cosf(x); break;
+    case 1: dst[i] = sinf(x); break;
+    case 2: dst[i] = log2f(x); break;
+    case 3: dst[i] = sqrtf(x); break;
+    case 4: dst[i] = 1.f/ sqrtf(x); break;
+    case 5: dst[i] = 1.f / x; break;
+    case 6: dst[i] = tanf(x); break;
+    case 7: dst[i] = powf(x, 0.3333333333333333333f); break;
+    case 8: dst[i] = ceilf(x); break;
+    case 9: dst[i] = cosf(PI * x); break;
+    default: dst[i] = 1.f; break;
   };
 }
 
-- 
1.8.1.2



More information about the Beignet mailing list