Issue with the convolutional output in the function : TIDL_refConv2d_i8u_032s_cn in tidl_conv2d_base.c
First, the test setup:
A simple convolutional network with 3x3 kernel and bias with 2 output channels. The first kernel has all zeros and the second kernel has all ones. Bias for first channel is 1 and second channel is 2.
Now all the variables involved:
input raw rgb = 255 (all 1s)
inQuantFactor = 65280
weightsQ = 65536
biasQ = 4194304
biasQFact = 255
rgb size input = 3x3x3
num of output channels = 2
In foating point:
input = 1.0
weights = [0, 1] (1st kernel all weights are zero, and second kernel all weights are 1)
bias = [ 1, 2]
The convolved output of the first channel should be 1. Just bias, because all weights are zero.
The convolved output of the second channel should be : 1.0 * (3x3x3) *1 + 2 = 29.
Ti fixed point:
weights having values[0,1] becomes approximately: [0,1]*weightsQ/255 = [0, 255].
biases [1, 2] becomes approximately: [1, 2]*biasQ/255 = [16384,32767].
Now checking the convolution in TIDL_refConv2d_i8u_032s_cn function:
There,
pInChannel contains inputs which is uint8, and all the values are 255.
Bias is multiplied by the biasQFact (255). I understand this is because of the inQuantFactor, and the bias needs to be scaled.
convolution happens as: input * weights + bias*biasQFact
for first channel, output is = bias*biasQFact = 4177920
for second channel: 255* (3*3*3)*255 + 32767*255 = 10111260
So floating point 1 is represented as 4177920 and 29 is represented as 10111260 which is wrong.
Since the bias and weights are not represented by the same Q factor, the output will match only when
the input also has a QFactor,
With inout Q factor, second channel should be: 255*64 * (3*3*3)*255 + 32767*255 = 120718785, which should be the output.
What am i missing here?
I have attached the model and inputs to reproduce this problem.