eddelbuettel / mkl4deb

Adding the Intel MKL to a Debian / Ubuntu system via one simple script
212 stars 37 forks source link

Adding MKL support to bioconductor docker #10

Closed shmohammadi86 closed 4 years ago

shmohammadi86 commented 4 years ago

Hi,

Thanks a lot for your wonderful script. I am trying to update bioconductor docker to support MKL. I followed all the mentioned steps, but I still get that sessionInfo() uses OpenBLAS:

sessionInfo() R version 4.0.0 (2020-04-24) Platform: x86_64-pc-linux-gnu (64-bit) Running under: Ubuntu 18.04.4 LTS

Matrix products: default BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/libopenblasp-r0.2.20.so

locale: [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_US.UTF-8 LC_COLLATE=en_US.UTF-8
[5] LC_MONETARY=en_US.UTF-8 LC_MESSAGES=C
[7] LC_PAPER=en_US.UTF-8 LC_NAME=C
[9] LC_ADDRESS=C LC_TELEPHONE=C
[11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C

attached base packages: [1] stats graphics grDevices utils datasets methods base

other attached packages: [1] BiocManager_1.30.10

loaded via a namespace (and not attached): [1] compiler_4.0.0

I were able to compile R 4.0 with MKL with no problem, and the performance increase is drastic. I am trying to see if I can achieve the same without compiling R from scratch. I would greatly appreciate your feedback.

Thanks, -- Shahin.

shmohammadi86 commented 4 years ago

Also, in case this helps:

root@5f1e9293c09c:/# update-alternatives --config liblapack.so.3-x86_64-linux-gnu There are 3 choices for the alternative liblapack.so.3-x86_64-linux-gnu (providing /usr/lib/x86_64-linux-gnu/liblapack.so.3).

Selection Path Priority Status

0 /opt/intel/mkl/lib/intel64/libmkl_rt.so 50 auto mode

eddelbuettel commented 4 years ago

I were able to compile R 4.0 with MKL .... without compiling R from scratch.

You never need to recompile R, or compile from scratch when you use Debian/Ubuntu. That is the whole point of the defined interface in which we simply switch the BLAS/LAPACK being used.

shmohammadi86 commented 4 years ago

Thanks for the quick reply. As I mentioned, I was NOT trying to recompile R in the Bioconductor docker, but just to simply make it use MKL using the instruction here.

nathanweeks commented 4 years ago

Hi @shmohammadi86 , I haven't tried the latest bioconductor/bioconductor_docker:RELEASE_3_11 yet (R 4.0.0), but for RELEASE_3_10 (R 3.6.2), I used the following Dockerfile to replace OpenBLAS with MKL, as well as rebuild zlib with Intel Performance Primitives optimizations, which seemed to result in "modest" (< 2x) but still-useful speedup for of relevant compression/decompression operations (e.g., on frequently-gzip'ed bioinformatics file formats, as well as R functions like save(..., compress=TRUE)):

FROM intel/oneapi-hpckit:2021.1-47.beta03-devel-ubuntu18.04 AS oneapi

RUN apt install -y wget 

SHELL ["/bin/bash", "-c"]

RUN wget -O - https://github.com/madler/zlib/archive/v1.2.11.tar.gz | tar -xzf - \
 && cd zlib-1.2.11 \
 && source /opt/intel/inteloneapi/setvars.sh > /dev/null \
 && tar -xzvf $IPPROOT/components/components_and_examples_lin.tgz \
 && patch -p1 < components/interfaces/ipp_zlib/zlib-1.2.11.patch \
 && export CFLAGS="-m64 -DWITH_IPP -I$IPPROOT/include" \
 && export LDFLAGS="-L$IPPROOT/lib/intel64 -lippdc -lipps -lippcore" \
 && ./configure --prefix=/artifacts/zlib \
 && make shared \
 && make install

# unneeded .so files are big; ensure they aren't copied into the final image

RUN find /opt/intel/inteloneapi/ipp/latest/lib/intel64/ -maxdepth 1 -mindepth 1 ! \(  -type f -name '*.so' \) -exec rm -rf {} +

FROM bioconductor/bioconductor_docker:RELEASE_3_10 AS final

COPY --from=oneapi /artifacts/zlib/lib/libz.so.1.2.11 /lib/x86_64-linux-gnu/libz.so.1.2.11
COPY --from=oneapi /opt/intel/inteloneapi/ipp/latest/lib/intel64/ /usr/local/lib/

RUN ldconfig

# https://github.com/eddelbuettel/mkl4deb/issues/8#issuecomment-548949944
# https://github.com/eddelbuettel/mkl4deb/blob/master/README.md#integrate-mkl
# https://github.com/eddelbuettel/mkl4deb/issues/8#issuecomment-548943912
RUN sed -i'' '/^deb /s/$/ non-free/' /etc/apt/sources.list \
 && apt update \
 && apt remove -y libopenblas-base \
 && apt install -y --no-install-recommends intel-mkl \
 && update-alternatives --install /usr/lib/x86_64-linux-gnu/libblas.so libblas.so-x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libmkl_rt.so 150 \
 && update-alternatives --install /usr/lib/x86_64-linux-gnu/libblas.so.3 libblas.so.3-x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libmkl_rt.so 150 \
 && update-alternatives --install /usr/lib/x86_64-linux-gnu/liblapack.so liblapack.so-x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libmkl_rt.so 150 \
 && update-alternatives --install /usr/lib/x86_64-linux-gnu/liblapack.so.3 liblapack.so.3-x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libmkl_rt.so 150 \
 && update-alternatives --install /usr/lib/x86_64-linux-gnu/libopenblas.so libopenblas.so-x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libmkl_rt.so 150 \
 && update-alternatives --install /usr/lib/x86_64-linux-gnu/libopenblas.so.0 libopenblas.so.0-x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libmkl_rt.so 150 \
 && rm -rf /var/lib/apt/lists/

.. other R packages installed here...

The resulting image (exported to Singularity using docker2singularity is launched as a Singularity container by users in an HPC environment.

It's been on my TODO list to test this with bioconductor_docker:RELEASE_3_11.

shmohammadi86 commented 4 years ago

@nathanweeks I have made a bioconductor+oneAPI container and using your help I made the following changes that made R link to MKL:

update-alternatives --install /usr/lib/x86_64-linux-gnu/libblas.so libblas.so-x86_64-linux-gnu ${MKLROOT}/lib/intel64/libmkl_rt.so 150 \
 && update-alternatives --install /usr/lib/x86_64-linux-gnu/libblas.so.3 libblas.so.3-x86_64-linux-gnu ${MKLROOT}/lib/intel64/libmkl_rt.so 150 \
 && update-alternatives --install /usr/lib/x86_64-linux-gnu/liblapack.so liblapack.so-x86_64-linux-gnu ${MKLROOT}/lib/intel64/libmkl_rt.so 150 \
 && update-alternatives --install /usr/lib/x86_64-linux-gnu/liblapack.so.3 liblapack.so.3-x86_64-linux-gnu ${MKLROOT}/lib/intel64/libmkl_rt.so 150 \
 && update-alternatives --install /usr/lib/x86_64-linux-gnu/libopenblas.so libopenblas.so-x86_64-linux-gnu ${MKLROOT}/lib/intel64/libmkl_rt.so 150 \
 && update-alternatives --install /usr/lib/x86_64-linux-gnu/libopenblas.so.0 libopenblas.so.0-x86_64-linux-gnu ${MKLROOT}/lib/intel64/libmkl_rt.so 150 \

Thanks a lot!

nathanweeks commented 4 years ago

@shmohammadi86 good to know! Was with bioconductor/bioconductor_docker:RELEASE_3_11 ?

eddelbuettel commented 4 years ago

May I kindly suggest that discussion take place somewhere else? It has ceased to have any (direct) relevance or bearing on the MKL script in this repo. Thanks so much!