Ubuntu 16.04 Python 3.5 install llvm 3.9.1, llvmlite 0.16.0, numba 0.30.0

Keywords: Attribute Linux github Python

Because the project needs to use python for large-scale computation, numba is used for acceleration. Numba needs to install llvmlite first, so this blog records part of the installation process of llvm, llvmlite and numba. Process main reference http://www.cnblogs.com/goingmyway/p/4493204.html . However, due to the difference of environment and version, many problems have been encountered and recorded.

LLVM

The following files need to be downloaded, download address http://llvm.org/releases/download.html#3.9.1

LLVM source code
Clang source code
Clang Tools Extra source code
Compiler RT source code
LibC++ source code

Then decompress, rename, move and so on as follows:

mv cfe-3.9.1.src clang
mv clang/ llvm-3.9.1.src/tools/

mv clang-tools-extra-3.9.1.src extra
mv extra/ llvm-3.9.1.src/tools/clang/

mv compiler-rt-3.9.1.src compiler-rt
mv compiler-rt llvm-3.9.1.src/projects/

Then create the folder build-3.9.1 in llvm-3.9.1.src's peer directory and enter it
At this time http://www.cnblogs.com/goingmyway/p/4493204.html The blog method cannot continue, prompting you to use cmake system, so execute the command

cmake ../llvm-3.9.1.src

Waiting for the command to be executed

Then execute the command

make -j4 #Compilation speed is very slow, just wait patiently.

Then execute the command

sudo make install

After the command is executed, the installation of llvm3.9.1 is completed, and the following commands are executed for testing:

dcooo@dcooo-Aspire-E5-572G:~$ clang++ -v
clang version 3.9.1 (tags/RELEASE_391/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/6.0.0
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/5.4.0
Candidate multilib: .;@m64
Selected multilib: .;@m64
Found CUDA installation: /usr/local/cuda, version unknown

LLVMLITE

This part of the installation process is different from the previous blog method, mainly because of version and environment reasons, there are also some problems in the installation process have not been solved.

Set the environment variable LLVM_CONFIG to the llvm-config directory in the installed LLVM, which is the result of running whereis llvm-config

First, according to numba's git home page https://github.com/numba/numba/blob/master/requirements.txt The environment requirement, llvmlite >= 0.16, is only updated to 0.15 on the official website of llvmlite, so the method of downloading source code installation from git of llvmlite is adopted as follows:

Download llvmlite source from github

git clone https://github.com/numba/llvmlite

Then go to the llvmlite directory

cd ~/llvmlite

Since we use clang when compiling llvm, running the command python setup.py build directly will cause an error. See the error type. https://github.com/numba/llvmlite/issues/54 The solution is also given below to execute the command:

CXX_FLTO_FLAGS= LD_FLTO_FLAGS= python3.5 setup.py build

If you do not set the value of the environment variable LLVM_CONFIG earlier, you may have an error prompting that you cannot find executable llvm-config. Specify

Then run the test program:

python runtests.py

At this point, failure unexpected dependenty'libtinfo'in {...} appears

My solution is to modify the source code directly and add libtinfo to allowed dependency, as follows:

vim ~/llvmlite/llvmlite/tests/test_binding.py
#vim command line mode input
:/allowed
 allowed = set(['librt', 'libdl', 'libpthread', 'libz', 'libm',
                       'libgcc_s', 'libc', 'ld-linux'])
        for dep in deps:
            if not dep.startswith('ld-linux-') and dep not in allowed:
                self.fail("unexpected dependency %r in %r" % (dep, deps))
#Add libtinfo to the allowed collection, after modification
 allowed = set(['librt', 'libdl', 'libpthread', 'libz', 'libm',
                       'libgcc_s', 'libc', 'ld-linux', 'libtinfo'])
        for dep in deps:
            if not dep.startswith('ld-linux-') and dep not in allowed:
                self.fail("unexpected dependency %r in %r" % (dep, deps))

Then run python runtest.py again, prompting OK

Execute installation commands

sudo python setup.py install

Complete llvmlite installation

NUMBA

Specific installation method, according to numba git Homepage https://github.com/numba/numba First, download numba from git with the following commands:

git clone https://github.com/numba/numba.git

Enter the numba directory

cd ~/numba

Perform sudo PIP3 install-r requirement.txt to install all other dependencies needed

At this point, it may be prompted that there is no satisfied llvmlite >= 0.16. This is because pip3 has not found the 016 version of llvmlite in the software library, so we need to download the latest version from the github source code. We have installed llvmlite 0.16 before, and we can see llvmlite and llvmlite 0.16 under / usr / local / lib / Python 3.5 / dist-packages. And other documents.

Execute orders:

python setup.py build _ext --inplace

and

python setup.py install

Complete the installation of numba, simple test:

from numba import jit

@jit
def sum(a, b):
    return a+b

if __name__ == '__main__':
    print(sum(a+b))

If prompted,'Target Data'object has no attribute'add_pass'

According to the llvm document, because the attribute add_pass has been removed from llvm 3.9.x, it is assumed that the installation of llvmlite or numba version is wrong. Please check carefully.

Due to the different personal machine environment and configuration, some commands need to use sudo. Please pay attention to the attempt. This installation took a whole day. Each part was installed many times before it could finally be used. With the environment, installing software is really a laborious and painstaking task.

Above.

Posted by spasm37 on Thu, 10 Jan 2019 18:27:10 -0800