gen_tf_pb.py 23.2 KB
Newer Older
1
2
3
# 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
4
5
import numpy as np
import tensorflow as tf
6
from tensorflow.core.framework import attr_value_pb2
Khalique's avatar
Khalique committed
7

Khalique's avatar
Khalique committed
8

Khalique's avatar
Khalique committed
9
10
11
12
def tf_test(op_test):
    def run_test():
        g1 = tf.Graph()
        op_test(g1)
Khalique's avatar
Khalique committed
13
14
15
16
17
        tf.io.write_graph(g1,
                          '.',
                          '{}.pb'.format(op_test.__name__),
                          as_text=False)

Khalique's avatar
Khalique committed
18
    return run_test
Khalique's avatar
Khalique committed
19

Khalique's avatar
Khalique committed
20

Khalique's avatar
Khalique committed
21
22
@tf_test
def add_test(g1):
Khalique's avatar
Khalique committed
23
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
24
25
26
27
28
29
        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
30
31
        tf.add(g1_input, g2_input, name='add1')

Khalique's avatar
Khalique committed
32

kahmed10's avatar
kahmed10 committed
33
34
35
36
37
38
39
40
41
42
43
44
@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
45
46
@tf_test
def add_bcast_test(g1):
Khalique's avatar
Khalique committed
47
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
48
49
        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
50
51
        tf.math.add(g1_input, g2_input, name='add_bcast1')

Khalique's avatar
Khalique committed
52

53
54
55
@tf_test
def argmax_test(g1):
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
56
57
58
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(3, 4, 5, 6),
                                            name='0')
59
60
61
62
63
64
        tf.argmax(g1_input, axis=2, name='argmax1')


@tf_test
def argmin_test(g1):
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
65
66
67
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(3, 4, 5, 6),
                                            name='0')
68
69
70
        tf.argmin(g1_input, axis=2, name='argmin1')


Khalique's avatar
Khalique committed
71
72
@tf_test
def assert_less_equal_test(g1):
Khalique's avatar
Khalique committed
73
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
74
75
        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
76
        with tf.control_dependencies(
kahmed10's avatar
kahmed10 committed
77
            [tf.compat.v1.assert_less_equal(g1_input, g2_input)]):
Khalique's avatar
Khalique committed
78
79
            tf.add(g1_input, g2_input, name='add1')

Khalique's avatar
Khalique committed
80

Khalique's avatar
Khalique committed
81
82
@tf_test
def batchmatmul_test(g1):
Khalique's avatar
Khalique committed
83
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
84
85
86
87
88
89
        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
90
91
92
93
94
95
        tf.matmul(g1_input,
                  g2_input,
                  transpose_a=True,
                  transpose_b=True,
                  name='batchmatmul1')

Khalique's avatar
Khalique committed
96

Khalique's avatar
Khalique committed
97
98
@tf_test
def batchnorm_test(g1):
Khalique's avatar
Khalique committed
99
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 32),
                                            name='0')
        g1_scale = tf.constant(1.0, dtype=tf.float32, shape=[32], name='1')
        g1_offset = tf.compat.v1.placeholder(tf.float32, shape=(32), name='2')
        g1_mean = tf.compat.v1.placeholder(tf.float32, shape=(32), name='3')
        g1_variance = tf.compat.v1.placeholder(tf.float32,
                                               shape=(32),
                                               name='4')
        tf.compat.v1.nn.fused_batch_norm(x=g1_input,
                                         scale=g1_scale,
                                         offset=g1_offset,
                                         mean=g1_mean,
                                         variance=g1_variance,
                                         epsilon=0.00001,
                                         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),
                                            name='0')
Khalique's avatar
Khalique committed
125
        g1_scale = tf.constant(1.0, dtype=tf.float32, shape=[32], name='1')
kahmed10's avatar
kahmed10 committed
126
127
128
129
130
131
132
133
134
135
136
137
138
        g1_offset = tf.compat.v1.placeholder(tf.float32, shape=(32), name='2')
        g1_mean = tf.compat.v1.placeholder(tf.float32, shape=(32), name='3')
        g1_variance = tf.compat.v1.placeholder(tf.float32,
                                               shape=(32),
                                               name='4')
        tf.raw_ops.FusedBatchNormV3(x=g1_input,
                                    scale=g1_scale,
                                    offset=g1_offset,
                                    mean=g1_mean,
                                    variance=g1_variance,
                                    epsilon=0.00001,
                                    is_training=False,
                                    name='batchnorm1')
Khalique's avatar
Khalique committed
139

Khalique's avatar
Khalique committed
140

Khalique's avatar
Khalique committed
141
142
@tf_test
def biasadd_test(g1):
Khalique's avatar
Khalique committed
143
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
144
145
146
147
        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
148
149
        tf.nn.bias_add(g1_input, g2_input, name='bias_add1')

Khalique's avatar
Khalique committed
150

kahmed10's avatar
kahmed10 committed
151
152
153
154
155
156
157
158
@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
159
160
@tf_test
def cast_test(g1):
Khalique's avatar
Khalique committed
161
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
162
163
164
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
165
166
        tf.cast(g1_input, dtype=tf.int32, name='cast1')

Khalique's avatar
Khalique committed
167

Khalique's avatar
Khalique committed
168
169
@tf_test
def concat_test(g1):
Khalique's avatar
Khalique committed
170
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
171
172
173
174
175
176
        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
177
178
        tf.concat([g1_input, g2_input], axis=1, name='concat1')

Khalique's avatar
Khalique committed
179

Khalique's avatar
Khalique committed
180
181
@tf_test
def const_test(g1):
Khalique's avatar
Khalique committed
182
    with g1.as_default():
Khalique's avatar
Khalique committed
183
184
        tf.constant(1.0, dtype=tf.float32, name='constant1')

Khalique's avatar
Khalique committed
185

Khalique's avatar
Khalique committed
186
187
@tf_test
def conv_test(g1):
Khalique's avatar
Khalique committed
188
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
189
190
191
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 3),
                                            name='0')
Khalique's avatar
Khalique committed
192
193
194
195
196
197
        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
198

kahmed10's avatar
kahmed10 committed
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
@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
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
@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
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
@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
267
268
@tf_test
def depthwiseconv_test(g1):
Khalique's avatar
Khalique committed
269
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
270
271
272
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 3),
                                            name='0')
Khalique's avatar
Khalique committed
273
274
275
276
        g1_weights = tf.constant(value=1.0,
                                 dtype=tf.float32,
                                 shape=(3, 3, 3, 1),
                                 name='1')
kahmed10's avatar
kahmed10 committed
277
278
279
280
        tf.compat.v1.nn.depthwise_conv2d_native(g1_input,
                                                g1_weights, [1, 1, 1, 1],
                                                "SAME",
                                                name='depthwiseconv1')
Khalique's avatar
Khalique committed
281

Khalique's avatar
Khalique committed
282

Khalique's avatar
Khalique committed
283
284
@tf_test
def expanddims_test(g1):
Khalique's avatar
Khalique committed
285
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
286
287
288
289
        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
290

Khalique's avatar
Khalique committed
291

Khalique's avatar
Khalique committed
292
293
@tf_test
def gather_test(g1):
Khalique's avatar
Khalique committed
294
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
295
        g1_input = tf.compat.v1.placeholder(tf.float32, shape=(2, 4), name='0')
Khalique's avatar
Khalique committed
296
297
        tf.gather(g1_input, [1, 1], axis=1, name='gather1')

Khalique's avatar
Khalique committed
298

Khalique's avatar
Khalique committed
299
300
@tf_test
def identity_test(g1):
Khalique's avatar
Khalique committed
301
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
302
303
304
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
305
306
        tf.identity(g1_input, 'identity')

Khalique's avatar
Khalique committed
307

Khalique's avatar
Khalique committed
308
309
@tf_test
def matmul_test(g1):
Khalique's avatar
Khalique committed
310
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
311
312
        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
313
314
315
316
317
318
        tf.matmul(g1_input,
                  g2_input,
                  transpose_a=True,
                  transpose_b=True,
                  name='matmul1')

Khalique's avatar
Khalique committed
319

Khalique's avatar
Khalique committed
320
321
@tf_test
def mean_test(g1):
Khalique's avatar
Khalique committed
322
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
323
324
325
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
326
327
328
329
330
331
        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
332

Khalique's avatar
Khalique committed
333
334
@tf_test
def mean_test_nhwc(g1):
Khalique's avatar
Khalique committed
335
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
336
337
338
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 16, 16, 3),
                                            name='0')
Khalique's avatar
Khalique committed
339
340
341
342
343
344
        tf.math.reduce_mean(g1_input, axis=(1, 2), keepdims=True, name='mean1')
        tf.math.reduce_mean(g1_input,
                            axis=(1, 2),
                            keepdims=False,
                            name='mean2')

Khalique's avatar
Khalique committed
345

Khalique's avatar
Khalique committed
346
347
@tf_test
def mul_test(g1):
Khalique's avatar
Khalique committed
348
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
349
350
351
352
353
354
        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
355
356
        tf.multiply(g1_input, g2_input, name='mul1')

Khalique's avatar
Khalique committed
357

kahmed10's avatar
kahmed10 committed
358
359
360
361
362
363
364
365
366
367
@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
368
369
370
371
372
373
@tf_test
def noop_test(g1):
    with g1.as_default():
        tf.raw_ops.NoOp(name='noop1')


kahmed10's avatar
kahmed10 committed
374
375
376
377
378
379
380
@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
381
382
@tf_test
def pack_test(g1):
Khalique's avatar
Khalique committed
383
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
384
385
386
        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
387
388
        tf.stack([g1_input, g2_input, g3_input], axis=1, name='pack1')

Khalique's avatar
Khalique committed
389

Khalique's avatar
Khalique committed
390
391
@tf_test
def pack_test_nhwc(g1):
Khalique's avatar
Khalique committed
392
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
393
394
395
396
397
398
399
400
401
        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
402
403
        tf.stack([g1_input, g2_input, g3_input], axis=3, name='pack1')

Khalique's avatar
Khalique committed
404

kahmed10's avatar
kahmed10 committed
405
406
407
408
409
410
411
412
413
@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
414
415
@tf_test
def pooling_test(g1):
Khalique's avatar
Khalique committed
416
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
        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
432

Khalique's avatar
Khalique committed
433

Khalique's avatar
Khalique committed
434
435
@tf_test
def pow_test(g1):
Khalique's avatar
Khalique committed
436
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
437
438
439
440
441
442
        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
443
444
        tf.pow(g1_input, g2_input, name='pow1')

Khalique's avatar
Khalique committed
445

Khalique's avatar
Khalique committed
446
447
@tf_test
def relu_test(g1):
Khalique's avatar
Khalique committed
448
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
449
450
451
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
452
453
        tf.nn.relu(g1_input, 'relu')

Khalique's avatar
Khalique committed
454

Khalique's avatar
Khalique committed
455
456
@tf_test
def relu6_test(g1):
Khalique's avatar
Khalique committed
457
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
458
459
460
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
461
462
        tf.nn.relu6(g1_input, 'relu6')

Khalique's avatar
Khalique committed
463

Khalique's avatar
Khalique committed
464
465
@tf_test
def reshape_test(g1):
Khalique's avatar
Khalique committed
466
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
467
        g1_input = tf.compat.v1.placeholder(tf.float32, shape=(16), name='0')
Khalique's avatar
Khalique committed
468
469
        tf.reshape(g1_input, (1, 1, 1, 16), 'reshape')

Khalique's avatar
Khalique committed
470

Khalique's avatar
Khalique committed
471
472
@tf_test
def rsqrt_test(g1):
Khalique's avatar
Khalique committed
473
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
474
475
476
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
477
478
        tf.math.rsqrt(g1_input, 'rsqrt')

Khalique's avatar
Khalique committed
479

480
481
482
@tf_test
def shape_test(g1):
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
483
484
485
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
486
487
488
    g1.create_op(op_type='Shape', inputs=[g1_input])


Khalique's avatar
Khalique committed
489
490
@tf_test
def slice_test(g1):
Khalique's avatar
Khalique committed
491
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
492
493
494
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(5, 10),
                                            name='0')
Khalique's avatar
Khalique committed
495
496
        tf.slice(g1_input, [1, 0], [2, -1], name='slice1')

Khalique's avatar
Khalique committed
497

Khalique's avatar
Khalique committed
498
499
@tf_test
def softmax_test(g1):
Khalique's avatar
Khalique committed
500
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
501
        g1_input = tf.compat.v1.placeholder(tf.float32, shape=(1, 3), name='0')
Khalique's avatar
Khalique committed
502
503
        tf.nn.softmax(g1_input, name='softmax')

Khalique's avatar
Khalique committed
504

kahmed10's avatar
kahmed10 committed
505
506
507
@tf_test
def split_test(g1):
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
508
509
510
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(5, 30),
                                            name='0')
kahmed10's avatar
kahmed10 committed
511
512
513
514
515
516
517
518
        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
519
520
521
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(5, 30),
                                            name='0')
kahmed10's avatar
kahmed10 committed
522
523
524
525
526
527
        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
528
529
530
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(5, 30),
                                            name='0')
kahmed10's avatar
kahmed10 committed
531
532
533
534
535
536
537
        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
538
539
@tf_test
def sqdiff_test(g1):
Khalique's avatar
Khalique committed
540
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
541
542
543
544
545
546
547
        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
548

Khalique's avatar
Khalique committed
549

Khalique's avatar
Khalique committed
550
551
@tf_test
def squeeze_test(g1):
Khalique's avatar
Khalique committed
552
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
553
554
555
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 2, 3, 1),
                                            name='0')
Khalique's avatar
Khalique committed
556
557
        tf.squeeze(g1_input, name='squeeze')

Khalique's avatar
Khalique committed
558

Khalique's avatar
Khalique committed
559
560
@tf_test
def stopgradient_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=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
565
566
        tf.stop_gradient(g1_input, 'stopgradient')

Khalique's avatar
Khalique committed
567

Khalique's avatar
Khalique committed
568
569
@tf_test
def stridedslice_test(g1):
Khalique's avatar
Khalique committed
570
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
571
572
573
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 1, 1, 10),
                                            name='0')
Khalique's avatar
Khalique committed
574
575
576
577
        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
578

Khalique's avatar
Khalique committed
579
580
@tf_test
def stridedslice_masks_test(g1):
Khalique's avatar
Khalique committed
581
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
582
583
584
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 3, 10),
                                            name='0')
Khalique's avatar
Khalique committed
585
586
587
588
589
        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
590

Khalique's avatar
Khalique committed
591
592
@tf_test
def sub_test(g1):
Khalique's avatar
Khalique committed
593
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
594
595
596
597
598
599
        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
600
601
        tf.subtract(g1_input, g2_input, name='sub1')

Khalique's avatar
Khalique committed
602

Khalique's avatar
Khalique committed
603
604
@tf_test
def tanh_test(g1):
Khalique's avatar
Khalique committed
605
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
606
607
608
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
609
610
        tf.tanh(g1_input, 'tanh')

Khalique's avatar
Khalique committed
611

Khalique's avatar
Khalique committed
612
613
@tf_test
def transpose_test(g1):
Khalique's avatar
Khalique committed
614
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
615
616
617
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(1, 3, 16, 16),
                                            name='0')
Khalique's avatar
Khalique committed
618
        tf.transpose(g1_input, perm=[0, 2, 3, 1], name='transpose')
619
620
621
622
623


@tf_test
def variable_batch_test(g1):
    with g1.as_default():
kahmed10's avatar
kahmed10 committed
624
625
626
        g1_input = tf.compat.v1.placeholder(tf.float32,
                                            shape=(0, 3, 16, 16),
                                            name='0')
627
        tf.identity(g1_input, name='identity')
kahmed10's avatar
kahmed10 committed
628
629
630
631
632
633
634
635
636
637
638
639
640


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
641
    biasadd_scalar_test()
kahmed10's avatar
kahmed10 committed
642
643
644
645
    cast_test()
    concat_test()
    const_test()
    conv_test()
kahmed10's avatar
kahmed10 committed
646
    conv_add_test()
kahmed10's avatar
kahmed10 committed
647
    conv_nchw_test()
kahmed10's avatar
kahmed10 committed
648
649
    conv_relu_test()
    conv_relu6_test()
kahmed10's avatar
kahmed10 committed
650
651
652
653
654
655
656
657
    depthwiseconv_test()
    expanddims_test()
    gather_test()
    identity_test()
    matmul_test()
    mean_test()
    mean_test_nhwc()
    mul_test()
kahmed10's avatar
kahmed10 committed
658
    multi_output_test()
kahmed10's avatar
kahmed10 committed
659
    noop_test()
kahmed10's avatar
kahmed10 committed
660
    onehot_test()
kahmed10's avatar
kahmed10 committed
661
662
    pack_test()
    pack_test_nhwc()
kahmed10's avatar
kahmed10 committed
663
    pad_test()
kahmed10's avatar
kahmed10 committed
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
    pooling_test()
    pow_test()
    relu_test()
    relu6_test()
    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()