<repo_name>awill139/cmpen417<file_sep>/417 Lab 4 HLS Starter Code/conv_algo.py
width=4
kwidth=3
image = [1,1,1,1,2,10,20,2,3,30,40,3,4,4,4,4]
kernel = [1,1,1,1,2,1,1,1,1];
Output= [118,128,69,6,147,157,76,9,89,89,55,7,12,12,8,4];

out=[]
for i in range(width):
    for j in range(width):
        psum=0
        for k in range(min(kwidth,width-i)):
            for l in range(min(kwidth,width-j)):
                print(k,l)
                psum+=image[(i+k)*width+j+l]*kernel[k*kwidth+l]
        out.append(psum)
print(out)
<file_sep>/417 Lab 4 HLS Starter Code/convolution.cpp
class imageClass
{
    int *imageData;

public:
    imageClass(int ima[IMAGE_WIDTH*IMAGE_WIDTH]){
    	imageData=ima;
    }
    // initialize use a pointer to an array	
    int getValue(int y, int x){
    	if(x >= IMAGE_WIDTH || y >= IMAGE_WIDTH){
    		return(0);
    	}
    	else{
    		return(imageData[y*IMAGE_WIDTH+x]);
    	}
    }
    void print();
};


void fpga_convolution(int image[IMAGE_WIDTH*IMAGE_WIDTH], int kernel[KERNEL_WIDTH*KERNEL_WIDTH], int output[OUTPUT_WIDTH*OUTPUT_WIDTH]){
	#pragma HLS INTERFACE m_axi port=image offset=slave depth=65536
	#pragma HLS INTERFACE m_axi port=kernel offset=slave depth=121
	#pragma HLS INTERFACE m_axi port=output offset=slave depth=65536
	#pragma HLS INTERFACE s_axilite port=return
	// Perform your convolution here (i.e., set the correct values in the "output" array)
	int imageIndex=0;
	int kernelIndex=0;
	int sum=0;
	cout <<"0 element is: ";
	cout << image[0];
	cout << "\n start\n";
	imageClass imageInstance = imageClass(image);

	for(int imageY=0; imageY < IMAGE_WIDTH; imageY++){				//These two loops iterate through 
		for(int imageX=0; imageX < IMAGE_WIDTH; imageX++){			//every value in the image.
			imageIndex=imageY*IMAGE_WIDTH+imageX;
			//for every value in the image iterate through the kernel and multiply by its corresponding value
			sum=0;
			for(int kernelY=0; kernelY < KERNEL_WIDTH; kernelY++){
				for(int kernelX=0; kernelX < KERNEL_WIDTH; kernelX++){
					kernelIndex=kernelY*KERNEL_WIDTH+kernelX;
					
					sum += kernel[kernelIndex]*imageInstance.getValue(imageY+kernelY, imageX+kernelX);
				}
			}
			cout << sum << ", ";
			output[imageIndex] = sum;
		}
		cout <<"\n";
	}
	return; // Don't remove or add any of your own returns
}
