Skip to content

Commit 499a790

Browse files
author
Rohan Yadav
committed
numpy,taco: updates to run full set of suitesparse benchmarks
1 parent 6b1e705 commit 499a790

File tree

5 files changed

+1757
-27
lines changed

5 files changed

+1757
-27
lines changed

numpy/ufuncs.py

+25-6
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,35 @@ def bench():
9292
def ufunc_bench_key(tensorName, funcName):
9393
return tensorName + "-" + funcName + "-numpy"
9494

95+
# UfuncInputCache attempts to avoid reading the same tensor from disk multiple
96+
# times in a benchmark run.
97+
class UfuncInputCache:
98+
def __init__(self):
99+
self.lastLoaded = None
100+
self.lastName = None
101+
self.tensor = None
102+
self.other = None
103+
104+
def load(self, tensor, suiteSparse):
105+
if self.lastName == str(tensor):
106+
return self.tensor, self.other
107+
else:
108+
if suiteSparse:
109+
self.lastLoaded = tensor.load(PydataMatrixMarketTensorLoader())
110+
else:
111+
self.lastLoaded = tensor.load()
112+
self.lastName = str(tensor)
113+
self.tensor = safeCastPydataTensorToInts(self.lastLoaded)
114+
self.other = PydataTensorShifter().shiftLastMode(self.tensor)
115+
return self.tensor, self.other
116+
inputCache = UfuncInputCache()
117+
95118
# Run benchmarks against the FROSTT collection.
96119
FROSTTTensors = TensorCollectionFROSTT()
97120
@pytest.mark.parametrize("tensor", FROSTTTensors.getTensors())
98121
@pytest.mark.parametrize("ufunc", [numpy.logical_xor, numpy.ldexp, numpy.right_shift])
99122
def bench_pydata_frostt_ufunc_sparse(tacoBench, tensor, ufunc):
100-
frTensor = safeCastPydataTensorToInts(tensor.load())
101-
shifter = PydataTensorShifter()
102-
other = shifter.shiftLastMode(frTensor)
123+
frTensor, other = inputCache.load(tensor, False)
103124
def bench():
104125
c = ufunc(frTensor, other)
105126
return c
@@ -118,9 +139,7 @@ def bench():
118139
@pytest.mark.parametrize("ufunc", [numpy.logical_xor, numpy.ldexp, numpy.right_shift])
119140
def bench_pydata_suitesparse_ufunc_sparse(tacoBench, ufunc):
120141
tensor = SuiteSparseTensor(os.getenv('SUITESPARSE_TENSOR_PATH'))
121-
ssTensor = safeCastPydataTensorToInts(tensor.load(PydataMatrixMarketTensorLoader()))
122-
shifter = PydataTensorShifter()
123-
other = shifter.shiftLastMode(ssTensor)
142+
ssTensor, other = inputCache.load(tensor, True)
124143
def bench():
125144
c = ufunc(ssTensor, other)
126145
return c

scripts/suitesparse_runner.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
#SBATCH -N 1
3+
#SBATCH --mem 120000
4+
#SBATCH -p lanka-v3
5+
#SBATCH --exclusive
6+
7+
set -u
8+
9+
source venv/bin/activate
10+
11+
sspath=data/suitesparse
12+
# out=suitesparse-ufunc-bench/taco
13+
out=suitesparse-ufunc-bench/numpy
14+
15+
mkdir -p "$out"
16+
17+
while read line; do
18+
matrix="$sspath/$line/$line.mtx"
19+
# csvout="$out/result-$line.csv"
20+
# LANKA=ON SUITESPARSE_TENSOR_PATH="$matrix" TACO_OUT="$csvout" make -j8 taco-bench BENCHES="bench_suitesparse_ufunc"
21+
jsonout="$out/result-$line.json"
22+
LANKA=ON SUITESPARSE_TENSOR_PATH="$matrix" NUMPY_JSON="$jsonout" make python-bench BENCHES="numpy/ufuncs.py::bench_pydata_suitesparse_ufunc_sparse"
23+
done <$1
24+
25+
# for path in $sspath/*; do
26+
# if [ ! -d $path ]; then
27+
# continue
28+
# fi
29+
# name="$(cut -d'/' -f3 <<< "$path")"
30+
# matrix="$path/$name.mtx"
31+
#
32+
# csvout="$out/result-$name.csv"
33+
#
34+
# LANKA=ON SUITESPARSE_TENSOR_PATH="$matrix" TACO_OUT="$csvout" make -j8 taco-bench BENCHES="bench_suitesparse_ufunc"
35+
# done

scripts/taco_bench_aggregator.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ def aggregateTacoBenches(folder, outfile, labelSet=None):
2020
with open(fname, 'r') as f:
2121
# Discard the first 10 lines. This corresponds to the
2222
# google-benchmark generated header.
23-
for i in range(0, 10):
24-
f.readline()
23+
# for i in range(0, 10):
24+
# f.readline()
2525
# Open the rest of the file as a CSV.
2626
reader = csv.reader(f)
2727
# Attempt to read the header from CSV. If this fails,
@@ -33,14 +33,14 @@ def aggregateTacoBenches(folder, outfile, labelSet=None):
3333
continue
3434
# Find the column that contains label. We're going to skip
3535
# entries that have a skip marker in the label.
36-
labelIdx = header.index("label")
36+
# labelIdx = header.index("label", 0)
3737
if first:
3838
writer.writerow(header)
3939
first = False
4040
for row in reader:
41-
if "SKIPPED" not in row[labelIdx]:
42-
validLabels.add(row[labelIdx])
43-
writer.writerow(row)
41+
# if "SKIPPED" not in row[labelIdx]:
42+
# validLabels.add(row[labelIdx])
43+
writer.writerow(row)
4444
# Write out the set of valid labels.
4545
if labelSet is not None:
4646
with open(labelSet, 'w+') as validSet:

taco/ufuncs.cpp

+19-15
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ TACO_BENCH_ARGS(bench_ufunc_sparse, rightShift_0.01, 0.01, ">>")->Apply(applyBen
161161
// time from caching these inputs.
162162
struct UfuncInputCache {
163163
template<typename U>
164-
std::pair<taco::Tensor<int64_t>, taco::Tensor<int64_t>> getUfuncInput(std::string path, U format) {
164+
std::pair<taco::Tensor<int64_t>, taco::Tensor<int64_t>> getUfuncInput(std::string path, U format, bool countNNZ = false) {
165165
// See if the paths match.
166166
if (this->lastPath == path) {
167167
// TODO (rohany): Not worrying about whether the format was the same as what was asked for.
@@ -175,6 +175,12 @@ struct UfuncInputCache {
175175
this->lastPath = path;
176176
this->inputTensor = castToType<int64_t>("A", this->lastLoaded);
177177
this->otherTensor = shiftLastMode<int64_t, int64_t>("B", this->inputTensor);
178+
if (countNNZ) {
179+
this->nnz = 0;
180+
for (auto& it : iterate<int64_t>(this->inputTensor)) {
181+
this->nnz++;
182+
}
183+
}
178184
return std::make_pair(this->inputTensor, this->otherTensor);
179185
}
180186

@@ -183,6 +189,7 @@ struct UfuncInputCache {
183189

184190
taco::Tensor<int64_t> inputTensor;
185191
taco::Tensor<int64_t> otherTensor;
192+
int64_t nnz;
186193
};
187194
UfuncInputCache inputCache;
188195

@@ -295,29 +302,32 @@ static void bench_suitesparse_ufunc(benchmark::State& state, Func op) {
295302
// Counters must be present in every run to get reported to the CSV.
296303
state.counters["dimx"] = 0;
297304
state.counters["dimy"] = 0;
298-
if (ssTensors.tensors.size() == 0) {
305+
state.counters["nnz"] = 0;
306+
307+
auto tensorPath = getEnvVar("SUITESPARSE_TENSOR_PATH");
308+
if (tensorPath == "") {
299309
state.error_occurred();
300310
return;
301311
}
302-
int tensorIdx = state.range(0);
303-
auto tensorPath = ssTensors.tensors[tensorIdx];
312+
304313
auto pathSplit = taco::util::split(tensorPath, "/");
305314
auto filename = pathSplit[pathSplit.size() - 1];
306315
auto tensorName = taco::util::split(filename, ".")[0];
307316
state.SetLabel(tensorName);
308317

309318
taco::Tensor<int64_t> ssTensor, other;
310319
try {
311-
std::tie(ssTensor, other) = inputCache.getUfuncInput(tensorPath, CSR);
320+
std::tie(ssTensor, other) = inputCache.getUfuncInput(tensorPath, CSR, true /* countNNZ */);
312321
} catch (TacoException& e) {
313322
// Counters don't show up in the generated CSV if we used SkipWithError, so
314323
// just add in the label that this run is skipped.
315-
state.SetLabel(tensorName+"-SKIPPED-FAILED-READ");
324+
state.SetLabel(tensorName+"/SKIPPED-FAILED-READ");
316325
return;
317326
}
318327

319328
state.counters["dimx"] = ssTensor.getDimension(0);
320329
state.counters["dimy"] = ssTensor.getDimension(1);
330+
state.counters["nnz"] = inputCache.nnz;
321331

322332
for (auto _ : state) {
323333
state.PauseTiming();
@@ -339,12 +349,6 @@ static void bench_suitesparse_ufunc(benchmark::State& state, Func op) {
339349
}
340350
}
341351

342-
static void applySuiteSparse(benchmark::internal::Benchmark* b) {
343-
for (int i = 0; i < ssTensors.tensors.size(); i++) {
344-
b->Arg(i);
345-
}
346-
}
347-
348-
TACO_BENCH_ARGS(bench_suitesparse_ufunc, xor, xorOp)->Apply(applySuiteSparse);
349-
TACO_BENCH_ARGS(bench_suitesparse_ufunc, ldExp, ldExp)->Apply(applySuiteSparse);
350-
TACO_BENCH_ARGS(bench_suitesparse_ufunc, rightShift, rightShift)->Apply(applySuiteSparse);
352+
TACO_BENCH_ARGS(bench_suitesparse_ufunc, xor, xorOp);
353+
TACO_BENCH_ARGS(bench_suitesparse_ufunc, ldExp, ldExp);
354+
TACO_BENCH_ARGS(bench_suitesparse_ufunc, rightShift, rightShift);

0 commit comments

Comments
 (0)