[Libclc-dev] [PATCH 6/6] Implement fast_normalize builtin

Tom Stellard thomas.stellard at amd.com
Thu Mar 19 08:35:59 PDT 2015


This implementation was ported from the AMD builtin library
and has been tested with piglit, OpenCV, and the ocl conformance tests.
---
 generic/include/clc/clc.h                        |  1 +
 generic/include/clc/geometric/fast_normalize.h   | 24 +++++++++
 generic/include/clc/geometric/fast_normalize.inc | 24 +++++++++
 generic/lib/SOURCES                              |  1 +
 generic/lib/geometric/fast_normalize.cl          | 67 ++++++++++++++++++++++++
 5 files changed, 117 insertions(+)
 create mode 100644 generic/include/clc/geometric/fast_normalize.h
 create mode 100644 generic/include/clc/geometric/fast_normalize.inc
 create mode 100644 generic/lib/geometric/fast_normalize.cl

diff --git a/generic/include/clc/clc.h b/generic/include/clc/clc.h
index 20ced60..d028dcc 100644
--- a/generic/include/clc/clc.h
+++ b/generic/include/clc/clc.h
@@ -120,6 +120,7 @@
 #include <clc/geometric/dot.h>
 #include <clc/geometric/fast_distance.h>
 #include <clc/geometric/fast_length.h>
+#include <clc/geometric/fast_normalize.h>
 #include <clc/geometric/length.h>
 #include <clc/geometric/normalize.h>
 
diff --git a/generic/include/clc/geometric/fast_normalize.h b/generic/include/clc/geometric/fast_normalize.h
new file mode 100644
index 0000000..cba69c2
--- /dev/null
+++ b/generic/include/clc/geometric/fast_normalize.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2014,2015 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#define __CLC_BODY <clc/geometric/fast_normalize.inc>
+#include <clc/geometric/floatn.inc>
diff --git a/generic/include/clc/geometric/fast_normalize.inc b/generic/include/clc/geometric/fast_normalize.inc
new file mode 100644
index 0000000..3ef8f86
--- /dev/null
+++ b/generic/include/clc/geometric/fast_normalize.inc
@@ -0,0 +1,24 @@
+/*
+ * Copyright (c) 2014,2015 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+
+_CLC_OVERLOAD _CLC_DECL __CLC_FLOATN fast_normalize(__CLC_FLOATN p);
diff --git a/generic/lib/SOURCES b/generic/lib/SOURCES
index 7ecd7b8..eacc030 100644
--- a/generic/lib/SOURCES
+++ b/generic/lib/SOURCES
@@ -37,6 +37,7 @@ geometric/distance.cl
 geometric/dot.cl
 geometric/fast_distance.cl
 geometric/fast_length.cl
+geometric/fast_normalize.cl
 geometric/length.cl
 geometric/normalize.cl
 integer/abs.cl
diff --git a/generic/lib/geometric/fast_normalize.cl b/generic/lib/geometric/fast_normalize.cl
new file mode 100644
index 0000000..2dfb9d3
--- /dev/null
+++ b/generic/lib/geometric/fast_normalize.cl
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2014 Advanced Micro Devices, Inc.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include <clc/clc.h>
+
+_CLC_OVERLOAD _CLC_DEF float fast_normalize(float p) {
+  return normalize(p);
+}
+
+_CLC_OVERLOAD _CLC_DEF float2 fast_normalize(float2 p) {
+  float l2 = dot(p, p);
+  return l2 == 0.0F ? p : p * half_rsqrt(l2);
+}
+
+_CLC_OVERLOAD _CLC_DEF float3 fast_normalize(float3 p) {
+  float l2 = dot(p, p);
+  return l2 == 0.0F ? p : p * half_rsqrt(l2);
+}
+
+_CLC_OVERLOAD _CLC_DEF float4 fast_normalize(float4 p) {
+  float l2 = dot(p, p);
+  return l2 == 0.0F ? p : p * half_rsqrt(l2);
+}
+
+#ifdef cl_khr_fp64
+
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
+
+_CLC_OVERLOAD _CLC_DEF double fast_normalize(double p) {
+  return normalize(p);
+}
+
+_CLC_OVERLOAD _CLC_DEF double2 fast_normalize(double2 p) {
+  double l2 = dot(p, p);
+  return l2 == 0.0F ? p : p * half_rsqrt(l2);
+}
+
+_CLC_OVERLOAD _CLC_DEF double3 fast_normalize(double3 p) {
+  double l2 = dot(p, p);
+  return l2 == 0.0F ? p : p * half_rsqrt(l2);
+}
+
+_CLC_OVERLOAD _CLC_DEF double4 fast_normalize(double4 p) {
+  double l2 = dot(p, p);
+  return l2 == 0.0F ? p : p * half_rsqrt(l2);
+}
+
+#endif
-- 
2.0.4





More information about the Libclc-dev mailing list