halide 19.0.0__cp38-cp38-macosx_11_0_x86_64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- halide/__init__.py +39 -0
- halide/_generator_helpers.py +835 -0
- halide/bin/adams2019_retrain_cost_model +0 -0
- halide/bin/adams2019_weightsdir_to_weightsfile +0 -0
- halide/bin/anderson2021_retrain_cost_model +0 -0
- halide/bin/anderson2021_weightsdir_to_weightsfile +0 -0
- halide/bin/featurization_to_sample +0 -0
- halide/bin/gengen +0 -0
- halide/bin/get_host_target +0 -0
- halide/halide_.cpython-38-darwin.so +0 -0
- halide/imageio.py +60 -0
- halide/include/Halide.h +35293 -0
- halide/include/HalideBuffer.h +2618 -0
- halide/include/HalidePyTorchCudaHelpers.h +64 -0
- halide/include/HalidePyTorchHelpers.h +120 -0
- halide/include/HalideRuntime.h +2221 -0
- halide/include/HalideRuntimeCuda.h +89 -0
- halide/include/HalideRuntimeD3D12Compute.h +91 -0
- halide/include/HalideRuntimeHexagonDma.h +104 -0
- halide/include/HalideRuntimeHexagonHost.h +157 -0
- halide/include/HalideRuntimeMetal.h +112 -0
- halide/include/HalideRuntimeOpenCL.h +119 -0
- halide/include/HalideRuntimeQurt.h +32 -0
- halide/include/HalideRuntimeVulkan.h +137 -0
- halide/include/HalideRuntimeWebGPU.h +44 -0
- halide/lib/cmake/Halide/FindHalide_LLVM.cmake +152 -0
- halide/lib/cmake/Halide/FindV8.cmake +33 -0
- halide/lib/cmake/Halide/Halide-shared-deps.cmake +0 -0
- halide/lib/cmake/Halide/Halide-shared-targets-release.cmake +29 -0
- halide/lib/cmake/Halide/Halide-shared-targets.cmake +154 -0
- halide/lib/cmake/Halide/HalideConfig.cmake +162 -0
- halide/lib/cmake/Halide/HalideConfigVersion.cmake +65 -0
- halide/lib/cmake/HalideHelpers/FindHalide_WebGPU.cmake +27 -0
- halide/lib/cmake/HalideHelpers/Halide-Interfaces-release.cmake +116 -0
- halide/lib/cmake/HalideHelpers/Halide-Interfaces.cmake +236 -0
- halide/lib/cmake/HalideHelpers/HalideGeneratorHelpers.cmake +1056 -0
- halide/lib/cmake/HalideHelpers/HalideHelpersConfig.cmake +28 -0
- halide/lib/cmake/HalideHelpers/HalideHelpersConfigVersion.cmake +54 -0
- halide/lib/cmake/HalideHelpers/HalideTargetHelpers.cmake +99 -0
- halide/lib/cmake/HalideHelpers/MutexCopy.ps1 +31 -0
- halide/lib/cmake/HalideHelpers/TargetExportScript.cmake +55 -0
- halide/lib/cmake/Halide_Python/Halide_Python-targets-release.cmake +30 -0
- halide/lib/cmake/Halide_Python/Halide_Python-targets.cmake +125 -0
- halide/lib/cmake/Halide_Python/Halide_PythonConfig.cmake +26 -0
- halide/lib/cmake/Halide_Python/Halide_PythonConfigVersion.cmake +65 -0
- halide/lib/libHalide.dylib +0 -0
- halide/lib/libHalidePyStubs.a +0 -0
- halide/lib/libHalide_GenGen.a +0 -0
- halide/lib/libautoschedule_adams2019.so +0 -0
- halide/lib/libautoschedule_anderson2021.so +0 -0
- halide/lib/libautoschedule_li2018.so +0 -0
- halide/lib/libautoschedule_mullapudi2016.so +0 -0
- halide/share/doc/Halide/LICENSE.txt +233 -0
- halide/share/doc/Halide/README.md +439 -0
- halide/share/doc/Halide/doc/BuildingHalideWithCMake.md +626 -0
- halide/share/doc/Halide/doc/CodeStyleCMake.md +393 -0
- halide/share/doc/Halide/doc/FuzzTesting.md +104 -0
- halide/share/doc/Halide/doc/HalideCMakePackage.md +812 -0
- halide/share/doc/Halide/doc/Hexagon.md +73 -0
- halide/share/doc/Halide/doc/Python.md +844 -0
- halide/share/doc/Halide/doc/RunGen.md +283 -0
- halide/share/doc/Halide/doc/Testing.md +125 -0
- halide/share/doc/Halide/doc/Vulkan.md +287 -0
- halide/share/doc/Halide/doc/WebAssembly.md +228 -0
- halide/share/doc/Halide/doc/WebGPU.md +128 -0
- halide/share/tools/RunGen.h +1470 -0
- halide/share/tools/RunGenMain.cpp +642 -0
- halide/share/tools/adams2019_autotune_loop.sh +227 -0
- halide/share/tools/anderson2021_autotune_loop.sh +591 -0
- halide/share/tools/halide_benchmark.h +240 -0
- halide/share/tools/halide_image.h +31 -0
- halide/share/tools/halide_image_info.h +318 -0
- halide/share/tools/halide_image_io.h +2794 -0
- halide/share/tools/halide_malloc_trace.h +102 -0
- halide/share/tools/halide_thread_pool.h +161 -0
- halide/share/tools/halide_trace_config.h +559 -0
- halide-19.0.0.data/data/share/cmake/Halide/HalideConfig.cmake +6 -0
- halide-19.0.0.data/data/share/cmake/Halide/HalideConfigVersion.cmake +65 -0
- halide-19.0.0.data/data/share/cmake/HalideHelpers/HalideHelpersConfig.cmake +6 -0
- halide-19.0.0.data/data/share/cmake/HalideHelpers/HalideHelpersConfigVersion.cmake +54 -0
- halide-19.0.0.dist-info/METADATA +301 -0
- halide-19.0.0.dist-info/RECORD +84 -0
- halide-19.0.0.dist-info/WHEEL +5 -0
- halide-19.0.0.dist-info/licenses/LICENSE.txt +233 -0
@@ -0,0 +1,240 @@
|
|
1
|
+
#ifndef BENCHMARK_H
|
2
|
+
#define BENCHMARK_H
|
3
|
+
|
4
|
+
#include <algorithm>
|
5
|
+
#include <cassert>
|
6
|
+
#include <chrono>
|
7
|
+
#include <functional>
|
8
|
+
#include <limits>
|
9
|
+
|
10
|
+
#if defined(__EMSCRIPTEN__)
|
11
|
+
#include <emscripten.h>
|
12
|
+
#endif
|
13
|
+
|
14
|
+
namespace Halide {
|
15
|
+
namespace Tools {
|
16
|
+
|
17
|
+
#if !(defined(__EMSCRIPTEN__) && defined(HALIDE_BENCHMARK_USE_EMSCRIPTEN_GET_NOW))
|
18
|
+
|
19
|
+
// Prefer high_resolution_clock, but only if it's steady...
|
20
|
+
template<bool HighResIsSteady = std::chrono::high_resolution_clock::is_steady>
|
21
|
+
struct SteadyClock {
|
22
|
+
using type = std::chrono::high_resolution_clock;
|
23
|
+
};
|
24
|
+
|
25
|
+
// ...otherwise use steady_clock.
|
26
|
+
template<>
|
27
|
+
struct SteadyClock<false> {
|
28
|
+
using type = std::chrono::steady_clock;
|
29
|
+
};
|
30
|
+
|
31
|
+
inline SteadyClock<>::type::time_point benchmark_now() {
|
32
|
+
return SteadyClock<>::type::now();
|
33
|
+
}
|
34
|
+
|
35
|
+
inline double benchmark_duration_seconds(
|
36
|
+
SteadyClock<>::type::time_point start,
|
37
|
+
SteadyClock<>::type::time_point end) {
|
38
|
+
return std::chrono::duration_cast<std::chrono::duration<double>>(end - start).count();
|
39
|
+
}
|
40
|
+
|
41
|
+
#else // __EMSCRIPTEN__
|
42
|
+
|
43
|
+
// Emscripten's std::chrono::steady_clock and/or high_resolution_clock
|
44
|
+
// can throw an exception (!) if the runtime doesn't have a truly
|
45
|
+
// steady clock available. Advice from emscripten-discuss suggested
|
46
|
+
// that emscripten_get_now() is the best bet, as it is milliseconds
|
47
|
+
// (but returned as a double, with microseconds in the fractional portion),
|
48
|
+
// using either performance.now() or performance.hrtime() depending on the
|
49
|
+
// environment. Unfortunately, it's not guaranteed to be steady, and the
|
50
|
+
// auto-benchmark algorithm reacts badly to negative times, so we'll leave this
|
51
|
+
// disabled for now; you can opt-in to this by defining HALIDE_BENCHMARK_USE_EMSCRIPTEN_GET_NOW
|
52
|
+
// if you need to build for a wasm runtime with the exception behavior above.
|
53
|
+
inline double benchmark_now() {
|
54
|
+
return emscripten_get_now();
|
55
|
+
}
|
56
|
+
|
57
|
+
inline double benchmark_duration_seconds(double start, double end) {
|
58
|
+
// emscripten_get_now is *not* guaranteed to be steady.
|
59
|
+
// Clamping to a positive value is arguably better than nothing,
|
60
|
+
// but still produces unpredictable results in the adaptive case
|
61
|
+
// (which is why this is disabled by default).
|
62
|
+
return std::max((end - start) / 1000.0, 1e-9);
|
63
|
+
}
|
64
|
+
|
65
|
+
#endif
|
66
|
+
|
67
|
+
// Benchmark the operation 'op'. The number of iterations refers to
|
68
|
+
// how many times the operation is run for each time measurement, the
|
69
|
+
// result is the minimum over a number of samples runs. The result is the
|
70
|
+
// amount of time in seconds for one iteration.
|
71
|
+
//
|
72
|
+
// NOTE: it is usually simpler and more accurate to use the adaptive
|
73
|
+
// version of benchmark() later in this file; this function is provided
|
74
|
+
// for legacy code.
|
75
|
+
//
|
76
|
+
// IMPORTANT NOTE: Using this tool for timing GPU code may be misleading,
|
77
|
+
// as it does not account for time needed to synchronize to/from the GPU;
|
78
|
+
// if the callback doesn't include calls to device_sync(), the reported
|
79
|
+
// time may only be that to queue the requests; if the callback *does*
|
80
|
+
// include calls to device_sync(), it might exaggerate the sync overhead
|
81
|
+
// for real-world use. For now, callers using this to benchmark GPU
|
82
|
+
// code should measure with extreme caution.
|
83
|
+
|
84
|
+
inline double benchmark(uint64_t samples, uint64_t iterations, const std::function<void()> &op) {
|
85
|
+
double best = std::numeric_limits<double>::infinity();
|
86
|
+
for (uint64_t i = 0; i < samples; i++) {
|
87
|
+
auto start = benchmark_now();
|
88
|
+
for (uint64_t j = 0; j < iterations; j++) {
|
89
|
+
op();
|
90
|
+
}
|
91
|
+
auto end = benchmark_now();
|
92
|
+
double elapsed_seconds = benchmark_duration_seconds(start, end);
|
93
|
+
best = std::min(best, elapsed_seconds);
|
94
|
+
}
|
95
|
+
return best / iterations;
|
96
|
+
}
|
97
|
+
|
98
|
+
// Benchmark the operation 'op': run the operation until at least min_time
|
99
|
+
// has elapsed; the number of iterations is expanded as we
|
100
|
+
// progress (based on initial runs of 'op') to minimize overhead. The time
|
101
|
+
// reported will be that of the best single iteration.
|
102
|
+
//
|
103
|
+
// Most callers should be able to get good results without needing to specify
|
104
|
+
// custom BenchmarkConfig values.
|
105
|
+
//
|
106
|
+
// IMPORTANT NOTE: Using this tool for timing GPU code may be misleading,
|
107
|
+
// as it does not account for time needed to synchronize to/from the GPU;
|
108
|
+
// if the callback doesn't include calls to device_sync(), the reported
|
109
|
+
// time may only be that to queue the requests; if the callback *does*
|
110
|
+
// include calls to device_sync(), it might exaggerate the sync overhead
|
111
|
+
// for real-world use. For now, callers using this to benchmark GPU
|
112
|
+
// code should measure with extreme caution.
|
113
|
+
|
114
|
+
constexpr uint64_t kBenchmarkMaxIterations = 1000000000;
|
115
|
+
|
116
|
+
struct BenchmarkConfig {
|
117
|
+
// Attempt to use this much time (in seconds) for the meaningful samples
|
118
|
+
// taken; initial iterations will be done to find an iterations-per-sample
|
119
|
+
// count that puts the total runtime in this ballpark.
|
120
|
+
double min_time{0.1};
|
121
|
+
|
122
|
+
// Set an absolute upper time limit. Defaults to min_time * 4.
|
123
|
+
double max_time{0.1 * 4};
|
124
|
+
|
125
|
+
// Maximum value for the computed iters-per-sample.
|
126
|
+
// We need this for degenerate cases in which we have a
|
127
|
+
// very coarse-grained timer (e.g. some Emscripten/browser environments),
|
128
|
+
// and a very short operation being benchmarked; in these cases,
|
129
|
+
// we can get timings that are effectively zero, which can explode
|
130
|
+
// the predicted next-iter into ~100B or more. It should be unusual
|
131
|
+
// that client code needs to adjust this value.
|
132
|
+
uint64_t max_iters_per_sample{1000000};
|
133
|
+
|
134
|
+
// Terminate when the relative difference between the best runtime
|
135
|
+
// seen and the third-best runtime seen is no more than
|
136
|
+
// this. Controls accuracy. The closer to zero this gets the more
|
137
|
+
// reliable the answer, but the longer it may take to run.
|
138
|
+
double accuracy{0.03};
|
139
|
+
};
|
140
|
+
|
141
|
+
struct BenchmarkResult {
|
142
|
+
// Best elapsed wall-clock time per iteration (seconds).
|
143
|
+
double wall_time;
|
144
|
+
|
145
|
+
// Number of samples used for measurement.
|
146
|
+
// (There might be additional samples taken that are not used
|
147
|
+
// for measurement.)
|
148
|
+
uint64_t samples;
|
149
|
+
|
150
|
+
// Total number of iterations across all samples.
|
151
|
+
// (There might be additional iterations taken that are not used
|
152
|
+
// for measurement.)
|
153
|
+
uint64_t iterations;
|
154
|
+
|
155
|
+
// Measured accuracy between the best and third-best result.
|
156
|
+
// Will be <= config.accuracy unless max_time is exceeded.
|
157
|
+
double accuracy;
|
158
|
+
|
159
|
+
operator double() const {
|
160
|
+
return wall_time;
|
161
|
+
}
|
162
|
+
};
|
163
|
+
|
164
|
+
inline BenchmarkResult benchmark(const std::function<void()> &op, const BenchmarkConfig &config = {}) {
|
165
|
+
BenchmarkResult result{0, 0, 0};
|
166
|
+
|
167
|
+
const double min_time = std::max(10 * 1e-6, config.min_time);
|
168
|
+
const double max_time = std::max(config.min_time, config.max_time);
|
169
|
+
|
170
|
+
const double accuracy = 1.0 + std::min(std::max(0.001, config.accuracy), 0.1);
|
171
|
+
|
172
|
+
// We will do (at least) kMinSamples samples; we will do additional
|
173
|
+
// samples until the best the kMinSamples'th results are within the
|
174
|
+
// accuracy tolerance (or we run out of iterations).
|
175
|
+
constexpr int kMinSamples = 3;
|
176
|
+
double times[kMinSamples + 1] = {0};
|
177
|
+
|
178
|
+
double total_time = 0;
|
179
|
+
uint64_t iters_per_sample = 1;
|
180
|
+
for (;;) {
|
181
|
+
result.samples = 0;
|
182
|
+
result.iterations = 0;
|
183
|
+
total_time = 0;
|
184
|
+
for (int i = 0; i < kMinSamples; i++) {
|
185
|
+
times[i] = benchmark(1, iters_per_sample, op);
|
186
|
+
result.samples++;
|
187
|
+
result.iterations += iters_per_sample;
|
188
|
+
total_time += times[i] * iters_per_sample;
|
189
|
+
}
|
190
|
+
std::sort(times, times + kMinSamples);
|
191
|
+
|
192
|
+
// Any time result <= to this is considered 'zero' here.
|
193
|
+
const double kTimeEpsilon = 1e-9;
|
194
|
+
if (times[0] < kTimeEpsilon) {
|
195
|
+
// If the fastest time is tiny, then trying to use it to predict next_iters
|
196
|
+
// can just explode into something unpredictably huge, which could take far too
|
197
|
+
// long to complete. Just double iters_per_sample and try again (or terminate if
|
198
|
+
// we're over the max).
|
199
|
+
iters_per_sample *= 2;
|
200
|
+
} else {
|
201
|
+
const double time_factor = std::max(times[0] * kMinSamples, kTimeEpsilon);
|
202
|
+
if (time_factor * iters_per_sample >= min_time) {
|
203
|
+
break;
|
204
|
+
}
|
205
|
+
// Use an estimate based on initial times to converge faster.
|
206
|
+
const double next_iters = std::max(min_time / time_factor,
|
207
|
+
iters_per_sample * 2.0);
|
208
|
+
iters_per_sample = (uint64_t)(next_iters + 0.5);
|
209
|
+
}
|
210
|
+
|
211
|
+
// Ensure we never explode beyond the max.
|
212
|
+
if (iters_per_sample >= config.max_iters_per_sample) {
|
213
|
+
iters_per_sample = config.max_iters_per_sample;
|
214
|
+
break;
|
215
|
+
}
|
216
|
+
}
|
217
|
+
|
218
|
+
// - Keep taking samples until we are accurate enough (even if we run over min_time).
|
219
|
+
// - If we are already accurate enough but have time remaining, keep taking samples.
|
220
|
+
// - No matter what, don't go over max_time; this is important, in case
|
221
|
+
// we happen to get faster results for the first samples, then happen to transition
|
222
|
+
// to throttled-down CPU state.
|
223
|
+
while ((times[0] * accuracy < times[kMinSamples - 1] || total_time < min_time) &&
|
224
|
+
total_time < max_time) {
|
225
|
+
times[kMinSamples] = benchmark(1, iters_per_sample, op);
|
226
|
+
result.samples++;
|
227
|
+
result.iterations += iters_per_sample;
|
228
|
+
total_time += times[kMinSamples] * iters_per_sample;
|
229
|
+
std::sort(times, times + kMinSamples + 1);
|
230
|
+
}
|
231
|
+
result.wall_time = times[0];
|
232
|
+
result.accuracy = (times[kMinSamples - 1] / times[0]) - 1.0;
|
233
|
+
|
234
|
+
return result;
|
235
|
+
}
|
236
|
+
|
237
|
+
} // namespace Tools
|
238
|
+
} // namespace Halide
|
239
|
+
|
240
|
+
#endif
|
@@ -0,0 +1,31 @@
|
|
1
|
+
#ifndef HALIDE_TOOLS_IMAGE_H
|
2
|
+
#define HALIDE_TOOLS_IMAGE_H
|
3
|
+
|
4
|
+
/** \file
|
5
|
+
*
|
6
|
+
* This allows code that relied on halide_image.h and
|
7
|
+
* Halide::Tools::Image to continue to work with newer versions of
|
8
|
+
* Halide where HalideBuffer.h and Halide::Buffer are the way to work
|
9
|
+
* with data.
|
10
|
+
*
|
11
|
+
* Besides mapping Halide::Tools::Image to Halide::Buffer, it defines
|
12
|
+
* USING_HALIDE_BUFFER to allow code to conditionally compile for one
|
13
|
+
* or the other.
|
14
|
+
*
|
15
|
+
* It is intended as a stop-gap measure until the code can be updated.
|
16
|
+
*/
|
17
|
+
|
18
|
+
#include "HalideBuffer.h"
|
19
|
+
|
20
|
+
namespace Halide {
|
21
|
+
namespace Tools {
|
22
|
+
|
23
|
+
#define USING_HALIDE_BUFFER
|
24
|
+
|
25
|
+
template<typename T>
|
26
|
+
using Image = Buffer<T>;
|
27
|
+
|
28
|
+
} // namespace Tools
|
29
|
+
} // namespace Halide
|
30
|
+
|
31
|
+
#endif // #ifndef HALIDE_TOOLS_IMAGE_H
|
@@ -0,0 +1,318 @@
|
|
1
|
+
// This header defines several methods useful for debugging programs that
|
2
|
+
// operate on the Buffer class supporting images with arbitrary dimensions.
|
3
|
+
//
|
4
|
+
// Buffer<uint16_t> input = load_image(argv[1]);
|
5
|
+
//
|
6
|
+
// info(input, "input"); // Output the Buffer header info
|
7
|
+
// dump(input, "input"); // Dump the Buffer data
|
8
|
+
// stats(input, "input"); // Report statistics for the Buffer
|
9
|
+
//
|
10
|
+
//
|
11
|
+
#ifndef HALIDE_TOOLS_IMAGE_INFO_H
|
12
|
+
#define HALIDE_TOOLS_IMAGE_INFO_H
|
13
|
+
|
14
|
+
#include <cassert>
|
15
|
+
#include <cstdlib>
|
16
|
+
#include <iomanip>
|
17
|
+
#include <iostream>
|
18
|
+
#include <limits>
|
19
|
+
#include <memory>
|
20
|
+
#include <sstream>
|
21
|
+
#include <stdint.h>
|
22
|
+
#include <vector>
|
23
|
+
|
24
|
+
#include "HalideBuffer.h"
|
25
|
+
#include "HalideRuntime.h"
|
26
|
+
|
27
|
+
namespace Halide {
|
28
|
+
namespace Tools {
|
29
|
+
|
30
|
+
static inline void print_dimid(int d, int val) {
|
31
|
+
static const char *dimid[] = {"x", "y", "z", "w"};
|
32
|
+
int numdimid = 4;
|
33
|
+
if (d < numdimid) {
|
34
|
+
std::cout << " " << dimid[d] << ":" << val;
|
35
|
+
} else {
|
36
|
+
std::cout << " extent[" << d << "]:" << val;
|
37
|
+
}
|
38
|
+
}
|
39
|
+
|
40
|
+
static inline void print_loc(const std::vector<int32_t> &loc, int dim, const halide_buffer_t *buf) {
|
41
|
+
for (int d = 0; d < dim; d++) {
|
42
|
+
if (d) {
|
43
|
+
std::cout << ",";
|
44
|
+
}
|
45
|
+
std::cout << loc[d] + buf->dim[d].min;
|
46
|
+
}
|
47
|
+
}
|
48
|
+
|
49
|
+
static inline void print_memalign(intptr_t val) {
|
50
|
+
intptr_t align_chk = 1024 * 1024;
|
51
|
+
while (align_chk > 0) {
|
52
|
+
if ((val & (align_chk - 1)) == 0) {
|
53
|
+
char aunit = ' ';
|
54
|
+
if (align_chk >= 1024) {
|
55
|
+
align_chk >>= 10;
|
56
|
+
aunit = 'K';
|
57
|
+
}
|
58
|
+
if (align_chk >= 1024) {
|
59
|
+
align_chk >>= 10;
|
60
|
+
aunit = 'M';
|
61
|
+
}
|
62
|
+
std::cout << "align:" << align_chk;
|
63
|
+
if (aunit != ' ') {
|
64
|
+
std::cout << aunit;
|
65
|
+
}
|
66
|
+
break;
|
67
|
+
}
|
68
|
+
align_chk >>= 1;
|
69
|
+
}
|
70
|
+
}
|
71
|
+
|
72
|
+
template<typename T>
|
73
|
+
void info(Runtime::Buffer<T> &img, const char *tag = "Buffer") {
|
74
|
+
halide_buffer_t *buf = &(*img);
|
75
|
+
int dim = img.dimensions();
|
76
|
+
int img_bpp = buf->type.bytes();
|
77
|
+
int img_tsize = sizeof(T);
|
78
|
+
int img_csize = sizeof(Runtime::Buffer<T>);
|
79
|
+
int img_bsize = sizeof(halide_buffer_t);
|
80
|
+
int32_t size = 1;
|
81
|
+
uint64_t dev = buf->device;
|
82
|
+
bool host_dirty = buf->host_dirty();
|
83
|
+
bool dev_dirty = buf->device_dirty();
|
84
|
+
|
85
|
+
std::cout << std::endl
|
86
|
+
<< "-----------------------------------------------------------------------------";
|
87
|
+
std::cout << std::endl
|
88
|
+
<< "Buffer info: " << tag
|
89
|
+
<< " dim:" << dim << " bpp:" << img_bpp;
|
90
|
+
for (int d = 0; d < dim; d++) {
|
91
|
+
print_dimid(d, buf->dim[d].extent);
|
92
|
+
size *= buf->dim[d].extent;
|
93
|
+
}
|
94
|
+
std::cout << std::endl;
|
95
|
+
std::cout << tag << " class = 0x" << std::left << std::setw(10) << (void *)img
|
96
|
+
<< std::right << " # ";
|
97
|
+
print_memalign((intptr_t)&img);
|
98
|
+
std::cout << std::endl;
|
99
|
+
std::cout << tag << " class size = " << img_csize
|
100
|
+
<< " (0x" << std::hex << img_csize << std::dec << ")\n";
|
101
|
+
std::cout << tag << "-class => [ 0x" << (void *)&img
|
102
|
+
<< ", 0x" << (void *)(((char *)&img) + img_csize - 1)
|
103
|
+
<< " ], # size:" << img_csize << ", ";
|
104
|
+
print_memalign((intptr_t)&img);
|
105
|
+
std::cout << std::endl;
|
106
|
+
std::cout << tag << " buf_t size = " << img_bsize
|
107
|
+
<< " (0x" << std::hex << img_bsize << std::dec << ")\n";
|
108
|
+
std::cout << tag << "-buf_t => [ 0x" << (void *)&buf
|
109
|
+
<< ", 0x" << (void *)(((char *)&buf) + img_bsize - 1)
|
110
|
+
<< " ], # size:" << img_bsize << ", ";
|
111
|
+
print_memalign((intptr_t)&buf);
|
112
|
+
std::cout << std::endl;
|
113
|
+
if (img_bpp != img_tsize) {
|
114
|
+
std::cout << tag << " sizeof(T) = " << img_tsize << std::endl;
|
115
|
+
}
|
116
|
+
std::cout << tag << " host_dirty = " << host_dirty << std::endl;
|
117
|
+
std::cout << tag << " dev_dirty = " << dev_dirty << std::endl;
|
118
|
+
std::cout << tag << " dev handle = " << dev << std::endl;
|
119
|
+
std::cout << tag << " elem_size = " << img_bpp << std::endl;
|
120
|
+
std::cout << tag << " img_dim = " << dim << std::endl;
|
121
|
+
std::cout << tag << " width = " << img.width() << std::endl;
|
122
|
+
std::cout << tag << " height = " << img.height() << std::endl;
|
123
|
+
std::cout << tag << " channels = " << img.channels() << std::endl;
|
124
|
+
std::cout << tag << " extent[] = ";
|
125
|
+
for (int d = 0; d < dim; d++) {
|
126
|
+
std::cout << buf->dim[d].extent << " ";
|
127
|
+
}
|
128
|
+
std::cout << std::endl;
|
129
|
+
std::cout << tag << " min[] = ";
|
130
|
+
for (int d = 0; d < dim; d++) {
|
131
|
+
std::cout << buf->dim[d].min << " ";
|
132
|
+
}
|
133
|
+
std::cout << std::endl;
|
134
|
+
std::cout << tag << " stride[] = ";
|
135
|
+
for (int d = 0; d < dim; d++) {
|
136
|
+
std::cout << buf->dim[d].stride << " ";
|
137
|
+
}
|
138
|
+
std::cout << std::endl;
|
139
|
+
if (img_bpp > 1) {
|
140
|
+
for (int d = 0; d < dim; d++) {
|
141
|
+
std::cout << tag << " str[" << d << "]*bpp = "
|
142
|
+
<< std::left << std::setw(12) << buf->dim[d].stride * img_bpp
|
143
|
+
<< std::right << " # ";
|
144
|
+
print_memalign(buf->dim[d].stride * img_bpp);
|
145
|
+
std::cout << std::endl;
|
146
|
+
}
|
147
|
+
}
|
148
|
+
|
149
|
+
const T *img_data = img.data();
|
150
|
+
const T *img_next = img_data + size;
|
151
|
+
int32_t img_size = size * img_bpp;
|
152
|
+
int32_t data_size = (char *)img_next - (char *)img_data;
|
153
|
+
std::cout << tag << " size = " << size << " (0x"
|
154
|
+
<< std::hex << size << ")" << std::dec << std::endl;
|
155
|
+
std::cout << tag << " img_size = " << img_size << " (0x"
|
156
|
+
<< std::hex << img_size << ")" << std::dec << std::endl;
|
157
|
+
std::cout << tag << " data = 0x" << std::left << std::setw(10) << (void *)img_data
|
158
|
+
<< std::right << " # ";
|
159
|
+
print_memalign((intptr_t)img_data);
|
160
|
+
std::cout << std::endl;
|
161
|
+
std::cout << tag << " next = 0x" << std::left << std::setw(10) << (void *)img_next
|
162
|
+
<< std::right << " # ";
|
163
|
+
print_memalign((intptr_t)img_next);
|
164
|
+
std::cout << std::endl;
|
165
|
+
std::cout << tag << " data_size = " << data_size << " (0x"
|
166
|
+
<< std::hex << data_size << ")" << std::dec << std::endl;
|
167
|
+
std::cout << tag << " => [ 0x" << (void *)img_data
|
168
|
+
<< ", 0x" << (void *)(((char *)img_next) - 1)
|
169
|
+
<< "], # size:" << data_size << ", ";
|
170
|
+
print_memalign((intptr_t)img_data);
|
171
|
+
std::cout << std::endl;
|
172
|
+
}
|
173
|
+
|
174
|
+
template<typename T>
|
175
|
+
void dump(Runtime::Buffer<T> &img, const char *tag = "Buffer") {
|
176
|
+
halide_buffer_t *buf = &(*img);
|
177
|
+
int dim = img.dimensions();
|
178
|
+
int bpp = buf->type.bytes();
|
179
|
+
int32_t size = 1;
|
180
|
+
|
181
|
+
std::cout << std::endl
|
182
|
+
<< "Buffer dump: " << tag
|
183
|
+
<< " dim:" << dim << " bpp:" << bpp;
|
184
|
+
for (int d = 0; d < dim; d++) {
|
185
|
+
print_dimid(d, buf->dim[d].extent);
|
186
|
+
size *= buf->dim[d].extent;
|
187
|
+
}
|
188
|
+
|
189
|
+
// Arbitrary dimension image traversal
|
190
|
+
const T *ptr = img.data();
|
191
|
+
std::vector<int32_t> curloc(dim);
|
192
|
+
for (int d = 1; d < dim; d++) {
|
193
|
+
curloc[d] = -1;
|
194
|
+
}
|
195
|
+
curloc[0] = 0;
|
196
|
+
|
197
|
+
for (int32_t i = 0; i < size; i++) {
|
198
|
+
// Track changes in position in higher dimensions
|
199
|
+
for (int d = 1; d < dim; d++) {
|
200
|
+
if ((i % buf->dim[d].stride) == 0) {
|
201
|
+
curloc[d]++;
|
202
|
+
for (int din = 0; din < d; din++) {
|
203
|
+
curloc[din] = 0;
|
204
|
+
}
|
205
|
+
std::cout << std::endl;
|
206
|
+
// Print separators for dimensions beyond (x0,y1)
|
207
|
+
if (d > 1) {
|
208
|
+
print_dimid(d, curloc[d] + buf->dim[d].min);
|
209
|
+
std::cout << "\n==========================================";
|
210
|
+
}
|
211
|
+
}
|
212
|
+
}
|
213
|
+
|
214
|
+
// Check for start of row (or wrap due to width)
|
215
|
+
if ((curloc[0] % 16) == 0) {
|
216
|
+
int widx = 0;
|
217
|
+
std::ostringstream idx;
|
218
|
+
if (dim > 1) { // Multi-dim, just report (x0,y1) on each row
|
219
|
+
idx << "(" << curloc[0] + buf->dim[0].min << "," << curloc[1] + buf->dim[1].min << ")";
|
220
|
+
widx = 12;
|
221
|
+
} else { // Single-dim
|
222
|
+
idx << curloc[0] + buf->dim[0].min;
|
223
|
+
widx = 4;
|
224
|
+
}
|
225
|
+
std::cout << std::endl
|
226
|
+
<< std::setw(widx) << idx.str() << ": ";
|
227
|
+
}
|
228
|
+
|
229
|
+
// Display data
|
230
|
+
std::cout << std::setw(4) << *ptr++ + 0 << " ";
|
231
|
+
|
232
|
+
curloc[0]++; // Track position in row
|
233
|
+
}
|
234
|
+
std::cout << std::endl;
|
235
|
+
}
|
236
|
+
|
237
|
+
template<typename T>
|
238
|
+
void stats(Runtime::Buffer<T> &img, const char *tag = "Buffer") {
|
239
|
+
halide_buffer_t *buf = &(*img);
|
240
|
+
int dim = img.dimensions();
|
241
|
+
int bpp = buf->type.bytes();
|
242
|
+
int32_t size = 1;
|
243
|
+
std::cout << std::endl
|
244
|
+
<< "Buffer stats: " << tag
|
245
|
+
<< " dim:" << dim << " bpp:" << bpp;
|
246
|
+
for (int d = 0; d < dim; d++) {
|
247
|
+
print_dimid(d, buf->dim[d].extent);
|
248
|
+
size *= buf->dim[d].extent;
|
249
|
+
}
|
250
|
+
|
251
|
+
// Arbitrary dimension image traversal
|
252
|
+
const T *ptr = img.data();
|
253
|
+
std::vector<int32_t> curloc(dim);
|
254
|
+
for (int d = 1; d < dim; d++) {
|
255
|
+
curloc[d] = -1;
|
256
|
+
}
|
257
|
+
curloc[0] = 0;
|
258
|
+
|
259
|
+
// Statistics
|
260
|
+
int32_t cnt = 0;
|
261
|
+
double sum = 0;
|
262
|
+
T minval = *ptr;
|
263
|
+
T maxval = *ptr;
|
264
|
+
std::vector<int32_t> minloc(dim);
|
265
|
+
std::vector<int32_t> maxloc(dim);
|
266
|
+
for (int d = 0; d < dim; d++) {
|
267
|
+
minloc[d] = 0;
|
268
|
+
maxloc[d] = 0;
|
269
|
+
}
|
270
|
+
|
271
|
+
for (int32_t i = 0; i < size; i++) {
|
272
|
+
// Track changes in position in higher dimensions
|
273
|
+
for (int d = 1; d < dim; d++) {
|
274
|
+
if ((i % buf->dim[d].stride) == 0) {
|
275
|
+
curloc[d]++;
|
276
|
+
for (int din = 0; din < d; din++) {
|
277
|
+
curloc[din] = 0;
|
278
|
+
}
|
279
|
+
}
|
280
|
+
}
|
281
|
+
|
282
|
+
// Collect data
|
283
|
+
T val = *ptr++;
|
284
|
+
sum += val;
|
285
|
+
cnt++;
|
286
|
+
if (val < minval) {
|
287
|
+
minval = val;
|
288
|
+
for (int d = 0; d < dim; d++) {
|
289
|
+
minloc[d] = curloc[d];
|
290
|
+
}
|
291
|
+
}
|
292
|
+
if (val > maxval) {
|
293
|
+
maxval = val;
|
294
|
+
for (int d = 0; d < dim; d++) {
|
295
|
+
maxloc[d] = curloc[d];
|
296
|
+
}
|
297
|
+
}
|
298
|
+
|
299
|
+
curloc[0]++; // Track position in row
|
300
|
+
}
|
301
|
+
|
302
|
+
double avg = sum / cnt;
|
303
|
+
std::cout << std::endl;
|
304
|
+
std::cout << "min = " << minval + 0 << " @ (";
|
305
|
+
print_loc(minloc, dim, buf);
|
306
|
+
std::cout << ")" << std::endl;
|
307
|
+
std::cout << "max = " << maxval + 0 << " @ (";
|
308
|
+
print_loc(maxloc, dim, buf);
|
309
|
+
std::cout << ")" << std::endl;
|
310
|
+
std::cout << "mean = " << avg << std::endl;
|
311
|
+
std::cout << "N = " << cnt << std::endl;
|
312
|
+
std::cout << std::endl;
|
313
|
+
}
|
314
|
+
|
315
|
+
} // namespace Tools
|
316
|
+
} // namespace Halide
|
317
|
+
|
318
|
+
#endif // HALIDE_TOOLS_IMAGE_INFO_H
|