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

Cargo fails to build on Apple M1 #10

Closed
certik opened this issue Mar 4, 2023 · 7 comments
Closed

Cargo fails to build on Apple M1 #10

certik opened this issue Mar 4, 2023 · 7 comments

Comments

@certik
Copy link

certik commented Mar 4, 2023

Here is what I got:

$ git clone https://github.com/Narsil/fast_gpt2
Cloning into 'fast_gpt2'...
remote: Enumerating objects: 405, done.
remote: Counting objects: 100% (229/229), done.
remote: Compressing objects: 100% (147/147), done.
remote: Total 405 (delta 153), reused 142 (delta 82), pack-reused 176
Receiving objects: 100% (405/405), 802.48 KiB | 2.57 MiB/s, done.
Resolving deltas: 100% (236/236), done.
$ cd fast_gpt2 
$ cargo run --example run --release
    Updating crates.io index
    Updating git repository `https://github.com/coreylowman/cudarc`
    Updating git repository `https://github.com/Narsil/dfdx`
    Updating git repository `https://github.com/huggingface/safetensors`
    Updating git repository `https://github.com/huggingface/tokenizers`
  Downloaded rayon-core v1.10.2
  Downloaded cc v1.0.79
  Downloaded reqwest v0.11.14
  Downloaded rustix v0.36.8
  Downloaded tokio-macros v1.8.2
  Downloaded tower-layer v0.3.2
  Downloaded tracing v0.1.37
  Downloaded base64 v0.21.0
  Downloaded memmap2 v0.5.10
  Downloaded tower-http v0.3.5
  Downloaded once_cell v1.17.1
  Downloaded proc-macro2 v1.0.51
  Downloaded macro_rules_attribute v0.1.3
  Downloaded security-framework-sys v2.8.0
  Downloaded tinyvec_macros v0.1.1
  Downloaded tempfile v3.4.0
  Downloaded tokio-util v0.7.7
  Downloaded serde_path_to_error v0.1.9
  Downloaded ryu v1.0.12
  Downloaded pin-project v1.0.12
  Downloaded tower-http v0.4.0
  Downloaded thread_local v1.1.7
  Downloaded serde_json v1.0.93
  Downloaded tracing-core v0.1.30
  Downloaded unicode-bidi v0.3.10
  Downloaded syn v1.0.109
  Downloaded serde_derive v1.0.152
  Downloaded unicode-ident v1.0.6
  Downloaded tracing-log v0.1.3
  Downloaded unicode-segmentation v1.10.1
  Downloaded slab v0.4.8
  Downloaded quote v1.0.23
  Downloaded rustversion v1.0.11
  Downloaded mio v0.8.6
  Downloaded tracing-subscriber v0.3.16
  Downloaded spin v0.9.5
  Downloaded tower v0.4.13
  Downloaded thread-tree v0.3.3
  Downloaded regex v1.7.1
  Downloaded crossbeam-utils v0.8.15
  Downloaded darling v0.14.3
  Downloaded crossbeam-channel v0.5.7
  Downloaded darling_macro v0.14.3
  Downloaded darling_core v0.14.3
  Downloaded futures v0.3.26
  Downloaded futures-channel v0.3.26
  Downloaded fastrand v1.9.0
  Downloaded derive_builder_macro v0.12.0
  Downloaded derive_builder_core v0.12.0
  Downloaded derive_builder v0.12.0
  Downloaded aho-corasick v0.7.20
  Downloaded futures-io v0.3.26
  Downloaded futures-task v0.3.26
  Downloaded glob v0.3.1
  Downloaded futures-macro v0.3.26
  Downloaded futures-core v0.3.26
  Downloaded crossbeam-epoch v0.9.14
  Downloaded crossbeam-deque v0.8.3
  Downloaded futures-executor v0.3.26
  Downloaded base64 v0.13.1
  Downloaded httparse v1.8.0
  Downloaded futures-util v0.3.26
  Downloaded http-range-header v0.3.0
  Downloaded io-lifetimes v1.0.5
  Downloaded h2 v0.3.16
  Downloaded either v1.8.1
  Downloaded http v0.2.9
  Downloaded thiserror-impl v1.0.38
  Downloaded thiserror v1.0.38
  Downloaded hyper v0.14.24
  Downloaded matchit v0.7.0
  Downloaded macro_rules_attribute-proc_macro v0.1.3
  Downloaded nu-ansi-term v0.46.0
  Downloaded onig v6.4.0
  Downloaded no-std-compat v0.4.1
  Downloaded native-tls v0.2.11
  Downloaded ipnet v2.7.1
  Downloaded memoffset v0.8.0
  Downloaded serde v1.0.152
  Downloaded paste v1.0.11
  Downloaded half v2.2.1
  Downloaded itoa v1.0.5
  Downloaded indexmap v1.9.2
  Downloaded futures-sink v0.3.26
  Downloaded num_cpus v1.15.0
  Downloaded async-trait v0.1.64
  Downloaded matrixmultiply v0.3.2
  Downloaded pin-project-internal v1.0.12
  Downloaded pkg-config v0.3.26
  Downloaded nom v7.1.3
  Downloaded tokio-native-tls v0.3.1
  Downloaded security-framework v2.8.2
  Downloaded ppv-lite86 v0.2.17
  Downloaded sync_wrapper v0.1.2
  Downloaded sharded-slab v0.1.4
  Downloaded rand_core v0.6.4
  Downloaded overload v0.1.1
  Downloaded rayon v1.6.1
  Downloaded find_cuda_helper v0.2.0
  Downloaded try-lock v0.2.4
  Downloaded axum-core v0.3.2
  Downloaded libc v0.2.139
  Downloaded tokio v1.25.0
  Downloaded onig_sys v69.8.1
  Downloaded encoding_rs v0.8.32
  Downloaded tracing-attributes v0.1.23
  Downloaded bytes v1.4.0
  Downloaded axum v0.6.9
  Downloaded 108 crates (8.8 MB) in 1.72s (largest was `encoding_rs` at 1.4 MB)
   Compiling proc-macro2 v1.0.51
   Compiling unicode-ident v1.0.6
   Compiling quote v1.0.23
   Compiling syn v1.0.109
   Compiling cfg-if v1.0.0
   Compiling autocfg v1.1.0
   Compiling libc v0.2.139
   Compiling memchr v2.5.0
   Compiling log v0.4.17
   Compiling once_cell v1.17.1
   Compiling pin-project-lite v0.2.9
   Compiling futures-core v0.3.26
   Compiling itoa v1.0.5
   Compiling bytes v1.4.0
   Compiling slab v0.4.8
   Compiling futures-channel v0.3.26
   Compiling futures-sink v0.3.26
   Compiling futures-task v0.3.26
   Compiling futures-util v0.3.26
   Compiling tracing-core v0.1.30
   Compiling futures-io v0.3.26
   Compiling pin-utils v0.1.0
   Compiling bitflags v1.3.2
   Compiling num_cpus v1.15.0
   Compiling tokio v1.25.0
   Compiling serde_derive v1.0.152
   Compiling crossbeam-utils v0.8.15
   Compiling socket2 v0.4.7
   Compiling mio v0.8.6
   Compiling serde v1.0.152
   Compiling fnv v1.0.7
   Compiling core-foundation-sys v0.8.3
   Compiling http v0.2.9
   Compiling memoffset v0.8.0
   Compiling io-lifetimes v1.0.5
   Compiling tower-service v0.3.2
   Compiling lazy_static v1.4.0
   Compiling rustversion v1.0.11
   Compiling crossbeam-epoch v0.9.14
   Compiling indexmap v1.9.2
   Compiling rustix v0.36.8
   Compiling strsim v0.10.0
   Compiling ident_case v1.0.1
   Compiling crossbeam-channel v0.5.7
   Compiling http-body v0.4.5
   Compiling errno v0.2.8
   Compiling ryu v1.0.12
   Compiling hashbrown v0.12.3
   Compiling scopeguard v1.1.0
   Compiling httparse v1.8.0
   Compiling core-foundation v0.9.3
   Compiling security-framework-sys v2.8.0
   Compiling tower-layer v0.3.2
   Compiling try-lock v0.2.4
   Compiling tinyvec_macros v0.1.1
   Compiling cc v1.0.79
   Compiling percent-encoding v2.2.0
   Compiling pkg-config v0.3.26
   Compiling serde_json v1.0.93
   Compiling either v1.8.1
   Compiling native-tls v0.2.11
   Compiling rayon-core v1.10.2
   Compiling fastrand v1.9.0
   Compiling form_urlencoded v1.1.0
   Compiling want v0.3.0
   Compiling tinyvec v1.6.0
   Compiling tempfile v3.4.0
   Compiling security-framework v2.8.2
   Compiling crossbeam-deque v0.8.3
   Compiling getrandom v0.2.8
   Compiling paste v1.0.11
   Compiling async-trait v0.1.64
   Compiling glob v0.3.1
   Compiling httpdate v1.0.2
   Compiling find_cuda_helper v0.2.0
   Compiling rand_core v0.6.4
   Compiling onig_sys v69.8.1
   Compiling axum-core v0.3.2
   Compiling minimal-lexical v0.2.1
   Compiling smallvec v1.10.0
   Compiling darling_core v0.14.3
   Compiling unicode-normalization v0.1.22
   Compiling esaxx-rs v0.1.8
   Compiling ppv-lite86 v0.2.17
   Compiling http-range-header v0.3.0
   Compiling unicode-bidi v0.3.10
   Compiling thiserror v1.0.38
   Compiling mime v0.3.16
   Compiling idna v0.3.0
   Compiling rand_chacha v0.3.1
   Compiling nom v7.1.3
   Compiling cudarc v0.7.5 (https://github.com/coreylowman/cudarc#6a01c299)
   Compiling rayon v1.6.1
   Compiling itertools v0.8.2
   Compiling axum v0.6.9
   Compiling aho-corasick v0.7.20
   Compiling base64 v0.13.1
   Compiling overload v0.1.1
   Compiling regex-syntax v0.6.28
   Compiling macro_rules_attribute-proc_macro v0.1.3
   Compiling unicode-segmentation v1.10.1
   Compiling nu-ansi-term v0.46.0
   Compiling futures-macro v0.3.26
   Compiling tokio-macros v1.8.2
   Compiling tracing-attributes v0.1.23
   Compiling darling_macro v0.14.3
   Compiling pin-project-internal v1.0.12
   Compiling thiserror-impl v1.0.38
   Compiling darling v0.14.3
   Compiling derive_builder_core v0.12.0
   Compiling pin-project v1.0.12
   Compiling regex v1.7.1
   Compiling tracing v0.1.37
   Compiling derive_builder_macro v0.12.0
   Compiling rayon-cond v0.1.0
   Compiling macro_rules_attribute v0.1.3
   Compiling url v2.3.1
error: failed to run custom build command for `cudarc v0.7.5 (https://github.com/coreylowman/cudarc#6a01c299)`

Caused by:
  process didn't exit successfully: `/Users/ondrej/repos/fast_gpt2/target/release/build/cudarc-d4bd025549ae484a/build-script-build` (exit status: 101)
  --- stderr
  thread 'main' panicked at 'Could not find a cuda installation', /Users/ondrej/.cargo/registry/src/github.com-1ecc6299db9ec823/find_cuda_helper-0.2.0/src/lib.rs:12:13
  note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
warning: build failed, waiting for other jobs to finish...

Do you require a GPU to run fast_gpt2?

@Narsil
Copy link
Owner

Narsil commented Mar 4, 2023

Do you have cuda installed ? If yes, try setting CUDA_HOME so it can be detected.

@Narsil
Copy link
Owner

Narsil commented Mar 4, 2023

And no, you shouldn't need cuda, but I may have messed up my options.

It's going to be slow on M1, as there's no matmul acceleration on M1 for now, I focused on inteal and cuda.

@certik
Copy link
Author

certik commented Mar 4, 2023

I have a working matmul acceleration using the Accelerate framework on M1, it's very fast, here is how you do it:

#include <Accelerate/Accelerate.h>

void acc_sgemm(int m, int n, int k, float *A, float *B, float *C) {
    //A[m][k]
    //B[k][n]
    //C[m][n]
    cblas_sgemm(CblasColMajor, CblasNoTrans, CblasNoTrans, m, n, k, 1.0, A, m, B, k, 0.0, C, m);
}

void acc_sgemm_t(int m, int n, int k, float *A, float *B, float *C) {
    //A[k][m] (to be transposed)
    //B[k][n]
    //C[m][n]
    cblas_sgemm(CblasColMajor, CblasTrans, CblasNoTrans, m, n, k, 1.0, A, k, B, k, 0.0, C, m);
}

and compile with:

clang -framework accelerate ...

Let's get it working first without acceleration. I don't have cuda, I don't think it even works on M1, correct?

Do you know what I need to do to compile your code and run it?

@Narsil
Copy link
Owner

Narsil commented Mar 4, 2023

I fixed on main.

@certik
Copy link
Author

certik commented Mar 4, 2023

It works now:

$ cargo run --example run --release
   Compiling serde v1.0.152
   Compiling tokio-util v0.7.7
   Compiling onig_sys v69.8.1
   Compiling tower v0.4.13
   Compiling tokio-native-tls v0.3.1
   Compiling axum-core v0.3.2
   Compiling derive_builder v0.12.0
   Compiling unicode-normalization-alignments v0.1.12
   Compiling esaxx-rs v0.1.8
   Compiling rand v0.8.5
   Compiling itertools v0.9.0
   Compiling onig v6.4.0
   Compiling thread-tree v0.3.3
   Compiling tower-http v0.4.0
   Compiling h2 v0.3.16
   Compiling sharded-slab v0.1.4
   Compiling tracing-log v0.1.3
   Compiling futures-executor v0.3.26
   Compiling thread_local v1.1.7
   Compiling encoding_rs v0.8.32
   Compiling sync_wrapper v0.1.2
   Compiling ipnet v2.7.1
   Compiling fast_gpt2 v0.1.0 (/Users/ondrej/repos/fast_gpt2)
   Compiling matchit v0.7.0
   Compiling unicode_categories v0.1.1
   Compiling rawpointer v0.2.1
   Compiling base64 v0.21.0
   Compiling matrixmultiply v0.3.2
   Compiling tracing-subscriber v0.3.16
   Compiling futures v0.3.26
   Compiling tower-http v0.3.5
   Compiling memmap2 v0.5.10
   Compiling serde_json v1.0.93
   Compiling serde_urlencoded v0.7.1
   Compiling serde_path_to_error v0.1.9
   Compiling spm_precompiled v0.1.4
   Compiling safetensors v0.2.9 (https://github.com/huggingface/safetensors#488d945c)
   Compiling tokenizers v0.13.2 (https://github.com/huggingface/tokenizers?branch=main#ac552ff8)
   Compiling hyper v0.14.24
   Compiling hyper-tls v0.5.0
   Compiling axum v0.6.9
   Compiling reqwest v0.11.14
    Finished release [optimized] target(s) in 36.00s
     Running `target/release/examples/run`
Downloading "https://huggingface.co/gpt2/resolve/main/model.safetensors" into "model-gpt2.safetensors"
Safetensors 108.405665s
Downloading "https://huggingface.co/gpt2/resolve/main/tokenizer.json" into "tokenizer-gpt2.json"
Tokenizer 109.764477208s
Loaded & encoded 110.203344708s
Loop in 83.535791ms
Loop in 81.04725ms
Loop in 80.296291ms
Loop in 79.598666ms
Loop in 82.383833ms
Loop in 79.87375ms
Loop in 80.236916ms
Loop in 80.190708ms
Loop in 80.888ms
Loop in 79.666916ms
Result Ok("My name is John. I'm a man of God. I")
Total Inference 111.011249708s

Thanks for the fix!

@certik certik closed this as completed Mar 4, 2023
@Narsil
Copy link
Owner

Narsil commented Mar 4, 2023

--features cblas is already better, I'm trying to get accelerate in the mix.

@Narsil
Copy link
Owner

Narsil commented Mar 4, 2023

Somehow accelerate using blas-src seems much slower... Very odd.

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

2 participants