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 "include/include_all.cl"
21 #define GET_INDEX(prefix, num) \
22 CAT(CAT(prefix, num), _OFFSET) + \
23 ((d1 * CAT(CAT(prefix, num), _STRIDE_X)) % CAT(CAT(prefix, num), _SIZE_X))*CAT(CAT(prefix, num), _X_PITCH) +\
24 ((d2 * CAT(CAT(prefix, num), _STRIDE_Y)) % CAT(CAT(prefix, num), _SIZE_Y))*CAT(CAT(prefix, num), _Y_PITCH) +\
25 (d3 % CAT(CAT(prefix, num), _FEATURE_NUM))*CAT(CAT(prefix, num), _FEATURE_PITCH) + \
26 (d4 % CAT(CAT(prefix, num), _BATCH_NUM ))*CAT(CAT(prefix, num), _BATCH_PITCH)
30 #if ELTWISE_LAYOUT_BASED || QUANTIZATION_TERM || ELTWISE_BROADCAST
32 #define GET_INDEX(prefix, num) \
33 CAT(CAT(prefix, num), _OFFSET) + \
34 (d1 % CAT(CAT(prefix, num), _SIZE_X ))*CAT(CAT(prefix, num), _X_PITCH) + \
35 (d2 % CAT(CAT(prefix, num), _SIZE_Y ))*CAT(CAT(prefix, num), _Y_PITCH) + \
36 (d3 % CAT(CAT(prefix, num), _FEATURE_NUM))*CAT(CAT(prefix, num), _FEATURE_PITCH) + \
37 (d4 % CAT(CAT(prefix, num), _BATCH_NUM ))*CAT(CAT(prefix, num), _BATCH_PITCH)
39 #elif ELTWISE_NO_PITCH_SAME_DIMS
40 #define GET_INDEX(prefix, num) \
41 CAT(CAT(prefix, num), _OFFSET) + d1
45 #define GET_INDEX(prefix, num) \
46 CAT(CAT(prefix, num), _OFFSET) + \
47 (d1 % CAT(CAT(prefix, num), _SIZES)[0])*CAT(CAT(prefix, num), _PITCHES)[0] + \
48 (d2 % CAT(CAT(prefix, num), _SIZES)[1])*CAT(CAT(prefix, num), _PITCHES)[1] + \
49 (d3 % CAT(CAT(prefix, num), _SIZES)[2])*CAT(CAT(prefix, num), _PITCHES)[2] + \
50 (d4 % CAT(CAT(prefix, num), _SIZES)[3])*CAT(CAT(prefix, num), _PITCHES)[3]
59 __global UNIT_TYPE* output
61 , const __global float* calibrations
65 #if ELTWISE_LAYOUT_BASED || QUANTIZATION_TERM || ELTWISE_BROADCAST
66 const uint d1 = get_global_id(GWS_YX) % OUTPUT_SIZE_X; // X
67 const uint d2 = get_global_id(GWS_YX) / OUTPUT_SIZE_X; // Y
68 const uint d3 = get_global_id(GWS_FEATURE); // Feature
69 const uint d4 = get_global_id(GWS_BATCH); // Batch
71 uint output_offset = OUTPUT_OFFSET +
74 d3*OUTPUT_FEATURE_PITCH +
75 d4*OUTPUT_BATCH_PITCH;
76 #elif ELTWISE_NO_PITCH_SAME_DIMS
77 const uint d1 = get_global_id(0);
78 uint output_offset = OUTPUT_OFFSET + d1;
80 const uint d1 = get_global_id(0);
81 const uint d2 = get_global_id(1);
82 const uint d3 = get_global_id(2) % OUTPUT_SIZES[2];
83 const uint d4 = get_global_id(2) / OUTPUT_SIZES[2];
85 uint output_offset = OUTPUT_OFFSET +
86 d1*OUTPUT_PITCHES[0] +
87 d2*OUTPUT_PITCHES[1] +
88 d3*OUTPUT_PITCHES[2] +
100 #if QUANTIZATION_TERM
102 res = (int)round(((float)res) * calibrations[d3]);
103 #else // CALIBRATION_TERM
104 res = (int)round(((float)res) * O_QF);
105 #endif // CALIBRATION_TERM
106 #endif // QUANTIZATION_TERM
108 #if QUANTIZATION_TERM
109 output[output_offset] = ACTIVATION(convert_char(res), NL_M, NL_N);
111 output[output_offset] = ACTIVATION(res, NL_M, NL_N);