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