Rust-Simd Hello World
我找不到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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
用
std :: Simd
是type :: 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
istype::from(array)
, for examplef32x4::from([1.0, 1.0, 1.0, 1.0])
. This is mentioned in the documentation.#![feature(portable_simd)]
应该在顶部包装的主文件,例如Main.R。
正如您已经提到的:
然后在您使用SIMD的文件中,您需要
这样:
然后simd :: from_array的方法期望一个数组[f32; n_vec]其中n_vec是范围内2的功率量[1,64]
:例如:
#![feature(portable_simd)]
should be at the topof the main file of the package, e.g. main.rs.
and as you already mentioned:
then in the file where you are using simd, you need
this:
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: