forked from hxmhuang/OpenArray_Dev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcache.cpp
More file actions
62 lines (53 loc) · 1.39 KB
/
cache.cpp
File metadata and controls
62 lines (53 loc) · 1.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "cache.hpp"
#include <map>
#include <string>
#include "Node.hpp"
#include "Operator.hpp"
#include <unordered_map>
typedef std::unordered_map<std::string, NodePtr> Cached_Nodes;
Cached_Nodes _cached_nodes;
extern "C"{
void find_node(NodePtr& p, std::string key) {
Cached_Nodes::iterator it;
it = _cached_nodes.find(key);
if (it != _cached_nodes.end()) {
p = it->second;
}else{
NodePtr np;
p = np;
}
return;
}
void cache_node(NodePtr& p, std::string key) {
Cached_Nodes::iterator it;
it = _cached_nodes.find(key);
if(it != _cached_nodes.end()){
std::cout<<"Error: found a same key already cached. Maybe hash conflicted?";
}else{
_cached_nodes[key] = p;
oa::ops::gen_kernels_JIT_with_op(p);
}
}
std::string gen_node_key(const char* file, const int line) {
string tmp_node_key = "";
tmp_node_key = file;
tmp_node_key += ":";
int templine = line;
tmp_node_key += to_string((long long)templine);
std::cout<<tmp_node_key<<endl;
return tmp_node_key;
}
bool is_valid(NodePtr& p) {
if (p == NULL) printf("not found node\n");
else printf("found node\n");
return (p != NULL);
}
void clear_cache() {
/*
for (auto it = _cached_nodes.begin(); it != _cached_nodes.end(); it++) {
cout<<it->first<<" "<<it->second<<endl;
}
*/
_cached_nodes.clear();
}
}