Step by step to enable x264 with OpenCL – NVIDIA solution


x264 project added OpenCL video acceleration to it’s implementation early at about 2013(not sure with the date), and my goal here is test the video encoding performance of x264 when with OpenCL video accelerator enabled.

Test hardware environments: HP Pavilion 14
1. Graphic card: NVIDIA GeForce GT730M card.
2. CPU: Intel Core Ivy Bridge i7-3632QM

Here we go.

1. Install OS: Ubuntu 14.10 64 bit version
2. Install g++ cmake yasm

sudo apt-get install g++ cmake yasm git subversion openssh-server

3. Update graphic driver to NVIDIA version 331.89
4. Some preparation for the tests *If you already have a YUV file, you can skip the ffmpeg related steps.
a. Download source code: x264, ffmpeg
b. Compile x264

./configure --enable-static --enable-shared

c. Compile ffmpeg

./configure --enable-libx264 --enable-gpl --enable-static

c. Use the newly compiled ffmpeg to decode a video file to yuv

ffmpeg -i ~/Videos/park_joy_1080p_CABAC_b_0_6M.264 ~/Videos/parkjoy_1920x1080.yuv

5. Check whether my graphic driver support opencl
First install clinfo:

    sudo apt-get install clinfo

however, running clinfo return with a message like this:

    I: ICD loader reports no usable platforms

Never mind, according to my hardware environment, I have two ways to run the test: Intel graphic drive and NVIDIA graphic driver. However, I’ll test NVIDIA solution first.

——————————————————–
NVIDIA solution
1. Download CUDA 7.0 Toolkit
Go visit NVIDIA web site(http://www.nvidia.com/getcuda) and download a copy of CUDA ToolKit 7.0. I choosed cuda_7.0.28_linux-ubuntu.run
Downloaded a CUDA 7.0 Toolkit, 1.1 GB, took me 4 hours, about 20+KB per second, seems it’s me whose network sucked.

2. Install CUDA 7.0 Toolkit
Excute cuda_7.0.28_linux-ubuntu.run directly. If you logged in the desktop, the installation will finally return with an error like this:

Enter CUDA Samples Location [ default is /home/jacky ]:
Installing the NVIDIA display driver…
It appears that an X server is running. Please exit X before installation. If you’re sure that X is not running, but are getting this error, please delete any X lock files in /tmp.

===========
= Summary =
===========

Driver:   Installation Failed
Toolkit:  Installation skipped
Samples:  Installation skipped

Logfile is /tmp/cuda_install_10084.log

Tried the following these steps to fix it:

a. Exit x-window by using short key Ctrl+Alt+F1
b. Login in terminal and stop x-window by service lightdm stop.
c. Start install CUDA 7.0 ToolKit.
If the installation wizard tells you reboot, just do it. And you’ll finally get a successful installation.
d. Reboot Ubuntu after finished, and login Ubuntu with x-window.

Installing the NVIDIA display driver…
Installing the CUDA Toolkit in /usr/local/cuda-7.0 …
Missing recommended library: libGLU.so
Missing recommended library: libXi.so
Missing recommended library: libXmu.so

Installing the CUDA Samples in /home/jacky …
Copying samples to /home/jacky/NVIDIA_CUDA-7.0_Samples now…
Finished copying samples.

===========
= Summary =
===========

Driver:   Installed
Toolkit:  Installed in /usr/local/cuda-7.0
Samples:  Installed in /home/jacky, but missing recommended libraries

Please make sure that
–   PATH includes /usr/local/cuda-7.0/bin
–   LD_LIBRARY_PATH includes /usr/local/cuda-7.0/lib64, or, add /usr/local/cuda-7.0/lib64 to /etc/ld.so.conf and run ldconfig as root

To uninstall the CUDA Toolkit, run the uninstall script in /usr/local/cuda-7.0/bin
To uninstall the NVIDIA Driver, run nvidia-uninstall

Please see CUDA_Getting_Started_Guide_For_Linux.pdf in /usr/local/cuda-7.0/doc/pdf for detailed information on setting up CUDA.

Logfile is /tmp/cuda_install_2719.log

To fix the missing recommended libraries warning, just:

sudo apt-get install libglu1-mesa-dev

Run the installation again, everything was OK.

3. Try verify the installation with a simple test program

#include <stdio.h>
#include <stdlib.h>
#ifdef __APPLE__
#include <OpenCL/cl.h>
#elif defined(__linux__)
#include <CL/cl.h>
#endif
int main()
{
    cl_int status=0;
    size_t deviceListSize;
    cl_uint numPlatforms;
    cl_platform_id platfomr=NULL;
    status=clGetPlatformIDs(0,NULL,&numPlatforms);
    printf("status=%d, %s.\n",status,status ? "failed": "succeeded");
    return 0;
}

Name it with test_cuda.c, and compile it with command:

gcc test_cuda.c -o test_cuda -lOpenCL -I/usr/local/cuda/include

If return with success, means the installation was OK.

4. Try run x264

cd /usr/local/bin
x264 -o ~/Videos/parkjoy.264 ~/Videos/parkjoy_1920x1080.yuv --preset ultrafast --opencl

The encoding was started with OpenCL enabled.

Leave a comment

Your email address will not be published. Required fields are marked *