1
1
#include < fstream>
2
2
// We're using c++14, so wer're stuck with experimental filesystem.
3
3
#include < experimental/filesystem>
4
+ #include < tuple>
4
5
5
6
#include " bench.h"
6
7
#include " benchmark/benchmark.h"
@@ -154,9 +155,34 @@ static void applyBenchSizes(benchmark::internal::Benchmark* b) {
154
155
TACO_BENCH_ARGS (bench_ufunc_sparse, xor_0.01 , 0.01 , " xor" )->Apply(applyBenchSizes);
155
156
TACO_BENCH_ARGS (bench_ufunc_sparse, rightShift_0.01 , 0.01 , " >>" )->Apply(applyBenchSizes);
156
157
157
- // fileCache is a cache of paths to tensors so that reads of the same tensor
158
- // don't need to perform duplicate disk IO.
159
- TacoTensorFileCache fileCache;
158
+ // UfuncInputCache is a cache for the input to ufunc benchmarks. These benchmarks
159
+ // operate on a tensor loaded from disk and the same tensor shifted slightly. Since
160
+ // these operations are run multiple times, we can save alot in benchmark startup
161
+ // time from caching these inputs.
162
+ struct UfuncInputCache {
163
+ template <typename U>
164
+ std::pair<taco::Tensor<int64_t >, taco::Tensor<int64_t >> getUfuncInput (std::string path, U format) {
165
+ // See if the paths match.
166
+ if (this ->lastPath == path) {
167
+ // TODO (rohany): Not worrying about whether the format was the same as what was asked for.
168
+ return std::make_pair (this ->inputTensor , this ->otherTensor );
169
+ }
170
+
171
+ // Otherwise, we missed the cache. Load in the target tensor and process it.
172
+ this ->lastPath = path;
173
+ this ->lastLoaded = taco::read (path, format);
174
+ this ->inputTensor = castToType<int64_t >(" A" , this ->lastLoaded );
175
+ this ->otherTensor = shiftLastMode<int64_t , int64_t >(" B" , this ->inputTensor );
176
+ return std::make_pair (this ->inputTensor , this ->otherTensor );
177
+ }
178
+
179
+ taco::Tensor<double > lastLoaded;
180
+ std::string lastPath;
181
+
182
+ taco::Tensor<int64_t > inputTensor;
183
+ taco::Tensor<int64_t > otherTensor;
184
+ };
185
+ UfuncInputCache inputCache;
160
186
161
187
static void bench_frostt_ufunc (benchmark::State& state, std::string tnsPath, Func op) {
162
188
auto path = getTacoTensorPath ();
@@ -168,8 +194,8 @@ static void bench_frostt_ufunc(benchmark::State& state, std::string tnsPath, Fun
168
194
frosttTensorPath += tnsPath;
169
195
170
196
// TODO (rohany): What format do we want to do here?
171
- auto frosttTensor = fileCache. readIntoType <int64_t >( " frostt " , frosttTensorPath, Sparse) ;
172
- Tensor< int64_t > other = shiftLastMode< int64_t , int64_t >( " other " , frosttTensor );
197
+ Tensor <int64_t > frosttTensor, other ;
198
+ std::tie (frosttTensor, other) = inputCache. getUfuncInput (frosttTensorPath, Sparse );
173
199
174
200
for (auto _ : state) {
175
201
state.PauseTiming ();
@@ -243,8 +269,8 @@ static void bench_suitesparse_ufunc(benchmark::State& state, Func op) {
243
269
auto tensorName = taco::util::split (filename, " ." )[0 ];
244
270
state.SetLabel (tensorName);
245
271
246
- auto ssTensor = fileCache. readIntoType <int64_t >( " ssTensor" , tensorPath, CSR) ;
247
- auto other = shiftLastMode< int64_t , int64_t >( " other " , ssTensor );
272
+ taco::Tensor <int64_t > ssTensor, other ;
273
+ std::tie (ssTensor, other) = inputCache. getUfuncInput (tensorPath, CSR );
248
274
249
275
state.counters [" dimx" ] = ssTensor.getDimension (0 );
250
276
state.counters [" dimy" ] = ssTensor.getDimension (1 );
0 commit comments