| Summary: | Create Vector Math library shared with Rust's project portable SIMD (`std::simd`) | ||
|---|---|---|---|
| Product: | Libre-SOC's first SoC | Reporter: | Jacob Lifshay <programmerjake> |
| Component: | Source Code | Assignee: | Jacob Lifshay <programmerjake> |
| Status: | IN_PROGRESS --- | ||
| Severity: | enhancement | CC: | libre-soc-bugs, lkcl, programmerjake |
| Priority: | --- | ||
| Version: | unspecified | ||
| Hardware: | Other | ||
| OS: | Linux | ||
| NLnet milestone: | NLnet.2019.02.012 | total budget (EUR) for completion of task and all subtasks: | 1000 |
| budget (EUR) for this task, excluding subtasks' budget: | 0 | parent task for budget allocation: | 54 |
| child tasks for budget allocation: | 652 | The table of payments (in EUR) for this task; TOML format: | |
| Bug Depends on: | 652 | ||
| Bug Blocks: | 54 | ||
|
Description
Jacob Lifshay
2021-04-26 00:28:41 BST
Matching bug on Rust's std::simd bugtracker: https://github.com/rust-lang/stdsimd/issues/109 provisionally assigning EUR 2000, to be adjusted as needed. (In reply to Jacob Lifshay from comment #2) > provisionally assigning EUR 2000, to be adjusted as needed. be very careful about assigning funds: there is only around EUR 2500 left from the NLnet 2019 or it might actually be over-budget. we *may* be able to receive some funds from NLnet if they have spare, however it is not guaranteed. very quick hack to get the total payments issued per top-level milestone https://git.libre-soc.org/?p=utils.git;a=commitdiff;h=df61adb514d7e33819e3672eebf6fde279118d2c Milestone(identifier='NLnet.2019.02', canonical_bug_id=191) 27525 we're good. it's a lot less than i thought. at least 22,000 available. ah. just a reminder, jacob: we cannot deviate from the original (agreed) Memorandum of Understanding. we simply cannot arbitrarily "add new tasks". however, if during the course of implementing one such pre-agreed task, a library happens to be needed which does not exist, then yes, that's perfectly fine. (In reply to Luke Kenneth Casson Leighton from comment #5) > ah. just a reminder, jacob: we cannot deviate from the original > (agreed) Memorandum of Understanding. we simply cannot arbitrarily > "add new tasks". > > however, if during the course of implementing one such pre-agreed task, > a library happens to be needed which does not exist, then yes, > that's perfectly fine. Yup! We'd need this library because a SimpleV-capable math library doesn't exist, we need to build one. We can share the implementation costs with Rust's std::simd (which also wants a vector math library without libc, libm, or OS dependencies for use in Rust's `core` library). In particular, this means the math library will have generic vector-length-independent implementations written in Rust. Started an implementation at https://salsa.debian.org/Kazan-team/vector-math From https://github.com/rust-lang/stdsimd/issues/109#issuecomment-831196244 Got all the vector traits wired up for use with scalars (where all vectors are length 1 for testing purposes or otherwise) and with generating demo compiler IR. Still need to wire up `std::simd` support. https://salsa.debian.org/Kazan-team/vector-math/-/blob/7975aa9639f3a5a702b130a7cf992ffe71c86e2a/src/ir.rs#L1547 The following Rust: ```rust fn f<Ctx: Context>(ctx: Ctx, a: Ctx::VecU8, b: Ctx::VecF32) -> Ctx::VecF64 { let a: Ctx::VecF32 = a.into(); (a - (a + b - ctx.make(5f32)).floor()).to() } ``` (the `to()` function is a replacement for the `as` keyword) Generates the following demo IR: ``` function(in<arg_0>: vec<U8>, in<arg_1>: vec<F32>) -> vec<F64> { op_0: vec<F32> = Cast in<arg_0> op_1: vec<F32> = Add op_0, in<arg_1> op_2: vec<F32> = Sub op_1, splat(0x40A00000_f32) op_3: vec<F32> = Floor op_2 op_4: vec<F32> = Sub op_0, op_3 op_5: vec<F64> = Cast op_4 Return op_5 } ``` Opinions on ease of use for writing functions like `f`? From https://github.com/rust-lang/stdsimd/issues/109#issuecomment-832573074 I added bindings for std::simd: https://salsa.debian.org/Kazan-team/vector-math/-/commit/d77893b257c86d7ddc81f3772b5e143ce768d291 Looking at the assembly generated for stdsimd::tests::do_ilogb_f32x4, it looks pretty reasonable, everything's inlined, however there is still some branching that llvm didn't optimize out: <snip> Compiled using: cargo rustc --release --tests --features=ir,fma,stdsimd -- --emit=asm -C target-cpu=native on a Ryzen 3900X on Ubuntu From https://github.com/rust-lang/stdsimd/issues/109#issuecomment-836310527 I added implementations of `sin_pi` and `cos_pi` for `f16` and `f32`, I tested all possible inputs, the functions are accurate to 2ULP though aren't guaranteed to give the correct sign for zeros. Testing the `f32` functions required writing a custom reference implementation of `sin_cos_pi` since `(x * f64::consts::PI).sin_cos()` isn't accurate enough when the exact mathematical value of either `sin` or `cos` is close to zero (e.g. `sin_pi(1.0) == 0.0` but `f64::consts::PI.sin() != 0.0` due to round-off error). https://salsa.debian.org/Kazan-team/vector-math/-/blob/d79f43bed2398cbc4f6b75b8e55ee317289599a1/src/algorithms/trig_pi.rs#L180 Added implementations for sin_pi/cos_pi/sin_cos_pi_f16/f32/f64 I added sin_pi and cos_pi for f64, as well as adding abs, copy_sign, and trunc for all of f16/f32/f64. (In reply to Jacob Lifshay from comment #8) > https://salsa.debian.org/Kazan-team/vector-math/-/blob/ > 7975aa9639f3a5a702b130a7cf992ffe71c86e2a/src/ir.rs#L1547 remember always always always request / create a git.libre-soc.org repository. done now https://git.libre-soc.org/?p=vector-math.git;a=summary (In reply to Luke Kenneth Casson Leighton from comment #13) > remember always always always request / create a git.libre-soc.org > repository. > > done now > https://git.libre-soc.org/?p=vector-math.git;a=summary I'll manually keep that up to date (setting up mirroring is a pain), but, since vector-math is part of Kazan, the canonical repo location is https://salsa.debian.org/Kazan-team/vector-math I added round_to_nearest_ties_to_even, ceil, floor, and tan_pi Added count_leading_zeros, count_trailing_zeros, and count_ones |