Skip to content

Commit ba4646b

Browse files
committed
Add intel simd [skip ci]
1 parent f36afb8 commit ba4646b

12 files changed

+1057
-202
lines changed

benchmark_analysis.ipynb

Lines changed: 292 additions & 0 deletions
Large diffs are not rendered by default.

simd-bench.sh

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/bin/bash
2+
set -e
3+
4+
options=("OFF" "ON")
5+
BENCH_ITERS=${SECP256K1_BENCH_ITERS:-20000}
6+
7+
GREEN='\033[0;32m'
8+
RED='\033[0;31m'
9+
YELLOW='\033[1;33m'
10+
NC='\033[0m'
11+
12+
echo 1 | sudo tee /sys/devices/system/cpu/intel_pstate/no_turbo > /dev/null
13+
sudo cpupower -c 0 frequency-set -g performance > /dev/null
14+
command -v taskset > /dev/null && TASKSET_CMD="taskset -c 0"
15+
16+
run_bench() {
17+
local dir=$1 bin=$2 log=$3
18+
(
19+
cd "$dir"
20+
$TASKSET_CMD env SECP256K1_BENCH_ITERS=$BENCH_ITERS nice -n 0 ./bin/$bin >> "../../$log" 2>&1
21+
echo "" >> "../../$log"
22+
)
23+
}
24+
25+
bench_config() {
26+
local config="$1"
27+
local dir="build/$config"
28+
local log="${config}_bench.csv"
29+
30+
if [[ ! -d "$dir" ]]; then
31+
echo -e "${RED}$config${NC} (no dir)"
32+
return 1
33+
fi
34+
35+
{
36+
echo "Benchmark results for $config"
37+
echo "Generated on $(date)"
38+
echo "Iterations: $BENCH_ITERS"
39+
echo ""
40+
} > "$log"
41+
42+
for bin in bench bench_ecmult bench_internal; do
43+
if run_bench "$dir" "$bin" "$log"; then
44+
echo -e " ${GREEN}$bin${NC}"
45+
else
46+
echo -e " ${RED}$bin${NC}"
47+
return 1
48+
fi
49+
done
50+
51+
echo -e "${GREEN}$config${NC} (log: $log)"
52+
}
53+
54+
for sse2 in "${options[@]}"; do
55+
for avx2 in "${options[@]}"; do
56+
config="INT128"
57+
[[ $sse2 == "ON" ]] && config+="_SSE2"
58+
[[ $avx2 == "ON" ]] && config+="_AVX2"
59+
60+
bench_config "$config"
61+
done
62+
done
63+
64+
for sse2 in "${options[@]}"; do
65+
config="INT64"
66+
[[ $sse2 == "ON" ]] && config+="_SSE2"
67+
68+
bench_config "$config"
69+
done
70+
71+
echo -e "\n${YELLOW}All benchmarks successful. Logs in project root${NC}"

simd-build.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/bin/bash
2+
set -e
3+
4+
mkdir -p build
5+
6+
GREEN='\033[0;32m'
7+
RED='\033[0;31m'
8+
YELLOW='\033[1;33m'
9+
NC='\033[0m'
10+
11+
build() {
12+
local config="$1"
13+
local flags="-O3 -msse2 -mavx2 $2"
14+
local dir="build/$config"
15+
16+
mkdir -p "$dir"
17+
18+
if (cd "$dir" && cmake ../.. -G Ninja -DSECP256K1_APPEND_CFLAGS="$flags" > /dev/null 2>&1 && ninja > /dev/null 2>&1); then
19+
echo -e "${GREEN}$config${NC}"
20+
else
21+
echo -e "${RED}$config failed${NC}"
22+
return 1
23+
fi
24+
}
25+
26+
for sse2 in OFF ON; do
27+
for avx2 in OFF ON; do
28+
config="INT128"
29+
flags=""
30+
31+
if [[ $sse2 == "ON" ]]; then
32+
config+="_SSE2"
33+
else
34+
flags+=" -U__SSE2__"
35+
fi
36+
37+
if [[ $avx2 == "ON" ]]; then
38+
config+="_AVX2"
39+
else
40+
flags+=" -U__AVX2__"
41+
fi
42+
43+
build "$config" "$flags"
44+
done
45+
done
46+
47+
for sse2 in OFF ON; do
48+
config="INT64"
49+
flags="-DUSE_FORCE_WIDEMUL_INT64=1"
50+
51+
if [[ $sse2 == "ON" ]]; then
52+
config+="_SSE2"
53+
else
54+
flags+=" -U__SSE2__"
55+
fi
56+
57+
build "$config" "$flags"
58+
done
59+
60+
echo -e "\n${YELLOW}All builds done. Logs in project root${NC}"

simd-test.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
set -e
3+
4+
options=("OFF" "ON")
5+
6+
GREEN='\033[0;32m'
7+
RED='\033[0;31m'
8+
YELLOW='\033[1;33m'
9+
NC='\033[0m'
10+
11+
test_config() {
12+
local config="$1"
13+
local dir="build/$config"
14+
local log="${config}_test.log"
15+
16+
if [[ ! -d "$dir" ]]; then
17+
echo -e "${RED}$config${NC} (no dir)"
18+
return 1
19+
fi
20+
21+
if (cd "$dir" && ctest --output-on-failure -j"$(nproc)" &> "../../$log"); then
22+
echo -e "${GREEN}$config${NC} (log: $log)"
23+
else
24+
echo -e "${RED}$config${NC} (log: $log)"
25+
return 1
26+
fi
27+
}
28+
29+
for sse2 in "${options[@]}"; do
30+
for avx2 in "${options[@]}"; do
31+
config="INT128"
32+
[[ $sse2 == "ON" ]] && config+="_SSE2"
33+
[[ $avx2 == "ON" ]] && config+="_AVX2"
34+
35+
test_config "$config"
36+
done
37+
done
38+
39+
for sse2 in "${options[@]}"; do
40+
config="INT64"
41+
[[ $sse2 == "ON" ]] && config+="_SSE2"
42+
43+
test_config "$config"
44+
done
45+
46+
echo -e "\n${YELLOW}All tests passed. Logs in project root${NC}"

0 commit comments

Comments
 (0)