Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworking f16 #46

Merged
merged 8 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 29 additions & 5 deletions .github/workflows/build_push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ jobs:
- uses: actions/checkout@v4
- uses: actions-rust-lang/setup-rust-toolchain@v1
- run: rustup target add aarch64-unknown-linux-gnu x86_64-unknown-linux-gnu i686-unknown-linux-gnu powerpc-unknown-linux-gnu riscv64gc-unknown-linux-gnu
- run: RUSTFLAGS="-C target-feature=+neon,-fp16" cargo build --target aarch64-unknown-linux-gnu --features half
- run: RUSTFLAGS="-C target-feature=+neon,+fp16" cargo build --target aarch64-unknown-linux-gnu --features half
- run: RUSTFLAGS="-C target-feature=+neon,-fp16" cargo build --target aarch64-unknown-linux-gnu
- run: RUSTFLAGS="-C target-feature=+neon,+fp16" cargo +nightly build --target aarch64-unknown-linux-gnu --features nightly_f16
- run: RUSTFLAGS="-C target-feature=+sse4.1" cargo build --target i686-unknown-linux-gnu
- run: cargo build --target powerpc-unknown-linux-gnu
- run: cargo build --target riscv64gc-unknown-linux-gnu
- run: RUSTFLAGS="-C target-feature=+sse4.1" cargo build --target x86_64-unknown-linux-gnu
- run: RUSTFLAGS="-C target-feature=+sse4.1,+f16c" cargo build --features half --target x86_64-unknown-linux-gnu
- run: RUSTFLAGS="-C target-feature=+avx2,+f16c" cargo build --features half --target x86_64-unknown-linux-gnu
- run: RUSTFLAGS="-C target-feature=+sse4.1,+f16c" cargo +nightly build --features nightly_f16 --target x86_64-unknown-linux-gnu
- run: RUSTFLAGS="-C target-feature=+avx2,+f16c" cargo +nightly build --features nightly_f16 --target x86_64-unknown-linux-gnu
- run: RUSTFLAGS="-C target-feature=+avx2" cargo build --target x86_64-unknown-linux-gnu

clippy:
Expand All @@ -42,7 +42,18 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo clippy
- run: cargo clippy -- -D warnings

clippy_nightly:
name: Clippy Nightly
strategy:
matrix:
os: [ ubuntu-latest, macos-latest ]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo clippy --all-features -- -D warnings

tests:
name: Testing
Expand Down Expand Up @@ -71,6 +82,18 @@ jobs:
- run: cargo fuzz run resize_plane -- -max_total_time=30
- run: cargo fuzz run colorspaces -- -max_total_time=10

fuzz_rgba_8bit_no_rdm:
name: Fuzzing 8bit wo RDM
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz run resize_rgba --no-default-features -- -max_total_time=30
- run: cargo fuzz run resize_rgb --no-default-features -- -max_total_time=30
- run: cargo fuzz run resize_cbcr8 --no-default-features -- -max_total_time=30
- run: cargo fuzz run resize_plane --no-default-features -- -max_total_time=30

fuzz_rgba_high_bit:
name: Fuzzing High bit-depth
strategy:
Expand All @@ -82,6 +105,7 @@ jobs:
- uses: dtolnay/rust-toolchain@nightly
- run: cargo install cargo-fuzz
- run: cargo fuzz run resize_rgba_u16 -- -max_total_time=30
- run: cargo fuzz run resize_rgba_f16 -- -max_total_time=30
- run: cargo fuzz run resize_rgb_u16 -- -max_total_time=30
- run: cargo fuzz run resize_cbcr16 -- -max_total_time=30
- run: cargo fuzz run resize_plane_u16 -- -max_total_time=30
Expand Down
11 changes: 1 addition & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 5 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ workspace = { members = ["app", "wasm", "fuzz", "app/accelerate"], exclude = ["p

[package]
name = "pic-scale"
version = "0.4.2"
version = "0.5.0"
edition = "2021"
description = "High performance image scaling"
readme = "README.md"
Expand All @@ -18,15 +18,16 @@ rust-version = "1.82.0"

[dependencies]
colorutils-rs = {version = "0.7.4", optional = true}
half = { version = "2.4.1", optional = true, features = ["alloc", "std", "num-traits"] }
num-traits = { version = "0.2.19", features = ["std"] }
rayon = "1.10.0"

[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
libc = "0.2.158"

[features]
default = ["colorspaces"]
default = ["colorspaces", "rdm"]
colorspaces = ["dep:colorutils-rs"]
nightly_avx512 = []
nightly_avx512fp16 = ["nightly_avx512"]
nightly_avx512fp16 = ["nightly_avx512"]
nightly_f16 = []
rdm = []
5 changes: 2 additions & 3 deletions app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ edition = "2021"

[dependencies]
image = { version = "0.25.5", features = ["default"] }
#image = { path= "../../../RustroverProjects/image", features = ["default", "avif", "avif-native"] }
pic-scale = { path = "..", features = ["half"], default-features = true }
pic-scale = { path = "..", features = ["nightly_f16"], default-features = false }
fast_image_resize = { version = "5.0.0", features = [] }
half = { version = "2.4.1", default-features = true }
accelerate = {path = "accelerate/"}
Expand All @@ -16,7 +15,7 @@ libc = "0.2.169"
criterion = "0.5.1"
#image = { version = "0.25.2", features = ["default"] }
fast_image_resize = { version = "5.0.0", features = [] }
pic-scale = { path = "..", features = ["half"] }
pic-scale = { path = "..", features = ["nightly_f16", "rdm"], default-features = false }

[[bench]]
name = "resize_rgb"
Expand Down
9 changes: 9 additions & 0 deletions app/accelerate/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ mod accelerate {
flags: libc::c_uint,
) -> libc::c_int;

#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
pub fn vImageScale_XRGB2101010W(
src: *const vImage_Buffer,
dest: *mut vImage_Buffer,
temp_buffer: *mut libc::c_void,
flags: libc::c_uint,
) -> libc::c_int;

#[allow(non_camel_case_types)]
#[allow(non_snake_case)]
pub fn vImageScale_ARGBFFFF(
Expand Down
18 changes: 17 additions & 1 deletion app/benches/resize_rgb/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use fast_image_resize::{CpuExtensions, PixelType, ResizeAlg, ResizeOptions, Resi
use image::{EncodableLayout, GenericImageView, ImageReader};
use pic_scale::{
ImageStore, ImageStoreMut, ResamplingFunction, Scaler, Scaling, ScalingF32, ScalingU16,
ThreadingPolicy,
ThreadingPolicy, WorkloadStrategy,
};

pub fn criterion_benchmark(c: &mut Criterion) {
Expand All @@ -25,6 +25,22 @@ pub fn criterion_benchmark(c: &mut Criterion) {
b.iter(|| {
let mut scaler = Scaler::new(ResamplingFunction::Lanczos3);
scaler.set_threading_policy(ThreadingPolicy::Single);
scaler.set_workload_strategy(WorkloadStrategy::PreferSpeed);
let mut target =
ImageStoreMut::alloc(dimensions.0 as usize / 4, dimensions.1 as usize / 4);
scaler.resize_rgb(&store, &mut target).unwrap();
})
});

c.bench_function("Pic scale RGB: Lanczos 3/Quality", |b| {
let copied: Vec<u8> = Vec::from(src_bytes);
let store =
ImageStore::<u8, 3>::from_slice(&copied, dimensions.0 as usize, dimensions.1 as usize)
.unwrap();
b.iter(|| {
let mut scaler = Scaler::new(ResamplingFunction::Lanczos3);
scaler.set_threading_policy(ThreadingPolicy::Single);
scaler.set_workload_strategy(WorkloadStrategy::PreferQuality);
let mut target =
ImageStoreMut::alloc(dimensions.0 as usize / 4, dimensions.1 as usize / 4);
scaler.resize_rgb(&store, &mut target).unwrap();
Expand Down
Loading