4#include <unordered_map>
5#include <unordered_set>
19namespace Autoscheduler {
22struct GlobalAccessAccumulator;
24struct SharedAccessAccumulator;
26struct LocalAccessAccumulator;
33 static constexpr double bytes_per_transaction = 32;
40 static constexpr double bytes_per_transaction = 128;
47 static constexpr double bytes_per_transaction = 32;
60 return total_num_transactions;
81 total_num_transactions +=
other.total_num_transactions;
82 total_num_bytes_used +=
other.total_num_bytes_used;
83 total_num_bytes +=
other.total_num_bytes;
87 if (total_num_bytes == 0) {
91 double result = total_num_bytes_used / total_num_bytes;
103 double total_num_transactions = 0;
104 double total_num_bytes_used = 0;
105 double total_num_bytes = 0;
117 explicit Strides(
const std::vector<int64_t> &storage_strides)
118 : storage_strides{storage_strides} {
138 for (
size_t i = 0;
i < storage_strides.size(); ++
i) {
141 return std::abs(result);
144 void dump(
bool verbose =
false) {
149 for (
size_t i = 0;
i < storage_strides.size(); ++
i) {
151 aslog(2) <<
"stride " <<
i <<
": invalid\n";
154 aslog(2) <<
"storage_stride " <<
i <<
": " << storage_strides[
i] <<
"\n";
157 for (
size_t i = 0;
i < index_strides.size(); ++
i) {
158 for (
size_t j = 0;
j < index_strides[
i].size(); ++
j) {
159 aslog(2) <<
"index_stride " <<
i <<
", storage_stride " <<
j <<
": " << index_strides[
i][
j] <<
" ";
166 void add(
const std::vector<double> &strides,
bool e) {
167 index_strides.push_back(strides);
168 is_valid.push_back(e);
171 std::vector<int64_t> storage_strides;
172 std::vector<std::vector<double>> index_strides;
173 std::vector<bool> is_valid;
178 : bytes_per_access{bytes_per_access},
179 dimensions{dimensions},
190 aslog(2) <<
"thread_id: " <<
thread_id <<
" (" << x <<
", " << y <<
", " << z <<
")\n";
195 for (
size_t i = 0;
i < dimensions; ++
i) {
196 if (!strides.valid(
i)) {
200 byte += bytes_per_access * strides.offset(
i,
thread_ids[
i]);
204 aslog(2) <<
"byte accessed: " <<
byte <<
"\n";
209 aslog(2) <<
"sectors accessed: ";
211 for (
int i = 0;
i < bytes_per_access; ++
i) {
215 sectors_accessed[
sector].insert(
byte +
i);
233 for (
const auto &
sector : sectors_accessed) {
253 int bytes_per_access;
257 int unknown_sectors = 0;
258 std::unordered_map<int64_t, std::unordered_set<int64_t>> sectors_accessed;
263 : bytes_per_access{bytes_per_access},
264 dimensions{dimensions},
275 aslog(2) <<
"thread_id: " <<
thread_id <<
" (" << x <<
", " << y <<
", " << z <<
")\n";
280 for (
size_t i = 0;
i < dimensions; ++
i) {
281 if (!strides.valid(
i)) {
285 byte += bytes_per_access * strides.offset(
i,
thread_ids[
i]);
289 aslog(2) <<
"bytes accessed: ";
290 for (
int i = 0;
i < bytes_per_access; ++
i) {
291 aslog(2) <<
byte +
i <<
" ";
297 aslog(2) <<
"banks accessed: ";
299 for (
int i = 0;
i < bytes_per_access; ++
i) {
305 bytes_accessed.insert(
byte +
i);
306 bank_to_words_accessed[
bank].insert(
word);
315 for (
const auto &
bank : bank_to_words_accessed) {
346 int bytes_per_access;
350 int unknown_banks = 0;
351 std::unordered_set<int64_t> bytes_accessed;
352 std::array<std::unordered_set<int64_t>, 32> bank_to_words_accessed;
357 : bytes_per_access{bytes_per_access},
369 aslog(2) <<
"thread_id: " <<
thread_id <<
" (" << x <<
", " << y <<
", " << z <<
")\n";
399 int bytes_per_access;
401 int thread_count = 0;
402 std::unordered_map<int64_t, std::unordered_set<int64_t>> sectors_accessed;
#define internal_assert(c)
typename MemTraits< T >::Accumulator Accumulator
This file defines the class FunctionDAG, which is our representation of a Halide pipeline,...
@ Internal
Not visible externally, similar to 'static' linkage in C.
Internal::ConstantInterval cast(Type t, const Internal::ConstantInterval &a)
Cast operators for ConstantIntervals.
signed __INT64_TYPE__ int64_t
GlobalAccessAccumulator(int bytes_per_access, size_t dimensions, const Strides &strides, bool verbose)
void operator()(int thread_id, int x, int y, int z, int active, bool last_thread)
void add_access_info(int num_requests, GlobalMemInfo &global_mem_info, bool is_tail_warp) const
void add_access_info(int num_requests, LocalMemInfo &local_mem_info, bool is_tail_warp) const
LocalAccessAccumulator(int bytes_per_access, bool verbose)
void operator()(int thread_id, int x, int y, int z, int active, bool last_thread)
void add_access_info(double num_requests, double num_transactions_per_request, double num_bytes_used_per_request)
static constexpr double bytes_per_transaction
double efficiency() const
double num_transactions() const
void add(const MemInfo< T > &other)
void operator()(int thread_id, int x, int y, int z, int active, bool last_thread)
SharedAccessAccumulator(int bytes_per_access, size_t dimensions, const Strides &strides, bool verbose)
void add_access_info(int num_requests, SharedMemInfo &shared_mem_info, bool is_tail_warp) const
bool valid(size_t loop_index) const
void dump(bool verbose=false)
void add_valid(const std::vector< double > &strides)
Strides(const std::vector< int64_t > &storage_strides)
int64_t offset(size_t loop_index, int64_t point) const