Can cython be compiled with icc?

*爱你&永不变心* 提交于 2019-12-19 08:29:50

问题


I am trying to build cython from source with icc compiler on Ubuntu 14.04 as my python is compiled with Intel icc compiler.

When I tried to install cython using pip3 install cython and then ran cython I got following error

Traceback (most recent call last):
File "/usr/local/bin/cython", line 9, in <module>
load_entry_point('Cython==0.24', 'console_scripts', 'cython')()
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 351, in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2363, in load_entry_point
return ep.load()
File "/usr/lib/python3/dist-packages/pkg_resources.py", line 2088, in load
entry = __import__(self.module_name, globals(),globals(), ['__name__'])
File "/usr/local/lib/python3.4/dist-packages/Cython/Compiler/Main.py", line 28, in <module>
from .Scanning import PyrexScanner, FileSourceDescriptor
ImportError: /usr/local/lib/python3.4/dist-packages/Cython/Compiler/Scanning.cpython-34m.so: undefined symbol: __intel_sse2_strchr 

How does one go about installing cython from source using icc compiler ?

I tried this and it does not work

From the cython directory(downloaded from github)

python3.4 setup.py CC=icc

I get the following message -

/home/aa/libPython/cython/Cython/Distutils/build_ext.py:20: UserWarning:    
Cython.Distutils.build_ext does not properly handle dependencies and is deprectated. Use Cython.Build.build_ext instead.
"Cython.Distutils.build_ext does not properly handle dependencies "
 Unable to find pgen, not compiling formal grammar.
 invalid command name 'CC=icc'

回答1:


CC=icc is not enough to build with icc. You should also link with icc (https://stackoverflow.com/a/10891764/196561; icc will add its internal libraries to ELF file), so find name of linker variable for your setup.py, probably LD and set it to icc too LD=icc (default is probably gcc).

Actually it is LINKCC - https://github.com/cython/cython/blob/970c2fc0e676ca22016e14147ada0edba937dc6b/Cython/Build/BuildExecutable.py

CC = get_config_var('CC', os.environ.get('CC', ''))
CFLAGS = get_config_var('CFLAGS') + ' ' + os.environ.get('CFLAGS', '')
LINKCC = get_config_var('LINKCC', os.environ.get('LINKCC', CC))

So, correct build for cython with icc should be with CC=icc LINKCC=icc, don't know how variables should be passed into setup.py, check How to tell distutils to use gcc? or try

CC=icc LINKCC=icc python3.4 setup.py

Update: According to message from gansub, "LDSHARED=icc" env. variable will help to build cython: "You need to set the environment variable LDSHARED=icc" - http://chat.stackoverflow.com/transcript/message/31231907#31231907 and https://stackoverflow.com/a/37914227

Update from Syrtis Major: There is article "Thread Parallelism in Cython*" https://software.intel.com/en-us/articles/thread-parallelism-in-cython by Nguyen, Loc Q (Intel), December 15, 2016 with recommendation of LDSHARED="icc -shared" CC=icc:

To explicitly use the Intel icc to compile this application, execute the setup.py file with the following command:

 $ LDSHARED="icc -shared" CC=icc python setup.py build_ext --inplace


来源:https://stackoverflow.com/questions/37904377/can-cython-be-compiled-with-icc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!