@@ -959,15 +959,16 @@ def _test_pool2d_int(opfunc, reffunc, dtype):
959
959
# test execution
960
960
dtype = "int32"
961
961
dshape = (1 , 3 , 28 , 28 )
962
- x = relay .var ("x" , shape = dshape , dtype = dtype )
963
- y = opfunc (x , pool_size = (2 , 2 ), strides = (2 , 2 ), padding = (0 , 0 ))
964
- func = relay .Function ([x ], y )
965
- data = np .random .randint (low = - 128 , high = 128 , size = dshape )
966
- ref_res = reffunc (data .reshape (1 , 3 , 14 , 2 , 14 , 2 ), axis = (3 , 5 )).astype (dtype )
967
- for target , ctx in tvm .testing .enabled_targets ():
968
- intrp1 = relay .create_executor ("graph" , ctx = ctx , target = target )
969
- op_res1 = intrp1 .evaluate (func )(data )
970
- tvm .testing .assert_allclose (op_res1 .asnumpy (), ref_res , rtol = 1e-5 , atol = 1e-5 )
962
+ for shape_dtype in ["int32" , "int64" ]:
963
+ x = relay .var ("x" , shape = [tvm .tir .IntImm (shape_dtype , x ) for x in dshape ], dtype = dtype )
964
+ y = opfunc (x , pool_size = (2 , 2 ), strides = (2 , 2 ), padding = (0 , 0 ))
965
+ func = relay .Function ([x ], y )
966
+ data = np .random .randint (low = - 128 , high = 128 , size = dshape )
967
+ ref_res = reffunc (data .reshape (1 , 3 , 14 , 2 , 14 , 2 ), axis = (3 , 5 )).astype (dtype )
968
+ for target , ctx in tvm .testing .enabled_targets ():
969
+ intrp1 = relay .create_executor ("graph" , ctx = ctx , target = target )
970
+ op_res1 = intrp1 .evaluate (func )(data )
971
+ tvm .testing .assert_allclose (op_res1 .asnumpy (), ref_res , rtol = 1e-5 , atol = 1e-5 )
971
972
972
973
973
974
def _test_global_pool2d (opfunc , reffunc ):
@@ -1010,32 +1011,34 @@ def test_pool2d():
1010
1011
1011
1012
@tvm .testing .uses_gpu
1012
1013
def test_pool1d ():
1013
- def _test_pool1d (opfunc , pool_size = (2 ,), strides = (2 ,), padding = (0 , 0 )):
1014
+ def _test_pool1d (opfunc , pool_size = (2 ,), strides = (2 ,), padding = (0 , 0 ), dtype = "float32" ):
1014
1015
n , c , w = te .var ("n" ), 10 , 224
1015
1016
x = relay .var ("x" , relay .TensorType ((n , c , w ), "float32" ))
1016
1017
y = opfunc (x , pool_size = (1 ,))
1017
1018
assert "pool_size=" in y .astext ()
1018
1019
yy = run_infer_type (y )
1019
1020
assert yy .checked_type == relay .TensorType ((n , 10 , 224 ), "float32" )
1020
1021
# test execution
1021
- dtype = "float32"
1022
1022
dshape = (1 , 3 , 32 )
1023
- x = relay .var ("x" , shape = dshape )
1024
- pool_type = "max" if "max" in str (opfunc ) else "avg"
1025
- y = opfunc (x , pool_size = pool_size , strides = strides , padding = padding )
1026
- func = relay .Function ([x ], y )
1027
- data = np .random .uniform (size = dshape ).astype (dtype )
1028
- ref_res = tvm .topi .testing .pool1d_ncw_python (
1029
- data , (2 ,), (2 ,), (0 , 0 ), (1 , 3 , 16 ), pool_type , False
1030
- )
1031
- for target , ctx in tvm .testing .enabled_targets ():
1032
- intrp1 = relay .create_executor ("graph" , ctx = ctx , target = target )
1033
- op_res1 = intrp1 .evaluate (func )(data )
1034
- tvm .testing .assert_allclose (op_res1 .asnumpy (), ref_res , rtol = 1e-5 , atol = 1e-5 )
1023
+ for shape_dtype in ["int32" , "int64" ]:
1024
+ x = relay .var ("x" , shape = [tvm .tir .IntImm (shape_dtype , x ) for x in dshape ], dtype = dtype )
1025
+ pool_type = "max" if "max" in str (opfunc ) else "avg"
1026
+ y = opfunc (x , pool_size = pool_size , strides = strides , padding = padding )
1027
+ func = relay .Function ([x ], y )
1028
+ data = np .random .uniform (size = dshape ).astype (dtype )
1029
+ ref_res = tvm .topi .testing .pool1d_ncw_python (
1030
+ data , (2 ,), (2 ,), (0 , 0 ), (1 , 3 , 16 ), pool_type , False
1031
+ )
1032
+ for target , ctx in tvm .testing .enabled_targets ():
1033
+ intrp1 = relay .create_executor ("graph" , ctx = ctx , target = target )
1034
+ op_res1 = intrp1 .evaluate (func )(data )
1035
+ tvm .testing .assert_allclose (op_res1 .asnumpy (), ref_res , rtol = 1e-5 , atol = 1e-5 )
1035
1036
1036
1037
_test_pool1d (relay .nn .max_pool1d )
1038
+ _test_pool1d (relay .nn .max_pool1d , dtype = "int32" )
1037
1039
_test_pool1d (relay .nn .max_pool1d , pool_size = 2 , strides = 2 , padding = 0 )
1038
1040
_test_pool1d (relay .nn .avg_pool1d )
1041
+ _test_pool1d (relay .nn .avg_pool1d , dtype = "int32" )
1039
1042
_test_pool1d (relay .nn .avg_pool1d , pool_size = 2 , strides = 2 , padding = 0 )
1040
1043
1041
1044
@@ -1047,6 +1050,7 @@ def _test_pool3d(
1047
1050
strides = (2 , 2 , 2 ),
1048
1051
padding = (0 , 0 , 0 , 0 , 0 , 0 ),
1049
1052
out_shape = (1 , 3 , 16 , 16 , 16 ),
1053
+ dtype = "float32" ,
1050
1054
):
1051
1055
n , c , d , h , w = te .size_var ("n" ), 10 , 5 , 224 , 224
1052
1056
x = relay .var ("x" , relay .TensorType ((n , c , d , h , w ), "float32" ))
@@ -1057,30 +1061,33 @@ def _test_pool3d(
1057
1061
# test execution
1058
1062
dtype = "float32"
1059
1063
dshape = (1 , 3 , 32 , 32 , 32 )
1060
- x = relay .var ("x" , shape = dshape )
1061
- pool_type = "max" if "max" in str (opfunc ) else "avg"
1062
- y = opfunc (x , pool_size = pool_size , strides = strides , padding = padding )
1063
- func = relay .Function ([x ], y )
1064
- # check output shape
1065
- f_out_shape = tuple (map (lambda x : int (x ), run_infer_type (func ).ret_type .shape ))
1066
- assert out_shape == f_out_shape , "Output shape mismatch. expected {}, actual {}" .format (
1067
- out_shape , f_out_shape
1068
- )
1069
- data = np .random .uniform (size = dshape ).astype (dtype )
1070
- ref_res = tvm .topi .testing .pool3d_ncdhw_python (
1071
- data , pool_size , strides , padding , out_shape , pool_type , False
1072
- )
1073
- for target , ctx in tvm .testing .enabled_targets ():
1074
- intrp1 = relay .create_executor ("graph" , ctx = ctx , target = target )
1075
- op_res1 = intrp1 .evaluate (func )(data )
1076
- tvm .testing .assert_allclose (op_res1 .asnumpy (), ref_res , rtol = 1e-5 , atol = 1e-5 )
1064
+ for shape_dtype in ["int32" , "int64" ]:
1065
+ x = relay .var ("x" , shape = [tvm .tir .IntImm (shape_dtype , x ) for x in dshape ], dtype = dtype )
1066
+ pool_type = "max" if "max" in str (opfunc ) else "avg"
1067
+ y = opfunc (x , pool_size = pool_size , strides = strides , padding = padding )
1068
+ func = relay .Function ([x ], y )
1069
+ # check output shape
1070
+ f_out_shape = tuple (map (lambda x : int (x ), run_infer_type (func ).ret_type .shape ))
1071
+ assert out_shape == f_out_shape , "Output shape mismatch. expected {}, actual {}" .format (
1072
+ out_shape , f_out_shape
1073
+ )
1074
+ data = np .random .uniform (size = dshape ).astype (dtype )
1075
+ ref_res = tvm .topi .testing .pool3d_ncdhw_python (
1076
+ data , pool_size , strides , padding , out_shape , pool_type , False
1077
+ )
1078
+ for target , ctx in tvm .testing .enabled_targets ():
1079
+ intrp1 = relay .create_executor ("graph" , ctx = ctx , target = target )
1080
+ op_res1 = intrp1 .evaluate (func )(data )
1081
+ tvm .testing .assert_allclose (op_res1 .asnumpy (), ref_res , rtol = 1e-5 , atol = 1e-5 )
1077
1082
1078
1083
_test_pool3d (relay .nn .max_pool3d )
1084
+ _test_pool3d (relay .nn .max_pool3d , dtype = "int32" )
1079
1085
_test_pool3d (relay .nn .max_pool3d , padding = (2 , 0 , 0 , 2 , 0 , 0 ), out_shape = (1 , 3 , 18 , 16 , 16 ))
1080
1086
_test_pool3d (relay .nn .max_pool3d , padding = (0 , 3 , 0 , 0 , 3 , 0 ), out_shape = (1 , 3 , 16 , 19 , 16 ))
1081
1087
_test_pool3d (relay .nn .max_pool3d , padding = (0 , 0 , 4 , 0 , 0 , 4 ), out_shape = (1 , 3 , 16 , 16 , 20 ))
1082
1088
_test_pool3d (relay .nn .max_pool3d , pool_size = 2 , padding = 0 , strides = 2 )
1083
1089
_test_pool3d (relay .nn .avg_pool3d )
1090
+ _test_pool3d (relay .nn .avg_pool3d , dtype = "int32" )
1084
1091
_test_pool3d (relay .nn .avg_pool3d , padding = (2 , 0 , 0 , 2 , 0 , 0 ), out_shape = (1 , 3 , 18 , 16 , 16 ))
1085
1092
_test_pool3d (relay .nn .avg_pool3d , padding = (0 , 3 , 0 , 0 , 3 , 0 ), out_shape = (1 , 3 , 16 , 19 , 16 ))
1086
1093
_test_pool3d (relay .nn .avg_pool3d , padding = (0 , 0 , 4 , 0 , 0 , 4 ), out_shape = (1 , 3 , 16 , 16 , 20 ))
0 commit comments