[Bf-blender-cvs] [260bb49] opensubdiv-modifier: Use updated version of CUEW

Sergey Sharybin noreply at git.blender.org
Wed Jun 18 12:02:06 CEST 2014


Commit: 260bb49b29cec2024ef14932d0ccb16c464ad059
Author: Sergey Sharybin
Date:   Wed Jun 18 15:53:35 2014 +0600
https://developer.blender.org/rB260bb49b29cec2024ef14932d0ccb16c464ad059

Use updated version of CUEW

This wrangler is now automatically generated from
cuda.h and cudaGL.h which is really handy from the
maintenance point of view: with new CUDA toolkit
release it should be rather simple to update the
wrangler.

Currently it's generated from CUDA toolkit 5 since
it's the version which comes in Debian Wheezy.

Also bundling the generator scripts, so others
can tweak/improve it.

Works fine on Linux, didn't verify it on Windows.

===================================================================

A	extern/cuew/auto/cuda_errors.py
A	extern/cuew/auto/cuew_gen.py
A	extern/cuew/auto/cuew_gen.sh
A	extern/cuew/auto/stdlib.h
M	extern/cuew/include/cuew.h
M	extern/cuew/src/cuew.c

===================================================================

diff --git a/extern/cuew/auto/cuda_errors.py b/extern/cuew/auto/cuda_errors.py
new file mode 100644
index 0000000..464b776
--- /dev/null
+++ b/extern/cuew/auto/cuda_errors.py
@@ -0,0 +1,35 @@
+CUDA_ERRORS={
+'CUDA_SUCCESS': "No errors",
+'CUDA_ERROR_INVALID_VALUE': "Invalid value",
+'CUDA_ERROR_OUT_OF_MEMORY': "Out of memory",
+'CUDA_ERROR_NOT_INITIALIZED': "Driver not initialized",
+'CUDA_ERROR_DEINITIALIZED': "Driver deinitialized",
+'CUDA_ERROR_NO_DEVICE': "No CUDA-capable device available",
+'CUDA_ERROR_INVALID_DEVICE': "Invalid device",
+'CUDA_ERROR_INVALID_IMAGE': "Invalid kernel image",
+'CUDA_ERROR_INVALID_CONTEXT': "Invalid context",
+'CUDA_ERROR_CONTEXT_ALREADY_CURRENT': "Context already current",
+'CUDA_ERROR_MAP_FAILED': "Map failed",
+'CUDA_ERROR_UNMAP_FAILED': "Unmap failed",
+'CUDA_ERROR_ARRAY_IS_MAPPED': "Array is mapped",
+'CUDA_ERROR_ALREADY_MAPPED': "Already mapped",
+'CUDA_ERROR_NO_BINARY_FOR_GPU': "No binary for GPU",
+'CUDA_ERROR_ALREADY_ACQUIRED': "Already acquired",
+'CUDA_ERROR_NOT_MAPPED': "Not mapped",
+'CUDA_ERROR_NOT_MAPPED_AS_ARRAY': "Mapped resource not available for access as an array",
+'CUDA_ERROR_NOT_MAPPED_AS_POINTER': "Mapped resource not available for access as a pointer",
+'CUDA_ERROR_ECC_UNCORRECTABLE': "Uncorrectable ECC error detected",
+'CUDA_ERROR_UNSUPPORTED_LIMIT': "CUlimit not supported by device",
+'CUDA_ERROR_INVALID_SOURCE': "Invalid source",
+'CUDA_ERROR_FILE_NOT_FOUND': "File not found",
+'CUDA_ERROR_SHARED_OBJECT_SYMBOL_NOT_FOUND': "Link to a shared object failed to resolve",
+'CUDA_ERROR_SHARED_OBJECT_INIT_FAILED': "Shared object initialization failed",
+'CUDA_ERROR_INVALID_HANDLE': "Invalid handle",
+'CUDA_ERROR_NOT_FOUND': "Not found",
+'CUDA_ERROR_NOT_READY': "CUDA not ready",
+'CUDA_ERROR_LAUNCH_FAILED': "Launch failed",
+'CUDA_ERROR_LAUNCH_OUT_OF_RESOURCES': "Launch exceeded resources",
+'CUDA_ERROR_LAUNCH_TIMEOUT': "Launch exceeded timeout",
+'CUDA_ERROR_LAUNCH_INCOMPATIBLE_TEXTURING': "Launch with incompatible texturing",
+'CUDA_ERROR_UNKNOWN': "Unknown error",
+}
diff --git a/extern/cuew/auto/cuew_gen.py b/extern/cuew/auto/cuew_gen.py
new file mode 100644
index 0000000..c0575ff
--- /dev/null
+++ b/extern/cuew/auto/cuew_gen.py
@@ -0,0 +1,548 @@
+# Copyright 2014 Blender Foundation
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License
+
+import os
+import sys
+from cuda_errors import CUDA_ERRORS
+from pycparser import c_parser, c_ast, parse_file
+from subprocess import Popen, PIPE
+
+LIB = "CUEW"
+REAL_LIB = "CUDA"
+VERSION_MAJOR = "1"
+VERSION_MINOR = "0"
+COPYRIGHT = """/*
+ * Copyright 2011-2014 Blender Foundation
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */"""
+FILES = ["cuda.h", "cudaGL.h"]
+
+TYPEDEFS = []
+FUNC_TYPEDEFS = []
+SYMBOLS = []
+DEFINES = []
+DEFINES_V2 = []
+ERRORS = []
+
+
+class FuncDefVisitor(c_ast.NodeVisitor):
+    indent = 0
+    prev_complex = False
+    dummy_typedefs = ['size_t', 'CUdeviceptr']
+
+    def _get_quals_string(self, node):
+        if node.quals:
+            return ' '.join(node.quals) + ' '
+        return ''
+
+    def _get_ident_type(self, node):
+        if isinstance(node, c_ast.PtrDecl):
+            return self._get_ident_type(node.type.type) + '*'
+        if isinstance(node, c_ast.ArrayDecl):
+            return self._get_ident_type(node.type)
+        elif isinstance(node, c_ast.Struct):
+            if node.name:
+                return 'struct ' + node.name
+            else:
+                self.indent += 1
+                struct = self._stringify_struct(node)
+                self.indent -= 1
+                return "struct {\n" + \
+                       struct + ("  " * self.indent) + "}"
+        elif isinstance(node, c_ast.Union):
+            self.indent += 1
+            union = self._stringify_struct(node)
+            self.indent -= 1
+            return "union {\n" + union + ("  " * self.indent) + "}"
+        elif isinstance(node, c_ast.Enum):
+            return 'enum ' + node.name
+        elif isinstance(node, c_ast.TypeDecl):
+            return self._get_ident_type(node.type)
+        else:
+            return node.names[0]
+
+    def _stringify_param(self, param):
+        param_type = param.type
+        result = self._get_quals_string(param)
+        result += self._get_ident_type(param_type)
+        if param.name:
+            result += ' ' + param.name
+        if isinstance(param_type, c_ast.ArrayDecl):
+            # TODO(sergey): Workaround to deal with the
+            # preprocessed file where array size got
+            # substituded.
+            dim = param_type.dim.value
+            if param.name == "reserved" and dim == "64":
+                dim = "CU_IPC_HANDLE_SIZE"
+            result += '[' + dim + ']'
+        return result
+
+    def _stringify_params(self, params):
+        result = []
+        for param in params:
+            result.append(self._stringify_param(param))
+        return ', '.join(result)
+
+    def _stringify_struct(self, node):
+        result = ""
+        children = node.children()
+        for child in children:
+            member = self._stringify_param(child[1])
+            result += ("  " * self.indent) + member + ";\n"
+        return result
+
+    def _stringify_enum(self, node):
+        result = ""
+        children = node.children()
+        for child in children:
+            if isinstance(child[1], c_ast.EnumeratorList):
+                enumerators = child[1].enumerators
+                for enumerator in enumerators:
+                    result += ("  " * self.indent) + enumerator.name
+                    if enumerator.value:
+                        result += " = " + enumerator.value.value
+                    result += ",\n"
+                    if enumerator.name.startswith("CUDA_ERROR_"):
+                        ERRORS.append(enumerator.name)
+        return result
+
+    def visit_Decl(self, node):
+        if node.type.__class__.__name__ == 'FuncDecl':
+            if isinstance(node.type, c_ast.FuncDecl):
+                func_decl = node.type
+                func_decl_type = func_decl.type
+
+                typedef = 'typedef '
+                symbol_name = None
+
+                if isinstance(func_decl_type, c_ast.TypeDecl):
+                    symbol_name = func_decl_type.declname
+                    typedef += self._get_quals_string(func_decl_type)
+                    typedef += self._get_ident_type(func_decl_type.type)
+                    typedef += ' CUDAAPI'
+                    typedef += ' (*t' + symbol_name + ') '
+                elif isinstance(func_decl_type, c_ast.PtrDecl):
+                    ptr_type = func_decl_type.type
+                    symbol_name = ptr_type.declname
+                    typedef += self._get_quals_string(ptr_type)
+                    typedef += self._get_ident_type(func_decl_type)
+                    typedef += ' CUDAAPI'
+                    typedef += ' (*t' + symbol_name + ') '
+
+                typedef += '(' + \
+                    self._stringify_params(func_decl.args.params) + \
+                    ');'
+
+                SYMBOLS.append(symbol_name)
+                FUNC_TYPEDEFS.append(typedef)
+
+    def visit_Typedef(self, node):
+        if node.name in self.dummy_typedefs:
+            return
+
+        complex = False
+        type = self._get_ident_type(node.type)
+        quals = self._get_quals_string(node)
+
+        if isinstance(node.type.type, c_ast.Struct):
+            self.indent += 1
+            struct = self._stringify_struct(node.type.type)
+            self.indent -= 1
+            typedef = quals + type + " {\n" + struct + "} " + node.name
+            complex = True
+        elif isinstance(node.type.type, c_ast.Enum):
+            self.indent += 1
+            enum = self._stringify_enum(node.type.type)
+            self.indent -= 1
+            typedef = quals + type + " {\n" + enum + "} " + node.name
+            complex = True
+        else:
+            typedef = quals + type + " " + node.name
+        if complex or self.prev_complex:
+            typedef = "\ntypedef " + typedef + ";"
+        else:
+            typedef = "typedef " + typedef + ";"
+
+        TYPEDEFS.append(typedef)
+
+        self.prev_complex = complex
+
+
+def get_latest_cpp():
+    path_prefix = "/usr/bin"
+    for cpp_version in ["9", "8", "7", "6", "5", "4"]:
+        test_cpp = os.path.join(path_prefix, "cpp-4." + cpp_version)
+        if os.path.exists(test_cpp):
+            return test_cpp
+    return None
+
+
+def preprocess_file(filename, cpp_path):
+    args = [cpp_path, "-I./"]
+    if filename.endswith("GL.h"):
+        args.append("-DCUDAAPI= ")
+    args.append(filename)
+
+    try:
+        pipe = Popen(args,
+                     stdout=PIPE,
+                     universal_newlines=True)
+        text = pipe.communicate()[0]
+    except OSError as e:
+        raise RuntimeError("Unable to invoke 'cpp'.  " +
+            'Make sure its path was passed correctly\n' +
+            ('Original error: %s' % e))
+
+    return text
+
+
+def parse_files():
+    parser = c_parser.CParser()
+    cpp_path = get_latest_cpp()
+
+    for filename in FILES:
+        dummy_typedefs 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list