-
Notifications
You must be signed in to change notification settings - Fork 160
/
Copy pathfactory_cpu.hpp
579 lines (498 loc) · 18.9 KB
/
factory_cpu.hpp
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
// Copyright (C) 2019. Huawei Technologies Co., Ltd. All rights reserved.
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
// COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#ifndef _FACTORY_CPU_H
#define _FACTORY_CPU_H
#include "factory.hpp"
#include "attention.hpp"
#include "jump.hpp"
#include "cpu/resize_cpu.hpp"
#include "cpu/pooling_cpu.hpp"
#include "cpu/convolution_cpu.hpp"
#include "cpu/deconvolution_cpu.hpp"
#include "cpu/eltwise_cpu.hpp"
#include "cpu/softmax_cpu.hpp"
#include "cpu/logsoftmax_cpu.hpp"
#include "cpu/activation_cpu.hpp"
#include "cpu/fully_connected_cpu.hpp"
#include "cpu/scale_cpu.hpp"
#include "cpu/concat_cpu.hpp"
#include "cpu/clip_cpu.hpp"
#include "cpu/squeeze_cpu.hpp"
#include "cpu/reshape_cpu.hpp"
#include "cpu/embedding_cpu.hpp"
#include "cpu/layer_norm_cpu.hpp"
#include "cpu/matmul_cpu.hpp"
#include "cpu/power_cpu.hpp"
#include "cpu/transpose_cpu.hpp"
#include "cpu/slice_cpu.hpp"
#include "cpu/shared_weight_cpu.hpp"
#include "cpu/repeat_cpu.hpp"
#include "cpu/copy_cpu.hpp"
#include "cpu/check_cpu.hpp"
#include "cpu/preallocated_memory_cpu.hpp"
#include "cpu/argmax_cpu.hpp"
#include "cpu/unsqueeze_cpu.hpp"
#include "cpu/rnncell_cpu.hpp"
#include "cpu/rnn_cpu.hpp"
#include "cpu/padding_cpu.hpp"
#include "attention_mask.hpp"
#include "relative_position_embedding.hpp"
#include "relative_shift.hpp"
#include "cpu/detection_output_cpu.hpp"
#include "cpu/prior_box_cpu.hpp"
#include "yolov3_detection_output.hpp"
#include "cpu/channel_resize_cpu.hpp"
#include "cpu/l2norm_cpu.hpp"
#include "cpu/tile_cpu.hpp"
#include "cpu/prelu_cpu.hpp"
#include "cpu/tfslice_cpu.hpp"
#include "cpu/splice_cpu.hpp"
#include "cpu/shape_cpu.hpp"
#include "cpu/reduction_cpu.hpp"
#include "cpu/where_cpu.hpp"
#include "cpu/tdnn_convolution_cpu.hpp"
#include "cpu/tdnn_fully_connected_cpu.hpp"
#include "cpu/batch_norm_cpu.hpp"
#include "cpu/cast_cpu.hpp"
#include "cpu/instance_norm_cpu.hpp"
#include "cpu/expand_cpu.hpp"
#include "cpu/scatter_cpu.hpp"
#include "cpu/gather_cpu.hpp"
#include "cpu/select_cpu.hpp"
#include "cpu/topk_cpu.hpp"
#include "cpu/gat_cpu.hpp"
#include "cpu/quantizelinear_cpu.hpp"
#include "cpu/grid_sample_cpu.hpp"
#include "cpu/onehot_cpu.hpp"
#include "cpu/cum_cpu.hpp"
#include "cpu/non_max_suppression_cpu.hpp"
#include "cpu/constant_of_shape_cpu.hpp"
#include "cpu/non_zero_cpu.hpp"
#include "cpu/roialign_cpu.hpp"
#include "cpu/range_cpu.hpp"
#include "cpu/depth2space_cpu.hpp"
#include "cpu/space2depth_cpu.hpp"
#include "cpu/einsum_cpu.hpp"
#include "cpu/unpooling_cpu.hpp"
#include "cpu/random_cpu.hpp"
#include "cpu/flatten_cpu.hpp"
#include "cpu/convert_color_cpu.hpp"
#include "cpu/bilateral_slice_apply_cpu.hpp"
#include "cpu/lut_preprocess_cpu.hpp"
#include "cpu/lut_cpu.hpp"
class FactoryCPU : public Factory {
public:
std::shared_ptr<Operator> createConvolution(DataType dt,
ConvolutionParamSpec p,
ActivationParamSpec dwActivationParamSpec,
ActivationParamSpec pwActivationParamSpec) override
{
auto cep =
(Convolution *)(new ConvolutionCPU(dt, p, dwActivationParamSpec, pwActivationParamSpec));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createPooling(PoolingParamSpec p) override
{
auto cep = (Pooling *)(new PoolingCPU(p));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createActivation(ActivationParamSpec activeDesc) override
{
auto cep = (Activation *)new ActivationCPU(activeDesc);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createEltwise(EltwiseParamSpec eltwiseDesc) override
{
auto cep = (Eltwise *)new EltwiseCPU(eltwiseDesc);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createChannelResize(DataType dt, ChannelResizeParamSpec p) override
{
auto cep = new ChannelResizeCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createFullyConnected(
DataType dt, FullyConnectedParamSpec p, U32 numInput) override
{
auto cep = (FullyConnected *)(new FullyConnectedCPU(dt, p, numInput));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createReshape(DataType dt, ReshapeParamSpec p) override
{
auto cep = (Reshape *)(new ReshapeCPU(dt, p));
return std::shared_ptr<Operator>(cep);
}
#ifdef _USE_INT8
std::shared_ptr<Operator> createQuantizeLinear(DataType dt, QuantizeLinearParamSpec p) override
{
auto cep = new QuantizeLinearCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
#endif
#ifndef _USE_LITE
std::shared_ptr<Operator> createConcat(ConcatParamSpec p) override
{
auto cep = (Concat *)(new ConcatCPU(p));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createFlatten(FlattenParamSpec p) override
{
auto cep = new FlattenCPU(p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createDeconvolution(
DataType dt, ConvolutionParamSpec p, ActivationParamSpec activationDesc) override
{
auto cep = new DeconvolutionCPU(dt, p, activationDesc);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createSoftmax(DataType dt, SoftmaxParamSpec p) override
{
auto cep = new SoftmaxCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createLogSoftmax(DataType dt, SoftmaxParamSpec p) override
{
auto cep = new LogSoftmaxCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createScale(DataType dt, ScaleParamSpec p, int numChannels) override
{
auto cep = (Scale *)(new ScaleCPU(dt, p, numChannels));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createRNN(DataType dt, RNNParamSpec p) override
{
auto cep = (RNNCell *)new RNNCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createRNNCell(DataType dt, RNNParamSpec p) override
{
auto cep = (RNNCell *)new RNNCellCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createEmbedding(DataType dt, EmbedParamSpec p) override
{
auto cep = (Embedding *)(new EmbeddingCPU(dt, p));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createPower(DataType dt, PowerParamSpec p) override
{
auto cep = (Power *)(new PowerCPU(dt, p));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createMatMul(DataType dt, MatMulParamSpec p) override
{
auto cep = (MatMul *)(new MatMulCPU(dt, p));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createLayerNorm(
DataType dt, LayerNormParamSpec p, U32 weightNum) override
{
auto cep = (LayerNorm *)(new LayerNormCPU(dt, p, weightNum));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createResize(DataType paramDT, ResizeParamSpec p) override
{
auto cep = (Resize *)(new ResizeCPU(paramDT, p));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createSlice(DataType dt, SliceParamSpec p) override
{
auto cep = (Slice *)(new SliceCPU(dt, p));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createTranspose(DataType dt, TransposeParamSpec p) override
{
auto cep = (Transpose *)new TransposeCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createAttention(DataType dt, AttentionParamSpec p) override
{
auto cep = new Attention(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createClip(DataType dt, ClipParamSpec p) override
{
auto cep = (Clip *)(new ClipCPU(dt, p));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createSqueeze(DataType dt, SqueezeParamSpec p) override
{
auto cep = (Squeeze *)(new SqueezeCPU(dt, p));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createUnsqueeze(DataType dt, UnsqueezeParamSpec p) override
{
auto cep = (Unsqueeze *)new UnsqueezeCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createReduction(DataType dt, ReductionParamSpec p) override
{
auto cep = new ReductionCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createArgMax(DataType dt, ArgMaxParamSpec p) override
{
auto cep = (ArgMax *)new ArgMaxCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createCopy(DataType dt, CopyParamSpec p) override
{
auto cep = (Copy *)new CopyCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createCheck(DataType dt, CheckParamSpec p) override
{
auto cep = (Check *)new CheckCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createRepeat(
DataType dt, RepeatParamSpec p, I32 jumpOperatorIndex, I32 currentOperatorIndex) override
{
auto cep = (Repeat *)new RepeatCPU(dt, p, jumpOperatorIndex, currentOperatorIndex);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createBilateralSliceApply(BilateralSliceApplyParamSpec p) override
{
auto cep = (Repeat *)new BilateralSliceApplyCPU(p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createPreAllocatedMemory(PreAllocatedMemoryParamSpec p) override
{
auto cep = (PreAllocatedMemory *)new PreAllocatedMemoryCPU(p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createSharedWeight(DataType dt,
TensorDesc desc,
std::string outputTensorName,
std::map<std::string, std::shared_ptr<Tensor>> *tensorMapPtr) override
{
auto cep = (SharedWeight *)new SharedWeightCPU(dt, desc, outputTensorName, tensorMapPtr);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createJump(
DataType dt, I32 jumpOperatorIndex, I32 currentOperatorIndex) override
{
auto cep = new Jump(dt, jumpOperatorIndex, currentOperatorIndex);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createSpace2Depth(DataType dt, Space2DepthParamSpec p) override
{
auto cep = new Space2DepthCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createDepth2Space(DataType dt, Depth2SpaceParamSpec p) override
{
auto cep = new Depth2SpaceCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createPReLU(DataType dt) override
{
auto cep = new PReLUCPU(dt);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createAttentionMask(DataType dt, AttentionMaskParamSpec p) override
{
auto cep = new AttentionMask(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createRelativePositionEmbedding(DataType dt, EmbedParamSpec p) override
{
auto cep = new RelativePositionEmbedding(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createRelativeShift(DataType dt, RelativeShiftParamSpec p) override
{
auto cep = new RelativeShift(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createPadding(DataType dt, PadParamSpec p) override
{
auto cep = (Padding *)(new PaddingCPU(dt, p));
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createPriorBox(DataType dt, PriorBoxParamSpec p) override
{
auto cep = new PriorBoxCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createDetectionOutput(DataType dt, DetectionOutputParamSpec p) override
{
auto cep = new DetectionOutputCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createYolov3DetectionOutput(
DataType dt, Yolov3DetectionOutputParamSpec p) override
{
auto cep = new Yolov3DetectionOutput(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createL2Norm(DataType dt) override
{
auto cep = new L2NormCPU(dt);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createTile(DataType dt, TileParamSpec p) override
{
auto cep = new TileCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createTfSlice(DataType dt, TfSliceParamSpec p) override
{
auto cep = new TfSliceCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createSplice(DataType dt, SpliceParamSpec p) override
{
auto cep = new SpliceCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createShape() override
{
auto cep = new ShapeCPU();
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createWhere(DataType dt) override
{
auto cep = new WhereCPU(dt);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createTdnn(DataType dt, TdnnParamSpec p) override
{
//auto cep = new TdnnConvolutionCPU(dt, p);
auto cep = new TdnnFullyConnectedCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createBatchNorm(DataType dt, BatchNormParamSpec p) override
{
auto cep = new BatchNormCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createTopK(DataType dt, TopKParamSpec p) override
{
auto cep = new TopKCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createCast(DataType dt, CastParamSpec p) override
{
auto cep = new CastCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createInstanceNorm(DataType dt, InstanceNormParamSpec p) override
{
auto cep = new InstanceNormCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createExpand(DataType dt, ExpandParamSpec p) override
{
auto cep = new ExpandCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createScatter(DataType dt, ScatterParamSpec p) override
{
auto cep = new ScatterCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createGather(DataType dt, GatherParamSpec p) override
{
auto cep = new GatherCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createSelect(DataType dt) override
{
auto cep = new SelectCPU(dt);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createRoIAlign(DataType dt, RoIAlignParamSpec p) override
{
auto cep = new RoIAlignCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createGenerateProposals(
DataType dt, GenerateProposalsParamSpec p) override
{
OP_UNSUP(2, dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createGAT(DataType dt, GATParamSpec p) override
{
auto cep = new GATCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createGridSample(DataType dt, GridSampleParamSpec p) override
{
auto cep = new GridSampleCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createOneHot(DataType dt, OneHotParamSpec p) override
{
auto cep = new OneHotCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createCum(DataType dt, CumParamSpec p) override
{
auto cep = new CumCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createNonMaxSuppression(
DataType dt, NonMaxSuppressionParamSpec p) override
{
auto cep = new NonMaxSuppressionCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createConstantOfShape(DataType dt, ConstantOfShapeParamSpec p) override
{
auto cep = new ConstantOfShapeCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createNonZero(DataType dt) override
{
auto cep = new NonZeroCPU(dt);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createRange(DataType dt, RangeParamSpec p) override
{
auto cep = new RangeCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createEinsum(DataType dt, EinsumParamSpec p) override
{
auto cep = new EinsumCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createUnPooling(PoolingParamSpec p) override
{
auto cep = new UnPoolingCPU(p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createRandom(RandomParamSpec p) override
{
auto cep = new RandomCPU(p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createConvertColor(DataType dt, ConvertColorParamSpec p) override
{
auto cep = new ConvertColorCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createLutPreprocess(DataType dt) override
{
auto cep = new LutPreprocessCPU(dt);
return std::shared_ptr<Operator>(cep);
}
std::shared_ptr<Operator> createLut(DataType dt, LutParamSpec p) override
{
auto cep = new LutCPU(dt, p);
return std::shared_ptr<Operator>(cep);
}
#endif
};
#endif // _FACTORY_CPU_H