2 // Copyright (c) 2016 Intel Corporation
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
8 // http://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "fully_connected_kernel_fb_io_b8_f8.h"
19 namespace kernel_selector
21 ParamsKey FullyConnected_fb_io_b8_f8::GetSupportedKey() const
24 k.EnableInputDataType(Datatype::F32);
25 k.EnableInputDataType(Datatype::F16);
26 k.EnableOutputDataType(Datatype::F32);
27 k.EnableOutputDataType(Datatype::F16);
28 k.EnableInputWeightsType(WeightsType::F32);
29 k.EnableInputWeightsType(WeightsType::F16);
30 k.EnableAllInputLayout();
31 k.EnableOutputLayout(DataLayout::fb);
33 k.EnableBiasPerFeature();
34 k.EnableNonBiasTerm();
39 FullyConnected_fb_io_b8_f8::DispatchData FullyConnected_fb_io_b8_f8::SetDefault(const fully_connected_params& arg, int ) const
41 auto kd = FullyConnectedBlockKernelBase::SetDefault(arg);
43 const auto& output = arg.output;
45 size_t groups_per_batches = GetLocalGroupsSize(arg);
46 kd.gws0 = Align(output.LogicalSize() / (GetNeuronsPerWorkItem(arg) * GetBatchesPerWorkItem(arg) * groups_per_batches), 8);
47 kd.gws1 = groups_per_batches;
54 bool FullyConnected_fb_io_b8_f8::Validate(const Params& p, const optional_params& o) const
56 if (!FullyConnectedBlockKernelBase::Validate(p, o))
61 const auto& params = static_cast<const fully_connected_params&>(p);
63 const auto& output = params.output;
64 const auto batches = output.Batch().v;
65 const auto x_size = output.LogicalSize() / batches;
67 const auto& input = params.inputs[0];
68 const auto input_x_size = input.LogicalSize() / input.Batch().v;
69 const bool proper_input_aligment = (input_x_size % 8) == 0;
70 const bool proper_output_aligment = (output.LogicalSize() / (GetNeuronsPerWorkItem(params) * GetBatchesPerWorkItem(params) * GetLocalGroupsSize(params)) % 8) == 0;
71 const bool bSupportedBatch = (batches % 8) == 0;
72 const bool bSupportedFeature = (x_size % 8) == 0;
74 if (!bSupportedBatch ||
76 !proper_input_aligment ||
77 !proper_output_aligment)
85 KernelsData FullyConnected_fb_io_b8_f8::GetKernelsData(const Params& params, const optional_params& optParams) const
87 assert(params.GetType() == KernelType::FULLY_CONNECTED);
89 const auto& orgParams = static_cast<const fully_connected_params&>(params);
91 float estimated_time =
92 orgParams.inputs[0].GetDType() == Datatype::F16 && orgParams.output.Batch().v >= 16 ?
93 FORCE_PRIORITY_3 : FORCE_PRIORITY_5;
95 for (size_t i = 0; i < autoTuneOptions.size(); i++)
97 KernelsData kd = GetTunedKernelsDataByIndex(params, optParams, DataLayout::fb, { WeightsLayout::io }, estimated_time, (int)i);
100 res.emplace_back(kd[0]);