├── LICENSE └── cython_icc_mkl ├── mkl_version.py ├── mkl_cython.pyx ├── cy.sh └── README.md /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018, Intel Corporation 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, 7 | this list of conditions and the following disclaimer. 8 | * Redistributions in binary form must reproduce the above copyright 9 | notice, this list of conditions and the following disclaimer in the 10 | documentation and/or other materials provided with the distribution. 11 | * Neither the name of Intel Corporation nor the names of its contributors 12 | may be used to endorse or promote products derived from this software 13 | without specific prior written permission. 14 | 15 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 19 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | -------------------------------------------------------------------------------- /cython_icc_mkl/mkl_version.py: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Intel Corporation 2 | # 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions are met: 5 | # 6 | # * Redistributions of source code must retain the above copyright notice, 7 | # this list of conditions and the following disclaimer. 8 | # * Redistributions in binary form must reproduce the above copyright 9 | # notice, this list of conditions and the following disclaimer in the 10 | # documentation and/or other materials provided with the distribution. 11 | # * Neither the name of Intel Corporation nor the names of its contributors 12 | # may be used to endorse or promote products derived from this software 13 | # without specific prior written permission. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 19 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | 27 | import mkl_cython 28 | 29 | if __name__ == '__main__': 30 | mkl_cython.print_mkl_version() 31 | -------------------------------------------------------------------------------- /cython_icc_mkl/mkl_cython.pyx: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2018, Intel Corporation 2 | # 3 | # Redistribution and use in source and binary forms, with or without 4 | # modification, are permitted provided that the following conditions are met: 5 | # 6 | # * Redistributions of source code must retain the above copyright notice, 7 | # this list of conditions and the following disclaimer. 8 | # * Redistributions in binary form must reproduce the above copyright 9 | # notice, this list of conditions and the following disclaimer in the 10 | # documentation and/or other materials provided with the distribution. 11 | # * Neither the name of Intel Corporation nor the names of its contributors 12 | # may be used to endorse or promote products derived from this software 13 | # without specific prior written permission. 14 | # 15 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 16 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 18 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 19 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 21 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 22 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 23 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 24 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | 26 | 27 | cdef extern from "mkl_service.h": 28 | cdef void mkl_get_version_string (char* buf, int len) nogil 29 | 30 | def print_mkl_version(): 31 | cdef int length = 198 32 | cdef char buff[198] 33 | mkl_get_version_string(buff, length) 34 | print(buff) 35 | -------------------------------------------------------------------------------- /cython_icc_mkl/cy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -x 2 | 3 | # Copyright (c) 2018, Intel Corporation 4 | # 5 | # Redistribution and use in source and binary forms, with or without 6 | # modification, are permitted provided that the following conditions are met: 7 | # 8 | # * Redistributions of source code must retain the above copyright notice, 9 | # this list of conditions and the following disclaimer. 10 | # * Redistributions in binary form must reproduce the above copyright 11 | # notice, this list of conditions and the following disclaimer in the 12 | # documentation and/or other materials provided with the distribution. 13 | # * Neither the name of Intel Corporation nor the names of its contributors 14 | # may be used to endorse or promote products derived from this software 15 | # without specific prior written permission. 16 | # 17 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 18 | # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | # DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 21 | # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | 28 | if [ ! -f ./build ]; then 29 | mkdir build 30 | fi 31 | 32 | cython mkl_cython.pyx 33 | 34 | icc -I`python3-config --exec-prefix`/include \ 35 | -I`python3-config --exec-prefix`/include/python3.6m \ 36 | -DNDEBUG -O2 -Wall -fPIC -c mkl_cython.c -o build/mkl_cython.o 37 | 38 | icc -shared -Wl,-rpath=$ORIGIN/../lib/:`python3-config --exec-prefix`/lib \ 39 | -L`python3-config --exec-prefix`/lib \ 40 | -lmkl_rt build/mkl_cython.o -o mkl_cython.so 41 | 42 | rm -rf build 43 | -------------------------------------------------------------------------------- /cython_icc_mkl/README.md: -------------------------------------------------------------------------------- 1 | # Using Cython with the Intel Compiler and MKL 2 | 3 | This is a minimal example of using the Intel compiler with Cython and MKL. 4 | 5 | **Assumption:** You've sourced **icc**-related environment variables (via **iccvars.sh**) - i.e. you have **icc** on **PATH** and icc-related header-files and libraries on **CPATH** and **LD_LIBRARY_PATH**, respectively. 6 | 7 | 1. If you don't have a local installation of Python, the following can be performed to setup a miniminal configuration required to run this example: 8 | 1. [Get miniconda](https://conda.io/miniconda.html): ```wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh``` 9 | 2. Install miniconda: ```bash Miniconda3-latest-Linux-x86_64.sh -b -p miniconda3``` 10 | 3. Update miniconda: ```./miniconda3/bin/conda update -c anaconda conda -y``` 11 | 4. Create a conda-environment with required dependencies: ```./miniconda3/bin/conda create -n cy_icc_test -c intel python=3.6 mkl-devel cython -y``` 12 | 5. Activate conda-environment: ```source ./miniconda3/bin/activate cy_icc_test``` 13 | 14 | Once the conda-environment is activated (i.e. Step.5), the default python (\`which python\`) would be the one with all the required dependencies installed. 15 | 16 | You can deactivate this conda-environment after running this example: ```source ./miniconda3/bin/deactivate``` 17 | 18 | 2. If you have a local Python installation: 19 | 1. Install required dependencies: ```/bin/pip install cython mkl-devel``` 20 | 2. Update **cy.sh** to ensure that correct library directory and include directory are used while building this extension: 21 |      In **cy.sh**: 22 | 1. replace ```cython``` with ```/bin/cython``` 23 | 2. replace **all** instances of **\`python3-config --exec-prefix\`** with `````` 24 | 3. replace **\`python3-config --exec-prefix\`/include/python3.6m** with the absolute path to include-directory of CPython's header files, for e.g. ```/include/python2.7``` 25 | 26 | To build this example, run ```bash cy.sh``` 27 | which creates `mkl_cython.so`, that can be imported and used in a regular python script. To check if everything built correctly, run: 28 | ``` 29 | python mkl_version.py 30 | ``` 31 | --------------------------------------------------------------------------------