Skip to content

Commit

Permalink
Add the intrinsic test tool to the CI
Browse files Browse the repository at this point in the history
  • Loading branch information
JamieCunliffe committed Jun 16, 2021
1 parent 4520108 commit 4311578
Show file tree
Hide file tree
Showing 7 changed files with 4,402 additions and 24 deletions.
6 changes: 5 additions & 1 deletion ci/docker/aarch64-unknown-linux-gnu/Dockerfile
@@ -1,13 +1,17 @@
FROM ubuntu:20.04
RUN apt-get update && apt-get install -y --no-install-recommends \
gcc \
g++ \
ca-certificates \
libc6-dev \
gcc-aarch64-linux-gnu \
g++-aarch64-linux-gnu \
libc6-dev-arm64-cross \
qemu-user \
make \
file
file \
clang-9 \
lld

ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER=aarch64-linux-gnu-gcc \
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER="qemu-aarch64 -L /usr/aarch64-linux-gnu" \
Expand Down
4 changes: 3 additions & 1 deletion ci/run-docker.sh
Expand Up @@ -9,7 +9,7 @@ run() {
target=$(echo "${1}" | sed 's/-emulated//')
echo "Building docker container for TARGET=${1}"
docker build -t stdarch -f "ci/docker/${1}/Dockerfile" ci/
mkdir -p target
mkdir -p target c_programs rust_programs
echo "Running docker"
# shellcheck disable=SC2016
docker run \
Expand All @@ -29,6 +29,8 @@ run() {
--volume "$(rustc --print sysroot)":/rust:ro \
--volume "$(pwd)":/checkout:ro \
--volume "$(pwd)"/target:/checkout/target \
--volume "$(pwd)"/c_programs:/checkout/c_programs \
--volume "$(pwd)"/rust_programs:/checkout/rust_programs \
--init \
--workdir /checkout \
--privileged \
Expand Down
7 changes: 7 additions & 0 deletions ci/run.sh
Expand Up @@ -65,6 +65,8 @@ cargo_test() {
CORE_ARCH="--manifest-path=crates/core_arch/Cargo.toml"
STD_DETECT="--manifest-path=crates/std_detect/Cargo.toml"
STDARCH_EXAMPLES="--manifest-path=examples/Cargo.toml"
INTRINSIC_TEST="--manifest-path=crates/intrinsic-test/Cargo.toml"

cargo_test "${CORE_ARCH} --release"

if [ "$NOSTD" != "1" ]; then
Expand Down Expand Up @@ -111,6 +113,11 @@ case ${TARGET} in

esac

if [ "${TARGET}" = "aarch64-unknown-linux-gnu" ]; then
export CPPFLAGS="-fuse-ld=lld -I/usr/aarch64-linux-gnu/include/ -I/usr/aarch64-linux-gnu/include/c++/9/aarch64-linux-gnu/"
cargo run ${INTRINSIC_TEST} --release --bin intrinsic-test -- crates/intrinsic-test/neon-intrinsics.csv --runner "${CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_RUNNER}" --cppcompiler "clang++-9"
fi

if [ "$NORUN" != "1" ] && [ "$NOSTD" != 1 ]; then
# Test examples
(
Expand Down
3 changes: 2 additions & 1 deletion crates/intrinsic-test/README.md
Expand Up @@ -12,7 +12,8 @@ FLAGS:
OPTIONS:
--cppcompiler <CPPCOMPILER> The C++ compiler to use for compiling the c++ code [default: clang++]
--toolchain <TOOLCHAIN> The rust toolchain to use for building the rust code [default: nightly]
--runner <RUNNER> Run the C programs under emulation with this command
--toolchain <TOOLCHAIN> The rust toolchain to use for building the rust code
ARGS:
<INPUT> The input file containing the intrinsics
Expand Down
4,356 changes: 4,356 additions & 0 deletions crates/intrinsic-test/neon-intrinsics.csv

Large diffs are not rendered by default.

38 changes: 23 additions & 15 deletions crates/intrinsic-test/src/main.rs
Expand Up @@ -67,12 +67,6 @@ fn generate_rust_program(intrinsic: &Intrinsic) -> String {
#![feature(stdsimd)]
#![allow(overflowing_literals)]
use core::arch::aarch64::*;
#[allow(unused_macros)]
macro_rules! bits_to_float(
($t:ty, $bits:expr) => (
{{ let x: $t = ::std::mem::transmute($bits); x }}
)
);
fn main() {{
{passes}
Expand All @@ -86,14 +80,17 @@ fn main() {{
}

fn compile_c(c_filename: &str, intrinsic: &Intrinsic, compiler: &str) -> bool {
let flags = std::env::var("CPPFLAGS").unwrap_or("".into());

let output = Command::new("sh")
.arg("-c")
.arg(format!(
"{cpp} -Wno-narrowing -O2 -target {target} -o c_programs/{intrinsic} {filename}",
"{cpp} {cppflags} -Wno-narrowing -O2 -target {target} -o c_programs/{intrinsic} {filename}",
target = "aarch64-unknown-linux-gnu",
filename = c_filename,
intrinsic = intrinsic.name,
cpp = compiler,
cppflags = flags,
))
.output();
if let Ok(output) = output {
Expand Down Expand Up @@ -182,8 +179,9 @@ path = "{intrinsic}/main.rs""#,
.current_dir("rust_programs")
.arg("-c")
.arg(format!(
"cargo +{toolchain} build --release",
"cargo {toolchain} build --release --target {target}",
toolchain = toolchain,
target = "aarch64-unknown-linux-gnu",
))
.output();
if let Ok(output) = output {
Expand Down Expand Up @@ -217,7 +215,6 @@ fn main() {
.arg(
Arg::with_name("TOOLCHAIN")
.takes_value(true)
.default_value("nightly")
.long("toolchain")
.help("The rust toolchain to use for building the rust code"),
)
Expand All @@ -228,12 +225,21 @@ fn main() {
.long("cppcompiler")
.help("The C++ compiler to use for compiling the c++ code"),
)
.arg(
Arg::with_name("RUNNER")
.takes_value(true)
.long("runner")
.help("Run the C programs under emulation with this command"),
)
.get_matches();

let filename = matches.value_of("INPUT").unwrap();
let toolchain = matches.value_of("TOOLCHAIN").unwrap();
let cpp_compiler = matches.value_of("CPPCOMPILER").unwrap();
let toolchain = matches
.value_of("TOOLCHAIN")
.map_or("".into(), |t| format!("+{}", t));

let cpp_compiler = matches.value_of("CPPCOMPILER").unwrap();
let c_runner = matches.value_of("RUNNER").unwrap_or("");
let mut csv_reader = csv::Reader::from_reader(std::fs::File::open(filename).unwrap());

let mut intrinsics = csv_reader
Expand Down Expand Up @@ -288,7 +294,7 @@ fn main() {
std::process::exit(3);
}

if !compare_outputs(&intrinsics, &toolchain) {
if !compare_outputs(&intrinsics, &toolchain, &c_runner) {
std::process::exit(1)
}
}
Expand All @@ -299,24 +305,26 @@ enum FailureReason {
Difference(String, String, String),
}

fn compare_outputs(intrinsics: &Vec<Intrinsic>, toolchain: &str) -> bool {
fn compare_outputs(intrinsics: &Vec<Intrinsic>, toolchain: &str, runner: &str) -> bool {
let intrinsics = intrinsics
.par_iter()
.filter_map(|intrinsic| {
let c = Command::new("sh")
.arg("-c")
.arg(format!(
"./c_programs/{intrinsic}",
"{runner} ./c_programs/{intrinsic}",
runner = runner,
intrinsic = intrinsic.name,
))
.output();
let rust = Command::new("sh")
.current_dir("rust_programs")
.arg("-c")
.arg(format!(
"cargo +{toolchain} run --release --bin {intrinsic}",
"cargo {toolchain} run --release --target {target} --bin {intrinsic}",
intrinsic = intrinsic.name,
toolchain = toolchain,
target = "aarch64-unknown-linux-gnu",
))
.output();

Expand Down
12 changes: 6 additions & 6 deletions crates/intrinsic-test/src/types.rs
Expand Up @@ -366,10 +366,10 @@ impl IntrinsicType {
} => (0..(simd_len.unwrap_or(1) * vec_len.unwrap_or(1)))
.map(|i| {
format!(
"{}{})",
"{}({})",
match language {
&Language::Rust => "bits_to_float!(f32, ",
&Language::C => "cast<float, uint32_t>(",
&Language::Rust => "f32::from_bits",
&Language::C => "cast<float, uint32_t>",
},
values_for_pass(32, i, pass),
)
Expand All @@ -385,10 +385,10 @@ impl IntrinsicType {
} => (0..(simd_len.unwrap_or(1) * vec_len.unwrap_or(1)))
.map(|i| {
format!(
"{}{}{})",
"{}({}{})",
match language {
&Language::Rust => "bits_to_float!(f64,",
&Language::C => "cast<double, uint64_t>(",
&Language::Rust => "f64::from_bits",
&Language::C => "cast<double, uint64_t>",
},
values_for_pass(64, i, pass),
match language {
Expand Down

0 comments on commit 4311578

Please sign in to comment.