Rust-Simd Hello World

发布于 2025-02-01 12:14:35 字数 791 浏览 5 评论 0原文

我找不到Rust-Simd的工作示例。我能找到的最接近的是。调整后,它变成了:

#![feature(core)]
#![feature(portable_simd)]

use std::simd::f32x4;

fn main() {
    let x = f32x4(1.0, 1.0, 1.0, 1.0);
}

但是在建造过程中仍然抱怨货物

error[E0423]: expected function, found type alias `f32x4`
 --> src/main.rs:7:13
  |
7 |     let x = f32x4(1.0, 1.0, 1.0, 1.0);
  |             ^^^^^
  |
  = note: can't use a type alias as a constructor

我如何获得这个简单的示例?

cargo.toml

[package]
name = "rust-simd"
version = "0.1.0"
edition = "2021"

[dependencies]

我有夜间已经打开了:Rustup默认默认夜间

I couldn't find a working example for Rust-SIMD. The closest I can find is this one. After adjusting, it becomes:

#![feature(core)]
#![feature(portable_simd)]

use std::simd::f32x4;

fn main() {
    let x = f32x4(1.0, 1.0, 1.0, 1.0);
}

But still cargo complains

error[E0423]: expected function, found type alias `f32x4`
 --> src/main.rs:7:13
  |
7 |     let x = f32x4(1.0, 1.0, 1.0, 1.0);
  |             ^^^^^
  |
  = note: can't use a type alias as a constructor

during building.

How do I get this simple example working?

Cargo.toml:

[package]
name = "rust-simd"
version = "0.1.0"
edition = "2021"

[dependencies]

I have nightly switched on already: rustup default nightly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

末蓝 2025-02-08 12:14:35

std :: Simdtype :: From(array),例如f32x4 ::来自([1.0,1.0,1.0,1.0, 1.0,1.0])。提到

The way to construct a SIMD vector with std::simd is type::from(array), for example f32x4::from([1.0, 1.0, 1.0, 1.0]). This is mentioned in the documentation.

月竹挽风 2025-02-08 12:14:35

#![feature(portable_simd)]应该在顶部
包装的主文件,例如Main.R。

正如您已经提到的:

rustup default nightly

然后在您使用SIMD的文件中,您需要
这样:

use std::simd::prelude::*;

然后simd :: from_array的方法期望一个数组[f32; n_vec]其中n_vec是范围内2的功率量[1,64]

:例如:

const N_VEC: usize = 16;
let a:[f32; N_VEC] = [1.0f32; N_VEC];
let a_simd: Simd<f32, N_VEC> = Simd::from_array(a);

#![feature(portable_simd)] should be at the top
of the main file of the package, e.g. main.rs.

and as you already mentioned:

rustup default nightly

then in the file where you are using simd, you need
this:

use std::simd::prelude::*;

then the method Simd::from_array expects an array [f32; N_VEC] where N_VEC is a const of power of 2 in range [1, 64]

for example:

const N_VEC: usize = 16;
let a:[f32; N_VEC] = [1.0f32; N_VEC];
let a_simd: Simd<f32, N_VEC> = Simd::from_array(a);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文