Skip to content

Commit 274345d

Browse files
committed
*: add google-benchmark and taco benchmarking
Add the google-benchmark library and taco as a submodule to benchmark TACO kernels.
1 parent 6ade402 commit 274345d

File tree

8 files changed

+104
-2
lines changed

8 files changed

+104
-2
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
*__pycache__*
2+
*CMakeFiles/
3+
*.idea/*

.gitmodules

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
[submodule "taco/taco"]
2+
path = taco/taco
3+
url = git@github.com:tensor-compiler/taco.git
4+
[submodule "taco/benchmark"]
5+
path = taco/benchmark
6+
url = git@github.com:google/benchmark.git

Makefile

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,31 @@
1-
BENCHES :=
1+
BENCHES := ""
22
BENCHFLAGS :=
33

44
python-bench: numpy/*.py
55
pytest $(BENCHFLAGS) $(BENCHES)
66

7+
taco-bench: build-taco-bench
8+
ifeq ($(BENCHES),"")
9+
taco/build/taco-bench $(BENCHFLAGS)
10+
else
11+
taco/build/taco-bench $(BENCHFLAGS) --benchmark_filter="$(BENCHES)"
12+
endif
13+
14+
build-taco-bench: check-and-reinit-submodules taco/build taco/build/taco-bench
15+
$(MAKE) -C taco/build taco-bench
16+
17+
taco-bench-build: taco/build
18+
mkdir taco/build
19+
cd taco/build
20+
cmake ../
21+
cd ../../
22+
23+
bench-gtest: taco/benchmark/googletest/README.md
24+
git clone https://github.com/google/googletest taco/benchmark/googletest
25+
26+
.PHONY: check-and-reinit-submodules
27+
check-and-reinit-submodules:
28+
@if git submodule status | egrep -q '^[-]|^[+]' ; then \
29+
echo "INFO: Need to reinitialize git submodules"; \
30+
git submodule update --init; \
31+
fi

numpy/windowing.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ def test_add_sparse_window(benchmark):
77
matrix = random(dim, dim, format="csr")
88

99
def bench():
10-
res = matrix[1:(dim-1), 1:(dim-1)] + matrix[1:(dim-1), 1:(dim-1)]
10+
x = matrix[1:(dim-1), 1:(dim-1)]
11+
res = x + x
1112
benchmark.pedantic(bench, iterations=10)
1213

1314
def test_add_multiple_sparse_windows(benchmark):

taco/.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
build/*
2+
.idea/*

taco/CMakeLists.txt

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
cmake_minimum_required(VERSION 2.8.12 FATAL_ERROR)
2+
project(taco-bench)
3+
set(CMAKE_BUILD_TYPE "release")
4+
5+
add_subdirectory(taco)
6+
add_subdirectory(benchmark)
7+
8+
include_directories(taco taco/include benchmark/include)
9+
10+
file(GLOB TEST_SOURCES *.cpp)
11+
12+
set(CMAKE_CXX_FLAGS "${C_CXX_FLAGS} -std=c++14")
13+
14+
add_executable(taco-bench ${TEST_SOURCES})
15+
target_link_libraries(taco-bench benchmark::benchmark)
16+
target_link_libraries(taco-bench taco)
17+

taco/main.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
//int main() {
2+
// return 0;
3+
//}
4+
//int foo () {
5+
// return 0;
6+
//}
7+
8+
#include "benchmark/include/benchmark/benchmark.h"
9+
BENCHMARK_MAIN();

taco/windowing.cpp

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include "benchmark/benchmark.h"
2+
3+
#include "taco/tensor.h"
4+
#include "taco/format.h"
5+
#include "taco/index_notation/index_notation.h"
6+
7+
using namespace taco;
8+
9+
static void BM_basic_windowing(benchmark::State& state) {
10+
auto dim = 10000;
11+
auto sparsity = 0.01;
12+
// CSR format.
13+
Tensor<float> matrix("A", {dim, dim}, {Dense, Sparse});
14+
Tensor<float> result("B", {dim-2, dim-2}, {Dense, Sparse});
15+
16+
srand(4357);
17+
for (int i = 0; i < dim; i++) {
18+
for (int j = 0; j < dim; j++) {
19+
float rand_float = (float)rand()/(float)(RAND_MAX);
20+
if (rand_float < sparsity) {
21+
matrix.insert({i, j}, (float) ((int) (rand_float*3/sparsity)));
22+
}
23+
}
24+
}
25+
matrix.pack();
26+
27+
IndexVar i, j;
28+
result(i, j) = matrix(i(1, dim-1), j(1, dim-1)) + matrix(i(1, dim-1), j(1, dim-1));
29+
result.compile();
30+
result.assemble();
31+
32+
for (auto _ : state) {
33+
// This code gets timed. Setup goes outside the loop.
34+
result.compute();
35+
}
36+
}
37+
// Have benchmarking report milliseconds and run for 10 iterations.
38+
BENCHMARK(BM_basic_windowing)->Unit(benchmark::kMillisecond)->Iterations(10);
39+

0 commit comments

Comments
 (0)