OK,

Vecmathlib mode does not crash the compilation but the tests
fail with wrong results and even hangs. You can see it when
running the convert_types test by hand:

kernel/kernel test_convert_type
...
FAIL: convert_ulong16_rte((float16)) - sample#: 14 element#: 4 expected: 0x0000000000000002 actual: 0000000000000000 FAIL: convert_ulong16_sat_rte((float16)) - sample#: 14 element#: 0 expected: 0x00038d7ea4000000 actual: 0x00038d7eac000000 FAIL: convert_ulong16_rtp((float16)) - sample#: 14 element#: 4 expected: 0x0000000000000002 actual: 0000000000000000 FAIL: convert_ulong16_sat_rtp((float16)) - sample#: 14 element#: 0 expected: 0x00038d7ea4000000 actual: 0x00038d7e9c000000 FAIL: convert_ulong16_rtn((float16)) - sample#: 14 element#: 4 expected: 0x0000000000000001 actual: 0000000000000000 FAIL: convert_ulong16_sat_rtn((float16)) - sample#: 14 element#: 0 expected: 0x00038d7ea4000000 actual: 0x00038d7eac000000 FAIL: convert_ulong16_rte((float16)) - sample#: 15 element#: 4 expected: 0x0000000000000002 actual: 0000000000000000 FAIL: convert_ulong16_rtp((float16)) - sample#: 15 element#: 4 expected: 0x0000000000000002 actual: 0000000000000000 FAIL: convert_ulong16_rtn((float16)) - sample#: 15 element#: 4 expected: 0x0000000000000001 actual: 0000000000000000



Hangs here. The convert type implementations call some of
the VML functions.

My first suspicion is the conversion routine between
the VML vector datatypes and the pocl's which is done with
a memcpy. Erik, are you sure it is a 1:1 match and copying like
this is safe?

Attached is a patch to VML which adds prefixes to functions
which need them (to avoid using the std C functions that get
converted to LLVM intrinsics in the frontend).


On 03/13/2013 04:27 AM, Erik Schnetter wrote:
would be compiled when pocl is built, creating bc files. When kernels
are compiled, these bc files are used.


--
--Pekka
diff --git a/pocl/generate-files.py b/pocl/generate-files.py
index 5c638c9..845dd5b 100755
--- a/pocl/generate-files.py
+++ b/pocl/generate-files.py
@@ -76,9 +76,34 @@ vmlfuncs = [
     ("signbit"  , [VF        ], VJ, [VF        ], VB),
     ]
 
-# This is prepended to the generated function names.
-func_prefix = ""
-
+# This is always prepended to the generated function names.
+forced_func_prefix = ""
+
+# Some of the functions need prefixes to avoid using the C standard
+# library ones.
+masked_functions = [
+    "atan2",
+    "rint",
+    "acos",
+    "asin",
+    "atan",
+    "ceil",
+    "copysign"
+    "cos",
+    "exp",
+    "exp2",
+    "fabs",
+    "floor",
+    "fma",
+    "log",
+    "log2",
+    "pow",
+    "round",
+    "sin",
+    "sqrt",
+    "tan",
+    "trunc"]
+    
 directfuncs = [
     # Section 6.12.2
     ("acospi"        , [VF         ], VF, "acos(x0)/(scalar_t)M_PI"),
@@ -141,8 +166,9 @@ directfuncs = [
     ("native_tan"    , [VF         ], VF, "tan(x0)"),
     
     # Section 6.12.4
-    ("clamp"         , [VF, VF, VF ], VF, "fmin(fmax(x0,x1),x2)"),
-    ("clamp"         , [VF, SF, SF ], VF, "fmin(fmax(x0,x1),x2)"),
+# clamp(signed, signed, signed) is missing so use the pocl default one for now.
+#    ("clamp"         , [VF, VF, VF ], VF, "fmin(fmax(x0,x1),x2)"),
+#    ("clamp"         , [VF, SF, SF ], VF, "fmin(fmax(x0,x1),x2)"),
     ("degrees"       , [VF         ], VF, "(scalar_t)(180.0/M_PI)*x0"),
     ("max"           , [VF, VF     ], VF, "fmax(x0,x1)"),
     ("max"           , [VF, SF     ], VF, "fmax(x0,x1)"),
@@ -182,6 +208,10 @@ directfuncs = [
 # Unchecked: 6.12.12 (miscellaneous vector functions)
 
 
+def func_prefix(func_name):
+    pocl_func_prefix = forced_func_prefix
+    if func_name in masked_functions: pocl_func_prefix += "_cl_"
+    return pocl_func_prefix
 
 outfile = None
 outfile_did_truncate = set()
@@ -261,6 +291,7 @@ def mkvmltype(tp, vectype):
 
 
 def output_vmlfunc_vml(func, vectype):
+    global func_prefix
     (name, args, ret, vmlargs, vmlret) = func
     out("// Implement %s by calling vecmathlib" % name)
     (basetype, size) = re.match("([A-Za-z]+)([0-9]*)", vectype).groups()
@@ -272,8 +303,8 @@ def output_vmlfunc_vml(func, vectype):
                                    "%s x%d" % (mktype(arg, vectype), n),
                                zip(range(0, 100), args)))
     funcretstr = mktype(ret, vectype)
-    decl("%s %s%s(%s)" % (funcretstr, func_prefix, name, funcargstr))
-    out("%s %s%s(%s)" % (funcretstr, func_prefix, name, funcargstr))
+    decl("%s %s%s(%s)" % (funcretstr, func_prefix(name), name, funcargstr))
+    out("%s %s%s(%s)" % (funcretstr, func_prefix(name), name, funcargstr))
     out("{")
     for (n, arg, vmlarg) in zip(range(0, 100), args, vmlargs):
         out("  %s y%d = bitcast<%s,%s>(x%d);" %
@@ -323,8 +354,8 @@ def output_vmlfunc_libm(func, vectype):
     funcargstr = ", ".join(map(lambda (n, arg):
                                    "%s x%d" % (mktype(arg, vectype), n),
                                zip(range(0, 100), args)))
-    decl("%s %s%s(%s)" % (vectype, func_prefix, name, funcargstr))
-    out("%s %s%s(%s)" % (vectype, func_prefix, name, funcargstr))
+    decl("%s %s%s(%s)" % (vectype, func_prefix(name), name, funcargstr))
+    out("%s %s%s(%s)" % (vectype, func_prefix(name), name, funcargstr))
     out("{")
     for (n, arg) in zip(range(0, 100), args):
         out("  %s y%d = x%d;" % (othertype, n, n))
@@ -345,12 +376,12 @@ def output_vmlfunc_upcast(func, vectype):
     othertype = "%s%s" % (basetype, size2)
     declargstr = ", ".join(map(lambda (n, arg): "%s" % mktype(arg, othertype),
                                zip(range(0, 100), args)))
-    out("%s %s%s(%s);" % (mktype(ret, othertype), func_prefix, name, declargstr))
+    out("%s %s%s(%s);" % (mktype(ret, othertype), func_prefix(name), name, declargstr))
     funcargstr = ", ".join(map(lambda (n, arg):
                                    "%s x%d" % (mktype(arg, vectype), n),
                                zip(range(0, 100), args)))
-    decl("%s %s%s(%s)" % (mktype(ret, vectype), func_prefix, name, funcargstr))
-    out("%s %s%s(%s)" % (mktype(ret, vectype), func_prefix, name, funcargstr))
+    decl("%s %s%s(%s)" % (mktype(ret, vectype), func_prefix(name), name, funcargstr))
+    out("%s %s%s(%s)" % (mktype(ret, vectype), func_prefix(name), name, funcargstr))
     out("{")
     for (n, arg) in zip(range(0, 100), args):
         out("  %s y%d = bitcast<%s,%s>(x%d);" %
@@ -358,7 +389,7 @@ def output_vmlfunc_upcast(func, vectype):
              mktype(arg, vectype), mktype(arg, othertype), n))
     callargstr = ", ".join(map(lambda (n, arg): "y%d" % n,
                                zip(range(0, 100), args)))
-    out("  %s r = %s%s(%s);" % (mktype(ret, othertype), func_prefix, name, callargstr))
+    out("  %s r = %s%s(%s);" % (mktype(ret, othertype), func_prefix(name), name, callargstr))
     out("  return bitcast<%s,%s>(r);" %
         (mktype(ret, othertype), mktype(ret, vectype)))
     out("}")
@@ -373,12 +404,12 @@ def output_vmlfunc_split(func, vectype):
     othertype = "%s%s" % (basetype, size2)
     declargstr = ", ".join(map(lambda (n, arg): "%s" % mktype(arg, othertype),
                                zip(range(0, 100), args)))
-    out("%s %s%s(%s);" % (mktype(ret, othertype), func_prefix, name, declargstr))
+    out("%s %s%s(%s);" % (mktype(ret, othertype), func_prefix(name), name, declargstr))
     funcargstr = ", ".join(map(lambda (n, arg):
                                    "%s x%d" % (mktype(arg, vectype), n),
                                zip(range(0, 100), args)))
-    decl("%s %s%s(%s)" % (mktype(ret, vectype), func_prefix, name, funcargstr))
-    out("%s %s%s(%s)" % (mktype(ret, vectype), func_prefix, name, funcargstr))
+    decl("%s %s%s(%s)" % (mktype(ret, vectype), func_prefix(name), name, funcargstr))
+    out("%s %s%s(%s)" % (mktype(ret, vectype), func_prefix(name), name, funcargstr))
     out("{")
     out("  struct pair { %s lo, hi; };" % othertype)
     for (n, arg) in zip(range(0, 100), args):
@@ -387,7 +418,7 @@ def output_vmlfunc_split(func, vectype):
              mktype(arg, vectype), mktype(arg, othertype), n))
     callargstr = ", ".join(map(lambda (n, arg): "y%d" % n,
                                zip(range(0, 100), args)))
-    out("  %s r = %s%s(%s);" % (mktype(ret, othertype), func_prefix, name, callargstr))
+    out("  %s r = %s%s(%s);" % (mktype(ret, othertype), func_prefix(name), name, callargstr))
     out("  return bitcast<%s,%s>(r);" %
         (mktype(ret, othertype), mktype(ret, vectype)))
     out("}")
@@ -403,9 +434,9 @@ def output_directfunc_direct(func, vectype):
                                    "%s x%d" % (mktype(arg, vectype), n),
                                zip(range(0, 100), args)))
     funcretstr = mktype(ret, vectype)
-    decl("%s %s%s(%s)" % (funcretstr, func_prefix, name, funcargstr))
+    decl("%s %s%s(%s)" % (funcretstr, func_prefix(name), name, funcargstr))
     out("__attribute__((__overloadable__))");
-    out("%s %s%s(%s)" % (funcretstr, func_prefix, name, funcargstr))
+    out("%s %s%s(%s)" % (funcretstr, func_prefix(name), name, funcargstr))
     out("{")
     out("  typedef %s kscalar_t;" % mktype(SK, vectype))
     out("  typedef %s scalar_t;" % mktype(SF, vectype))
@@ -441,7 +472,7 @@ def output_vmlfunc(func):
     decl("")
     decl("// %s: %s -> %s" % (name, args, ret))
     decl("#undef %s" % name)
-    decl("#define %s %s%s" % (name, func_prefix, name))
+    decl("#define %s %s%s" % (name, func_prefix(name), name))
     out("// %s: %s -> %s" % (name, args, ret))
     for basetype in ["float", "double"]:
         if basetype=="double":
@@ -494,7 +525,7 @@ def output_directfunc(func):
     decl("")
     decl("// %s: %s -> %s" % (name, args, ret))
     decl("#undef %s" % name)
-    decl("#define %s %s%s" % (name, func_prefix, name))
+    decl("#define %s %s%s" % (name, func_prefix(name), name))
     out("// %s: %s -> %s" % (name, args, ret))
     if any(map(lambda arg: arg in (PVK, PVF), args)):
         spaces = ["global", "local", "private"]
diff --git a/pocl/pocl-compat.h b/pocl/pocl-compat.h
index 62480ed..978daba 100644
--- a/pocl/pocl-compat.h
+++ b/pocl/pocl-compat.h
@@ -5,14 +5,14 @@
 
 // Make things go fast (and debugging difficult...)
 #define VML_NODEBUG
+
+
 #include "../vecmathlib.h"
 
 #include <algorithm>
 #include <cstdint>
 #include <cstring>
 
-
-
 // Define vector types
 
 using std::int32_t;
------------------------------------------------------------------------------
Everyone hates slow websites. So do we.
Make your web apps faster with AppDynamics
Download AppDynamics Lite for free today:
http://p.sf.net/sfu/appdyn_d2d_mar
_______________________________________________
pocl-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pocl-devel

Reply via email to