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