Skip to content

Commit a10fdd0

Browse files
author
Глеб Брыкин
authored
Add files via upload
1 parent ff4217a commit a10fdd0

File tree

2 files changed

+40
-32
lines changed

2 files changed

+40
-32
lines changed

Implementation/src/MKL/Ops/Forward/AvgPool2d.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//* The code is available under the Apache-2.0 license. Read the License for details.
44
//***************************************************************************************************
55

6-
//-> Latest commit: Brykin Gleb, 21.03.2021
6+
//-> Latest commit: Brykin Gleb, 22.03.2021
77

88
using System;
99
using System.Threading;
@@ -66,10 +66,10 @@ public static void AvgPool2d(Half[] x, int[] x_shape, System.Tuple<int, int> ker
6666
{
6767
continue;
6868
}
69-
mean += x[((iy * x_width + ix) * x_channel + c) * x_batch + b];
69+
mean += x[((c * x_batch + b) * x_height + iy) * x_width + ix];
7070
}
7171
}
72-
y[((oy * y_width + ox) * y_channel + c) * y_batch + b] = mean / norm;
72+
y[((c * y_batch + b) * y_height + oy) * y_width + ox] = mean / norm;
7373
}
7474
}
7575
});
@@ -121,10 +121,10 @@ public static void AvgPool2d(float[] x, int[] x_shape, System.Tuple<int, int> ke
121121
{
122122
continue;
123123
}
124-
mean += x[((iy * x_width + ix) * x_channel + c) * x_batch + b];
124+
mean += x[((c * x_batch + b) * x_height + iy) * x_width + ix];
125125
}
126126
}
127-
y[((oy * y_width + ox) * y_channel + c) * y_batch + b] = mean / norm;
127+
y[((c * y_batch + b) * y_height + oy) * y_width + ox] = mean / norm;
128128
}
129129
}
130130
});
@@ -176,10 +176,10 @@ public static void AvgPool2d(double[] x, int[] x_shape, System.Tuple<int, int> k
176176
{
177177
continue;
178178
}
179-
mean += x[((iy * x_width + ix) * x_channel + c) * x_batch + b];
179+
mean += x[((c * x_batch + b) * x_height + iy) * x_width + ix];
180180
}
181181
}
182-
y[((oy * y_width + ox) * y_channel + c) * y_batch + b] = mean / norm;
182+
y[((c * y_batch + b) * y_height + oy) * y_width + ox] = mean / norm;
183183
}
184184
}
185185
});

Implementation/src/MKL/Ops/Forward/MaxPool2d.cs

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//* The code is available under the Apache-2.0 license. Read the License for details.
44
//***************************************************************************************************
55

6-
//-> Latest commit: Brykin Gleb, 20.01.2021
6+
//-> Latest commit: Brykin Gleb, 22.01.2021
77

88
using System;
99
using System.Threading;
@@ -66,7 +66,7 @@ public static void MaxPool2d(Half[] x, int[] x_shape, System.Tuple<int, int> ker
6666
{
6767
continue;
6868
}
69-
var i = ((iy * x_width + ix) * x_channel + c) * x_batch + b;
69+
var i = ((c * x_batch + b) * x_height + iy) * x_width + ix;
7070
var v = x[i];
7171
if(v > max)
7272
{
@@ -75,8 +75,9 @@ public static void MaxPool2d(Half[] x, int[] x_shape, System.Tuple<int, int> ker
7575
}
7676
}
7777
}
78-
y[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max;
79-
indices[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max_i;
78+
var index = ((c * y_batch + b) * y_height + oy) * y_width + ox;
79+
y[index] = max;
80+
indices[index] = max_i;
8081
}
8182
}
8283
});
@@ -128,7 +129,7 @@ public static void MaxPool2d(float[] x, int[] x_shape, System.Tuple<int, int> ke
128129
{
129130
continue;
130131
}
131-
var i = ((iy * x_width + ix) * x_channel + c) * x_batch + b;
132+
var i = ((c * x_batch + b) * x_height + iy) * x_width + ix;
132133
var v = x[i];
133134
if(v > max)
134135
{
@@ -137,8 +138,9 @@ public static void MaxPool2d(float[] x, int[] x_shape, System.Tuple<int, int> ke
137138
}
138139
}
139140
}
140-
y[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max;
141-
indices[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max_i;
141+
var index = ((c * y_batch + b) * y_height + oy) * y_width + ox;
142+
y[index] = max;
143+
indices[index] = max_i;
142144
}
143145
}
144146
});
@@ -190,7 +192,7 @@ public static void MaxPool2d(double[] x, int[] x_shape, System.Tuple<int, int> k
190192
{
191193
continue;
192194
}
193-
var i = ((iy * x_width + ix) * x_channel + c) * x_batch + b;
195+
var i = ((c * x_batch + b) * x_height + iy) * x_width + ix;
194196
var v = x[i];
195197
if(v > max)
196198
{
@@ -199,8 +201,9 @@ public static void MaxPool2d(double[] x, int[] x_shape, System.Tuple<int, int> k
199201
}
200202
}
201203
}
202-
y[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max;
203-
indices[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max_i;
204+
var index = ((c * y_batch + b) * y_height + oy) * y_width + ox;
205+
y[index] = max;
206+
indices[index] = max_i;
204207
}
205208
}
206209
});
@@ -252,7 +255,7 @@ public static void MaxPool2d(byte[] x, int[] x_shape, System.Tuple<int, int> ker
252255
{
253256
continue;
254257
}
255-
var i = ((iy * x_width + ix) * x_channel + c) * x_batch + b;
258+
var i = ((c * x_batch + b) * x_height + iy) * x_width + ix;
256259
var v = x[i];
257260
if(v > max)
258261
{
@@ -261,8 +264,9 @@ public static void MaxPool2d(byte[] x, int[] x_shape, System.Tuple<int, int> ker
261264
}
262265
}
263266
}
264-
y[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max;
265-
indices[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max_i;
267+
var index = ((c * y_batch + b) * y_height + oy) * y_width + ox;
268+
y[index] = max;
269+
indices[index] = max_i;
266270
}
267271
}
268272
});
@@ -314,7 +318,7 @@ public static void MaxPool2d(sbyte[] x, int[] x_shape, System.Tuple<int, int> ke
314318
{
315319
continue;
316320
}
317-
var i = ((iy * x_width + ix) * x_channel + c) * x_batch + b;
321+
var i = ((c * x_batch + b) * x_height + iy) * x_width + ix;
318322
var v = x[i];
319323
if(v > max)
320324
{
@@ -323,8 +327,9 @@ public static void MaxPool2d(sbyte[] x, int[] x_shape, System.Tuple<int, int> ke
323327
}
324328
}
325329
}
326-
y[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max;
327-
indices[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max_i;
330+
var index = ((c * y_batch + b) * y_height + oy) * y_width + ox;
331+
y[index] = max;
332+
indices[index] = max_i;
328333
}
329334
}
330335
});
@@ -376,7 +381,7 @@ public static void MaxPool2d(short[] x, int[] x_shape, System.Tuple<int, int> ke
376381
{
377382
continue;
378383
}
379-
var i = ((iy * x_width + ix) * x_channel + c) * x_batch + b;
384+
var i = ((c * x_batch + b) * x_height + iy) * x_width + ix;
380385
var v = x[i];
381386
if(v > max)
382387
{
@@ -385,8 +390,9 @@ public static void MaxPool2d(short[] x, int[] x_shape, System.Tuple<int, int> ke
385390
}
386391
}
387392
}
388-
y[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max;
389-
indices[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max_i;
393+
var index = ((c * y_batch + b) * y_height + oy) * y_width + ox;
394+
y[index] = max;
395+
indices[index] = max_i;
390396
}
391397
}
392398
});
@@ -438,7 +444,7 @@ public static void MaxPool2d(int[] x, int[] x_shape, System.Tuple<int, int> kern
438444
{
439445
continue;
440446
}
441-
var i = ((iy * x_width + ix) * x_channel + c) * x_batch + b;
447+
var i = ((c * x_batch + b) * x_height + iy) * x_width + ix;
442448
var v = x[i];
443449
if(v > max)
444450
{
@@ -447,8 +453,9 @@ public static void MaxPool2d(int[] x, int[] x_shape, System.Tuple<int, int> kern
447453
}
448454
}
449455
}
450-
y[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max;
451-
indices[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max_i;
456+
var index = ((c * y_batch + b) * y_height + oy) * y_width + ox;
457+
y[index] = max;
458+
indices[index] = max_i;
452459
}
453460
}
454461
});
@@ -500,7 +507,7 @@ public static void MaxPool2d(long[] x, int[] x_shape, System.Tuple<int, int> ker
500507
{
501508
continue;
502509
}
503-
var i = ((iy * x_width + ix) * x_channel + c) * x_batch + b;
510+
var i = ((c * x_batch + b) * x_height + iy) * x_width + ix;
504511
var v = x[i];
505512
if(v > max)
506513
{
@@ -509,8 +516,9 @@ public static void MaxPool2d(long[] x, int[] x_shape, System.Tuple<int, int> ker
509516
}
510517
}
511518
}
512-
y[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max;
513-
indices[((oy * y_width + ox) * y_channel + c) * y_batch + b] = max_i;
519+
var index = ((c * y_batch + b) * y_height + oy) * y_width + ox;
520+
y[index] = max;
521+
indices[index] = max_i;
514522
}
515523
}
516524
});

0 commit comments

Comments
 (0)