From e8fd5735d34b11f6e035890263e834b5697229be Mon Sep 17 00:00:00 2001 From: wintonwang Date: Tue, 25 May 2021 18:45:54 +0800 Subject: [PATCH 1/3] fix: get nvcc version --- src/blade/toolchain.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/blade/toolchain.py b/src/blade/toolchain.py index 76b74f24..8a9512c5 100644 --- a/src/blade/toolchain.py +++ b/src/blade/toolchain.py @@ -13,12 +13,15 @@ from __future__ import print_function import os +import re import subprocess import tempfile from blade import console from blade.util import var_to_list, iteritems, to_string +# example: Cuda compilation tools, release 11.0, V11.0.194 +_nvcc_version_re = re.compile(r'V(\d+\.\d+\.\d+)') class BuildArchitecture(object): """ @@ -159,11 +162,11 @@ def get_cc_target_arch(): def _get_nvcc_version(): """Get the nvcc version.""" nvcc = os.environ.get('NVCC', 'nvcc') - returncode, stdout, stderr = ToolChain._execute(nvcc + ' --version') + returncode, stdout, _ = ToolChain._execute(nvcc + ' --version') if returncode == 0: - version_line = stdout.splitlines(True)[-1] - version = version_line.split()[5] - return version + res = re.search(_nvcc_version_re, stdout) + if res: + return res.group(1) return '' @staticmethod From e98b2ddfc4cb757ced4dd90c5d7f0989bfab07fc Mon Sep 17 00:00:00 2001 From: wintonwang Date: Thu, 27 May 2021 16:59:02 +0800 Subject: [PATCH 2/3] fix: get cuda include path --- src/blade/toolchain.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/blade/toolchain.py b/src/blade/toolchain.py index 8a9512c5..91b99885 100644 --- a/src/blade/toolchain.py +++ b/src/blade/toolchain.py @@ -160,7 +160,10 @@ def get_cc_target_arch(): @staticmethod def _get_nvcc_version(): - """Get the nvcc version.""" + """Get the nvcc version. + + :return: 11.0.194 + """ nvcc = os.environ.get('NVCC', 'nvcc') returncode, stdout, _ = ToolChain._execute(nvcc + ' --version') if returncode == 0: @@ -177,12 +180,10 @@ def _get_cuda_include(): include_list.append('%s/include' % cuda_path) include_list.append('%s/samples/common/inc' % cuda_path) return include_list - returncode, stdout, stderr = ToolChain._execute('nvcc --version') - if returncode == 0: - version_line = stdout.splitlines(True)[-1] - version = version_line.split()[4] - version = version.replace(',', '') - if os.path.isdir('/usr/local/cuda-%s' % version): + # nvcc_version: 11.0.194 --> version: 11.0 + nvcc_version = ToolChain._get_nvcc_version() + version = '.'.join(nvcc_version.split('.')[:2]) + if version and os.path.isdir('/usr/local/cuda-%s' % version): include_list.append('/usr/local/cuda-%s/include' % version) include_list.append('/usr/local/cuda-%s/samples/common/inc' % version) return include_list From 4571d712b061ef513626cedf045fa1c5719f5722 Mon Sep 17 00:00:00 2001 From: wintonwang Date: Tue, 29 Jun 2021 18:40:28 +0800 Subject: [PATCH 3/3] protoc supports multiple plugins --- src/blade/proto_library_target.py | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/blade/proto_library_target.py b/src/blade/proto_library_target.py index 5519b93a..cad3ba7e 100644 --- a/src/blade/proto_library_target.py +++ b/src/blade/proto_library_target.py @@ -311,15 +311,15 @@ def _proto_descriptor_rules(self): self.generate_build('protodescriptors', output, inputs=inputs, variables={'first': inputs[0]}) def _protoc_plugin_parameters(self, language): - """Return a tuple of (plugin path, vars) used as parameters for ninja build.""" - path, vars = '', {} + """Return a tuple of (plugin paths, vars) used as parameters for ninja build.""" + paths, vars = [], {} for p in self.data['protoc_plugin_objects']: if language in p.code_generation: - path = p.path - flag = p.protoc_plugin_flag(self.build_dir) - vars = {'protoc%spluginflags' % language: flag} - break - return path, vars + paths.append(p.path) + flag_key = 'protoc%spluginflags' % language + flag_value = p.protoc_plugin_flag(self.build_dir) + vars[flag_key] = vars[flag_key] + ' ' + flag_value if flag_key in vars else flag_value + return paths, vars def _add_protoc_direct_dependencies(self, vars): """ Add a `--direct_dependencies` optiopn to protocflags. @@ -333,11 +333,10 @@ def _add_protoc_direct_dependencies(self, vars): vars['protocflags'] = '--direct_dependencies %s' % ':'.join(dependencies) def _proto_cpp_rules(self): - plugin, vars = self._protoc_plugin_parameters('cpp') + plugin_paths, vars = self._protoc_plugin_parameters('cpp') self._add_protoc_direct_dependencies(vars) implicit_deps = self.protoc_direct_dependencies() - if plugin: - implicit_deps.append(plugin) + implicit_deps.extend(plugin_paths) cpp_sources = [] for src in self.srcs: full_source, full_header = self._proto_gen_cpp_files(src) @@ -350,10 +349,9 @@ def _proto_cpp_rules(self): self._cc_library(objs) def _proto_java_rules(self): - plugin, vars = self._protoc_plugin_parameters('java') + plugin_paths, vars = self._protoc_plugin_parameters('java') implicit_deps = self.protoc_direct_dependencies() - if plugin: - implicit_deps.append(plugin) + implicit_deps.extend(plugin_paths) java_sources = [] for src in self.srcs: input = self._source_file_path(src)