@@ -1313,5 +1313,50 @@ def _verify(out, params, inputs):
13131313 _verify (* (_get_model ((1 , 128 , 4 , 4 ))))
13141314
13151315
1316+ @pytest .mark .parametrize ("dtype" , ["float16" , "float32" ])
1317+ @pytest .mark .parametrize (
1318+ "trials" ,
1319+ [
1320+ [(1 , 32 , 256 , 256 ), - 1 , 1 ],
1321+ [(1 , 8 , 64 , 64 ), 0 , 1 ],
1322+ ],
1323+ )
1324+ @tvm .testing .requires_openclml
1325+ @tvm .testing .parametrize_targets ("opencl -device=adreno" )
1326+ def test_clip (remote , dtype , target , executor_type , trials ):
1327+ def _verify (shape , a_min , a_max ):
1328+ np .random .seed (0 )
1329+ a = relay .var ("a" , shape = (shape ), dtype = dtype )
1330+ out = relay .clip (a , a_min , a_max )
1331+ inputs = {"a" : tvm .nd .array (np .random .uniform (- 1 , 1 , shape ).astype (dtype ))}
1332+ params = {}
1333+ mod = IRModule .from_expr (out )
1334+ outputs = _build_and_run_network (remote , mod , params , inputs , target , executor_type )
1335+ out_tol = 1e-3 if dtype == "float16" else 1e-5
1336+ tvm .testing .assert_allclose (
1337+ outputs [0 ].asnumpy (), outputs [1 ].asnumpy (), rtol = out_tol , atol = out_tol
1338+ )
1339+ exp_codegen = [
1340+ {"attrs" : {"dtype" : [[dtype ]], "shape" : [[shape ]]}, "name" : "" , "op" : "input" },
1341+ {
1342+ "attrs" : {
1343+ "a_max" : [[str (a_max )]],
1344+ "a_min" : [[str (a_min )]],
1345+ "dtype" : [[dtype ]],
1346+ "num_inputs" : "1" ,
1347+ "num_outputs" : "1" ,
1348+ "shape" : [[shape ]],
1349+ },
1350+ "inputs" : [[0 , 0 , 0 ]],
1351+ "name" : "clip" ,
1352+ "op" : "kernel" ,
1353+ },
1354+ ]
1355+
1356+ verify_codegen (remote , mod , params , exp_codegen , target )
1357+
1358+ _verify (trials [0 ], trials [1 ], trials [2 ])
1359+
1360+
13161361if __name__ == "__main__" :
13171362 tvm .testing .main ()
0 commit comments