Publishing R3
[platform/upstream/dldt.git] / inference-engine / thirdparty / clDNN / kernel_selector / core / actual_kernels / fully_connected / fully_connected_kernel_MMAD.cpp
1 /*
2 // Copyright (c) 2016 Intel Corporation
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 //      http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 */
16
17 #include "fully_connected_kernel_MMAD.h"
18 #include "kernel_selector_utils.h"
19  
20 namespace kernel_selector 
21 {
22     ParamsKey FullyConnectedKernelMMAD::GetSupportedKey() const
23     {
24         ParamsKey k;
25         k.EnableInputDataType(Datatype::INT8);
26         k.EnableOutputDataType(Datatype::INT8);
27         k.EnableInputWeightsType(WeightsType::INT8);
28         k.EnableInputLayout(DataLayout::byxf_af32);
29         k.EnableOutputLayout(DataLayout::bf);
30         k.EnableOutputLayout(DataLayout::fb);
31         k.EnableBiasPerOutput();
32         k.EnableBiasPerFeature();
33         k.EnableNonBiasTerm();
34         k.EnableTensorOffset();
35         k.EnableTensorPitches();
36         k.EnableBatching();
37         k.EnableInt8Quantization();
38         k.EnableOutputCalibration();
39         return k;
40     }
41
42     std::unique_ptr<FullyConnectedKernelMMAD::Parent::DispatchData> FullyConnectedKernelMMAD::SetDefault(const fully_connected_params& params) const
43     {
44         auto runInfo = Parent::SetDefault(params);
45         
46         constexpr size_t sub_group_size = 8;
47         const auto of_maps = params.output.Feature().v;
48         const size_t of_threads_per_batch = RoundUp(of_maps, sub_group_size);
49
50         runInfo->gws0 = 1;
51         runInfo->gws1 = 1;
52         runInfo->gws2 = of_threads_per_batch * params.output.Batch().v;
53
54         runInfo->lws0 = 1;
55         runInfo->lws1 = 1;
56         runInfo->lws2 = sub_group_size;
57
58         return std::move(runInfo);
59     }
60
61     JitConstants FullyConnectedKernelMMAD::GetJitConstants(const fully_connected_params& params, const DispatchData& runInfo) const
62     {
63         auto jit = Parent::GetJitConstants(params, runInfo);
64
65         jit.AddConstant(MakeJitConstant("SUB_GROUP_SIZE", runInfo.lws2));
66
67         // pitch for special block format used in this kernel
68         const size_t ifm_32_aligned = Align(params.weights.IFM().v, 32);
69         const size_t filter_ofm_block_pitch = (ifm_32_aligned / 32) * params.weights.X().v * params.weights.Y().v * 4 * 8 * 8;
70         jit.AddConstant(MakeJitConstant("FILTER_OFM_BLOCK_PITCH", filter_ofm_block_pitch));
71
72         return jit;
73     }
74
75     KernelsData FullyConnectedKernelMMAD::GetKernelsData(const Params& params, const optional_params& options) const
76     {
77         return GetCommonKernelsData(params, options, DataLayout::byxf_af32,
78         { WeightsLayout::os_is_yx_isa8_osv8_isv4 }
79         );
80     }
81 }