1 // Copyright (c) 2016-2020 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.
15 #include "softmax_kernel_items_class_optimized.h"
16 #include "kernel_selector_utils.h"
18 namespace kernel_selector {
19 // how many workitems we use to calculate item classes for one output, only 16 supported right now
20 static const auto workitems_per_classes = 16;
22 ParamsKey SoftmaxKerneItemsClassOptimized::GetSupportedKey() const { return GetDefaultSupportedKey(); }
24 SoftmaxKerneItemsClassOptimized::Parent::DispatchData SoftmaxKerneItemsClassOptimized::SetDefault(
25 const softmax_params& params,
26 const optional_params& optParams) const {
27 auto dispatchData = Parent::SetDefault(params, optParams);
29 auto& input = params.inputs[0];
31 size_t item_class_count = 0;
32 const auto global = GetSoftmaxDimGlobalSizes(params.dim, params.output);
34 assert(global.size() == 3);
38 item_class_count = input.X().v;
41 item_class_count = input.Y().v;
44 item_class_count = input.Z().v;
46 case SoftmaxDim::FEATURE:
47 item_class_count = input.Feature().v;
53 dispatchData.gws[0] = global[0];
54 dispatchData.gws[1] = global[1] * workitems_per_classes; // we multiply it by workitems_per_classes because we split computations of
55 // one "full item classes output" into multiple workitems by "full item
56 // classes output" i mean N outputs where N is number of item classes.
57 dispatchData.gws[2] = global[2];
59 dispatchData.lws = { 1, static_cast<size_t>(workitems_per_classes), 1 };
61 dispatchData.leftovers = item_class_count % workitems_per_classes;
63 if (item_class_count >= 32) {
64 dispatchData.efficiency = FORCE_PRIORITY_7;
66 dispatchData.efficiency = DONT_USE_IF_HAVE_SOMETHING_ELSE;
72 JitConstants SoftmaxKerneItemsClassOptimized::GetJitConstants(const softmax_params& params, DispatchData dispatchData) const {
73 auto jit = SoftmaxItemsClassKernelBase::GetJitConstants(params, dispatchData);
75 jit.AddConstant(MakeJitConstant("WORKITEMS_PER_CLASSES", workitems_per_classes));
76 jit.AddConstant(MakeJitConstant("HAS_DRIVER_PROBLEMS", params.engineInfo.bIMADSupport));
80 KernelsData SoftmaxKerneItemsClassOptimized::GetKernelsData(const Params& params,
81 const optional_params& options) const {
82 return GetCommonKernelsData(params, options);
84 } // namespace kernel_selector