File: fp16_fc_acc_op.cc

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (110 lines) | stat: -rw-r--r-- 3,422 bytes parent folder | download | duplicates (2)
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
/**
 * Copyright (c) 2016-present, Facebook, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include <functional>

#include "caffe2/contrib/fakelowp/fp16_fc_acc_op.h"
#include "caffe2/core/init.h"
#include "caffe2/core/tensor.h"
#include "caffe2/operators/fc_inference.h"

namespace caffe2 {

template <>
int Fp16FCAccOp<CPUContext, DefaultEngine, false>::runs = 0;
template <>
float Fp16FCAccOp<CPUContext, DefaultEngine, false>::total_error = 0.0;
template <>
float Fp16FCAccOp<CPUContext, DefaultEngine, false>::total_error_with_bias =
    0.0;

template <>
int Fp16FCAccOp<CPUContext, DefaultEngine, true>::runs = 0;
template <>
float Fp16FCAccOp<CPUContext, DefaultEngine, true>::total_error = 0.0;
template <>
float Fp16FCAccOp<CPUContext, DefaultEngine, true>::total_error_with_bias = 0.0;

REGISTER_CPU_OPERATOR(
    Fp16FCAcc32,
    Fp16FCAccOp<
        CPUContext,
        DefaultEngine,
        false /* USE_ACC_FP16 */,
        true /* USE_TMP_ACCUMULATOR */,
        false /* ADD_BIAS_FIRST */>);

using namespace std::placeholders;

OPERATOR_SCHEMA(Fp16FCAcc32)
    .NumInputs(3)
    .NumOutputs(1)
    .TensorInferenceFunction(std::bind(FCShapeInference, _1, _2, false))
    .CostInferenceFunction(OpSchema::CostInferenceFunctionType(
        std::bind(CostInferenceForFC, _1, _2, false)))
    .SetDoc(R"DOC(Same as FC)DOC");

REGISTER_CPU_OPERATOR(
    Fp16FCAcc16,
    Fp16FCAccOp<
        CPUContext,
        DefaultEngine,
        true /* USE_ACC_FP16 */,
        true /* USE_TMP_ACCUMULATOR */,
        false /* ADD_BIAS_FIRST */>);

OPERATOR_SCHEMA(Fp16FCAcc16)
    .NumInputs(3)
    .NumOutputs(1)
    .TensorInferenceFunction(std::bind(FCShapeInference, _1, _2, false))
    .CostInferenceFunction(OpSchema::CostInferenceFunctionType(
        std::bind(CostInferenceForFC, _1, _2, false)))
    .SetDoc(R"DOC(Same as FC)DOC");

REGISTER_CPU_OPERATOR(
    Fp16FCAcc32NNPI,
    Fp16FCAccOp<
        CPUContext,
        DefaultEngine,
        false /* USE_ACC_FP16 */,
        false /* USE_TMP_ACCUMULATOR */,
        true /* ADD_BIAS_FIRST */>);

OPERATOR_SCHEMA(Fp16FCAcc32NNPI)
    .NumInputs(3)
    .NumOutputs(1)
    .TensorInferenceFunction(std::bind(FCShapeInference, _1, _2, false))
    .CostInferenceFunction(OpSchema::CostInferenceFunctionType(
        std::bind(CostInferenceForFC, _1, _2, false)))
    .SetDoc(R"DOC(Same as FC)DOC");

REGISTER_CPU_OPERATOR(
    Fp16FCAcc16NNPI,
    Fp16FCAccOp<
        CPUContext,
        DefaultEngine,
        true /* USE_ACC_FP16 */,
        false /* USE_TMP_ACCUMULATOR */,
        true /* ADD_BIAS_FIRST */>);

OPERATOR_SCHEMA(Fp16FCAcc16NNPI)
    .NumInputs(3)
    .NumOutputs(1)
    .TensorInferenceFunction(std::bind(FCShapeInference, _1, _2, false))
    .CostInferenceFunction(OpSchema::CostInferenceFunctionType(
        std::bind(CostInferenceForFC, _1, _2, false)))
    .SetDoc(R"DOC(Same as FC)DOC");
} // namespace caffe2