Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What is the minimal requirements of Intel MKL version? #443

Closed
iwanhae opened this issue Aug 14, 2023 · 6 comments
Closed

What is the minimal requirements of Intel MKL version? #443

iwanhae opened this issue Aug 14, 2023 · 6 comments

Comments

@iwanhae
Copy link

iwanhae commented Aug 14, 2023

Hello, Thanks for the great work!

I've got an error while compiling with the -features mkl option.
For example cargo install --git https://github.com/huggingface/candle.git candle-examples --examples bert -F mkl

The error said

  = note: /usr/bin/ld: /workspaces/Kuberian/searcher/target/debug/deps/libcandle_core-0afc8671b4dae8af.rlib(candle_core-0afc8671b4dae8af.candle_core.b11884625c01537d-cgu.13.rcgu.o): in function `candle_core::mkl::hgemm':
          /usr/local/cargo/git/checkouts/candle-0c2b4fa9e5801351/60cd155/candle-core/src/mkl.rs:162: undefined reference to `hgemm_'
          collect2: error: ld returned 1 exit status
          
  = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
  = note: use the `-l` flag to specify native libraries to link
  = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorustc-link-libkindname)

I initially thought that I did not install intel mkl libs properly, but I found that

  1. intel-mkl-src automatically downloads the required library from ghcr
  2. intel mkl 2020.01, which automatically downloaded from here, simply does not implement hgemm while they do implement sgemm and dgemm
  3. the latest version of intel mkl does implement hgemm

So I tried the latest version of intel mkl, but it seems intel-mkl-src does not support it.

I'm wondering which intel-mkl version do you use for your development environment?

@LaurentMazare
Copy link
Collaborator

I'm using 2023.1.0, it worked out of the box with intel-mkl-src for me, no need to tweak anything.

@iwanhae
Copy link
Author

iwanhae commented Aug 14, 2023

Thx, I solved the problem.

For someone who might have trouble like me:
I'm using a dev container like below, and it works!

ARG VARIANT="bullseye"
FROM mcr.microsoft.com/vscode/devcontainers/rust:1-${VARIANT}

RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
| gpg --dearmor | sudo tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null && \
  echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | \
  sudo tee /etc/apt/sources.list.d/oneAPI.list

RUN apt update

# for builder
RUN apt install -y intel-oneapi-mkl-devel
# for runtime environment
RUN apt install -y libomp-dev

Just installing intel-oneapi-mkl is not enough for static linking.
I recognize my mistake from your hint. Thx @LaurentMazare :-)

@iwanhae iwanhae closed this as completed Aug 14, 2023
@akhildevelops
Copy link

Thanks @iwanhae, I was also struggling to run my binary, enabling mkl feature.
intel-mkl-src crate fetches outdated libraries, if the system doesn't have mkl.

It didn't worked even when I pointed to latest ones.

Finally I had to download the latest from Intel website as pointed by you.

apt install -y intel-oneapi-mkl-devel
apt install -y libomp-dev # (This is not from intel)

@nklsla
Copy link

nklsla commented Jan 1, 2024

For others who stumble upon this issue:
I got the same error message when I tried to build the vgg-example but in my case I had taken out the candle-examples/vgg/main.rs along with necessary parts and added it into another project.
The solution for me was suprisingly that I could not build it with the debug-mode but as soon as I tried release-mode it worked!

I'm quite new to Rust and I cannot explain why this is the case. If anyone do know I would apprecaite an explaination.

@birajsilwal
Copy link

using sudo cargo build and sudo cargo run worked for me.

@nklsla
Copy link

nklsla commented Feb 3, 2024

As I progressed into using a docker container the problem rised again. This time I solved thanks to @iwanhae with some slight modifications.
I wanted to use rust's offical docker image which also run on debian, had to remove the sudo commands otherwise it was the same, se full dockerfile below:

FROM rust:latest
WORKDIR /app
COPY /models .

RUN wget -O- https://apt.repos.intel.com/intel-gpg-keys/GPG-PUB-KEY-INTEL-SW-PRODUCTS.PUB \
    | gpg --dearmor | tee /usr/share/keyrings/oneapi-archive-keyring.gpg > /dev/null \
    && echo "deb [signed-by=/usr/share/keyrings/oneapi-archive-keyring.gpg] https://apt.repos.intel.com/oneapi all main" | \
    tee /etc/apt/sources.list.d/oneAPI.list \
    && apt-get update \
    && apt-get install -y libomp-dev intel-oneapi-mkl-devel \
    && cargo build --release

CMD ["./target/release/models","linear"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants