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

Use std::available_parallelism instead of num_cpus #633

Merged
merged 2 commits into from
May 21, 2022
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
1 change: 0 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository = "https://github.com/master-of-zen/Av1an"
keywords = ["video"]
categories = ["command-line-utilities"]
license = "GPL-3.0"
rust-version = "1.59"
edition = "2021"

[[bin]]
Expand Down
1 change: 1 addition & 0 deletions av1an-cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ repository = "https://github.com/master-of-zen/Av1an"
keywords = ["video"]
categories = ["command-line-utilities"]
license = "GPL-3.0"
rust-version = "1.59"
edition = "2021"

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion av1an-core/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[package]
name = "av1an-core"
version = "0.3.1"
rust-version = "1.59"
edition = "2021"
authors = ["Zen <[email protected]>"]
description = """
Expand All @@ -20,7 +21,6 @@ atty = "0.2.14"
av-format = "0.3.1"
av-ivf = "0.2.2"
memchr = "2.4.1"
num_cpus = "1.13.0"
anyhow = "1.0.42"
rand = "0.8.4"
serde = { version = "1.0", features = ["derive"] }
Expand Down
3 changes: 2 additions & 1 deletion av1an-core/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::process::ExitStatus;
use std::sync::atomic::{self, AtomicU64};
use std::sync::mpsc::Sender;
use std::sync::Arc;
use std::thread::available_parallelism;

use cfg_if::cfg_if;
use memchr::memmem;
Expand Down Expand Up @@ -123,7 +124,7 @@ impl<'a> Broker<'a> {
cfg_if! {
if #[cfg(any(target_os = "linux", target_os = "windows"))] {
if let Some(threads) = set_thread_affinity {
let available_threads = num_cpus::get();
let available_threads = available_parallelism().expect("Unrecoverable: Failed to get thread count").get();
let requested_threads = threads.saturating_mul(self.project.workers);
if requested_threads > available_threads {
warn!(
Expand Down
5 changes: 4 additions & 1 deletion av1an-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ use std::io::Write;
use std::path::{Path, PathBuf};
use std::string::ToString;
use std::sync::atomic::{AtomicBool, AtomicUsize};
use std::thread::available_parallelism;
use std::time::Instant;

use ::ffmpeg::color::TransferCharacteristic;
Expand Down Expand Up @@ -327,7 +328,9 @@ pub fn determine_workers(encoder: Encoder) -> u64 {
let mut system = sysinfo::System::new();
system.refresh_memory();

let cpu = num_cpus::get() as u64;
let cpu = available_parallelism()
.expect("Unrecoverable: Failed to get thread count")
.get() as u64;
// available_memory returns kb, convert to gb
let ram_gb = system.available_memory() / 10_u64.pow(6);

Expand Down
7 changes: 6 additions & 1 deletion av1an-core/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use std::path::{Path, PathBuf};
use std::process::{exit, Command, Stdio};
use std::sync::atomic::{self, AtomicBool, AtomicU64, AtomicUsize};
use std::sync::{mpsc, Arc};
use std::thread::available_parallelism;
use std::{cmp, fs, iter, thread};

use ansi_term::{Color, Style};
Expand Down Expand Up @@ -1340,7 +1341,11 @@ properly into a mkv file. Specify mkvmerge as the concatenation method by settin
Some(filter) => Some(filter),
None => None,
},
self.vmaf_threads.unwrap_or_else(num_cpus::get),
self.vmaf_threads.unwrap_or_else(|| {
available_parallelism()
.expect("Unrecoverable: Failed to get thread count")
.get()
}),
) {
error!("VMAF calculation failed with error: {}", e);
}
Expand Down
5 changes: 4 additions & 1 deletion av1an-core/src/target_quality.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::convert::TryInto;
use std::fmt::Error;
use std::path::{Path, PathBuf};
use std::process::Stdio;
use std::thread::available_parallelism;

use ffmpeg::format::Pixel;
use splines::{Interpolation, Key, Spline};
Expand Down Expand Up @@ -299,7 +300,9 @@ pub fn vmaf_auto_threads(workers: usize) -> usize {
const OVER_PROVISION_FACTOR: f64 = 1.25;

// Logical CPUs
let threads = num_cpus::get();
let threads = available_parallelism()
.expect("Unrecoverable: Failed to get thread count")
.get();

cmp::max(
((threads / workers) as f64 * OVER_PROVISION_FACTOR) as usize,
Expand Down