FreeTensor
Loading...
Searching...
No Matches
mem_type.h
Go to the documentation of this file.
1#ifndef FREE_TENSOR_MEM_TYPE_H
2#define FREE_TENSOR_MEM_TYPE_H
3
4#include <array>
5#include <iostream>
6#include <string>
7
8#include <container_utils.h>
9#include <except.h>
10#include <serialize/to_string.h>
11
12namespace freetensor {
13
14enum class MemType : size_t {
15 ByValue = 0, // Passed by value. Always in stack or registers
16 CPU, // Main memory
20 GPUWarp,
21 // ------
22 CPUHeap, // AccessType must be Cache
23 GPUGlobalHeap, // ditto
24 // ------
26};
27
28// First deduce array length, then assert, to ensure the length
29constexpr std::array memTypeNames = {
30 "byvalue", "cpu", "gpu/global", "gpu/shared",
31 "gpu/local", "gpu/warp", "cpu/heap", "gpu/global/heap",
32};
33static_assert(memTypeNames.size() == (size_t)MemType::NumTypes);
34
35namespace detail {
36
37template <typename T, T... i>
38constexpr auto createAllMemTypes(std::integer_sequence<T, i...>) {
39 return std::array{(MemType)i...};
40}
41
42} // namespace detail
43
45 std::make_index_sequence<(size_t)MemType::NumTypes>{});
46
47inline std::ostream &operator<<(std::ostream &os, MemType mtype) {
48 return os << memTypeNames.at((size_t)mtype);
49}
50
51inline MemType parseMType(const std::string &_str) {
52 auto &&str = tolower(_str);
53 for (auto &&[i, s] : views::enumerate(memTypeNames)) {
54 if (s == str) {
55 return (MemType)i;
56 }
57 }
58 ERROR(FT_MSG << "Unrecognized memory type \"" << _str
59 << "\". Candidates are (case-insensitive): "
60 << (memTypeNames | join(", ")));
61}
62
63} // namespace freetensor
64
65#endif // FREE_TENSOR_MEM_TYPE_H
#define ERROR(msg)
Definition: except.h:141
#define FT_MSG
Definition: except.h:23
constexpr auto createAllMemTypes(std::integer_sequence< T, i... >)
Definition: mem_type.h:38
Definition: allocator.h:9
std::string tolower(const std::string &s)
Definition: container_utils.h:142
constexpr std::array memTypeNames
Definition: mem_type.h:29
std::string join(Container &&c, const std::string &splitter)
Definition: container_utils.h:194
MemType parseMType(const std::string &_str)
Definition: mem_type.h:51
std::ostream & operator<<(std::ostream &os, const Dependence &dep)
Definition: deps.cc:1404
constexpr auto allMemTypes
Definition: mem_type.h:44
MemType
Definition: mem_type.h:14