I am trying to write a conv_padded operator i.e. instead of padding the input image, we keep the image size same but involve ‘if’ conditions to compute the output.
Example of 1D padded conv
for(ow = 0, 16){
for(k = 0, 3){
if(ow + k - 1 >= 0 && ow + k - 1 < 16)
conv_padded[ow] += data[ow + k - 1] * kernel[k];
The problem is to represent that ‘if’ condition. I don’t want to use ir_builder because that prevents us from the schedule optimizations like tiling, split.
I tried using tvm.select but it gets into infinite loop
def test_padded_conv():
data = tvm.placeholder((16, ), name='data')
kernel = tvm.placeholder((3, ), name='kernel')
k = tvm.reduce_axis((0, 3), name='kh')
# Unpadded conv looks something like this
# conv_padded = tvm.compute((16, ),
# lambda oh: tvm.sum(data[oh + k - 1] * kernel[k],
# axis=[k]),
# name="conv_padded")
conv_padded = tvm.compute((16, ),
lambda oh: tvm.sum(tvm.select( (oh+k-1>=0), (data[oh + k - 1]* kernel[k]), 0),
axis=[k]),
name="conv_padded")
s = tvm.create_schedule(conv_padded.op)
print(tvm.lower(s, [data, kernel], simple_mode=True))
Error is
Exception RuntimeError: 'maximum recursion depth exceeded while calling a Python object' in <object repr() failed> ignored
Any ideas on how to solve this?