This project demonstrates various convolutional neural network (CNN) operations using OpenCL for GPU acceleration. The operations include convolution, ReLU activation, max pooling, batch normalization, tensor concatenation, upsampling and sigmoid activation.
- Tensor Convolution
- ReLU Activation
- Max Pooling
- Batch Normalization
- Tensor Concatenation
- Upsampling
- OpenCL SDK
- OpenCV
- cnpy
- Meson
foo@bar:~$ sudo apt update
foo@bar:~$ sudo apt install intel-opencl-icdfoo@bar:~$ clinfo
foo@bar:~$
Number of platforms 1
Platform Name Intel(R) OpenCL HD Graphics
Platform Vendor Intel(R) Corporation
Platform Version OpenCL 3.0
Platform Profile FULL_PROFILE-
Install the required libraries:
sudo apt-get install opencl-headers ocl-icd-opencl-dev sudo apt-get install libopencv-dev sudo apt-get install libboost-all-dev sudo apt-get install cmake,meson pip install -r requirements.txt
-
Clone the repository:
git clone https://github.com/raghulrajn/OpenCL cd gpu -
Clone cnpy:
git clone https://github.com/rogersce/cnpy.git cp cnpy gpc/src
-
Download pretrained-kernel from ZF_UNET_224
python3 extractWeights zf_unet_224.h5
Weights and biases are extracted from the model and will be saved in
pretrainedKernelsfolder
├── pretrainedKernels
├── gpu
├── lib
│ ├── Core
│ ├── lib
│ ├── OpenCL
│ └── vx
├── src
│ └── cnpy
│ ├── conv2d.cl
│ ├── conv2d.cpp
├── meson.build
├── run.sh
├── results
├── sampleImages
└── utils
cd gpu
python3 genImage.py
chmod +x run.sh
./run.sh <PATH_TO_IMG NPY FILE>Results after CPU and GPU execution are stored in results folder
- conv2d.cpp: Main source file containing the implementation of Conv2d, Maxpool, Upsampling and UNET operations using OpenCL.
- conv2d.cl: Kernel code for all GPU operations
- pytorch.py: Python code for convolution, Relu, maxpool etc. Results are stored in npy folder
- compare.py: Python code to crosscheck CPU, GPU and Pytorch results
- genImage.py: Python code to create sample images for inference. png image and npy file of the same will generated




