Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can cython be compiled with icc?

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'
like image 845
gansub Avatar asked Jun 19 '16 05:06

gansub


1 Answers

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" - https://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
like image 50
osgx Avatar answered Sep 20 '22 00:09

osgx