Skip to content

Commit b914408

Browse files
committed
taco: add partial ufunc benchmark for FROSTT tensors
1 parent 4ba0f2f commit b914408

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

taco/bench.cpp

+8-4
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,20 @@
66
#include "taco/tensor.h"
77
#include "taco/util/strings.h"
88

9-
std::string constructRandomTensorKey(std::vector<int> dims, float sparsity) {
9+
std::string getTacoTensorPath() {
1010
auto path = std::getenv("TACO_TENSOR_PATH");
1111
if (path == nullptr) {
1212
std::cout << "TACO_TENSOR_PATH is unset" << std::endl;
1313
assert(false);
1414
}
15-
std::string pathStr(path);
15+
return std::string(path);
16+
}
17+
18+
std::string constructRandomTensorKey(std::vector<int> dims, float sparsity) {
19+
auto path = getTacoTensorPath();
1620
std::stringstream result;
17-
result << pathStr;
18-
if (pathStr[pathStr.size() - 1] != '/') {
21+
result << path;
22+
if (path[path.size() - 1] != '/') {
1923
result << "/";
2024
}
2125
result << "random/";

taco/bench.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@
3434
BENCHMARK_CAPTURE(bench, name, __VA_ARGS__) \
3535
->Unit(benchmark::kMicrosecond) \
3636
->Repetitions(10) \
37-
->Iterations(5) \
37+
->Iterations(1) \
3838
->ReportAggregatesOnly(true) \
3939
->UseRealTime()
4040

41+
std::string getTacoTensorPath();
4142
taco::TensorBase loadRandomTensor(std::string name, std::vector<int> dims, float sparsity, taco::Format format);
4243

4344
template<typename T>

taco/ufuncs.cpp

+58
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,61 @@ static void applyBenchSizes(benchmark::internal::Benchmark* b) {
150150

151151
TACO_BENCH_ARGS(bench_ufunc_sparse, xor_0.01, 0.01, "xor")->Apply(applyBenchSizes);
152152
TACO_BENCH_ARGS(bench_ufunc_sparse, rightShift_0.01, 0.01, ">>")->Apply(applyBenchSizes);
153+
154+
static void bench_frostt_ufunc(benchmark::State& state, std::string tnsPath) {
155+
auto path = getTacoTensorPath();
156+
auto frosttTensorPath = path;
157+
if (frosttTensorPath[frosttTensorPath.size() - 1] != '/') {
158+
frosttTensorPath += "/";
159+
}
160+
frosttTensorPath += "FROSTT/";
161+
frosttTensorPath += tnsPath;
162+
163+
// TODO (rohany): What format do we want to do here?
164+
auto frosttTensor = read(frosttTensorPath, Sparse);
165+
Tensor<double> other = shiftLastMode<double>("other", frosttTensor);
166+
167+
// TODO (rohany): Parametrize by the ufunc as well.
168+
// TODO (rohany): Certain ufuncs need for operands to be of a certain type.
169+
// ldexp for example requires the right hand side to be an integer (for python
170+
// at least). Not sure how we'll handle that for this.
171+
Func ldExp("2^", Ldexp(), leftIncAlgebra());
172+
173+
for (auto _ : state) {
174+
state.PauseTiming();
175+
Tensor<double> result("result", frosttTensor.getDimensions(), frosttTensor.getFormat());
176+
switch (frosttTensor.getOrder()) {
177+
case 4: {
178+
IndexVar i, j, k, l;
179+
result(i, j, k, l) = ldExp(frosttTensor(i, j, k, l), other(i, j, k, l));
180+
break;
181+
}
182+
case 5: {
183+
IndexVar i, j, k, l, m;
184+
result(i, j, k, l, m) = ldExp(frosttTensor(i, j, k, l, m), other(i, j, k, l, m));
185+
break;
186+
}
187+
default:
188+
state.SkipWithError("invalid tensor dimension");
189+
return;
190+
}
191+
result.compile();
192+
result.assemble();
193+
state.ResumeTiming();
194+
195+
result.compute();
196+
}
197+
}
198+
199+
// TODO (rohany): We can define another macro to "nest" defining benchmarks
200+
// for each of the ufuncs that we want to operate on.
201+
#define FOREACH_FROSTT_TENSOR(__func__) \
202+
__func__(nips, "nips.tns") \
203+
__func__(uber_pickups, "uber-pickups.tns") \
204+
__func__(chicaco_crime, "chicago-crime.tns") \
205+
__func__(lbnl_network, "lbnl-network.tns")
206+
207+
#define DECLARE_FROSTT_UFUNC_BENCH(name, path) \
208+
TACO_BENCH_ARGS(bench_frostt_ufunc, name, path);
209+
210+
FOREACH_FROSTT_TENSOR(DECLARE_FROSTT_UFUNC_BENCH)

0 commit comments

Comments
 (0)