Skip to content

Commit

Permalink
UD is working, fix SR
Browse files Browse the repository at this point in the history
  • Loading branch information
yohanchatelain committed Jul 26, 2024
1 parent fbb2b2f commit 250df4c
Show file tree
Hide file tree
Showing 11 changed files with 793 additions and 2,159 deletions.
52 changes: 52 additions & 0 deletions experiments/online-instrumentation/numerics/random_sum/plot.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import numpy as np
import plotly.express as px
import pandas as pd
import glob
import argparse
import joblib
from functools import reduce


def parse_file(file):
with open(file, "r") as f:
for line in f:
if "msec" in line:
return float(line.split()[0])


def run():
files = glob.glob("*.perf")
values = {}
for file in files:
# opt_mode_type.perf
opt, mode, type = file.split(".")[0].split("_")
x = parse_file(file)
values["opt"] = values.get("opt", []) + [opt]
values["mode"] = values.get("mode", []) + [mode]
values["type"] = values.get("type", []) + [type]
values["slowdown"] = values.get("slowdown", []) + [x]
return pd.DataFrame(values)


def main():
df = run()
df[df["opt"] == "O0"]["slowdown"] /= 2 # O0
df[df["opt"] == "O0"]["slowdown"] /= 0.7 # O3
print(df)
fig = px.bar(
df, x="opt", y="slowdown", color="mode", barmode="group", facet_col="type"
)
# fig.update_yaxes(title_text="Slowdown")
fig.update_layout(
font=dict(
size=22,
)
)
fig.show()


if __name__ == "__main__":
main()


# /usr/local/bin/verificarlo-c++ -DAT_PER_OPERATOR_HEADERS -DCAFFE2_BUILD_MAIN_LIB -DCPUINFO_SUPPORTED_PLATFORM=1 -DFMT_HEADER_ONLY=1 -DFXDIV_USE_INLINE_ASSEMBLY=0 -DHAVE_MALLOC_USABLE_SIZE=1 -DHAVE_MMAP=1 -DHAVE_SHM_OPEN=1 -DHAVE_SHM_UNLINK=1 -DMINIZ_DISABLE_ZIP_READER_CRC32_CHECKS -DNNP_CONVOLUTION_ONLY=0 -DNNP_INFERENCE_ONLY=0 -DONNXIFI_ENABLE_EXT=1 -DONNX_ML=1 -DONNX_NAMESPACE=onnx_torch -DUSE_C10D_GLOO -DUSE_DISTRIBUTED -DUSE_EXTERNAL_MZCRC -DUSE_RPC -DUSE_TENSORPIPE -D_FILE_OFFSET_BITS=64 -Dtorch_cpu_EXPORTS -I/var/lib/jenkins/workspace/third_party/pocketfft -I/var/lib/jenkins/workspace/build/aten/src -I/var/lib/jenkins/workspace/aten/src -I/var/lib/jenkins/workspace/build -I/var/lib/jenkins/workspace -I/var/lib/jenkins/workspace/cmake/../third_party/benchmark/include-I/var/lib/jenkins/workspace/third_party/onnx -I/var/lib/jenkins/workspace/build/third_party/onnx -I/var/lib/jenkins/workspace/third_party/foxi -I/var/lib/jenkins/workspace/build/third_party/foxi -I/var/lib/jenkins/workspace/torch/csrc/api -I/var/lib/jenkins/workspace/torch/csrc/api/include -I/var/lib/jenkins/workspace/caffe2/aten/src/TH -I/var/lib/jenkins/workspace/build/caffe2/aten/src/TH -I/var/lib/jenkins/workspace/build/caffe2/aten/src -I/var/lib/jenkins/workspace/build/caffe2/../aten/src -I/var/lib/jenkins/workspace/torch/csrc -I/var/lib/jenkins/workspace/third_party/miniz-2.1.0 -I/var/lib/jenkins/workspace/third_party/kineto/libkineto/include -I/var/lib/jenkins/workspace/third_party/kineto/libkineto/src -I/var/lib/jenkins/workspace/aten/src/ATen/.. -I/var/lib/jenkins/workspace/third_party/FXdiv/include -I/var/lib/jenkins/workspace/c10/.. -I/var/lib/jenkins/workspace/third_party/pthreadpool/include -I/var/lib/jenkins/workspace/third_party/cpuinfo/include -I/var/lib/jenkins/workspace/third_party/QNNPACK/include -I/var/lib/jenkins/workspace/aten/src/ATen/native/quantized/cpu/qnnpack/include -I/var/lib/jenkins/workspace/aten/src/ATen/native/quantized/cpu/qnnpack/src -I/var/lib/jenkins/workspace/third_party/cpuinfo/deps/clog/include -I/var/lib/jenkins/workspace/third_party/NNPACK/include -I/var/lib/jenkins/workspace/third_party/fbgemm/include -I/var/lib/jenkins/workspace/third_party/fbgemm -I/var/lib/jenkins/workspace/third_party/fbgemm/third_party/asmjit/src -I/var/lib/jenkins/workspace/third_party/ittapi/src/ittnotify -I/var/lib/jenkins/workspace/third_party/FP16/include -I/var/lib/jenkins/workspace/third_party/tensorpipe -I/var/lib/jenkins/workspace/build/third_party/tensorpipe -I/var/lib/jenkins/workspace/third_party/tensorpipe/third_party/libnop/include -I/var/lib/jenkins/workspace/third_party/fmt/include -I/var/lib/jenkins/workspace/third_party/flatbuffers/include -isystem /var/lib/jenkins/workspace/build/third_party/gloo -isystem /var/lib/jenkins/workspace/cmake/../third_party/gloo -isystem /var/lib/jenkins/workspace/cmake/../third_party/tensorpipe/third_party/libuv/include -isystem /var/lib/jenkins/workspace/cmake/../third_party/googletest/googlemock/include -isystem /var/lib/jenkins/workspace/cmake/../third_party/googletest/googletest/include -isystem /var/lib/jenkins/workspace/third_party/protobuf/src -isystem /var/lib/jenkins/workspace/third_party/gemmlowp -isystem /var/lib/jenkins/workspace/third_party/neon2sse -isystem /var/lib/jenkins/workspace/third_party/XNNPACK/include -isystem /var/lib/jenkins/workspace/third_party/ittapi/include -isystem /var/lib/jenkins/workspace/cmake/../third_party/eigen -isystem /var/lib/jenkins/workspace/build/include -march=native --online-instrumentation=up-down --inst-fma -D_GLIBCXX_USE_CXX11_ABI=1 -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOCUPTI -DLIBKINETO_NOROCTRACER -DUSE_FBGEMM -DUSE_QNNPACK -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=braced-scalar-init -Wnarrowing -Wno-missing-field-initializers -Wno-type-limits -Wno-array-bounds -Wno-unknown-pragmas -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-strict-overflow -Wno-strict-aliasing -Wvla-extension -Wnewline-eof -Winconsistent-missing-override -Winconsistent-missing-destructor-override -Wno-range-loop-analysis -Wno-pass-failed -Wno-error=pedantic -Wno-error=old-style-cast -Wno-error=inconsistent-missing-override -Wno-error=inconsistent-missing-destructor-override -Wconstant-conversion -Wno-invalid-partial-specialization -Wno-unused-private-field -Wno-missing-braces -Wunused-lambda-capture -Qunused-arguments -fcolor-diagnostics -faligned-new -fno-math-errno -fno-trapping-math -Werror=format -DHAVE_AVX512_CPU_DEFINITION -DHAVE_AVX2_CPU_DEFINITION -O3 -DNDEBUG -DNDEBUG -std=gnu++17 -fPIC -DTORCH_USE_LIBUV -DCAFFE2_USE_GLOO -DTH_HAVE_THREAD -Wall -Wextra -Wno-unused-parameter -Wno-unused-function -Wno-unused-result -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-type-limits -Wno-array-bounds -Wno-strict-overflow -Wno-strict-aliasing -Wno-missing-braces -Wno-range-loop-analysis -fvisibility=hidden -O2 -Wmissing-prototypes -Werror=missing-prototypes -pthread -DASMJIT_STATIC -fopenmp=libiomp5 -MD -MT caffe2/CMakeFiles/torch_cpu.dir/__/aten/src/ATen/native/mkl/SpectralOps.cpp.o -MF CMakeFiles/torch_cpu.dir/__/aten/src/ATen/native/mkl/SpectralOps.cpp.o.d -o CMakeFiles/torch_cpu.dir/__/aten/src/ATen/native/mkl/SpectralOps.cpp.o -c /var/lib/jenkins/workspace/aten/src/ATen/native/mkl/SpectralOps.cpp
23 changes: 23 additions & 0 deletions experiments/online-instrumentation/numerics/random_sum/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// harmonic series
#include <math.h>
#include <stdio.h>
#include <stdlib.h>

#ifndef REAL
#define REAL double
#endif

int main(int argc, char *argv[]) {

int n = atoi(argv[1]);
int seed = atoi(argv[2]);

srand(seed);

REAL sum = 1;
for (int i = 1; i <= n; i++) {
sum += 0.1;
}
fprintf(stderr, "%.13a\n", sum);
return 0;
}
85 changes: 85 additions & 0 deletions experiments/online-instrumentation/numerics/random_sum/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#!/bin/bash

for type in float double; do

echo "Compiling test.c with $type precision"

verificarlo-c test.c -DREAL=$type --online-instrumentation=up-down -O0 -o test_O0_ud_$type
verificarlo-c test.c -DREAL=$type --online-instrumentation=up-down -O3 -o test_O3_ud_$type

# rm -rf ud_results_${type}_O0.*.txt
# rm -rf ud_results_${type}_O3.*.txt

# echo "Running up-down instrumentation"
# for i in {0..10}; do
# ./test_O0 $N $RANDOM >ud_results_${type}_O0.$i.txt
# ./test_O3 $N $RANDOM >ud_results_${type}_O3.$i.txt
# done

verificarlo-c test.c -DREAL=$type --online-instrumentation=sr -O0 -o test_O0_sr_$type -lm
verificarlo-c test.c -DREAL=$type --online-instrumentation=sr -O3 -o test_O3_sr_$type -lm

# rm -rf sr_results_${type}_O0.*.txt
# rm -rf sr_results_${type}_O3.*.txt

# echo "Running sr instrumentation"
# for i in {0..10}; do
# ./test_O0 $N $RANDOM >sr_results_${type}_O0.$i.txt
# ./test_O3 $N $RANDOM >sr_results_${type}_O3.$i.txt
# done

verificarlo-c test.c -DREAL=$type -o test_O0_ieee_$type
verificarlo-c test.c -DREAL=$type -o test_O3_ieee_$type

cp test_O0_ieee_$type test_O0_mca_$type
cp test_O3_ieee_$type test_O3_mca_$type

# rm -rf ieee_results_${type}_O0.*.txt
# rm -rf ieee_results_${type}_O3.*.txt

# export VFC_BACKENDS_LOGGER=False
# export VFC_BACKENDS_SILENT_LOAD=True
# export VFC_BACKENDS="libinterflop_ieee.so"

# echo "Running ieee instrumentation"
# for i in {0..10}; do
# ./test_O0 $N $RANDOM >ieee_results_${type}_O0.$i.txt
# ./test_O3 $N $RANDOM >ieee_results_${type}_O3.$i.txt
# done

# rm -rf mca_results_${type}_O0.*.txt
# rm -rf mca_results_${type}_O3.*.txt

# export VFC_BACKENDS="libinterflop_mca.so -m rr"

# echo "Running mca instrumentation"
# for i in {0..10}; do
# ./test_O0 $N $RANDOM >mca_results_${type}_O0.$i.txt
# ./test_O3 $N $RANDOM >mca_results_${type}_O3.$i.txt
# done

done

function run() {
N=1000000

local mode=$1
local type=$2
local backend=$3

rm -rf ${mode}_results_${type}_O0.*.txt
rm -rf ${mode}_results_${type}_O3.*.txt

export VFC_BACKENDS_LOGGER=False
export VFC_BACKENDS_SILENT_LOAD=True
export VFC_BACKENDS=$backend

echo "Running ${mode} instrumentation"
perf stat -o 00_${mode}_${type}.perf -r 10 -- ./test_O0_${mode}_${type} $N 23 2>/dev/null
perf stat -o 03_${mode}_${type}.perf -r 10 -- ./test_O3_${mode}_${type} $N 23 2>/dev/null

}

export -f run

parallel --progress -j 1 "run {1} {2} {3}" ::: ud sr ieee mca ::: float double ::: "libinterflop_ieee.so" "libinterflop_mca.so -m rr"
2 changes: 2 additions & 0 deletions src/libvfcinstrumentonline/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@ endif
libvfcinstrumentonline_la_CXXFLAGS = @LLVM_CPPFLAGS@ -I@INTERFLOP_INCLUDEDIR@ -Wfatal-errors
libvfcinstrumentonline_la_LDFLAGS = @LLVM_LDFLAGS@
libvfcinstrumentonline_la_SOURCES = libVFCInstrumentOnline.cpp

include_HEADERS = rand.cpp xoroshiro128+.cpp shishua.h
Loading

0 comments on commit 250df4c

Please sign in to comment.