From 9bd38c55581dd29ea297870ce432ab3d1d0a4952 Mon Sep 17 00:00:00 2001
From: Stephan Seitz <stephan.seitz@fau.de>
Date: Thu, 15 Aug 2019 14:12:21 +0200
Subject: [PATCH] Add opencl1.1_known_functions.txt

---
 .../backends/opencl1.1_known_functions.txt    | 100 ++++++++++++++++++
 pystencils/backends/opencl_backend.py         |  10 ++
 setup.py                                      |   5 +-
 3 files changed, 114 insertions(+), 1 deletion(-)
 create mode 100644 pystencils/backends/opencl1.1_known_functions.txt

diff --git a/pystencils/backends/opencl1.1_known_functions.txt b/pystencils/backends/opencl1.1_known_functions.txt
new file mode 100644
index 000000000..abeab2904
--- /dev/null
+++ b/pystencils/backends/opencl1.1_known_functions.txt
@@ -0,0 +1,100 @@
+acos
+acosh
+acospi
+asin
+asinh
+asinpi
+atan
+atan2
+atanh
+atanpi
+atan2pi
+cbrt
+ceil
+copysign
+cos
+cosh
+cospi
+erfc
+erf
+exp
+exp2
+exp10
+expm1
+fabs
+fdim
+floor
+fma
+fmax
+fmax
+fmin45
+fmin
+fmod
+fract
+frexp
+hypot
+ilogb
+ldexp
+lgamma
+lgamma_r
+log
+log2
+log10
+log1p
+logb
+mad 
+maxmag 
+minmag 
+modf 
+nextafter
+pow 
+pown
+powr
+remquo 
+intn
+remquo
+rint
+rootn
+rootn
+round
+rsqrt
+sin
+sincos
+sinh
+sinpi
+sqrt
+tan
+tanh
+tanpi
+tgamma
+trunc
+
+
+half_cos 
+half_divide
+half_exp 
+half_exp2 
+half_exp10 
+half_log 
+half_log2 
+half_log10 
+half_powr 
+half_recip 
+half_rsqrt 
+half_sin 
+half_sqrt 
+half_tan 
+native_cos 
+native_divide
+native_exp 
+native_exp2 
+native_exp10 
+native_log 
+native_log2 
+native_log10 
+native_powr 
+native_recip 
+native_rsqrt 
+native_sin 
+native_sqrt 
+native_tan 
diff --git a/pystencils/backends/opencl_backend.py b/pystencils/backends/opencl_backend.py
index b70b3ce72..01c2c410c 100644
--- a/pystencils/backends/opencl_backend.py
+++ b/pystencils/backends/opencl_backend.py
@@ -1,9 +1,15 @@
+from os.path import dirname, join
+
 import pystencils.data_types
 from pystencils.astnodes import Node
 from pystencils.backends.cbackend import CustomSympyPrinter, generate_c
 from pystencils.backends.cuda_backend import CudaBackend, CudaSympyPrinter
 from pystencils.fast_approximation import fast_division, fast_inv_sqrt, fast_sqrt
 
+with open(join(dirname(__file__), 'opencl1.1_known_functions.txt')) as f:
+    lines = f.readlines()
+    OPENCL_KNOWN_FUNCTIONS = {l.strip(): l.strip() for l in lines if l}
+
 
 def generate_opencl(astnode: Node, signature_only: bool = False) -> str:
     """Prints an abstract syntax tree node as CUDA code.
@@ -58,6 +64,10 @@ class OpenClSympyPrinter(CudaSympyPrinter):
         'gridDim': 'get_global_size'
     }
 
+    def __init__(self):
+        CustomSympyPrinter.__init__(self)
+        self.known_functions = OPENCL_KNOWN_FUNCTIONS
+
     def _print_ThreadIndexingSymbol(self, node):
         symbol_name: str = node.name
         function_name, dimension = tuple(symbol_name.split("."))
diff --git a/setup.py b/setup.py
index 3da19ffed..da6b82856 100644
--- a/setup.py
+++ b/setup.py
@@ -88,7 +88,10 @@ setup(name='pystencils',
       url='https://i10git.cs.fau.de/pycodegen/pystencils/',
       packages=['pystencils'] + ['pystencils.' + s for s in find_packages('pystencils')],
       install_requires=['sympy>=1.1', 'numpy', 'appdirs', 'joblib'],
-      package_data={'pystencils': ['include/*.h', 'backends/cuda_known_functions.txt']},
+      package_data={'pystencils': ['include/*.h',
+                                   'backends/cuda_known_functions.txt',
+                                   'backends/opencl1.1_known_functions.txt']},
+
       ext_modules=cython_extensions("pystencils.boundaries.createindexlistcython"),
       classifiers=[
           'Development Status :: 4 - Beta',
-- 
GitLab