Sunday, September 13, 2015

OpenCL on Ubuntu 14.04 + Intel/Nvidia Dual Graphic Card for Heterogeneous Computing

Install

Nowadays many laptops have dual graphic cards, one Intel Integrated GPU for general computing as web surfing or simple works and one Nvidia GPU for gaming. Windows already support handling this dual graphic card system dynamically. Linux also support it. As I thought, How Linux supports it is a little different from Windows'. To use this feature users have to install "nvidia-prime" library by apt-get". It means that users use nvidia-made-something instead of a os-supported feature.

The following list shows my installed nvidia-libraries.
nvidia-prime is for handling dual graphic cards on my laptop.
It is very easy to miss to installing "nvidia-modprobe". It is why I wrote "nvidia-modprobe" in red.
$ dpkg -l |  grep nvidia
ii  nvidia-340                                            340.76-0ubuntu0.1                                   amd64        NVIDIA binary driver - version 340.76
ii  nvidia-340-dev                                        340.76-0ubuntu0.1                                   amd64        NVIDIA binary Xorg driver development files
ii  nvidia-340-uvm                                        340.76-0ubuntu0.1                                   amd64        Transitional package for nvidia-340
ii  nvidia-libopencl1-331                                 340.76-0ubuntu0.1                                   amd64        Transitional package for nvidia-libopencl1-340
ii  nvidia-libopencl1-340                                 340.76-0ubuntu0.1                                   amd64        NVIDIA OpenCL Driver and ICD Loader library
ii  nvidia-modprobe                                       340.24-1~ubuntu14.04.1                              amd64        utility to load NVIDIA kernel modules and create device nodes
ii  nvidia-opencl-dev:amd64                               5.5.22-3ubuntu1                                     amd64        NVIDIA OpenCL development files
ii  nvidia-opencl-icd-340                                 340.76-0ubuntu0.1                                   amd64        NVIDIA OpenCL ICD
ii  nvidia-prime                                          0.6.2                                               amd64        Tools to enable NVIDIA's Prime
ii  nvidia-settings                                       331.20-0ubuntu8                                     amd64        Tool for configuring the NVIDIA graphics driver

 Verification

We can verify it using clinfo. Unfortunately something is wrong when I run clinfo right after "apt-get install clinfo". So I downloaded clinfo's source by apt-get source clinfo and built it by myself.

 $ ./clinfo
Number of platforms                               1
  Platform Name                                   NVIDIA CUDA
  Platform Vendor                                 NVIDIA Corporation
  Platform Version                                OpenCL 1.1 CUDA 6.5.45
  Platform Profile                                FULL_PROFILE
  Platform Extensions                             cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_copy_opts
  Platform Extensions function suffix             NV

  Platform Name                                   NVIDIA CUDA
Number of devices                                 1
  Device Name                                     GeForce GTX 765M
  Device Vendor                                   NVIDIA Corporation
  Device Vendor ID                                0x10de
                                             ...

Install Intel OpenCL for Heterogeneous Computing with Intel CPU + Nvidia GPU

Intel Providing 2 type of OpenCL. One is for CPU, the other is for Intel Integrated GPU. In this case I will setup only Intel OpenCL for Intel CPU.
If you search on Google using related keywords such as "intel opencl", you can find easily this kind of pages.

I use Ubuntu 14.04, so I download intel_code_builder_for_opencl_2015_ubuntu_5.0.0.43_x64.tgz and extract it.
$ ls -al
total 80
drwxr-xr-x 4 tmax tmax  4096 Jan 19  2015 .
drwxrwxr-x 6 tmax tmax  4096 Dec 29 14:22 ..
-rw-r--r-- 1 tmax tmax 23667 Jan 18  2015 EULA.txt
-rwxr-xr-x 1 tmax tmax   180 Jul 12  2014 install_GUI.sh
-rwxrwxr-x 1 tmax tmax 26066 Jan 19  2015 install.sh
drwxr-xr-x 6 tmax tmax  4096 Jan 19  2015 pset
-rw-rw-r-- 1 tmax tmax  1006 Jan 18  2015 PUBLIC_KEY.PUB
drwxrwxr-x 2 tmax tmax  4096 Jan 19  2015 rpm
-rw-rw-r-- 1 tmax tmax  1223 Jan 19  2015 silent.cfg

They provide convenient shell script for easier install. Just type enter key. Officially this version is supporting only Ubuntu 12.04. But it works well on 14.04

After then clinfo shows the following.

Number of platforms:                             2
  Platform Profile:                              FULL_PROFILE
  Platform Version:                              OpenCL 1.2 LINUX
  Platform Name:                                 Intel(R) OpenCL
  Platform Vendor:                               Intel(R) Corporation
  Platform Extensions:                           cl_khr_icd cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_depth_images cl_khr_3d_image_writes cl_intel_exec_by_local_thread cl_khr_spir cl_khr_fp64
  Platform Profile:                              FULL_PROFILE
  Platform Version:                              OpenCL 1.2 CUDA 7.5.23
  Platform Name:                                 NVIDIA CUDA
  Platform Vendor:                               NVIDIA Corporation
  Platform Extensions:                           cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_copy_opts

  Platform Name:                                 Intel(R) OpenCL
Number of devices:                               1
  Device Type:                                   CL_DEVICE_TYPE_CPU
  Device ID:                                     32902
 ....
  Platform ID:                                   0x1b90ad0
  Name:                                                  Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz
  Vendor:                                        Intel(R) Corporation
  Device OpenCL C version:                       OpenCL C 1.2
  Driver version:                                1.2.0.43
  Profile:                                       FULL_PROFILE
  Version:                                       OpenCL 1.2 (Build 43)
  Extensions:                                    cl_khr_icd cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_byte_addressable_store cl_khr_depth_images cl_khr_3d_image_writes cl_intel_exec_by_local_thread cl_khr_spir cl_khr_fp64
  Platform Name:                                 NVIDIA CUDA
Number of devices:                               1
  Device Type:                                   CL_DEVICE_TYPE_GPU
  Device ID:                                     4318
  Max compute units:                             2
  Max work items dimensions:                     3
  ....
  Platform ID:                                   0x1b9bff0
  Name:                                          GeForce GT 530
  Vendor:                                        NVIDIA Corporation
  Device OpenCL C version:                       OpenCL C 1.1
  Driver version:                                352.63
  Profile:                                       FULL_PROFILE
  Version:                                       OpenCL 1.1 CUDA
  Extensions:                                    cl_khr_byte_addressable_store cl_khr_icd cl_khr_gl_sharing cl_nv_compiler_options cl_nv_device_attribute_query cl_nv_pragma_unroll cl_nv_copy_opts  cl_khr_global_int32_base_atomics cl_khr_global_int32_extended_atomics cl_khr_local_int32_base_atomics cl_khr_local_int32_extended_atomics cl_khr_fp64

OpenCL should support multiple implementations on the same system( https://www.khronos.org/news/permalink/opencl-installable-client-driver-icd-loader ). You can see icd files in /etc/OpenCL/vendors/. They describe vendor driver names. libOpenCL.so is a simple wrapper. The core logic is located in the vendor own driver files.
$ tree /etc/OpenCL/
/etc/OpenCL/
└── vendors
    ├── intel64.icd -> /etc/alternatives/opencl-intel-runtime-icd
    └── nvidia.icd
There is one question. Which vendor should provide libOpenCL.so ? Intel and Nvidia provide their own libOpenCL.so. Now, I am using Intel-provided one. I did not test full combinations. According to my 1-year-ago test, some combination of libOpenCL.so and OpenCL Implementation from different vendors is not working well. (Because I did not test it seriously, my conclusion can be wrong.) I used Only one platform. It is just a parallel computing, not Heterogeneous one.

Anyway now it is OK. Whoever make it, libOpenCL.so should work well on different vendor-provided binaries.

Thursday, August 27, 2015

Apache, MySQL, PHP, JavaScript, JQuery

Development Install

sudo apt-get install apache2
sudo apt-get install mysql-common mysql-server mysql-client
sudo apt-get install php5-common php5-mysql libapache2-mod-php5
sudo apt-get install phpmyadmin  // for easier manipulating mysql

sudo service apache2 restart

MySQL

$ mysql -u root -p

Python Django for Web Development

Install on Ubuntu

sudo apt-get install python-django
//sudo apt-get install libmysqlclient-dev
sudo apt-get install python-mysqldb
//sudo apt-get install python-mysql.connector

Install the latest Django on Ubuntu

sudo apt-get install python-pip
sudo pip install -U pip
sudo pip install Django (or sudo pip install Django --upgrade )
./manage.py runserver 0.0.0.0:8000

sudo apt-get install python-dev
sudo pip install Pillow   // for handling modelsImageField (django 1.8)

chgrp -R www-data ./media


Install PyDev on Eclipse

WSGI

 sudo apt-get install libapache2-mod-wsgi

Examples

Tuesday, February 03, 2015

My Linux Setup

Bootable USB using Startup Disk Creator

Window 8.1 & Ubuntu 12.04 Dual Booting by using Boot-Repair

$ sudo add-apt-repository ppa:yannubuntu/boot-repair
$ sudo apt-get update
$ sudo apt-get install boot-repair

!!! Read the guide carefully

Recover Grub using grub rescue

grub rescue > ls
(hd0) (hd0,msdos5) (hd0,msdos3) (hd0,msdos2) (hd0,msdos1) (hd1) (hd1,msdos1)
grub rescue > ls (hd0,msdos1) # try to recognize which partition is this
grub rescue > ls (hd0,msdos2) # let's assume this is the linux partition
grub rescue > set root=(hd0,msdos2)
grub rescue > set prefix=(hd0,msdos2)/boot/grub # or wherever grub is installed
grub rescue > insmod normal # if this produced an error, reset root and prefix to something else ..
grub rescue > normal

Dual Graphic Cards Setup

Korean Input Setup

1. Dash Home -> Language Support -> Install/Remove Language -> Install "Korean"








2. Right Click Upper-right side "Keyboard" Button. -> Restart



3. Right Click "Keyboard" Button -> Double Click "preference" -> Show IBus Preference -> Check Input Method










Utilities

  • apt-file : for searching packages including files to install
    • apt-file search <file_name>
  • apt-cache :
    • apt-cache show <package_name>
  • gnome-color-chooser
    • for customizing ubuntu gnome color appearance
    • for Eclipse Tooltip customizing