gen_tf_pb.py 26.5 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#####################################################################################
# The MIT License (MIT)
#
# Copyright (c) 2015-2022 Advanced Micro Devices, Inc. All rights reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#####################################################################################
24
25
26
# This script generates tf pb files for MIGraphX tf operator tests.
# To generate an individual pb file, you can use the following
# command: python -c "import gen_tf_pb; gen_tf_pb.{test_name}_test()"
Khalique's avatar
Khalique committed
27
28
import tensorflow as tf

Khalique's avatar
Khalique committed
29

Khalique's avatar
Khalique committed
30
31
32
33
def tf_test(op_test):
    def run_test():
        g1 = tf.Graph()
        op_test(g1)
Khalique's avatar
Khalique committed
34
35
36
37
38
        tf.io.write_graph(g1,
                          '.',
                          '{}.pb'.format(op_test.__name__),
                          as_text=False)

Khalique's avatar
Khalique committed
39
    return run_test
Khalique's avatar
Khalique committed
40

Khalique's avatar
Khalique committed
41

Khalique's avatar
Khalique committed
42
43
@tf_test
def add_test(g1):
Khalique's avatar
Khalique committed
44
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
45
46
47
48
49
50
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 2, 3),
                                            name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 2, 3),
                                            name='1')
Khalique's avatar
Khalique committed
51
52
        tf.add(g1_input, g2_input, name='add1')

Khalique's avatar
Khalique committed
53

kahmed10's avatar
kahmed10 committed
54
55
56
57
58
59
60
61
62
63
64
65
@tf_test
def addv2_test(g1):
    with g1.as_default():
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 2, 3),
                                            name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 2, 3),
                                            name='1')
        tf.raw_ops.AddV2(x=g1_input, y=g2_input, name='add1')


Khalique's avatar
Khalique committed
66
67
@tf_test
def add_bcast_test(g1):
Khalique's avatar
Khalique committed
68
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
69
70
        g1_input = tf.compat.v1.placeholder(tf.float32, shape=(2, 3), name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32, shape=(2, 1), name='1')
Khalique's avatar
Khalique committed
71
72
        tf.math.add(g1_input, g2_input, name='add_bcast1')

Khalique's avatar
Khalique committed
73

74
75
76
@tf_test
def argmax_test(g1):
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
77
78
79
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(3, 4, 5, 6),
                                            name='0')
80
81
82
83
84
85
        tf.argmax(g1_input, axis=2, name='argmax1')


@tf_test
def argmin_test(g1):
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
86
87
88
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(3, 4, 5, 6),
                                            name='0')
89
90
91
        tf.argmin(g1_input, axis=2, name='argmin1')


Khalique's avatar
Khalique committed
92
93
@tf_test
def assert_less_equal_test(g1):
Khalique's avatar
Khalique committed
94
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
95
96
        g1_input = tf.compat.v1.placeholder(tf.float32, shape=(2, 3), name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32, shape=(2, 3), name='1')
Khalique's avatar
Khalique committed
97
        with tf.control_dependencies(
kahmed10's avatar
kahmed10 committed
98
            [tf.compat.v1.assert_less_equal(g1_input, g2_input)]):
Khalique's avatar
Khalique committed
99
100
            tf.add(g1_input, g2_input, name='add1')

Khalique's avatar
Khalique committed
101

Khalique's avatar
Khalique committed
102
103
@tf_test
def batchmatmul_test(g1):
Khalique's avatar
Khalique committed
104
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
105
106
107
108
109
110
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 8, 4),
                                            name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 4, 8),
                                            name='1')
Khalique's avatar
Khalique committed
111
112
113
114
115
116
        tf.matmul(g1_input,
                  g2_input,
                  transpose_a=True,
                  transpose_b=True,
                  name='batchmatmul1')

Khalique's avatar
Khalique committed
117

Khalique's avatar
Khalique committed
118
119
@tf_test
def batchnorm_test(g1):
Khalique's avatar
Khalique committed
120
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
121
122
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 32),
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
                                            name='x')
        g1_scale = tf.constant(1.0, dtype=tf.float32, shape=[32], name='scale')
        g1_offset = tf.compat.v1.placeholder(tf.float32,
                                             shape=(32),
                                             name='bias')
        g1_mean = tf.compat.v1.placeholder(tf.float32, shape=(32), name='mean')
        g1_variance = tf.compat.v1.placeholder(tf.float32,
                                               shape=(32),
                                               name='variance')
        tf.compat.v1.nn.fused_batch_norm(x=g1_input,
                                         scale=g1_scale,
                                         offset=g1_offset,
                                         mean=g1_mean,
                                         variance=g1_variance,
                                         epsilon=1e-4,
                                         is_training=False,
                                         name='batchnorm1')


@tf_test
def batchnorm_half_test(g1):
    with g1.as_default():
        g1_input = tf.compat.v1.placeholder(tf.float16,
                                            shape=(1, 16, 16, 32),
                                            name='x')
        g1_scale = tf.constant(1.0, dtype=tf.float32, shape=[32], name='scale')
        g1_offset = tf.compat.v1.placeholder(tf.float32,
                                             shape=(32),
                                             name='bias')
        g1_mean = tf.compat.v1.placeholder(tf.float32, shape=(32), name='mean')
kahmed10's avatar
kahmed10 committed
153
154
        g1_variance = tf.compat.v1.placeholder(tf.float32,
                                               shape=(32),
155
                                               name='variance')
kahmed10's avatar
kahmed10 committed
156
157
158
159
160
        tf.compat.v1.nn.fused_batch_norm(x=g1_input,
                                         scale=g1_scale,
                                         offset=g1_offset,
                                         mean=g1_mean,
                                         variance=g1_variance,
161
                                         epsilon=1e-4,
kahmed10's avatar
kahmed10 committed
162
163
164
165
166
167
168
169
170
                                         is_training=False,
                                         name='batchnorm1')


@tf_test
def batchnormv3_test(g1):
    with g1.as_default():
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 32),
171
172
173
174
175
176
                                            name='x')
        g1_scale = tf.constant(1.0, dtype=tf.float32, shape=[32], name='scale')
        g1_offset = tf.compat.v1.placeholder(tf.float32,
                                             shape=(32),
                                             name='bias')
        g1_mean = tf.compat.v1.placeholder(tf.float32, shape=(32), name='mean')
kahmed10's avatar
kahmed10 committed
177
178
        g1_variance = tf.compat.v1.placeholder(tf.float32,
                                               shape=(32),
179
                                               name='variance')
kahmed10's avatar
kahmed10 committed
180
181
182
183
184
        tf.raw_ops.FusedBatchNormV3(x=g1_input,
                                    scale=g1_scale,
                                    offset=g1_offset,
                                    mean=g1_mean,
                                    variance=g1_variance,
185
                                    epsilon=1e-6,
kahmed10's avatar
kahmed10 committed
186
187
                                    is_training=False,
                                    name='batchnorm1')
Khalique's avatar
Khalique committed
188

Khalique's avatar
Khalique committed
189

Khalique's avatar
Khalique committed
190
191
@tf_test
def biasadd_test(g1):
Khalique's avatar
Khalique committed
192
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
193
194
195
196
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 1, 1, 500),
                                            name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32, shape=(500), name='1')
Khalique's avatar
Khalique committed
197
198
        tf.nn.bias_add(g1_input, g2_input, name='bias_add1')

Khalique's avatar
Khalique committed
199

kahmed10's avatar
kahmed10 committed
200
201
202
203
204
205
206
207
@tf_test
def biasadd_scalar_test(g1):
    with g1.as_default():
        g1_input = tf.compat.v1.placeholder(tf.float32, shape=(1, 1), name='0')
        g2_const = tf.constant(1.0, tf.float32, shape=(1, ), name='1')
        tf.nn.bias_add(g1_input, g2_const, name='bias_add1')


Khalique's avatar
Khalique committed
208
209
@tf_test
def cast_test(g1):
Khalique's avatar
Khalique committed
210
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
211
212
213
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
214
215
        tf.cast(g1_input, dtype=tf.int32, name='cast1')

Khalique's avatar
Khalique committed
216

Khalique's avatar
Khalique committed
217
218
@tf_test
def concat_test(g1):
Khalique's avatar
Khalique committed
219
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
220
221
222
223
224
225
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(4, 7, 3),
                                            name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(4, 2, 3),
                                            name='1')
Khalique's avatar
Khalique committed
226
227
        tf.concat([g1_input, g2_input], axis=1, name='concat1')

Khalique's avatar
Khalique committed
228

Khalique's avatar
Khalique committed
229
230
@tf_test
def const_test(g1):
Khalique's avatar
Khalique committed
231
    with g1.as_default():
Khalique's avatar
Khalique committed
232
233
        tf.constant(1.0, dtype=tf.float32, name='constant1')

Khalique's avatar
Khalique committed
234

Khalique's avatar
Khalique committed
235
236
@tf_test
def conv_test(g1):
Khalique's avatar
Khalique committed
237
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
238
239
240
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 3),
                                            name='0')
Khalique's avatar
Khalique committed
241
242
243
244
245
246
        g1_weights = tf.constant(value=1.0,
                                 dtype=tf.float32,
                                 shape=(3, 3, 3, 32),
                                 name='1')
        tf.nn.conv2d(g1_input, g1_weights, [1, 1, 1, 1], "SAME", name='conv1')

Khalique's avatar
Khalique committed
247

kahmed10's avatar
kahmed10 committed
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
@tf_test
def conv_add_test(g1):
    with g1.as_default():
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 3),
                                            name='0')
        g1_weights = tf.constant(value=1.0,
                                 dtype=tf.float32,
                                 shape=(3, 3, 3, 32),
                                 name='1')
        conv = tf.nn.conv2d(g1_input,
                            g1_weights, [1, 1, 1, 1],
                            "SAME",
                            name='conv1')
        tf.add(conv, conv, name='add1')


kahmed10's avatar
kahmed10 committed
265
266
267
268
269
270
271
272
273
274
275
276
277
@tf_test
def conv_batch_test(g1):
    with g1.as_default():
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(None, 16, 16, 3),
                                            name='0')
        g1_weights = tf.constant(value=1.0,
                                 dtype=tf.float32,
                                 shape=(3, 3, 3, 32),
                                 name='1')
        tf.nn.conv2d(g1_input, g1_weights, [1, 1, 1, 1], "SAME", name='conv1')


kahmed10's avatar
kahmed10 committed
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
@tf_test
def conv_nchw_test(g1):
    with g1.as_default():
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
        g1_weights = tf.constant(value=1.0,
                                 dtype=tf.float32,
                                 shape=(3, 3, 3, 32),
                                 name='1')
        tf.nn.conv2d(g1_input,
                     g1_weights, [1, 1, 1, 1],
                     "SAME",
                     data_format='NCHW',
                     name='conv1')


kahmed10's avatar
kahmed10 committed
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
@tf_test
def conv_relu_test(g1):
    with g1.as_default():
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 3),
                                            name='0')
        g1_weights = tf.constant(value=1.0,
                                 dtype=tf.float32,
                                 shape=(3, 3, 3, 32),
                                 name='1')
        conv = tf.nn.conv2d(g1_input,
                            g1_weights, [1, 1, 1, 1],
                            "SAME",
                            name='conv1')
        tf.nn.relu(conv, name='relu1')


@tf_test
def conv_relu6_test(g1):
    with g1.as_default():
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 3),
                                            name='0')
        g1_weights = tf.constant(value=1.0,
                                 dtype=tf.float32,
                                 shape=(3, 3, 3, 32),
                                 name='1')
        conv = tf.nn.conv2d(g1_input,
                            g1_weights, [1, 1, 1, 1],
                            "SAME",
                            name='conv1')
        tf.nn.relu6(conv, name='relu1')


Khalique's avatar
Khalique committed
329
330
@tf_test
def depthwiseconv_test(g1):
Khalique's avatar
Khalique committed
331
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
332
333
334
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 3),
                                            name='0')
Khalique's avatar
Khalique committed
335
336
337
338
        g1_weights = tf.constant(value=1.0,
                                 dtype=tf.float32,
                                 shape=(3, 3, 3, 1),
                                 name='1')
kahmed10's avatar
kahmed10 committed
339
340
341
342
        tf.compat.v1.nn.depthwise_conv2d_native(g1_input,
                                                g1_weights, [1, 1, 1, 1],
                                                "SAME",
                                                name='depthwiseconv1')
Khalique's avatar
Khalique committed
343

Khalique's avatar
Khalique committed
344

Khalique's avatar
Khalique committed
345
346
@tf_test
def expanddims_test(g1):
Khalique's avatar
Khalique committed
347
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
348
349
350
351
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(2, 3, 4),
                                            name='0')
        tf.expand_dims(g1_input, axis=0, name='expanddims_neg')
Khalique's avatar
Khalique committed
352

Khalique's avatar
Khalique committed
353

Khalique's avatar
Khalique committed
354
355
@tf_test
def gather_test(g1):
Khalique's avatar
Khalique committed
356
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
357
        g1_input = tf.compat.v1.placeholder(tf.float32, shape=(2, 4), name='0')
Khalique's avatar
Khalique committed
358
359
        tf.gather(g1_input, [1, 1], axis=1, name='gather1')

Khalique's avatar
Khalique committed
360

Khalique's avatar
Khalique committed
361
362
@tf_test
def identity_test(g1):
Khalique's avatar
Khalique committed
363
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
364
365
366
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
367
368
        tf.identity(g1_input, 'identity')

Khalique's avatar
Khalique committed
369

Khalique's avatar
Khalique committed
370
371
@tf_test
def matmul_test(g1):
Khalique's avatar
Khalique committed
372
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
373
374
        g1_input = tf.compat.v1.placeholder(tf.float32, shape=(8, 4), name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32, shape=(4, 8), name='1')
Khalique's avatar
Khalique committed
375
376
377
378
379
380
        tf.matmul(g1_input,
                  g2_input,
                  transpose_a=True,
                  transpose_b=True,
                  name='matmul1')

Khalique's avatar
Khalique committed
381

Khalique's avatar
Khalique committed
382
383
@tf_test
def mean_test(g1):
Khalique's avatar
Khalique committed
384
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
385
386
387
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
388
389
390
391
392
393
        tf.math.reduce_mean(g1_input, axis=(2, 3), keepdims=True, name='mean1')
        tf.math.reduce_mean(g1_input,
                            axis=(2, 3),
                            keepdims=False,
                            name='mean2')

Khalique's avatar
Khalique committed
394

Khalique's avatar
Khalique committed
395
396
@tf_test
def mean_test_nhwc(g1):
Khalique's avatar
Khalique committed
397
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
398
399
400
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 3),
                                            name='0')
Khalique's avatar
Khalique committed
401
402
403
404
405
        tf.math.reduce_mean(g1_input,
                            axis=(1, 2),
                            keepdims=False,
                            name='mean2')

Khalique's avatar
Khalique committed
406

Khalique's avatar
Khalique committed
407
408
@tf_test
def mul_test(g1):
Khalique's avatar
Khalique committed
409
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
410
411
412
413
414
415
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 1, 1, 16),
                                            name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 1, 1, 16),
                                            name='1')
Khalique's avatar
Khalique committed
416
417
        tf.multiply(g1_input, g2_input, name='mul1')

Khalique's avatar
Khalique committed
418

kahmed10's avatar
kahmed10 committed
419
420
421
422
423
424
425
426
427
428
@tf_test
def multi_output_test(g1):
    with g1.as_default():
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
        tf.nn.relu(g1_input, 'relu')
        tf.tanh(g1_input, 'tanh')


kahmed10's avatar
kahmed10 committed
429
430
431
432
433
434
@tf_test
def noop_test(g1):
    with g1.as_default():
        tf.raw_ops.NoOp(name='noop1')


kahmed10's avatar
kahmed10 committed
435
436
437
438
439
440
441
@tf_test
def onehot_test(g1):
    with g1.as_default():
        g1_input = tf.constant((1, 1, 1, 1, 1), dtype=tf.int32)
        tf.one_hot(g1_input, 2, name='onehot1')


Khalique's avatar
Khalique committed
442
443
@tf_test
def pack_test(g1):
Khalique's avatar
Khalique committed
444
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
445
446
447
        g1_input = tf.compat.v1.placeholder(tf.float32, shape=(2), name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32, shape=(2), name='1')
        g3_input = tf.compat.v1.placeholder(tf.float32, shape=(2), name='2')
Khalique's avatar
Khalique committed
448
449
        tf.stack([g1_input, g2_input, g3_input], axis=1, name='pack1')

Khalique's avatar
Khalique committed
450

Khalique's avatar
Khalique committed
451
452
@tf_test
def pack_test_nhwc(g1):
Khalique's avatar
Khalique committed
453
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
454
455
456
457
458
459
460
461
462
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 1, 1, 2),
                                            name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 1, 1, 2),
                                            name='1')
        g3_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 1, 1, 2),
                                            name='2')
Khalique's avatar
Khalique committed
463
464
        tf.stack([g1_input, g2_input, g3_input], axis=3, name='pack1')

Khalique's avatar
Khalique committed
465

kahmed10's avatar
kahmed10 committed
466
467
468
469
470
471
472
473
474
@tf_test
def pad_test(g1):
    with g1.as_default():
        g1_input = tf.compat.v1.placeholder(tf.float32, shape=(2, 4), name='0')
        paddings = tf.constant([[1, 1], [2, 2]])

        tf.pad(g1_input, paddings, name='pad1')


Khalique's avatar
Khalique committed
475
476
@tf_test
def pooling_test(g1):
Khalique's avatar
Khalique committed
477
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 3),
                                            name='0')
        tf.compat.v1.nn.avg_pool(value=g1_input,
                                 ksize=(1, 2, 2, 1),
                                 strides=(1, 2, 2, 1),
                                 padding='VALID',
                                 data_format='NHWC',
                                 name='avg_pooling')
        tf.compat.v1.nn.max_pool(value=g1_input,
                                 ksize=(1, 2, 2, 1),
                                 strides=(1, 2, 2, 1),
                                 padding='VALID',
                                 data_format='NHWC',
                                 name='max_pooling')
Khalique's avatar
Khalique committed
493

Khalique's avatar
Khalique committed
494

Khalique's avatar
Khalique committed
495
496
@tf_test
def pow_test(g1):
Khalique's avatar
Khalique committed
497
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
498
499
500
501
502
503
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 2, 3),
                                            name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 2, 3),
                                            name='1')
Khalique's avatar
Khalique committed
504
505
        tf.pow(g1_input, g2_input, name='pow1')

Khalique's avatar
Khalique committed
506

Khalique's avatar
Khalique committed
507
508
@tf_test
def relu_test(g1):
Khalique's avatar
Khalique committed
509
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
510
511
512
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
513
514
        tf.nn.relu(g1_input, 'relu')

Khalique's avatar
Khalique committed
515

Khalique's avatar
Khalique committed
516
517
@tf_test
def relu6_test(g1):
Khalique's avatar
Khalique committed
518
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
519
520
521
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
522
523
        tf.nn.relu6(g1_input, 'relu6')

Khalique's avatar
Khalique committed
524

525
@tf_test
526
def relu6_half_test(g1):
527
528
    with g1.as_default():
        g1_input = tf.compat.v1.placeholder(tf.float16,
529
                                            shape=(1, 3, 16, 16),
530
531
532
533
                                            name='0')
        tf.nn.relu6(g1_input, 'relu6')


Khalique's avatar
Khalique committed
534
535
@tf_test
def reshape_test(g1):
Khalique's avatar
Khalique committed
536
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
537
        g1_input = tf.compat.v1.placeholder(tf.float32, shape=(16), name='0')
Khalique's avatar
Khalique committed
538
539
        tf.reshape(g1_input, (1, 1, 1, 16), 'reshape')

Khalique's avatar
Khalique committed
540

Khalique's avatar
Khalique committed
541
542
@tf_test
def rsqrt_test(g1):
Khalique's avatar
Khalique committed
543
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
544
545
546
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
547
548
        tf.math.rsqrt(g1_input, 'rsqrt')

Khalique's avatar
Khalique committed
549

550
551
552
@tf_test
def shape_test(g1):
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
553
554
555
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
556
557
558
    g1.create_op(op_type='Shape', inputs=[g1_input])


Khalique's avatar
Khalique committed
559
560
@tf_test
def slice_test(g1):
Khalique's avatar
Khalique committed
561
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
562
563
564
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(5, 10),
                                            name='0')
Khalique's avatar
Khalique committed
565
566
        tf.slice(g1_input, [1, 0], [2, -1], name='slice1')

Khalique's avatar
Khalique committed
567

Khalique's avatar
Khalique committed
568
569
@tf_test
def softmax_test(g1):
Khalique's avatar
Khalique committed
570
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
571
        g1_input = tf.compat.v1.placeholder(tf.float32, shape=(1, 3), name='0')
Khalique's avatar
Khalique committed
572
573
        tf.nn.softmax(g1_input, name='softmax')

Khalique's avatar
Khalique committed
574

kahmed10's avatar
kahmed10 committed
575
576
577
@tf_test
def split_test(g1):
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
578
579
580
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(5, 30),
                                            name='0')
kahmed10's avatar
kahmed10 committed
581
582
583
584
585
586
587
588
        split0, split1, split2 = tf.split(g1_input, 3, 1, name='split')
        tf.concat([split0, split1], axis=1, name='concat1')
        tf.concat([split1, split2], axis=1, name='concat2')


@tf_test
def split_test_one_output(g1):
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
589
590
591
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(5, 30),
                                            name='0')
kahmed10's avatar
kahmed10 committed
592
593
594
595
596
597
        tf.split(g1_input, 1, 1, name='split')


@tf_test
def split_test_vector_as_input(g1):
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
598
599
600
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(5, 30),
                                            name='0')
kahmed10's avatar
kahmed10 committed
601
602
603
604
605
606
607
        split0, split1, split2 = tf.split(g1_input, [4, 15, 11],
                                          1,
                                          name='split')
        tf.concat([split0, split1], axis=1, name='concat1')
        tf.concat([split1, split2], axis=1, name='concat2')


Khalique's avatar
Khalique committed
608
609
@tf_test
def sqdiff_test(g1):
Khalique's avatar
Khalique committed
610
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
611
612
613
614
615
616
617
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 2, 3),
                                            name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 2, 3),
                                            name='1')
        tf.compat.v1.squared_difference(g1_input, g2_input, name='sqdiff')
Khalique's avatar
Khalique committed
618

Khalique's avatar
Khalique committed
619

Khalique's avatar
Khalique committed
620
621
@tf_test
def squeeze_test(g1):
Khalique's avatar
Khalique committed
622
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
623
624
625
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 3, 1),
                                            name='0')
Khalique's avatar
Khalique committed
626
627
        tf.squeeze(g1_input, name='squeeze')

Khalique's avatar
Khalique committed
628

Khalique's avatar
Khalique committed
629
630
@tf_test
def stopgradient_test(g1):
Khalique's avatar
Khalique committed
631
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
632
633
634
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
635
636
        tf.stop_gradient(g1_input, 'stopgradient')

Khalique's avatar
Khalique committed
637

Khalique's avatar
Khalique committed
638
639
@tf_test
def stridedslice_test(g1):
Khalique's avatar
Khalique committed
640
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
641
642
643
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 1, 1, 10),
                                            name='0')
Khalique's avatar
Khalique committed
644
645
646
647
        tf.strided_slice(g1_input, [0, 0, 0, 0], [1, 1, 1, 5], [1, 1, 1, 1],
                         shrink_axis_mask=2,
                         name='stridedslice1')

Khalique's avatar
Khalique committed
648

Khalique's avatar
Khalique committed
649
650
@tf_test
def stridedslice_masks_test(g1):
Khalique's avatar
Khalique committed
651
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
652
653
654
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 3, 10),
                                            name='0')
Khalique's avatar
Khalique committed
655
656
657
658
659
        tf.strided_slice(g1_input, [0, 1, 1, 0], [0, 0, 0, 0], [1, 1, 1, 1],
                         begin_mask=9,
                         end_mask=15,
                         name='stridedslice1')

Khalique's avatar
Khalique committed
660

Khalique's avatar
Khalique committed
661
662
@tf_test
def sub_test(g1):
Khalique's avatar
Khalique committed
663
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
664
665
666
667
668
669
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 2, 3),
                                            name='0')
        g2_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 2, 3),
                                            name='1')
Khalique's avatar
Khalique committed
670
671
        tf.subtract(g1_input, g2_input, name='sub1')

Khalique's avatar
Khalique committed
672

Khalique's avatar
Khalique committed
673
674
@tf_test
def tanh_test(g1):
Khalique's avatar
Khalique committed
675
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
676
677
678
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
679
680
        tf.tanh(g1_input, 'tanh')

Khalique's avatar
Khalique committed
681

Khalique's avatar
Khalique committed
682
683
@tf_test
def transpose_test(g1):
Khalique's avatar
Khalique committed
684
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
685
686
687
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
688
        tf.transpose(g1_input, perm=[0, 2, 3, 1], name='transpose')
689
690
691
692
693


@tf_test
def variable_batch_test(g1):
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
694
695
696
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(0, 3, 16, 16),
                                            name='0')
697
        tf.identity(g1_input, name='identity')
kahmed10's avatar
kahmed10 committed
698
699
700
701
702
703
704
705
706
707
708
709
710


if __name__ == '__main__':
    add_test()
    addv2_test()
    add_bcast_test()
    argmax_test()
    argmin_test()
    assert_less_equal_test()
    batchmatmul_test()
    batchnorm_test()
    batchnormv3_test()
    biasadd_test()
kahmed10's avatar
kahmed10 committed
711
    biasadd_scalar_test()
kahmed10's avatar
kahmed10 committed
712
713
714
715
    cast_test()
    concat_test()
    const_test()
    conv_test()
kahmed10's avatar
kahmed10 committed
716
    conv_add_test()
kahmed10's avatar
kahmed10 committed
717
    conv_batch_test()
kahmed10's avatar
kahmed10 committed
718
    conv_nchw_test()
kahmed10's avatar
kahmed10 committed
719
720
    conv_relu_test()
    conv_relu6_test()
kahmed10's avatar
kahmed10 committed
721
722
723
724
725
726
727
728
    depthwiseconv_test()
    expanddims_test()
    gather_test()
    identity_test()
    matmul_test()
    mean_test()
    mean_test_nhwc()
    mul_test()
kahmed10's avatar
kahmed10 committed
729
    multi_output_test()
kahmed10's avatar
kahmed10 committed
730
    noop_test()
kahmed10's avatar
kahmed10 committed
731
    onehot_test()
kahmed10's avatar
kahmed10 committed
732
733
    pack_test()
    pack_test_nhwc()
kahmed10's avatar
kahmed10 committed
734
    pad_test()
kahmed10's avatar
kahmed10 committed
735
736
737
738
    pooling_test()
    pow_test()
    relu_test()
    relu6_test()
739
    relu6_half_test()
kahmed10's avatar
kahmed10 committed
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
    reshape_test()
    rsqrt_test()
    shape_test()
    slice_test()
    softmax_test()
    split_test()
    split_test_one_output()
    split_test_vector_as_input()
    sqdiff_test()
    squeeze_test()
    stopgradient_test()
    stridedslice_test()
    stridedslice_masks_test()
    sub_test()
    tanh_test()
    transpose_test()
    variable_batch_test()