1 // Copyright (c) 2019 Intel Corporation
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
16 #include "reorder_kernel_binary.h"
17 #include "kernel_selector_utils.h"
20 namespace kernel_selector {
21 ParamsKey ReorderKernelBinary::GetSupportedKey() const {
23 k.EnableInputDataType(Datatype::F16);
24 k.EnableInputDataType(Datatype::F32);
25 k.EnableInputDataType(Datatype::BINARY);
26 k.EnableOutputDataType(Datatype::BINARY);
27 k.EnableOutputDataType(Datatype::F32);
28 k.EnableOutputDataType(Datatype::F16);
29 k.EnableDifferentTypes();
30 k.EnableInputLayout(DataLayout::bfyx);
31 k.EnableInputLayout(DataLayout::b_fs_yx_32fp);
32 k.EnableOutputLayout(DataLayout::b_fs_yx_32fp);
33 k.EnableOutputLayout(DataLayout::bfyx);
34 k.EnableTensorOffset();
35 k.EnableTensorPitches();
40 JitConstants ReorderKernelBinary::GetJitConstants(const reorder_params& params) const {
41 auto jit = ReorderKernelBase::GetJitConstants(params);
42 KernelData kd = KernelData::Default<reorder_params>(params);
43 reorder_params& newParams = *static_cast<reorder_params*>(kd.params.get());
45 const auto& input = newParams.inputs[0];
46 jit.AddConstant(MakeJitConstant("ELEMENTS_COUNT", input.LogicalSize()));
47 jit.AddConstant(MakeJitConstant("IFM_PACK_SIZE", 32));
49 if (input.GetDType() == Datatype::BINARY) {
50 jit.AddConstant(MakeJitConstant("BINARY_INPUT", 1));
51 jit.AddConstant(MakeJitConstant("INPUT_PACKED_FEATURES_NUM", CeilDiv(input.Feature().v, 16)));
54 if (params.output.GetDType() == Datatype::BINARY) {
55 jit.AddConstant(MakeJitConstant("BINARY_OUTPUT", 1));
56 jit.AddConstant(MakeJitConstant("OUTPUT_PACKED_FEATURES_NUM", CeilDiv(params.output.Feature().v, 32)));
62 ReorderKernelBinary::DispatchData ReorderKernelBinary::SetDefault(const reorder_params& params) const {
65 const auto& input = params.inputs[0];
67 std::vector<size_t> global{input.Batch().v, CeilDiv(input.Feature().v, 32), input.Y().v * input.X().v};
68 auto local = GetOptimalLocalWorkGroupSizes(global);
81 KernelsData ReorderKernelBinary::GetKernelsData(const Params& params, const optional_params& options) const {
82 assert(params.GetType() == KernelType::REORDER);
84 const reorder_params& orgParams = static_cast<const reorder_params&>(params);
86 if (orgParams.inputs[0].GetDType() != Datatype::BINARY &&
87 orgParams.output.GetDType() != Datatype::BINARY)
90 if (orgParams.inputs[0].GetDType() == Datatype::BINARY &&
91 orgParams.inputs[0].GetLayout() != DataLayout::b_fs_yx_32fp)
94 if (orgParams.output.GetDType() == Datatype::BINARY &&
95 orgParams.output.GetLayout() != DataLayout::b_fs_yx_32fp)
98 auto estimatedTime = FORCE_PRIORITY_6;
100 return GetCommonKernelsData(orgParams, options, estimatedTime);
102 } // namespace kernel_selector