x86_64 intrinsics rustfft needs, and Windows symbols whose DLL is not loaded yet

Aperta
#264 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
18/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust

Direzione di ricerca

Two separate pieces. For the intrinsics, read libs/relax/compiler/std/core/arch/x86_64.rs and run libs/relax/compiler/tests/rustfft_avx_intrinsics.rs first; done means its expected numbers match rustc's stdarch output. For the Windows gap, start at find_system in libs/relax/compiler/src/os/proc.rs and reproduce with the winit 0.30 snippet (also with NO_DND=1); done means both print window created, theme: Some(Dark). The reporter's fork commits are the reference, but the fixed DLL list is called a stopgap, so expect design discussion.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Two independent gaps, both found running Suhina (an open-source DAW in Rust, on eframe/winit 0.30 and rustfft 6.4) under relax run on Windows; rustc builds and runs both cases. The first hits any program that uses rustfft 6.4 on x86_64: both its SSE and its AVX paths call intrinsics Relax's std lacks. The second hits Windows programs whose Win32 calls go through windows-sys 0.52 to 0.60 (windows-targets) when nothing has loaded the function's DLL yet; winit 0.30 does this for ole32 and uxtheme when it creates a window. windows-sys 0.61 and later (windows-link) name the DLL and are not affected.

Fixes for both are in my fork, linked in each section; the branch also carries an unrelated local commit, so please take the commits listed here only.

1. core::arch::x86_64 lacks intrinsics rustfft 6.4 calls

rustfft 6.4's SSE and AVX butterflies call intrinsics Relax's std lacks. On a CPU with AVX and FMA the first FFT stops at a compile error on _mm256_moveldup_ps and parks the thread that runs it; without AVX, the SSE path needs _mm_load1_ps, _mm_moveldup_ps, _mm_addsub_ps and _mm_blend_ps.

Every intrinsic the two paths name that std lacked:

_mm_load1_ps, _mm_load_ps1, _mm_moveldup_ps, _mm_addsub_ps, _mm_blend_ps, _mm_permute_ps, _mm_broadcast_ss, _mm_fmaddsub_ps, _mm_fmsubadd_ps, _mm256_moveldup_ps, _mm256_movehdup_ps, _mm256_blend_ps, _mm256_permute_ps, _mm256_broadcast_ss, _mm256_castps128_ps256, _mm256_zextps128_ps256, _mm256_insertf128_ps, _mm256_fmaddsub_ps, _mm256_fmsubadd_ps, _mm256_loadu2_m128d

Fix: the intrinsics in std/core/arch/x86_64.rs (commits 8992487, 64f17de, a1f8a5f), and a test, tests/rustfft_avx_intrinsics.rs, that checks the same expected numbers under rustc (against stdarch) and under Relax.

With the fix the intrinsics run 4 to 7 times slower than rustc's code (add and mul 3 to 4). rustfft 6.4 under the JIT, forward FFT, f32:

Size Relax main Relax with the fix rustc AVX
5400 points stops at the compile error 24–27 µs 7.5 µs
4096 points stops at the compile error 75–300 µs 4.5 µs

Which size is fast moves with small changes in std. The time left is in the O3 build of rustfft's large butterflies (Butterfly512Avx::column_butterflies_and_transpose), where the JIT also reports an inline candidate it leaves out.

2. Windows: a symbol whose DLL nothing has loaded yet is "not available on this host"

windows-targets 0.52 and 0.53 (used by windows-sys 0.52 to 0.60) name a function's DLL in link! only under windows_raw_dylib, a cfg cargo resolves dependencies by, so Relax cannot set it. Without it the extern block links the import library windows.0.5x.0, which names no DLL to load. windows-link (windows-sys 0.61+) always uses raw-dylib with the DLL's name, which Relax already loads.

Such a symbol resolves only once other code has loaded its DLL into the process. A winit 0.30 app that only opens a window meets it at once: winit calls OleInitialize (ole32.dll, for drag and drop) and SetWindowTheme (uxtheme.dll) while it creates the window, before anything has loaded either.

Reproduction (Windows 11, x86_64; winit 0.30.13, windows-sys 0.52.0):

[dependencies]
winit = { version = "=0.30.13", default-features = false, features = ["rwh_06"] }
use winit::application::ApplicationHandler;
use winit::event::WindowEvent;
use winit::event_loop::{ActiveEventLoop, EventLoop};
use winit::window::{Window, WindowId};

#[derive(Default)]
struct App {
    window: Option<Window>,
}

impl ApplicationHandler for App {
    fn resumed(&mut self, event_loop: &ActiveEventLoop) {
        println!("creating window");
        let attributes = {
            use winit::platform::windows::WindowAttributesExtWindows;
            Window::default_attributes()
                .with_title("winit-theme")
                .with_drag_and_drop(std::env::var_os("NO_DND").is_none())
        };
        match event_loop.create_window(attributes) {
            Ok(window) => {
                println!("window created, theme: {:?}", window.theme());
                self.window = Some(window);
            }
            Err(e) => println!("create_window failed: {e}"),
        }
        event_loop.exit();
    }

    fn window_event(&mut self, _: &ActiveEventLoop, _: WindowId, _: WindowEvent) {}
}

fn main() {
    let event_loop = match EventLoop::new() {
        Ok(l) => l,
        Err(e) => return println!("event loop failed: {e}"),
    };
    let mut app = App::default();
    if let Err(e) = event_loop.run_app(&mut app) {
        println!("run_app failed: {e}");
    }
    println!("done");
}

relax run on main (148c09246), registry paths shortened:

creating window

thread 'main' panicked at windows-sys-0.52.0/src/Windows/Win32/System/Ole/mod.rs:119:1:
foreign function `OleInitialize` is not available on this host -- cfg the call out or link its library
relax: `windows-sys` 0.52.0: an item Relax cannot compile (if cargo builds it, a Relax gap: report it)
relax: main panic: foreign function `OleInitialize` is not available on this host -- cfg the call out or link its library

With drag and drop off (NO_DND=1), the next one fails the same way:

creating window

thread 'main' panicked at windows-sys-0.52.0/src/Windows/Win32/UI/Controls/mod.rs:368:1:
foreign function `SetWindowTheme` is not available on this host -- cfg the call out or link its library
relax: `windows-sys` 0.52.0: an item Relax cannot compile (if cargo builds it, a Relax gap: report it)
relax: main panic: foreign function `SetWindowTheme` is not available on this host -- cfg the call out or link its library

The rustc build, and Relax with the fix below, print window created, theme: Some(Dark) and done in both forms.

Fix: find_system in src/os/proc.rs (commit 91a3608). When no loaded module exports the symbol, it also tries about 30 common system DLLs windows-sys imports from (user32, gdi32, uxtheme, dwmapi, shell32, ole32, dxgi, d3d12 and so on), loaded from System32 only. It works, but a fixed list is a stopgap: reading each symbol's DLL name from the import library would cover every DLL.

Lingua principale
Rust
Stelle
601
Fork
34
Merge medio
1h 58m
PR unite (30g)
45

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di makepad/relax

Tutte le issue di makepad/relax

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.