Preface |
|
xiii | |
Acknowledgment |
|
xxv | |
|
|
|
|
3 | (28) |
|
1.1 Metafunction and type_traits |
|
|
3 | (6) |
|
1.1.1 Introduction to Metafunctions |
|
|
3 | (1) |
|
|
4 | (2) |
|
1.1.3 Various Metafunctions |
|
|
6 | (2) |
|
|
8 | (1) |
|
1.1.5 Metafunctions and Macros |
|
|
8 | (1) |
|
1.1.6 The Nominating Method of Metafunctions in This Book |
|
|
9 | (1) |
|
1.2 Template Template Parameters and Container Templates |
|
|
9 | (4) |
|
1.2.1 Templates as the Input of Metafunctions |
|
|
10 | (1) |
|
1.2.2 Templates as the Output of Metafunctions |
|
|
10 | (1) |
|
1.2.3 Container Templates |
|
|
11 | (2) |
|
1.3 Writing of Sequences, Branches, and Looping Codes |
|
|
13 | (14) |
|
1.3.1 Codes Executed in Sequence Order |
|
|
13 | (1) |
|
1.3.2 Codes Executed in Branches |
|
|
14 | (1) |
|
1.3.2.1 Implementing Branches Using std::conditional and std::conditional_t |
|
|
15 | (1) |
|
1.3.2.2 Implementing Branches with (Partial) Specialization |
|
|
15 | (3) |
|
1.3.2.3 Implementing Branches Using std::enable_if and std::enable_if_t |
|
|
18 | (1) |
|
1.3.2.4 Compile-time Branches with Different Return Types |
|
|
19 | (1) |
|
1.3.2.5 Simplify Codes with if constexpr |
|
|
20 | (1) |
|
1.3.3 Codes Executed in Loops |
|
|
21 | (2) |
|
1.3.4 Caution: Instantiation Explosion and Compilation Crash |
|
|
23 | (2) |
|
1.3.5 Branch Selection and Short Circuit Logic |
|
|
25 | (2) |
|
1.4 Curiously Recurring Template Pattern (CRTP) |
|
|
27 | (2) |
|
|
29 | (1) |
|
|
29 | (2) |
|
2 Heterogeneous Dictionaries and Policy Templates |
|
|
31 | (38) |
|
2.1 Introduction to Named Arguments |
|
|
31 | (2) |
|
2.2 Heterogeneous Dictionaries |
|
|
33 | (13) |
|
2.2.1 How to Use the Module |
|
|
33 | (3) |
|
2.2.2 The Representation of the Keys |
|
|
36 | (2) |
|
2.2.3 Implementation of Heterogeneous Dictionaries |
|
|
38 | (1) |
|
2.2.3.1 External Framework |
|
|
38 | (1) |
|
2.2.3.2 Implementation of the Function Create |
|
|
39 | (2) |
|
2.2.3.3 The Main Frame of Values |
|
|
41 | (2) |
|
2.2.3.4 Logic Analysis of NewTupleType |
|
|
43 | (2) |
|
2.2.4 A Brief Analysis of VarTypeDict's Performance |
|
|
45 | (1) |
|
2.2.5 stdr.tuple as the Cache |
|
|
45 | (1) |
|
|
46 | (17) |
|
2.3.1 Introduction to Policies |
|
|
46 | (2) |
|
|
48 | (1) |
|
2.3.1.2 Policy Object Templates |
|
|
48 | (1) |
|
2.3.2 Defining Policies and Policy Objects (Templates) |
|
|
49 | (1) |
|
|
49 | (2) |
|
2.3.2.2 Declarations of Macros and Policy Objects (Templates) |
|
|
51 | (1) |
|
|
52 | (2) |
|
2.3.4 Background Knowledge: Dominance and Virtual Inheritance |
|
|
54 | (1) |
|
2.3.5 Policy Objects and Policy Dominance Structures |
|
|
55 | (2) |
|
2.3.6 Policy Selection Metafunction |
|
|
57 | (1) |
|
|
57 | (1) |
|
2.3.6.2 The Metafunction MinorCheck_ |
|
|
58 | (3) |
|
2.3.6.3 Construct the Final Return Type |
|
|
61 | (1) |
|
2.3.7 Simplifying Declarations of Policy Objects with Macros |
|
|
62 | (1) |
|
|
63 | (1) |
|
|
64 | (5) |
|
PART II THE DEEP LEARNING FRAMEWORK |
|
|
|
3 A Brief Introduction to Deep Learning |
|
|
69 | (14) |
|
3.1 Introduction to Deep Learning |
|
|
69 | (7) |
|
3.1.1 From Machine Learning to Deep Learning |
|
|
70 | (2) |
|
3.1.2 A Wide Variety of Artificial Neural Networks |
|
|
72 | (1) |
|
3.1.2.1 Artificial Neural Networks and Matrix Operations |
|
|
72 | (1) |
|
3.1.2.2 Deep Neural Network |
|
|
73 | (1) |
|
3.1.2.3 Recurrent Neural Networks |
|
|
73 | (1) |
|
3.1.2.4 Convolutional Neural Networks |
|
|
73 | (1) |
|
3.1.2.5 Components of Neural Networks |
|
|
73 | (1) |
|
3.1.3 Organization and Training of Deep Learning Systems |
|
|
74 | (1) |
|
3.1.3.1 Network Structure and Loss Function |
|
|
74 | (1) |
|
|
75 | (1) |
|
3.1.3.3 Predictions with Models |
|
|
76 | (1) |
|
3.2 The Framework Achieved in This Book---MetaNN |
|
|
76 | (6) |
|
3.2.1 From Computing Tools of Matrices to Deep Learning Frameworks |
|
|
76 | (1) |
|
3.2.2 Introduction to MetaNN |
|
|
77 | (2) |
|
3.2.3 What We Will Discuss |
|
|
79 | (1) |
|
3.2.3.1 Data Representation |
|
|
79 | (1) |
|
3.2.3.2 Matrix Operations |
|
|
80 | (1) |
|
3.2.3.3 Layers and Automatic Derivation |
|
|
80 | (1) |
|
3.2.3.4 Evaluation and Performance Optimization |
|
|
81 | (1) |
|
3.2.4 Topics Not Covered in This Book |
|
|
82 | (1) |
|
|
82 | (1) |
|
4 Type System and Basic Data Types |
|
|
83 | (48) |
|
|
84 | (8) |
|
4.1.1 Introduction to the Type System |
|
|
84 | (1) |
|
4.1.2 Classification Systems of Iterators |
|
|
85 | (2) |
|
4.1.3 Use Tags as Template Parameters |
|
|
87 | (1) |
|
4.1.4 The Type System of MetaNN |
|
|
88 | (2) |
|
4.1.5 Metafunctions Related to the Type System |
|
|
90 | (1) |
|
4.1.5.1 Metafunction IsXXX |
|
|
90 | (1) |
|
4.1.5.2 Metafunction DataCategory |
|
|
91 | (1) |
|
|
92 | (9) |
|
4.2.1 Support for Different Computing Devices and Computing Units |
|
|
92 | (1) |
|
4.2.2 Allocation and Maintenance of Storage Space |
|
|
93 | (1) |
|
4.2.2.1 Class Template Allocator |
|
|
93 | (1) |
|
4.2.2.2 Class Template ContinuousMemory |
|
|
94 | (2) |
|
4.2.3 Shallow Copy and Detection of Write Operations |
|
|
96 | (1) |
|
4.2.3.1 Data Types without Requirements of Support for Element-level Reading and Writing |
|
|
96 | (1) |
|
4.2.3.2 Element-level Writing and Shallow Copy |
|
|
97 | (1) |
|
4.2.4 Expansion of Underlying Interfaces |
|
|
98 | (1) |
|
4.2.5 Type Conversion and Evaluation |
|
|
99 | (1) |
|
4.2.6 Data Interface Specifications |
|
|
100 | (1) |
|
|
101 | (3) |
|
4.3.1 Declaration of Class Templates |
|
|
102 | (1) |
|
4.3.2 A Specialized Version Based on CPU |
|
|
102 | (1) |
|
4.3.2.1 Type Definitions and Data Members |
|
|
103 | (1) |
|
4.3.2.2 Construction, Assignment, and Movement |
|
|
103 | (1) |
|
4.3.2.3 Reading and Writing Elements |
|
|
103 | (1) |
|
4.3.2.4 Evaluating Related Interfaces |
|
|
104 | (1) |
|
4.3.3 The Principal Type of Scalars |
|
|
104 | (1) |
|
|
104 | (11) |
|
4.4.1 Class Template Matrix - |
|
|
105 | (1) |
|
4.4.1.1 Declarations and Interfaces |
|
|
105 | (1) |
|
4.4.1.2 Dimensional Information and Element-level Reading and Writing |
|
|
106 | (1) |
|
|
107 | (2) |
|
4.4.1.4 Underlying Access Interfaces of Matrix |
|
|
109 | (1) |
|
4.4.2 Special Matrices: Trivial Matrix, Zero Matrix, and One-hot Vector |
|
|
110 | (1) |
|
|
110 | (3) |
|
|
113 | (1) |
|
|
113 | (1) |
|
4.4.3 Introducing a New Matrix Class |
|
|
114 | (1) |
|
|
115 | (12) |
|
|
115 | (3) |
|
|
118 | (1) |
|
4.5.2.1 Introduction of the Template Array |
|
|
118 | (1) |
|
4.5.2.2 Class Template Arraylmp |
|
|
119 | (2) |
|
4.5.2.3 Metafunction IsIterator |
|
|
121 | (1) |
|
4.5.2.4 Construction of Array Objects |
|
|
122 | (1) |
|
4.5.3 Duplication and Template Duplicate |
|
|
123 | (1) |
|
4.5.3.1 Introduction of the Template Duplicate |
|
|
123 | (2) |
|
4.5.3.2 Class Template Duplicatelmp |
|
|
125 | (1) |
|
4.5.3.3 Construction of the Duplicate Object |
|
|
126 | (1) |
|
|
127 | (1) |
|
|
127 | (4) |
|
5 Operations and Expression Templates |
|
|
131 | (32) |
|
5.1 Introduction to Expression Templates |
|
|
131 | (3) |
|
5.2 The Design Principles of Operation Templates in MetaNN |
|
|
134 | (2) |
|
5.2.1 Problems of the Operation Template Add |
|
|
134 | (1) |
|
5.2.2 Behavior Analysis of Operation Templates |
|
|
134 | (1) |
|
5.2.2.1 Validation and Derivation of Types |
|
|
135 | (1) |
|
5.2.2.2 Division of Object Interfaces |
|
|
135 | (1) |
|
5.2.2.3 Auxiliary Class Templates |
|
|
136 | (1) |
|
5.3 Classification of Operations |
|
|
136 | (2) |
|
|
138 | (6) |
|
5.4.1 The Auxiliary Class Template OperElementType_I OperDeviceType_ |
|
|
138 | (1) |
|
5.4.2 The Auxiliary Class Template OperXXX_ |
|
|
139 | (1) |
|
5.4.3 The Auxiliary Class Template OperCateCal |
|
|
139 | (2) |
|
5.4.4 The Auxiliary Class Template OperOrganizer |
|
|
141 | (1) |
|
5.4.4.1 Specialization for Scalars |
|
|
141 | (1) |
|
5.4.4.2 Specialization for Lists of Scalars |
|
|
142 | (1) |
|
5.4.4.3 Other Specialized Versions |
|
|
143 | (1) |
|
5.4.5 The Auxiliary Class Template OperSeq |
|
|
143 | (1) |
|
5.5 Framework for Operation Templates |
|
|
144 | (2) |
|
5.5.1 Category Tags for Operation Templates |
|
|
144 | (1) |
|
5.5.2 Definition of UnaryOp |
|
|
145 | (1) |
|
5.6 Examples of Operation Implementations |
|
|
146 | (9) |
|
|
146 | (1) |
|
5.6.1.1 Function Interface |
|
|
147 | (1) |
|
5.6.1.2 Template OperSigmoid_ |
|
|
148 | (1) |
|
|
148 | (1) |
|
|
149 | (1) |
|
5.6.2.1 Function Interface |
|
|
150 | (1) |
|
5.6.2.2 The Implementation Framework of OperAdd_ |
|
|
150 | (2) |
|
5.6.2.3 The Implementation of OperAdd_::Eval |
|
|
152 | (1) |
|
5.6.3 Operation Transpose |
|
|
153 | (2) |
|
|
155 | (1) |
|
5.7 The List of Operations Supported by MetaNN |
|
|
155 | (4) |
|
|
156 | (1) |
|
|
156 | (2) |
|
|
158 | (1) |
|
5.8 The Trade-off and Limitations of Operations |
|
|
159 | (1) |
|
5.8.1 The Trade-off of Operations |
|
|
159 | (1) |
|
5.8.2 Limitations of Operations |
|
|
160 | (1) |
|
|
160 | (1) |
|
|
161 | (2) |
|
|
163 | (42) |
|
6.1 Design Principles of Layers |
|
|
163 | (8) |
|
6.1.1 Introduction to Layers |
|
|
163 | (2) |
|
6.1.2 Construction of Layer Objects |
|
|
165 | (1) |
|
6.1.2.1 Information Delivered through Constructors |
|
|
165 | (1) |
|
6.1.2.2 Information Specified through Template Parameters |
|
|
166 | (1) |
|
6.1.3 Initialization and Loading of Parameter Matrices |
|
|
166 | (1) |
|
6.1.4 Forward Propagation |
|
|
167 | (2) |
|
6.1.5 Preservation of Intermediate Results |
|
|
169 | (1) |
|
6.1.6 Backward Propagation |
|
|
170 | (1) |
|
6.1.7 Update of Parameter Matrices |
|
|
170 | (1) |
|
6.1.8 Acquisition of Parameter Matrices |
|
|
171 | (1) |
|
6.1.9 Neutral Detection of Layers |
|
|
171 | (1) |
|
6.2 Auxiliary Logic for Layers |
|
|
171 | (16) |
|
6.2.1 Initializing the Module |
|
|
171 | (1) |
|
6.2.1.1 Using the Initialization Module |
|
|
172 | (2) |
|
|
174 | (1) |
|
6.2.1.3 Class Template Paramlnitializer |
|
|
175 | (1) |
|
6.2.1.4 Class Template Initializer |
|
|
176 | (1) |
|
6.2.2 Class Template DynamicData |
|
|
177 | (1) |
|
6.2.2.1 Base Class Template DynamicCategory |
|
|
177 | (2) |
|
6.2.2.2 Derived Class Template DynamicWrapper |
|
|
179 | (1) |
|
6.2.2.3 Encapsulating Behaviors of Pointers with DynamicData |
|
|
180 | (1) |
|
|
181 | (1) |
|
6.2.2.5 Auxiliary Functions and Auxiliary Meta Functions |
|
|
181 | (1) |
|
6.2.2.6 DynamicData and Dynamic Type System |
|
|
182 | (1) |
|
6.2.3 Common Policy Objects for Layers |
|
|
183 | (1) |
|
6.2.3.1 Parameters Relevant to Update and Backward Propagation |
|
|
183 | (1) |
|
6.2.3.2 Parameters Relevant to Input |
|
|
183 | (1) |
|
6.2.3.3 Parameters Relevant to Operations |
|
|
184 | (1) |
|
6.2.4 Metafunction InjectPolicy |
|
|
184 | (1) |
|
6.2.5 Universal I/O Structure |
|
|
185 | (1) |
|
6.2.6 Universal Operation Functions |
|
|
185 | (2) |
|
6.3 Specific Implementations of Layers |
|
|
187 | (13) |
|
|
187 | (3) |
|
|
190 | (1) |
|
6.3.2.1 Recording Intermediate Results |
|
|
190 | (1) |
|
6.3.2.2 Forward and Backward Propagation |
|
|
191 | (2) |
|
6.3.2.3 Neutral Detection |
|
|
193 | (1) |
|
|
193 | (1) |
|
|
193 | (2) |
|
6.3.3.2 Initialization and Loading of Parameters |
|
|
195 | (2) |
|
6.3.3.3 Obtaining Parameters |
|
|
197 | (1) |
|
6.3.3.4 Forward and Backward Propagation |
|
|
198 | (1) |
|
6.3.3.5 Collecting Parameter Gradients |
|
|
199 | (1) |
|
6.3.3.6 Neutral Detection |
|
|
200 | (1) |
|
6.4 Basic Layers achieved in MetaNN |
|
|
200 | (2) |
|
|
202 | (1) |
|
|
202 | (3) |
|
7 Composite and Recurrent Layers |
|
|
205 | (56) |
|
7.1 Interfaces and Design Principles of Composite Layers |
|
|
206 | (6) |
|
|
206 | (1) |
|
7.1.2 Syntax for Structural Description |
|
|
207 | (1) |
|
7.1.3 The Inheritance Relationship of Policies |
|
|
208 | (1) |
|
7.1.4 Correction of Policies |
|
|
209 | (1) |
|
7.1.5 Constructors of Composite Layers |
|
|
210 | (1) |
|
7.1.6 An Example of Complete Construction of a Composite Layer |
|
|
210 | (2) |
|
7.2 Implementation of Policy Inheritance and Correction |
|
|
212 | (3) |
|
7.2.1 Implementation of Policy Inheritance |
|
|
212 | (1) |
|
7.2.1.1 The Container SubPolicyContainer and the Functions Related |
|
|
212 | (1) |
|
7.2.1.2 The Implementation of PlainPolicy |
|
|
212 | (1) |
|
7.2.1.3 The Metafunction SubPolicyPicker |
|
|
213 | (2) |
|
7.2.2 Implementation of Policy Correction |
|
|
215 | (1) |
|
7.3 The Implementation of ComposeTopology |
|
|
215 | (15) |
|
|
215 | (1) |
|
7.3.2 Introduction to the Topological Sorting Algorithm |
|
|
216 | (1) |
|
7.3.3 Main Steps Included in ComposeTopology |
|
|
217 | (1) |
|
7.3.4 Clauses for Structural Description and Their Classification |
|
|
217 | (3) |
|
7.3.5 Examination of Structural Validity |
|
|
220 | (2) |
|
7.3.6 Implementation of Topological Sorting |
|
|
222 | (1) |
|
7.3.6.1 Pre-processing of Topological Sorting |
|
|
223 | (1) |
|
|
224 | (1) |
|
7.3.6.3 Post-processing of Topological Sorting |
|
|
225 | (1) |
|
7.3.7 The Metafunction to Instantiate Sublayers |
|
|
226 | (1) |
|
7.3.7.1 Calculation of Policies for Each Sublayer |
|
|
226 | (1) |
|
7.3.7.2 Examination of the Output Gradient |
|
|
227 | (1) |
|
7.3.7.3 Policy Correction |
|
|
228 | (1) |
|
7.3.7.4 Instantiations of Sublayers |
|
|
229 | (1) |
|
7.4 The Implementation of ComposeKernel |
|
|
230 | (16) |
|
7.4.1 Declarations of Class Templates |
|
|
230 | (1) |
|
7.4.2 Management of Sublayer Objects |
|
|
231 | (3) |
|
7.4.3 Parameter Acquisition, Gradient Collection, and Neutrality Detection |
|
|
234 | (1) |
|
7.4.4 Initialization and Loading of Parameters |
|
|
235 | (2) |
|
7.4.5 Forward Propagation |
|
|
237 | (1) |
|
7.4.5.1 The Interface ComposeKernel::FeedForward |
|
|
238 | (1) |
|
7.4.5.2 Saving the Calculation Results of Sublayers |
|
|
239 | (1) |
|
|
240 | (1) |
|
7.4.5.4 Constructing Input Containers of Sublayers |
|
|
240 | (2) |
|
7.4.5.5 The Implementation Logic of Input from in Connect |
|
|
242 | (1) |
|
7.4.5.6 The Implementation Logic of Input From Internal Connect |
|
|
243 | (2) |
|
7.4.5.7 Forward Propagation and Filling in Results of Output |
|
|
245 | (1) |
|
7.4.6 Backward Propagation |
|
|
246 | (1) |
|
7.5 Examples of Composite Layer Implementations |
|
|
246 | (1) |
|
|
247 | (9) |
|
|
247 | (3) |
|
7.6.2 Building a RecurrentLayer Class Template |
|
|
250 | (1) |
|
7.6.2.1 Main Definitions of RecurrentLayer |
|
|
250 | (2) |
|
7.6.2.2 How to Use RecurrentLayer |
|
|
252 | (1) |
|
7.6.2.3 Implementations of Functions Such as SaveWeights |
|
|
252 | (1) |
|
7.6.2.4 Forward Propagation |
|
|
253 | (1) |
|
7.6.2.5 Backward Propagation |
|
|
254 | (1) |
|
7.6.2.6 The Function FeedStepBackward |
|
|
255 | (1) |
|
7.6.3 The Use of RecurrentLayer |
|
|
256 | (1) |
|
|
256 | (1) |
|
|
257 | (4) |
|
8 Evaluation and Its Optimization |
|
|
261 | (30) |
|
8.1 Evaluation Models of MetaNN |
|
|
262 | (9) |
|
8.1.1 Hierarchy of Operations |
|
|
262 | (1) |
|
8.1.2 Module Division of Evaluation Subsystems |
|
|
263 | (1) |
|
8.1.2.1 Overview of an Evaluation Process |
|
|
264 | (1) |
|
|
265 | (2) |
|
|
267 | (1) |
|
|
268 | (1) |
|
|
268 | (1) |
|
|
269 | (1) |
|
|
270 | (1) |
|
8.1.2.8 The Auxiliary Function Evaluate |
|
|
270 | (1) |
|
8.2 Basic Evaluation Logic |
|
|
271 | (7) |
|
8.2.1 Evaluation Interface of Principal Types |
|
|
271 | (1) |
|
8.2.2 Evaluation of Non-principal Basic Data Types |
|
|
271 | (3) |
|
8.2.3 Evaluation of Operation Templates |
|
|
274 | (3) |
|
8.2.4 DynamicData and Evaluation |
|
|
277 | (1) |
|
8.3 Optimization of Evaluation Processes |
|
|
278 | (10) |
|
8.3.1 Avoiding Repetitive Computations |
|
|
278 | (2) |
|
8.3.2 Merging Similar Computations |
|
|
280 | (1) |
|
8.3.3 Multi-operation Co-optimization |
|
|
281 | (1) |
|
|
281 | (1) |
|
|
282 | (2) |
|
8.3.3.3 Matching Evaluation Structures at Compile Time |
|
|
284 | (2) |
|
8.3.3.4 Equality Judgment of Objects in MetaNN |
|
|
286 | (2) |
|
8.3.3.5 Auto-trigger Optimization |
|
|
288 | (1) |
|
|
288 | (1) |
|
|
289 | (2) |
Postscript |
|
291 | (10) |
Index |
|
301 | |