Monday 16 December 2013

Mount shared folder to Ubuntu in VirtualBox


We cannot use the /media/sf_Dropbox as a mount point because of permission. Create new folder as <~/Dropbox> and mount shared folder for VirtualBox by

>>sudo mount -t vboxsf <Dropbox> <~/Dropbox>

The mount above performs by root so normal user cannot write on the folder. We can define user and group of normal user by specify uid and gid as shown below

>>sudo mount -t vboxsf -o rw,uid=1000,gid=1000  <Dropbox> <~/Dropbox>

And you can unmount by

>>sudo umount -a -t vboxsf

Tuesday 3 December 2013

Install Qt on Ubuntu 64 bit

I just got Lenovo L330 with Windows 8. I got a secured boot lock problem that made installing Ubuntu along with Windows 8. The secure boot lock must be disabled, for more detail please go to here.

Well, this note is about preparing Qt framework in Ubuntu 64 bit. I downloaded Qt online installer for Linux 64bit. It took about 30 minutes and installed with a warning message "This should not happen". I really don't know what does the message means. The installation finished and it looks OK.


3/12/13 10:40pm
Then I'm installing the g++ compiler by 
>>sudo apt-get install build-essential

Next the cmake, I found cmake in Synaptic Package Manager, installing  with 3 clicks. I also need OpenCV 2.3, another 3 clicks. The size of all OpenCV packages is quite large, so please be patient, it took me  20 minutes.

We just finished installed all package required for the project.

Thursday 24 October 2013

Storyline test!

Storyline test!
To compare, three different techniques (our method, [tanahashi] and [Munroe]) for drawing storyline chart.

Ref
[Tanahashi] Tanahashi, Y. & Ma, K.-L. Design Considerations for Optimizing Storyline Visualizations Visualization and Computer Graphics, IEEE Transactions on, 2012, 18, 2679 -2688

[Munroe] R. Munroe. Xkcd #657: Movie narrative charts. http://xkcd.com/657, December 2009.

Marker

Marker to label the class of pixels, by Wasit Limprasert
Source files: marker.cpp, CMakeLists.txt, number.png 
Requirement: OpenCV2.4.5, Cmake2.8
Description: Marker load an original image and let user label classes of pixels. The marked image is then saved into bitmap file. There are 10 classes to be selected by pressing key number 0-9. "-" and "=" are used for deleting and saving, respectively.

Sunday 21 April 2013

CUDA: multiple GPU setting (Ubuntu)

CUDA: multiple GPU setting (Ubuntu)

I have multiple GPUs are installed on a computer and want to make one of them do computing and another do displaying. This blog is going to tell how to set Ubuntu and code your CUDA.

Firstly, check the display devices by using a command /usr/bin/nvidia-settings. You will see installed GPUs. You can set display option here or edit a config file /etc/X11/xorg.config.

And then, we code a program to count the GPU, get info and set computing GPU by folowing command:

1. cudaGetDeviceCount(int* NumberOfGPUs); to count nymber of GPUs
2. cudaGetDeviceProperties(&deviceProp,GPU_ID);
3. cudaSetDevice(GPU_ID);

Example code:

int deviceNum;
cudaError error;
cudaGetDeviceCount(&deviceNum);
cudaDeviceProp deviceProp; //struct used to keep a GPU info
for(int i=0;i<deviceNum;i++){
    error=cudaGetDeviceProperties(&deviceProp,i);
    if(error)printf("Error:getting property DeviceID:%d ErrorCode:%d\n",i,error);
    printf("Device %d: %s\n",i,deviceProp.name);
}
cudaSetDevice(SELECTED_ID);

Saturday 16 March 2013

CMake+ MinGW + freeglut + Qt Creator

After a couple of days of studying by reading from various sources and hours of trial and errors, I just figured out how to set cmake, mingw, freeglut and qt creator to work as a single piece on my Windows Vista. The procedure is:


1. installing cmake
2. modifying FindGLUT.cmake
    C:\Program Files\CMake 2.8\share\cmake-2.8\Modules\FindGLUT.cmake
    replacing the old code in [if] by this
    -----------------------------
    IF (WIN32)
          FIND_PATH( GLUT_INCLUDE_DIR NAMES GL/glut.h
            PATHS ENV GLUT_ROOT_PATH
            PATH_SUFFIXES include
            )
          FIND_LIBRARY( GLUT_glut_LIBRARY NAMES glut glut32 freeglut
            PATHS ENV OPENGL_LIBRARY_DIR GLUT_ROOT_PATH
            PATH_SUFFIXES Release lib
            )
    ELSE (WIN32)
    -----------------------------
3. installing minGW and msys
4. download freeglut source files and make by using msys
    ./configure --with-x=no
    make
    make install
5. The output header library and dll files are in the folder [local]
6. Copy them to C:/MinGW/include, C:/MinGW/lib and Windows/system32
7. Add path into the CMakeLists.txt
    set(CMAKE_INCLUDE_PATH C:/MinGW)
    set(CMAKE_LIBRARY_PATH C:/MinGW)
8. Open the CMakeLists.txt with Qt creator
9. Build and run...job done!

References

http://public.kitware.com/Bug/view.php?id=13306
http://www.transmissionzero.co.uk/software/freeglut-devel/
http://www.mingw.org/category/wiki/glut
http://freeglut.sourceforge.net/
http://www.transmissionzero.co.uk/software/freeglut-devel/


Wednesday 6 March 2013

CUDA+QT+CMake on Ubuntu:

I'm about to implement some a CUDA program by QT creator and CMake on Ubuntu. I haven't played with them before this note will explain how I get through and make they work together.

I reviewed about cooperating between them and they should works properly, please see sn0v and Dayal.

Here is a brief explanation of the setting process:
  1. setting CUDA
    • download the CUDA 5 product from here
    • follow sn0v's instruction
      • install development tools:   
        • sudo apt-get install freeglut3-dev build-essential libx11-dev libxmu-dev libxi-dev libgl1-mesa-glx libglu1-mesa libglu1-mesa-devcuda
      • disable some graphics components by adding the blacklist: 
        • gedit /etc/modprobe.d/blacklist.conf
        • blacklist amd76x_edac
          blacklist vga16fb
          blacklist nouveau
          blacklist rivafb
          blacklist nvidiafb
          blacklist rivatv
      • to make sure the previous graphics components is clean:   
        • sudo apt-get remove --purge nvidia*
      • Now we are ready to install CUDA, firstly we need to reboot and press Ctrl+Alt+F1 and login window. It will switch to command-line mode.
      • Turn off the GUI service and install CUDA
        • sudo service lightdm stop 
        • sudo ./<CUDAInstallFile>.run
      • Follow the CUDA installer instruction. At this point you should get CUDA toolkit and CUDA Samples.
  2. Installing QT creator, CMake and compliers by following Dayal's tutorial.
    • Here is the list of all necessary packages (install by Synaptic Package Manager)
      • gcc
      • g++
      • gdb
      • qtcreator
      •  valgrind
      • cmake
    • It is almost done, next step is to create some simple project.
  3. Open QT creator and add new text file (CMakeLists.txt).
    • write this into the txt file
      • cmake_minimum_required(VERSION 2.6.2)

        project(CMakeCUDA)

        find_package(CUDA)
        if (CUDA_FOUND)
        message(" * CUDA ${CUDA_VERSION} was found")
        else(CUDA_FOUND)
            message(" * CUDA is not found")
            message(FATAL_ERROR "Not all CUDA libraries are found")
        endif(CUDA_FOUND)

        # add sources files
        set(SRCS
             main.cpp
             cuda.cu
        )
        cuda_add_executable(CMakeCUDA ${SRCS})
    •  Add main.cpp and write the code
      •  
    • Add cuda.cu file
    • reopen the CMakeLists.txt but this time open by the cmake wizard
  4. You just finished setting up a simple CUDA project. When you build and run in terminal you will see output numbers, please see click here to see more explanation of the program.
------------------------------------main.cpp-------------------------------------
//main.cpp
// simple warpper class of CUDA function.
// Vector A abd B is inititialized and transfered to the device.
// Thedevice performs addition and transfers the data back to host.
// by Wasit Limprasert created on 19-07-2011
// updated 23-08-2011: adding comment
#include <stdlib.h>
#include <stdio.h>
extern "C" void CUDA_Constructor(int** g_A,int** g_B,int size);
extern "C" void CUDA_SetData(int* g_dist, int* h_src, int size);
extern "C" void CUDA_Add(int* g_A,int* g_B,int size);
extern "C" void CUDA_GetData(int* h_dist, int* g_src,int size);
class VectorOperation{
public:
    int *h_A,*g_A;//h_A host pointer of vector A and g_A is a ponter to global memory on device.
    int *h_B,*g_B;
    int size;
    VectorOperation(int _size);
    ~VectorOperation(void){}
    void init(void);
    void SetA(int* h_src){CUDA_SetData(g_A,h_src,size);}
    void SetB(int* h_src){CUDA_SetData(g_B,h_src,size);}
    void Add(void){CUDA_Add(g_A,g_B,size);}
    void Result(void);
};
//constractor
//setting size of vectors and memory allocation on both host and device.
VectorOperation::VectorOperation(int _size){
    size=_size;
    CUDA_Constructor(&g_A,&g_B,size);
    h_A=(int*)malloc(sizeof(int)*size);
    h_B=(int*)malloc(sizeof(int)*size);
}
//initialization
//generating data for vector A and B then copy the data to device.
void VectorOperation::init(void){
    printf("A  =");
    for(int i=0;i<size;i++){
        h_A[i]=1;
        printf("%2d ",h_A[i]);
    }
    SetA(h_A);
    printf("\nB  =");
    for(int i=0;i<size;i++){
        h_B[i]=i;
        printf("%2d ",h_B[i]);
    }
    SetB(h_B);
    printf("\n");
}
//reading result,which is saved in g_A back to h_A and print out.
void VectorOperation::Result(void){
    CUDA_GetData(h_A,g_A,size);
    printf("A+B:");
    for(int i=0;i<size;i++){
        printf("%2d ",h_A[i]);
    }
    printf("\n");
}
//main
int main(){
    printf("Simple CUDA vector addition.\n");
    VectorOperation P = VectorOperation(16);
    P.init();
    P.Add();
    P.Result();
    getchar();
}
------------------------------------------------cuda.cu-------------------------------
//cuda.cu
//simple CUDA functions
//by Wasit 208-2011
#include <stdio.h>
#include <cuda_runtime.h>
//memory allocation on device side
extern "C" void CUDA_Constructor(int** g_A,int** g_B,int size){
    cudaMalloc(g_A,sizeof(int)*size);
    cudaMalloc(g_B,sizeof(int)*size);
}
//copying data from host to device
extern "C" void CUDA_SetData(int* g_dist, int* h_src,int size){
    cudaMemcpy(g_dist,h_src,sizeof(int)*size,cudaMemcpyHostToDevice);
}
//CUDA Kernel block and thread ID are indicated by blockIdx and threadIdx, respectively
__global__ void Kernel_Add(int* g_A,int* g_B){
    unsigned int x = blockIdx.x*blockDim.x + threadIdx.x;
    g_A[x]=g_A[x]+g_B[x];
}
//Addition function
//number of thread and block is set before call Kernel
extern "C" void CUDA_Add(int* g_A,int* g_B,int size){
    int threadnum=16;
    int blocknum=size/threadnum;
    Kernel_Add<<<threadnum,blocknum>>>(g_A,g_B);
}
//read data back to host
extern "C" void CUDA_GetData(int* h_dist, int* g_src,int size){
    cudaMemcpy(h_dist,g_src,sizeof(int)*size,cudaMemcpyDeviceToHost);
}

Wednesday 13 February 2013

Python and Ubuntu

I just removed Python2.7 from my Ubuntu. Initially, I needed to remove some Python packages but they locate in many folders. So, I used command "apt-get remove python2.7". The consequence was vital that all GUIs on desktop were deleted as well. Please be careful don't uninstall your Python desktop.

However, if you accidentally remove Python, here is a short solution. First, reinstall Python and desktop interfacing by following commands.
"apt-get install pythoin2.7"
"apt-get install ubuntu-desktop"

Monday 21 January 2013

OpenGL:


I'm using OpenGL and QT creator in Ubuntu environment. I will constantly make short notes about problems and solutions in programming.

Adding OpenGL Library


To add external library, right click on the project or .pro file then click >>Add new library >>External library >>Browse "usr/lib/libGLEW.so"

Or edit the *.pro file by adding "LIBS += -L$$PWD/../../../../../../usr/lib/ -lglut -lGLEW"

A good OpenGL tutorial can be found here or here.

Create a simple project

1. Firstly, open QT Creator and create a empty project.
2. Add libraries (see above). After adding two libraries you can see the "-lglut -lGLEW" in the *.pro file.
3. Add the main source file (main.cpp)
4. Finally build and execute the project.

------------------------------------main.cpp----------------------------------------
#include <GL/glut.h>
void display(){
    glClear(GL_COLOR_BUFFER_BIT);
    glBegin(GL_POLYGON);
    glVertex2f(-0.5, -0.5);
    glVertex2f(-0.5, 0.5);
    glVertex2f(0.5, 0.5);
    glVertex2f(0.5, -0.5);
    glEnd();
    glFlush();
}
void init(){
    glClearColor (0.0, 0.0, 0.0, 0.0);
    glColor3f(1.0, 1.0, 1.0);
    glMatrixMode (GL_PROJECTION);
    glLoadIdentity();
    glOrtho (-1.0, 1.0, -1.0, 1.0, -1.0, 1.0);
}
int main(int argc, char** argv){
    glutInit(&argc,argv);
    glutCreateWindow("simple");
    glutDisplayFunc(display);
    init();
    glutMainLoop();
}
-------------------------------------------------------------------------------------- 


Another useful material click here.

Ubuntu tips

Set LAN speed in Ubuntu
1. install ethtool "$sudo apt-get ethtool"
2. Add command to the start-up script "./etc/rc.local". Add command "/sbin/ethtool -s eth0 speed 100 duplex full".