-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreatCL2.cpp
More file actions
149 lines (99 loc) · 3.58 KB
/
creatCL2.cpp
File metadata and controls
149 lines (99 loc) · 3.58 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#include "rpucfg.h"
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <string>
#include <map>
#include <algorithm>
static bool VecSort(
Vector<reg32> left, Vector<reg32> right){
return left.front() < right.front();
}
#if 0
int RPUConfig::createCL2File(const String &fileName){
// Create file
std::ofstream CL2File(fileName.c_str());
assert(CL2File);
const String & graphName = dfgGraph.name();
// uppercase of name
String GRAPHNAME = graphName;
std::transform(GRAPHNAME.begin(), GRAPHNAME.end(),
GRAPHNAME.begin(), ::toupper);
CL2File<<
"/******************************************************\n"
" * This file is generated by RPUCompiler automatically.\n"
" * ----------------------------------------------------\n"
" * This file include CL2 context to initialize GCCM. \n"
" */\n\n"
"#ifndef "<<GRAPHNAME<<"_CL2_H\n"
"#define "<<GRAPHNAME<<"_CL2_H\n"<<std::endl;
CL2File<<"\n#define "<<GRAPHNAME<<"_CL2_GROUP_SIZE\t"
<<std::dec<<CL2Context.size()<<";\n\n";
int cl2SeqNo = 0;
Vector<Vector<reg32> >::iterator cl2Iter;
for(cl2Iter = CL2Context.begin();
cl2Iter != CL2Context.end(); ++ cl2Iter, ++ cl2SeqNo){
Vector<reg32> & curCL2Context = * cl2Iter;
const String & graphName = dfgGraph.name();
// Print context
//---------------------------------------------------------
int cl2Size = static_cast<int>(curCL2Context.size());
CL2File<<"\n#define "<<GRAPHNAME<<"_CL2_SIZE\t"<<std::dec<<cl2Size<<";\n\n";
CL2File<<"unsigned int "<<graphName<<"_cl2_ctx_"<<cl2SeqNo<<"[] = {";
CL2File.fill('0');
std::size_t cl2size = curCL2Context.size();
for(std::size_t i =0; i <cl2size; ++ i){
CL2File<<"\n\t\t0x"<<std::setw(8)<<std::hex<<curCL2Context[i];
if( i + 1 != cl2size)CL2File<<",";
}
CL2File<<"\n};\n\n"<<std::endl;
}
CL2File<<"#endif"<<std::endl;
return 0;
}
#endif
//Éú³Éesl·ÂÕæ¸ñʽ
int RPUConfig::createCL2File(const String &fileName,const String &C_fileName){
// Create file
std::ofstream CL2File(fileName.c_str());
std::ofstream C_CL2File(C_fileName.c_str());
assert(CL2File);
assert(C_CL2File);
// const String & graphName = dfgGraph.name();
// uppercase of name
// String GRAPHNAME = graphName;
// std::transform(GRAPHNAME.begin(), GRAPHNAME.end(),
// GRAPHNAME.begin(), ::toupper);
C_CL2File<<"[Core Context Memory]\n"<<"Context Cnt="<<std::dec<<CL2Context.size()<<"\n";
int cl2SeqNo = 0;
Vector<Vector<reg32> >::iterator cl2Iter;
sort(CL2Context.begin(),CL2Context.end(), VecSort);
for(cl2Iter = CL2Context.begin();cl2Iter != CL2Context.end(); ++ cl2Iter)
{
Vector<reg32> & curCL2Context = * cl2Iter;
//const String & graphName = dfgGraph.name();
// Print context
//---------------------------------------------------------
int cl2Size = static_cast<int>(curCL2Context.size());
//CL2File<<"\n#define "<<GRAPHNAME<<"_CL2_SIZE\t"<<std::dec<<cl2Size<<";\n\n";
CL2File.fill('0');
C_CL2File.fill('0');
std::size_t cl2size = curCL2Context.size();
cl2SeqNo = curCL2Context[0];
for(std::size_t i =1; i <cl2size; ++ i)
{
CL2File<<std::setw(8)<<std::hex<<curCL2Context[i]<<"\n";
C_CL2File<<"ContextWord["<<std::dec<<(cl2SeqNo+1)<<"."<<std::dec<<(i-1)<<"]=0x"<<std::setw(8)<<std::hex<<curCL2Context[i]<<"\n";
//if( i + 1 != cl2size)CL2File<<",";
}
for(int i = 0; i < 21; ++ i)
{
CL2File<<"ffffffff\n";
}
C_CL2File<<"\n\n"<<std::endl;
// CL2File<<"\n\n"<<std::endl;
}
//CL2File<<"#endif"<<std::endl;
return 0;
}