solana_perf/
lib.rs

1#![cfg_attr(feature = "frozen-abi", feature(min_specialization))]
2pub mod cuda_runtime;
3pub mod data_budget;
4pub mod deduper;
5pub mod discard;
6pub mod packet;
7pub mod perf_libs;
8pub mod recycler;
9pub mod recycler_cache;
10pub mod sigverify;
11pub mod test_tx;
12pub mod thread;
13
14#[macro_use]
15extern crate lazy_static;
16
17#[macro_use]
18extern crate log;
19
20#[cfg(test)]
21#[macro_use]
22extern crate assert_matches;
23
24#[macro_use]
25extern crate solana_metrics;
26
27#[cfg_attr(feature = "frozen-abi", macro_use)]
28#[cfg(feature = "frozen-abi")]
29extern crate solana_frozen_abi_macro;
30
31fn is_rosetta_emulated() -> bool {
32    #[cfg(target_os = "macos")]
33    {
34        use std::str::FromStr;
35        std::process::Command::new("sysctl")
36            .args(["-in", "sysctl.proc_translated"])
37            .output()
38            .map_err(|_| ())
39            .and_then(|output| String::from_utf8(output.stdout).map_err(|_| ()))
40            .and_then(|stdout| u8::from_str(stdout.trim()).map_err(|_| ()))
41            .map(|enabled| enabled == 1)
42            .unwrap_or(false)
43    }
44    #[cfg(not(target_os = "macos"))]
45    {
46        false
47    }
48}
49
50pub fn report_target_features() {
51    warn!(
52        "CUDA is {}abled",
53        if crate::perf_libs::api().is_some() {
54            "en"
55        } else {
56            "dis"
57        }
58    );
59
60    // Validator binaries built on a machine with AVX support will generate invalid opcodes
61    // when run on machines without AVX causing a non-obvious process abort.  Instead detect
62    // the mismatch and error cleanly.
63    if !is_rosetta_emulated() {
64        #[cfg(all(
65            any(target_arch = "x86", target_arch = "x86_64"),
66            build_target_feature_avx
67        ))]
68        {
69            if is_x86_feature_detected!("avx") {
70                info!("AVX detected");
71            } else {
72                error!(
73                "Incompatible CPU detected: missing AVX support. Please build from source on the target"
74            );
75                std::process::abort();
76            }
77        }
78
79        #[cfg(all(
80            any(target_arch = "x86", target_arch = "x86_64"),
81            build_target_feature_avx2
82        ))]
83        {
84            if is_x86_feature_detected!("avx2") {
85                info!("AVX2 detected");
86            } else {
87                error!(
88                    "Incompatible CPU detected: missing AVX2 support. Please build from source on the target"
89                );
90                std::process::abort();
91            }
92        }
93    }
94}