49

A pure Rust SIMD accelerated noise library

 5 years ago
source link: https://www.tuicool.com/articles/hit/a6v2eyi
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

rQ7Bben.jpg!web

SIMDNoise

Super fast SIMD noise library for Rust. PRs welcome!

Available on crates.io .

Documentation .

Requires nightly until 1.27 drops

Features

  • SSE2, SSE41, and AVX2 instruction sets, along with non SIMD fallback
  • AVX2 version also leverages FMA3
  • Runtime detection picks the best available instruction set
  • Simplex noise, fractal brownian motion, turbulence, and ridge
  • 2d and 3d

Benchmarks

Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz Single Threaded

2D 1000x1000 FBM Noise, 3 Octaves

  • scalar_2d ... bench: 74,207,703 ns/iter (+/- 2,184,952)
  • sse2_2d ... bench: 23,863,725 ns/iter (+/- 746,331)
  • sse41_2d ... bench: 22,440,765 ns/iter (+/- 995,336)
  • avx2_2d ... bench: 12,022,253 ns/iter (+/- 508,793)

3D 100x100x100 FBM Noise, 3 Octaves

  • scalar_3d ... bench: 102,543,499 ns/iter (+/- 3,310,472)
  • sse2_3d ... bench: 39,991,825 ns/iter (+/- 1,043,332)
  • sse41_3d ... bench: 38,852,436 ns/iter (+/- 1,350,831)
  • avx2_3d ... bench: 23,231,237 ns/iter (+/- 777,420)

Todo

  • AVX512 support
  • ARM NEON support
  • Voroni, Cell, and other noise types

Get a block of noise with runtime SIMD detection

The library will, at runtime, pick the fastest available options between SSE2, SSE41, and AVX2

use simdnoise::*;

// Set up noise type and parameters
let noise_type = simdnoise::NoiseType::FBM {
      freq: 0.04,
      lacunarity: 0.5,
      gain: 2.0,
      octaves: 3,
}; 

// Get a block of 2d 800x600 noise, with no scaling of resulting values
// min and max values are returned so you can apply your own scaling
let (an_f32_vec,min,max) = simdnoise::get_2d_noise(0.0, 800, 0.0, 600, noise_type);

// Get a block of 200x200x200 3d noise
let (an_f32_vec,min,max) = simdnoise::get_3d_noise(0.0, 200, 0.0, 200,0.0, 200, noise_type);

// Get a block of noise scaled between -1 and 1
let an_f32_vec = simdnoise::get_2d_scaled_noise(0.0, 800, 0.0, 600, noise_type,-1.0,1.0);

Call noise functions directly

Sometimes you need something other than a block, like the points on the surface of a sphere. Sometimes you may want to use SSE41 even with AVX2 is available

// get a block of 100x100 sse41 noise, skip runtime detection
let (noise,min,max) = simdnoise::sse41::get_2d_noise(0.0,100,0.0,100,noise_type);

// send your own SIMD x,y values to the noise functions directly
unsafe {
  // sse2 simplex noise
  let x = _mm_set1_ps(5.0);
  let y = _mm_set1_ps(10.0);
  let f : __m128 = simdnoise::sse2::simplex_2d(x,y);
  
  // avx2 turbulence
  let x = _mm256_set1_ps(5.0);
  let y = _mm256_set1_ps(10.0);
  let freq = _mm_256_set1_ps(1.0);
  let lacunarity = _mm256_set1_ps(0.5);
  let gain = _mm256_set1_ps(2.0);
  let octaves = 3;
  let f_turbulence : __m256 = simdnoise::avx2::turbulence_2d(x,y,freq,lacunarity,gain,octaves);
    
}

Recommend

  • 66
    • www.tuicool.com 5 years ago
    • Cache

    Rust 1.27 Adds Support for SIMD

    SIMD support is the most notable new feature in Rust 1.27 , along with a more explicit syntax for traits. SIMD support at the language lev...

  • 52
    • www.infoq.com 5 years ago
    • Cache

    Rust 1.27支持SIMD

    SIMD支持是 Rust 1.27 中最值得一提的新特性,这一版本的Rust同时还带来了更为明确的trait语法。 在语言层面支持SIMD意味着开发人员可以在更高级别...

  • 6
    • vorner.github.io 3 years ago
    • Cache

    Simd Library Plans

    SIMD library plans I believe Rust is a great language to make SIMD actually usable for ordinary humans. I’ve played with libraries to making it accessible two years ago (or was it 3?) and my impression was „Whoa...

  • 7
    • llogiq.github.io 3 years ago
    • Cache

    Rust Faster SIMD edition

    Rust Faster SIMD edition 06 September 2018 It’s been a while since I’ve been playing the benchmarksgame with Rust. But I recently...

  • 5
    • Github github.com 3 years ago
    • Cache

    Tracking issue for stable SIMD in Rust

    Tracking issue for stable SIMD in Rust #48556 alexcrichton op...

  • 4
    • vksegfault.github.io 2 years ago
    • Cache

    SIMD usage in C++, C# and Rust

    SIMD usage in C++, C# and Rust Adrian Jurczak on 9 d ago2021-08-06T00:00:00+02:00 Updated 13 hr ago2021-08-14T23:24:31+02:00 11 min readEveryone heard of SIMD, yet not so many use...

  • 4

    Using SIMD acceleration in rust to create the world’s fastest tac Featuring dynamically-enabled AVX2-acceler...

  • 1

    Authoring a SIMD enhanced Wasm library with Rust Published on: December 13, 2021 Chrome, Firefox, and Node LTS have all stabilized the

  • 9

    SIMD accelerated sorting in Java - how it works and why it was 3x faster 09 Jun 2022 In this post I explain a little about how to use Java’s Vector APIs, attempt to explain how they turn out fast, and then use them to implement a sort...

  • 5
    • www.da.vidbuchanan.co.uk 3 months ago
    • Cache

    SIMD in Pure Python

    SIMD in Pure Python By David Buchanan, 4th January 2024 First of all, this article is an exercise in recreational "because I can" programming. If you just want to make your Python code go fast, this is perhaps n...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK