提交 6d89dc2a authored 作者: James Bergstra's avatar James Bergstra

merge w conflict in cmodule

......@@ -1258,7 +1258,7 @@ dummy_in = open(os.devnull)
dummy_err = open(os.devnull, 'w')
p = None
try:
p = subprocess.Popen(['gcc', '-dumpversion'], stdout=subprocess.PIPE,
p = subprocess.Popen(['g++', '-dumpversion'], stdout=subprocess.PIPE,
stdin=dummy_in.fileno(), stderr=dummy_err.fileno())
p.wait()
gcc_version_str = p.stdout.readline().strip()
......
import atexit, os, stat, sys
import logging
from theano.compile import optdb
from theano import config
from theano.gof.cmodule import get_lib_extension
import nvcc_compiler
import logging
_logger_name = 'theano.sandbox.cuda'
_logger = logging.getLogger(_logger_name)
_logger.setLevel(logging.WARNING)
......@@ -69,6 +71,17 @@ date = max(stat_times)
cuda_ndarray_loc = os.path.join(config.compiledir, 'cuda_ndarray')
cuda_ndarray_so = os.path.join(cuda_ndarray_loc,
'cuda_ndarray.' + get_lib_extension())
libcuda_ndarray_so = os.path.join(cuda_ndarray_loc,
'libcuda_ndarray.' + get_lib_extension())
# Add the theano cache directory's cuda_ndarray subdirectory to the list of
# places that are hard-coded into compiled modules' runtime library search
# list. This works in conjunction with nvcc_compiler.nvcc_module_compile_str
# which adds this folder during compilation with -L and also adds -lcuda_ndarray
# when compiling modules.
nvcc_compiler.add_standard_rpath(cuda_ndarray_loc)
compile_cuda_ndarray = True
if os.path.exists(cuda_ndarray_so):
......@@ -85,7 +98,6 @@ if not compile_cuda_ndarray:
try:
if compile_cuda_ndarray:
import nvcc_compiler
if not nvcc_compiler.is_nvcc_available():
# Hide the error message if the user manually unset the
# config.cuda.root configuration variable.
......@@ -105,7 +117,14 @@ try:
code,
location=cuda_ndarray_loc,
include_dirs=[cuda_path], libs=['cublas'])
# If necessary,
# create a symlink called libcuda_ndarray.so
# which nvcc_module_compile_str uses when linking
# any module except "cuda_ndarray" itself.
try:
open(libcuda_ndarray_so).close()
except IOError:
os.symlink(cuda_ndarray_so, libcuda_ndarray_so)
from cuda_ndarray.cuda_ndarray import *
except Exception, e:
error( "Failed to compile cuda_ndarray.cu: %s" % str(e))
......
......@@ -71,9 +71,14 @@ if config.cuda.root == "AUTO":
is_nvcc_available()#to set nvcc_path correctly and get the version
rpath_defaults = []
def add_standard_rpath(rpath):
rpath_defaults.append(rpath)
def nvcc_module_compile_str(
module_name, src_code,
location=None, include_dirs=[], lib_dirs=[], libs=[], preargs=[]):
location=None, include_dirs=[], lib_dirs=[], libs=[], preargs=[],
rpaths=rpath_defaults):
"""
:param module_name: string (this has been embedded in the src_code
:param src_code: a complete c or c++ source listing for the module
......@@ -82,6 +87,7 @@ def nvcc_module_compile_str(
:param lib_dirs: a list of library search path directory names (each gets prefixed with -L)
:param libs: a list of libraries to link with (each gets prefixed with -l)
:param preargs: a list of extra compiler arguments
:param rpaths: list of rpaths to use with Xlinker. Defaults to `rpath_defaults`.
:returns: dynamically-imported python module of the compiled code.
......@@ -89,6 +95,8 @@ def nvcc_module_compile_str(
Otherwise nvcc never finish.
"""
rpaths = list(rpaths)
if sys.platform=="win32":
# Remove some compilation args that cl.exe does not understand.
# cl.exe is the compiler used by nvcc on Windows.
......@@ -171,19 +179,22 @@ def nvcc_module_compile_str(
cmd.extend(['-Xcompiler', ','.join(preargs2)])
if config.cuda.root and os.path.exists(os.path.join(config.cuda.root,'lib')):
cmd.extend(['-Xlinker',','.join(['-rpath',os.path.join(config.cuda.root,'lib')])])
rpaths.append(os.path.join(config.cuda.root,'lib'))
if sys.platform != 'darwin':
# the 64bit CUDA libs are in the same files as are named by the function above
cmd.extend(['-Xlinker',','.join(['-rpath',os.path.join(config.cuda.root,'lib64')])])
rpaths.append(os.path.join(config.cuda.root,'lib64'))
for rpath in rpaths:
cmd.extend(['-Xlinker',','.join(['-rpath',rpath])])
nvccflags = [flag for flag in config.cuda.nvccflags.split(' ') if flag]
cmd.extend(nvccflags)
cmd.extend('-I%s'%idir for idir in include_dirs)
cmd.extend(['-o',lib_filename])
cmd.append(os.path.split(cppfilename)[-1])
if module_name != 'cuda_ndarray':
cmd.append(os.path.join(os.path.split(cppfilename)[0],'..','cuda_ndarray','cuda_ndarray.'+get_lib_extension()))
cmd.extend(['-L%s'%ldir for ldir in lib_dirs])
cmd.extend(['-l%s'%l for l in libs])
if module_name != 'cuda_ndarray':
cmd.append("-lcuda_ndarray")
if sys.platform == 'darwin':
cmd.extend(darwin_python_lib.split())
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论