fixed too many files open issue
This commit is contained in:
parent
ca67119d5f
commit
e15d6fae92
4 changed files with 36 additions and 24 deletions
|
|
@ -2,11 +2,12 @@ use super::argument::Argument;
|
|||
use super::config::{AARCH_CONFIGURATIONS, POLY128_OSTREAM_DEF, build_notices};
|
||||
use super::format::Indentation;
|
||||
use super::intrinsic::Intrinsic;
|
||||
use crate::common::gen_c::{compile_c, create_c_files, generate_c_program};
|
||||
use crate::common::gen_rust::{compile_rust, create_rust_files, generate_rust_program};
|
||||
use crate::common::gen_c::{compile_c, create_c_filenames, generate_c_program};
|
||||
use crate::common::gen_rust::{compile_rust, create_rust_filenames, generate_rust_program};
|
||||
use crate::common::write_file;
|
||||
use itertools::Itertools;
|
||||
use rayon::prelude::*;
|
||||
use std::io::Write;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
// The number of times each intrinsic will be called.
|
||||
const PASSES: u32 = 20;
|
||||
|
|
@ -149,13 +150,14 @@ fn generate_rust_program_arm(intrinsic: &Intrinsic, target: &str) -> String {
|
|||
}
|
||||
|
||||
fn compile_c_arm(
|
||||
intrinsics_name_list: Vec<String>,
|
||||
intrinsics_name_list: &Vec<String>,
|
||||
filename_mapping: BTreeMap<&String, String>,
|
||||
compiler: &str,
|
||||
target: &str,
|
||||
cxx_toolchain_dir: Option<&str>,
|
||||
) -> bool {
|
||||
let compiler_commands = intrinsics_name_list.iter().map(|intrinsic_name|{
|
||||
let c_filename = format!(r#"c_programs/{intrinsic_name}.cpp"#);
|
||||
let compiler_commands = intrinsics_name_list.iter().map(|intrinsic_name| {
|
||||
let c_filename = filename_mapping.get(intrinsic_name).unwrap();
|
||||
let flags = std::env::var("CPPFLAGS").unwrap_or("".into());
|
||||
let arch_flags = if target.contains("v7") {
|
||||
"-march=armv8.6-a+crypto+crc+dotprod+fp16"
|
||||
|
|
@ -223,24 +225,29 @@ pub fn build_c(
|
|||
target: &str,
|
||||
cxx_toolchain_dir: Option<&str>,
|
||||
) -> bool {
|
||||
let _ = std::fs::create_dir("c_programs");
|
||||
let intrinsics_name_list = intrinsics
|
||||
.par_iter()
|
||||
.map(|i| i.name.clone())
|
||||
.collect::<Vec<_>>();
|
||||
let file_mapping = create_c_files(&intrinsics_name_list);
|
||||
let filename_mapping = create_c_filenames(&intrinsics_name_list);
|
||||
|
||||
intrinsics.par_iter().for_each(|i| {
|
||||
let c_code = generate_c_program_arm(&["arm_neon.h", "arm_acle.h", "arm_fp16.h"], i, target);
|
||||
match file_mapping.get(&i.name) {
|
||||
Some(mut file) => file.write_all(c_code.into_bytes().as_slice()).unwrap(),
|
||||
match filename_mapping.get(&i.name) {
|
||||
Some(filename) => write_file(filename, c_code),
|
||||
None => {}
|
||||
};
|
||||
});
|
||||
|
||||
match compiler {
|
||||
None => true,
|
||||
Some(compiler) => compile_c_arm(intrinsics_name_list, compiler, target, cxx_toolchain_dir),
|
||||
Some(compiler) => compile_c_arm(
|
||||
&intrinsics_name_list,
|
||||
filename_mapping,
|
||||
compiler,
|
||||
target,
|
||||
cxx_toolchain_dir,
|
||||
),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -254,12 +261,12 @@ pub fn build_rust(
|
|||
.par_iter()
|
||||
.map(|i| i.name.clone())
|
||||
.collect::<Vec<_>>();
|
||||
let file_mapping = create_rust_files(&intrinsics_name_list);
|
||||
let filename_mapping = create_rust_filenames(&intrinsics_name_list);
|
||||
|
||||
intrinsics.par_iter().for_each(|i| {
|
||||
let c_code = generate_rust_program_arm(i, target);
|
||||
match file_mapping.get(&i.name) {
|
||||
Some(mut file) => file.write_all(c_code.into_bytes().as_slice()).unwrap(),
|
||||
let rust_code = generate_rust_program_arm(i, target);
|
||||
match filename_mapping.get(&i.name) {
|
||||
Some(filename) => write_file(filename, rust_code),
|
||||
None => {}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use itertools::Itertools;
|
||||
use rayon::prelude::*;
|
||||
use std::collections::BTreeMap;
|
||||
use std::fs::File;
|
||||
use std::process::Command;
|
||||
|
||||
pub fn generate_c_program(
|
||||
|
|
@ -79,14 +78,14 @@ pub fn compile_c(compiler_commands: &[String]) -> bool {
|
|||
.is_none()
|
||||
}
|
||||
|
||||
pub fn create_c_files(identifiers: &Vec<String>) -> BTreeMap<&String, File> {
|
||||
pub fn create_c_filenames(identifiers: &Vec<String>) -> BTreeMap<&String, String> {
|
||||
let _ = std::fs::create_dir("c_programs");
|
||||
identifiers
|
||||
.par_iter()
|
||||
.map(|identifier| {
|
||||
let c_filename = format!(r#"c_programs/{identifier}.cpp"#);
|
||||
let file = File::create(&c_filename).unwrap();
|
||||
|
||||
(identifier, file)
|
||||
(identifier, c_filename)
|
||||
})
|
||||
.collect::<BTreeMap<&String, File>>()
|
||||
.collect::<BTreeMap<&String, String>>()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -115,16 +115,15 @@ path = "{binary}/main.rs""#,
|
|||
}
|
||||
}
|
||||
|
||||
pub fn create_rust_files(identifiers: &Vec<String>) -> BTreeMap<&String, File> {
|
||||
pub fn create_rust_filenames(identifiers: &Vec<String>) -> BTreeMap<&String, String> {
|
||||
identifiers
|
||||
.par_iter()
|
||||
.map(|identifier| {
|
||||
let rust_dir = format!(r#"rust_programs/{}"#, identifier);
|
||||
let _ = std::fs::create_dir_all(&rust_dir);
|
||||
let rust_filename = format!(r#"{rust_dir}/main.rs"#);
|
||||
let file = File::create(&rust_filename).unwrap();
|
||||
|
||||
(identifier, file)
|
||||
(identifier, rust_filename)
|
||||
})
|
||||
.collect::<BTreeMap<&String, File>>()
|
||||
.collect::<BTreeMap<&String, String>>()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
use crate::common::types::ProcessedCli;
|
||||
use std::fs::File;
|
||||
use std::io::Write;
|
||||
|
||||
pub mod compare;
|
||||
pub mod gen_c;
|
||||
|
|
@ -14,3 +16,8 @@ pub trait SupportedArchitectureTest {
|
|||
fn build_rust_file(&self) -> bool;
|
||||
fn compare_outputs(&self) -> bool;
|
||||
}
|
||||
|
||||
pub fn write_file(filename: &String, code: String) {
|
||||
let mut file = File::create(&filename).unwrap();
|
||||
file.write_all(code.into_bytes().as_slice()).unwrap();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue