4#include <unordered_map>
5#include <unordered_set>
18namespace Autoscheduler {
21struct GlobalAccessAccumulator;
23struct SharedAccessAccumulator;
25struct LocalAccessAccumulator;
32 static constexpr double bytes_per_transaction = 32;
39 static constexpr double bytes_per_transaction = 128;
46 static constexpr double bytes_per_transaction = 32;
59 return total_num_transactions;
80 total_num_transactions +=
other.total_num_transactions;
81 total_num_bytes_used +=
other.total_num_bytes_used;
82 total_num_bytes +=
other.total_num_bytes;
86 if (total_num_bytes == 0) {
90 double result = total_num_bytes_used / total_num_bytes;
102 double total_num_transactions = 0;
103 double total_num_bytes_used = 0;
104 double total_num_bytes = 0;
116 explicit Strides(
const std::vector<int64_t> &storage_strides)
117 : storage_strides{storage_strides} {
137 for (
size_t i = 0;
i < storage_strides.size(); ++
i) {
140 return std::abs(result);
143 void dump(
bool verbose =
false) {
148 for (
size_t i = 0;
i < storage_strides.size(); ++
i) {
150 aslog(2) <<
"stride " <<
i <<
": invalid\n";
153 aslog(2) <<
"storage_stride " <<
i <<
": " << storage_strides[
i] <<
"\n";
156 for (
size_t i = 0;
i < index_strides.size(); ++
i) {
157 for (
size_t j = 0;
j < index_strides[
i].size(); ++
j) {
158 aslog(2) <<
"index_stride " <<
i <<
", storage_stride " <<
j <<
": " << index_strides[
i][
j] <<
" ";
165 void add(
const std::vector<double> &strides,
bool e) {
166 index_strides.push_back(strides);
167 is_valid.push_back(e);
170 std::vector<int64_t> storage_strides;
171 std::vector<std::vector<double>> index_strides;
172 std::vector<bool> is_valid;
177 : bytes_per_access{bytes_per_access},
178 dimensions{dimensions},
189 aslog(2) <<
"thread_id: " <<
thread_id <<
" (" << x <<
", " << y <<
", " << z <<
")\n";
194 for (
size_t i = 0;
i < dimensions; ++
i) {
195 if (!strides.valid(
i)) {
199 byte += bytes_per_access * strides.offset(
i,
thread_ids[
i]);
203 aslog(2) <<
"byte accessed: " <<
byte <<
"\n";
208 aslog(2) <<
"sectors accessed: ";
210 for (
int i = 0;
i < bytes_per_access; ++
i) {
214 sectors_accessed[
sector].insert(
byte +
i);
232 for (
const auto &
sector : sectors_accessed) {
252 int bytes_per_access;
256 int unknown_sectors = 0;
257 std::unordered_map<int64_t, std::unordered_set<int64_t>> sectors_accessed;
262 : bytes_per_access{bytes_per_access},
263 dimensions{dimensions},
274 aslog(2) <<
"thread_id: " <<
thread_id <<
" (" << x <<
", " << y <<
", " << z <<
")\n";
279 for (
size_t i = 0;
i < dimensions; ++
i) {
280 if (!strides.valid(
i)) {
284 byte += bytes_per_access * strides.offset(
i,
thread_ids[
i]);
288 aslog(2) <<
"bytes accessed: ";
289 for (
int i = 0;
i < bytes_per_access; ++
i) {
290 aslog(2) <<
byte +
i <<
" ";
296 aslog(2) <<
"banks accessed: ";
298 for (
int i = 0;
i < bytes_per_access; ++
i) {
304 bytes_accessed.insert(
byte +
i);
305 bank_to_words_accessed[
bank].insert(
word);
314 for (
const auto &
bank : bank_to_words_accessed) {
345 int bytes_per_access;
349 int unknown_banks = 0;
350 std::unordered_set<int64_t> bytes_accessed;
351 std::array<std::unordered_set<int64_t>, 32> bank_to_words_accessed;
356 : bytes_per_access{bytes_per_access},
368 aslog(2) <<
"thread_id: " <<
thread_id <<
" (" << x <<
", " << y <<
", " << z <<
")\n";
398 int bytes_per_access;
400 int thread_count = 0;
401 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