本文整理汇总了Python中pytools.prefork.call_capture_output函数的典型用法代码示例。如果您正苦于以下问题:Python call_capture_output函数的具体用法?Python call_capture_output怎么用?Python call_capture_output使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了call_capture_output函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _build
def _build(self, tmpdir):
# File names
cn, on, ln = 'tmp.c', 'tmp.o', platform_libname('tmp')
# Write the source code out
with open(os.path.join(tmpdir, cn), 'w') as f:
f.write(self._src)
# Compile
cmd = [self._cc,
'-std=c99', # Enable C99 support
'-Ofast', # Optimise, incl. -ffast-math
'-march=native', # Use CPU-specific instructions
'-fopenmp', # Enable OpenMP support
'-fPIC', # Position-independent code for shared lib
'-c', '-o', on, cn]
call_capture_output(cmd, cwd=tmpdir)
# Link
cmd = [self._cc,
'-shared', # Create a shared library
'-fopenmp', # Required for OpenMP
'-o', ln, on,]
call_capture_output(cmd, cwd=tmpdir)
return ln
开发者ID:abudulemusa,项目名称:PyFR,代码行数:26,代码来源:compiler.py
示例2: __init__
def __init__(self, src, cfg):
# Find GCC (or a compatible alternative)
self.cc = cfg.getpath('backend-openmp', 'cc', 'cc')
# User specified compiler flags
self.cflags = shlex.split(cfg.get('backend-openmp', 'cflags', ''))
# Get the processor string
proc = platform.processor()
# Get the compiler version string
version = call_capture_output([self.cc, '-v'])
# Get the base compiler command strig
cmd = self.cc_cmd(None, None)
# Compute a digest of the current processor, compiler, and source
self.digest = digest(proc, version, cmd, src)
# Attempt to load the library from the cache
self.mod = self._cache_loadlib()
# Otherwise, we need to compile the kernel
if not self.mod:
# Create a scratch directory
tmpidx = next(self._dir_seq)
tmpdir = tempfile.mkdtemp(prefix='pyfr-{0}-'.format(tmpidx))
try:
# Compile and link the source into a shared library
cname, lname = 'tmp.c', platform_libname('tmp')
# Write the source code out
with open(os.path.join(tmpdir, cname), 'w') as f:
f.write(src)
# Invoke the compiler
call_capture_output(self.cc_cmd(cname, lname), cwd=tmpdir)
# Determine the fully qualified library name
lpath = os.path.join(tmpdir, lname)
# Add it to the cache and load
self.mod = self._cache_set_and_loadlib(lpath)
finally:
# Unless we're debugging delete the scratch directory
if 'PYFR_DEBUG_OMP_KEEP_LIBS' not in os.environ:
rm(tmpdir)
开发者ID:pv101,项目名称:PyFR,代码行数:48,代码来源:compiler.py
示例3: guess_toolchain
def guess_toolchain():
"""Guess and return a :class:`Toolchain` instance.
Raise :exc:`ToolchainGuessError` if no toolchain could be found.
"""
kwargs = _guess_toolchain_kwargs_from_python_config()
from pytools.prefork import call_capture_output
result, version, stderr = call_capture_output([kwargs["cc"], "--version"])
if result != 0:
raise ToolchainGuessError("compiler version query failed: "+stderr)
if "Free Software Foundation" in version:
if "-Wstrict-prototypes" in kwargs["cflags"]:
kwargs["cflags"].remove("-Wstrict-prototypes")
if "darwin" in version:
# Are we running in 32-bit mode?
# The python interpreter may have been compiled as a Fat binary
# So we need to check explicitly how we're running
# And update the cflags accordingly
import sys
if sys.maxint == 0x7fffffff:
kwargs["cflags"].extend(['-arch', 'i386'])
return GCCToolchain(**kwargs)
elif "Intel Corporation" in version:
return IntelToolchain(**kwargs)
else:
raise ToolchainGuessError("unknown compiler")
开发者ID:OP2,项目名称:codepy,代码行数:29,代码来源:toolchain.py
示例4: build_object
def build_object(self, ext_file, source_files, debug=False):
cc_cmdline = (
self._cmdline(source_files, True)
+ ["-o", ext_file]
)
from pytools.prefork import call_capture_output
if debug:
print " ".join(cc_cmdline)
result, stdout, stderr = call_capture_output(cc_cmdline)
print stderr
print stdout
if "error" in stderr:
# work around a bug in nvcc, which doesn't provide a non-zero
# return code even if it failed.
result = 1
if result != 0:
import sys
print >> sys.stderr, "FAILED compiler invocation:", \
" ".join(cc_cmdline)
raise CompileError, "module compilation failed"
开发者ID:OP2,项目名称:codepy,代码行数:25,代码来源:toolchain.py
示例5: preprocess_source
def preprocess_source(source, options, nvcc):
handle, source_path = mkstemp(suffix='.cu')
outf = open(source_path, 'w')
outf.write(source)
outf.close()
os.close(handle)
cmdline = [nvcc, '--preprocess'] + options + [source_path]
if 'win32' in sys.platform:
cmdline.extend(['--compiler-options', '-EP'])
else:
cmdline.extend(['--compiler-options', '-P'])
result, stdout, stderr = call_capture_output(cmdline, error_on_nonzero=False)
if result != 0:
from pycuda.driver import CompileError
raise CompileError("nvcc preprocessing of %s failed" % source_path,
cmdline, stderr=stderr)
# sanity check
if len(stdout) < 0.5*len(source):
from pycuda.driver import CompileError
raise CompileError("nvcc preprocessing of %s failed with ridiculously "
"small code output - likely unsupported compiler." % source_path,
cmdline, stderr=stderr.decode("utf-8", "replace"))
unlink(source_path)
return stdout.decode("utf-8", "replace")
开发者ID:drufat,项目名称:pycuda,代码行数:31,代码来源:compiler.py
示例6: detect
def detect(self, compiler):
from pytools.prefork import call_capture_output
try:
retcode, stdout, stderr = call_capture_output([compiler, "--version"])
except:
return False
return (retcode == 0)
开发者ID:kaewgb,项目名称:cluster_mrjob,代码行数:8,代码来源:config.py
示例7: get_nvcc_version
def get_nvcc_version(nvcc):
cmdline = [nvcc, "--version"]
result, stdout, stderr = call_capture_output(cmdline)
if result != 0 or not stdout:
from warnings import warn
warn("NVCC version could not be determined.")
stdout = "nvcc unknown version"
return stdout.decode("utf-8", "replace")
开发者ID:drufat,项目名称:pycuda,代码行数:10,代码来源:compiler.py
示例8: __enter__
def __enter__(self):
self.temp_dir_mgr = None
temp_dir_mgr = _TempDirManager()
try:
working_dir = temp_dir_mgr.path
from os.path import join
source_file_name = join(working_dir, "temp." + self.extension)
source_file = open(source_file_name, "w")
try:
source_file.write(self.source)
finally:
source_file.close()
output_file_name = join(working_dir, "output.msh")
cmdline = [self.gmsh_executable, "-%d" % self.dimensions, "-o", output_file_name, "-nopopup"]
if self.order is not None:
cmdline.extend(["-order", str(self.order)])
if self.incomplete_elements is not None:
cmdline.extend(["-string", "Mesh.SecondOrderIncomplete = %d;" % int(self.incomplete_elements)])
cmdline.extend(self.other_options)
cmdline.append(source_file_name)
from pytools.prefork import call_capture_output
retcode, stdout, stderr = call_capture_output(cmdline, working_dir)
if stderr and "error" in stderr.lower():
msg = "gmsh execution failed with message:\n\n"
if stdout:
msg += stdout + "\n"
msg += stderr + "\n"
raise GmshError(msg)
if stderr:
from warnings import warn
msg = "gmsh issued the following messages:\n\n"
if stdout:
msg += stdout + "\n"
msg += stderr + "\n"
warn(msg)
self.output_file = open(output_file_name, "r")
self.temp_dir_mgr = temp_dir_mgr
return self.output_file
except:
temp_dir_mgr.clean_up()
raise
开发者ID:kromar,项目名称:Blender_Addons,代码行数:53,代码来源:gmsh.py
示例9: get_nvcc_version
def get_nvcc_version(nvcc):
cmdline = [nvcc, "--version"]
try:
try:
from pytools.prefork import call_capture_output
except ImportError:
from pytools.prefork import call_capture_stdout
return call_capture_stdout(cmdline)
else:
retcode, stdout, stderr = call_capture_output(cmdline)
return stdout
except OSError, e:
raise OSError("%s was not found (is it on the PATH?) [%s]"
% (nvcc, str(e)))
开发者ID:minrk,项目名称:PyCUDA,代码行数:14,代码来源:compiler.py
示例10: get_dependencies
def get_dependencies(self, source_files):
from codepy.tools import join_continued_lines
from pytools.prefork import call_capture_output
result, stdout, stderr = call_capture_output(
[self.cc]
+ ["-M"]
+ ["-D%s" % define for define in self.defines]
+ ["-U%s" % undefine for undefine in self.defines]
+ ["-I%s" % idir for idir in self.include_dirs]
+ source_files
)
if result != 0:
raise CompileError("getting dependencies failed: "+stderr)
lines = join_continued_lines(stdout.split("\n"))
from pytools import flatten
return set(flatten(
line.split()[2:] for line in lines))
开发者ID:kaewgb,项目名称:cluster_mrjob,代码行数:20,代码来源:toolchain.py
示例11: get_nvcc_version
def get_nvcc_version(nvcc):
cmdline = [nvcc, "--version"]
try:
try:
from pytools.prefork import call_capture_output
except ImportError:
from pytools.prefork import call_capture_stdout
result = call_capture_stdout(cmdline)
else:
retcode, stdout, stderr = call_capture_output(cmdline)
result = stdout
if result is None:
from warnings import warn
warn("NVCC version could not be determined.")
result = "nvcc unknown version"
return result
except OSError, e:
raise OSError("%s was not found (is it on the PATH?) [%s]"
% (nvcc, str(e)))
开发者ID:bryancatanzaro,项目名称:catanzaro.pycuda,代码行数:22,代码来源:compiler.py
示例12: get_version
def get_version(self):
from pytools.prefork import call_capture_output
result, stdout, stderr = call_capture_output([self.cc, "--version"])
if result != 0:
raise RuntimeError("version query failed: "+stderr)
return stdout
开发者ID:OP2,项目名称:codepy,代码行数:6,代码来源:toolchain.py
示例13: __enter__
def __enter__(self):
self.temp_dir_mgr = None
temp_dir_mgr = _TempDirManager()
try:
working_dir = temp_dir_mgr.path
from os.path import join, abspath, exists
if isinstance(self.source, ScriptSource):
source_file_name = join(
working_dir, "temp."+self.source.extension)
with open(source_file_name, "w") as source_file:
source_file.write(self.source.source)
elif isinstance(self.source, FileSource):
source_file_name = abspath(self.source.filename)
if not exists(source_file_name):
raise IOError("'%s' does not exist" % source_file_name)
elif isinstance(self.source, ScriptWithFilesSource):
source_file_name = join(
working_dir, self.source.source_name)
with open(source_file_name, "w") as source_file:
source_file.write(self.source.source)
from os.path import basename
from shutil import copyfile
for f in self.source.filenames:
copyfile(f, join(working_dir, basename(f)))
else:
raise RuntimeError("'source' type unrecognized")
output_file_name = join(working_dir, self.output_file_name)
cmdline = [
self.gmsh_executable,
"-o", self.output_file_name,
"-nopopup"]
if self.dimensions is not None:
cmdline.append("-%d" % self.dimensions)
if self.order is not None:
cmdline.extend(["-order", str(self.order)])
if self.incomplete_elements is not None:
cmdline.extend(["-string",
"Mesh.SecondOrderIncomplete = %d;"
% int(self.incomplete_elements)])
cmdline.extend(self.other_options)
cmdline.append(source_file_name)
if self.dimensions is None:
cmdline.append("-")
logger.info("invoking gmsh: '%s'" % " ".join(cmdline))
from pytools.prefork import call_capture_output
retcode, stdout, stderr = call_capture_output(
cmdline, working_dir)
logger.info("return from gmsh")
stdout = stdout.decode("utf-8")
stderr = stderr.decode("utf-8")
if stderr and "error" in stderr.lower():
msg = "gmsh execution failed with message:\n\n"
if stdout:
msg += stdout+"\n"
msg += stderr+"\n"
raise GmshError(msg)
if stderr:
from warnings import warn
msg = "gmsh issued the following messages:\n\n"
if stdout:
msg += stdout+"\n"
msg += stderr+"\n"
warn(msg)
self.output_file = open(output_file_name, "r")
self.temp_dir_mgr = temp_dir_mgr
return self
except:
temp_dir_mgr.clean_up()
raise
开发者ID:elomi1345,项目名称:meshpy,代码行数:87,代码来源:gmsh.py
示例14: call
try:
from pytools.prefork import call_capture_output
except ImportError:
from pytools.prefork import call
try:
result = call(cmdline, cwd=file_dir)
except OSError, e:
raise OSError("%s was not found (is it on the PATH?) [%s]"
% (nvcc, str(e)))
stdout = None
stderr = None
else:
result, stdout, stderr = call_capture_output(
cmdline, cwd=file_dir,
error_on_nonzero=False)
try:
cubin_f = open(join(file_dir, file_root + ".cubin"), "rb")
except IOError:
no_output = True
else:
no_output = False
if result != 0 or (no_output and (stdout or stderr)):
if result == 0:
from warnings import warn
warn("PyCUDA: nvcc exited with status 0, but appears to have "
"encountered an error")
from pycuda.driver import CompileError
开发者ID:bryancatanzaro,项目名称:catanzaro.pycuda,代码行数:31,代码来源:compiler.py
示例15: compile_plain
def compile_plain(source, options, keep, nvcc, cache_dir, target="cubin"):
from os.path import join
assert target in ["cubin", "ptx", "fatbin"]
if cache_dir:
checksum = _new_md5()
if '#include' in source:
checksum.update(preprocess_source(source, options, nvcc).encode("utf-8"))
else:
checksum.update(source.encode("utf-8"))
for option in options:
checksum.update(option.encode("utf-8"))
checksum.update(get_nvcc_version(nvcc).encode("utf-8"))
from pycuda.characterize import platform_bits
checksum.update(str(platform_bits()).encode("utf-8"))
cache_file = checksum.hexdigest()
cache_path = join(cache_dir, cache_file + "." + target)
try:
cache_file = open(cache_path, "rb")
try:
return cache_file.read()
finally:
cache_file.close()
except:
pass
from tempfile import mkdtemp
file_dir = mkdtemp()
file_root = "kernel"
cu_file_name = file_root + ".cu"
cu_file_path = join(file_dir, cu_file_name)
outf = open(cu_file_path, "w")
outf.write(str(source))
outf.close()
if keep:
options = options[:]
options.append("--keep")
print("*** compiler output in %s" % file_dir)
cmdline = [nvcc, "--" + target] + options + [cu_file_name]
result, stdout, stderr = call_capture_output(cmdline,
cwd=file_dir, error_on_nonzero=False)
try:
result_f = open(join(file_dir, file_root + "." + target), "rb")
except IOError:
no_output = True
else:
no_output = False
if result != 0 or (no_output and (stdout or stderr)):
if result == 0:
from warnings import warn
warn("PyCUDA: nvcc exited with status 0, but appears to have "
"encountered an error")
from pycuda.driver import CompileError
raise CompileError("nvcc compilation of %s failed" % cu_file_path,
cmdline, stdout=stdout.decode("utf-8", "replace"),
stderr=stderr.decode("utf-8", "replace"))
if stdout or stderr:
lcase_err_text = (stdout+stderr).decode("utf-8", "replace").lower()
from warnings import warn
if "demoted" in lcase_err_text or "demoting" in lcase_err_text:
warn("nvcc said it demoted types in source code it "
"compiled--this is likely not what you want.",
stacklevel=4)
warn("The CUDA compiler succeeded, but said the following:\n"
+ (stdout+stderr).decode("utf-8", "replace"), stacklevel=4)
result_data = result_f.read()
result_f.close()
if cache_dir:
outf = open(cache_path, "wb")
outf.write(result_data)
outf.close()
if not keep:
from os import listdir, unlink, rmdir
for name in listdir(file_dir):
unlink(join(file_dir, name))
rmdir(file_dir)
return result_data
开发者ID:drufat,项目名称:pycuda,代码行数:95,代码来源:compiler.py
注:本文中的pytools.prefork.call_capture_output函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论