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

Support for Apple Silicon(aarch64, M1) #161

Closed
JakkuSakura opened this issue Dec 26, 2020 · 15 comments
Closed

Support for Apple Silicon(aarch64, M1) #161

JakkuSakura opened this issue Dec 26, 2020 · 15 comments

Comments

@JakkuSakura
Copy link

I ran into a problem while compiling.

   Compiling value-trait v0.1.19
error[E0425]: cannot find function `write_str_simd` in this scope
   --> /Users/jack/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/value-trait-0.1.19/src/generator.rs:162:19
    |
162 |             stry!(write_str_simd(self.get_writer(), &mut string,));
    |                   ^^^^^^^^^^^^^^ not found in this scope

I looked up the value-trait and added

value-trait = { version = "*", features = ["neon"] }

The problem became

   Compiling value-trait v0.1.19
error[E0614]: type `u8` cannot be dereferenced
   --> /Users/jack/.cargo/registry/src/mirrors.tuna.tsinghua.edu.cn-df7c3c540f42cdbd/value-trait-0.1.19/src/generator.rs:669:48
    |
669 |                 b'u' => stry!(u_encode(writer, *ch)),
    |                                                ^^^

Since value-trait is not in active development, I post the issue here as well.

➜  ~ neofetch
                    'c.          jack@jacks-MacBook-Air.local
                 ,xNMM.          ----------------------------
               .OMMMMo           OS: macOS 11.1 20C69 arm64
               OMMM0,            Host: MacBookAir10,1
     .;loddo:' loolloddol;.      Kernel: 20.2.0
   cKMMMMMMMMMMNWMMMMMMMMMM0:    Uptime: 18 hours, 36 mins
 .KMMMMMMMMMMMMMMMMMMMMMMMWd.    Packages: 45 (brew)
 XMMMMMMMMMMMMMMMMMMMMMMMX.      Shell: zsh 5.8
;MMMMMMMMMMMMMMMMMMMMMMMM:       Resolution: 1440x900
:MMMMMMMMMMMMMMMMMMMMMMMM:       DE: Aqua
.MMMMMMMMMMMMMMMMMMMMMMMMX.      WM: Quartz Compositor
 kMMMMMMMMMMMMMMMMMMMMMMMMWd.    WM Theme: Blue (Dark)
 .XMMMMMMMMMMMMMMMMMMMMMMMMMMk   Terminal: iTerm2
  .XMMMMMMMMMMMMMMMMMMMMMMMMK.   Terminal Font: FiraCode-Regular 12
    kMMMMMMMMMMMMMMMMMMMMMMd     CPU: Apple M1
     ;KMMMMMMMWXXWMMMMMMMk.      GPU: Apple M1
       .cooc,.    .,coo:.        Memory: 1296MiB / 8192MiB



@Gelbpunkt
Copy link
Contributor

Exact same issue happens with aarch64-unknown-linux-musl target and probably -gnu.

@Licenser
Copy link
Member

Thank you for reaching out, sorry for the late reply there was a vacation in the way. So far arm support has been experimental at best as the rust neon intrinsitcs are a moving target I'll go and see if things have stabalized a bit to iron this out.

@Licenser
Copy link
Member

Looking at it this requires finalzing the port to the new utf8 parsing to arm. @CJP10 any chance you can way in and hint me to where you ported the avx bits from I don't see it mapping to upstream simd_json but things change there quickly -.-

@CJP10
Copy link
Contributor

CJP10 commented Jan 15, 2021

@hkratz
Copy link
Contributor

hkratz commented May 2, 2021

I have extracted, much improved the UTF-8 validation in simdutf8 and just added aarch64 neon support (to be released). Once I have a proper streaming API implemented (see rusticstuff/simdutf8#25) I can add a pull request which replaces the UTF-8 validation in simd-json. This would serve as a good testcase for the streaming API as well.

If this does not work without a performance penalty I will expose a specialized 64-byte update function directly.

@Licenser, @CJP10 Would that be acceptable?

@Licenser
Copy link
Member

Licenser commented May 3, 2021

That would be absolutely lovely and hugely appreciated!

@hkratz
Copy link
Contributor

hkratz commented May 14, 2021

Since merging the simdutf8 integration the only missing piece for making it compile on aarch64 is the missing vmull_p64 intrinsic, see rust-lang/stdarch#1157. When that is merged and stdarch is updated in nightly we can try it out.

@Licenser
Copy link
Member

I relased your and @mfelsche fixes in v0.4.5 🚀

@hkratz
Copy link
Contributor

hkratz commented May 16, 2021

simd-json will work on aarch64 again real soon now, see #195. We are just waiting to get stdarch bumped in nightly.

@Licenser
Copy link
Member

You are incredible @hkratz ! :D

@Licenser
Copy link
Member

Licenser commented Jun 3, 2021

I think we can close this, M1 works, arm in general works too :D 🚀 it requires nightly but that's fine I think

Thank you all!

@Licenser Licenser closed this as completed Jun 3, 2021
@Sparkenstein
Copy link

Sparkenstein commented Feb 15, 2022

It looks like I am also facing the same issue. I am trying to use sidm-json with wasm-bindgen + deno that's the only difference. I checked if simd is enabled with webassembly with wasm-feature-detect and it looks like it's enabled as well.

Code:
rust function is simple hello world fn:

#[wasm_bindgen]
pub fn to_string(_s: &str) -> String {
    "test".to_string()
}

deno: (ignore the function names, the error is at build time)

import init, { greet } from "../pkg/denosimd.js";
await init(Deno.readFile("./pkg/denosimd_bg.wasm"));

greet("Hello from deno to rust");

Error:

[INFO]: Checking for the Wasm target...
[INFO]: Compiling to Wasm...
   Compiling value-trait v0.2.9
error[E0425]: cannot find function `write_str_simd` in this scope
   --> C:\Users\Spark\.cargo\registry\src\github.com-1ecc6299db9ec823\value-trait-0.2.9\src\generator.rs:162:19
    |
162 |             stry!(write_str_simd(self.get_writer(), &mut string,));
    |                   ^^^^^^^^^^^^^^ not found in this scope

For more information about this error, try `rustc --explain E0425`.
error: could not compile `value-trait` due to previous error
Error: Compiling your crate to WebAssembly failed

let me know if you need any more inputs from my side

@Licenser
Copy link
Member

Hi,

simd-json depends on the system running it exposes SIMD features, namely SSE4.2 or AVX2. AFAIK WASM is a runtime that doesn't expose CPU native instructions so SIMD isn't available there.

@sam-kirby
Copy link
Contributor

Whilst WASM doesn't expose the native CPU instructions, it does have its own SIMD intrinsics (see https://doc.rust-lang.org/core/arch/wasm32/index.html#simd).

I had a quick look at porting this crate to WASM this evening and it seems to be feasible. I've not had a chance to test it in the slightest, but it builds. (https://github.com/sam-kirby/simd-json/tree/wasm)

I'll try including it in a yew project I'm working on tomorrow and see if it a) works and b) offers any performance improvements.

@Licenser
Copy link
Member

Oh that's pretty neat! Lets put that in a new ticket so it's hot hidden somewhere ina closed issue about M1 support :)

@Licenser Licenser mentioned this issue Feb 18, 2022
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

7 participants