Tuesday, February 5, 2013

UMFPACK and CSPARSE

To use UMFPack in Ubuntu, it is included in suitesparse package.
1. To install the package in Ubuntu 
   >>sudo apt-get install libsuitesparse-dev
2. Add library flag -lumfpack
3. Include header file
   #include
4. Solve Ax=b in csparse format as following  
void IPSparse::setDir(FP_TYPE* dir,cs_ColSparse* coeffMat,FP_TYPE* rhs){
  void *Symbolic, *Numeric;
  (void) umfpack_di_symbolic(coeffMat->n, coeffMat->n, coeffMat->p, coeffMat->i, coeffMat->x, &Symbolic, NULL,NULL);
  (void) umfpack_di_numeric(coeffMat->p, coeffMat->i, coeffMat->x, Symbolic, &Numeric, NULL, NULL);
  umfpack_di_free_symbolic(&Symbolic);
  (void) umfpack_di_solve(UMFPACK_A, coeffMat->p, coeffMat->i, coeffMat->x, dir, rhs, Numeric, NULL, NULL);
  umfpack_di_free_numeric(&Numeric);

}

Thursday, December 6, 2012

Calling Lapack in c++

To use Lapack library, we need install it first. I like to use Ubuntu Synaptics to install, but the source can be obtained at http://www.netlib.org/lapack/.
 To install using Synaptics,
>> sudo apt-get install liblapack+[tab] #use tab to get the current version. We want dev and runtime

To access Lapack from c/c++, we need to install gsl. To install gsl,
>> sudo apt-get install libgsl0-dev libgsl0

Remember to include the header file in c/c++,
#include "gsl/gsl_math.h"
#include "gsl/gsl_eigen.h"

Friday, November 30, 2012

Magma1.3 + CUDA 5.0 + Ubuntu 11.10

At my work, we are trying to switch to Linear Algebra Solvers that out performs Lapack due to the size of problems we are interested in.

I just successfully installed and tested Magma1.3 along with CUDA 5.0 on an Ubuntu 11.10 server. I hope my note here would be helpful for whom just switched to CUDA 5.0 and want to use Magma 1.3 with the improved CUBLAS library.

1. I downloaded Magma 1.3 from http://icl.cs.utk.edu/magma/software/index.html and extracted it.

2. To compile Magma, I had to provide a make.inc file. Thanks to Magma Team, they'd provided sample make.inc files for different environment. There are four options,
  1. Intel's MKL
  2. AMD's ACML
  3. Netlib's LAPACK + ATLAS
  4. Netlib's LAPACK + GotoBLAS2
For each option, the sample make.inc.$(LIB) file are provided. Following the advice and instructions from  http://www.pavanky.com/installing-magma-with-gotoblas2/, I picked LAPACK and BLAS2 as well. Therefore, we have to install GotoBLAS2 first.

3. GotoBlas2 can be downloaded at Taxes Advance Computing Center. The GOTOBLAS2 is not in active development, so after downloading and untaring, it is not surprising I had to do some miner change. Thankfully, the link I was referencing provided the trick. In f_check file add a new line after line 237,
$link =~ s/\ -rpath\ s+/\ -rpath\@/g; # line 237
$link =~ s/\-l\ /\-l/g; # Add this. 
  
I'm using gcc4.6, it doesn't like empty linking string after "-l". The patch fixed the problem. 
After compilation,  copy libgoto2_barcelonap-r1.13.a to the library folder 
Note: For Intel Xeon-based architecture, we need to uncomment  the Nehalem line in file getarch.c.
Change /* #define FORCE_NEHALEN */ to  #define FORCE_NEHALEN

 
4. I referenced a post on Magma forum for modifying make.inc, to compile Magma test files which uses gcc-4.5 and gfortran-4.5, I had to make soft links from gcc-4.6 to gcc-4.5 and gfortran-4.6 to gfortran. I also had to change -lgoto to -lgoto2 and add flags -lblas, -lgfortran, -ldl and -lstdc++. Ofcourse, other environment variables are set to match my machine as well.
My make.inc is as the following:
 
GPU_TARGET = Tesla
CC = gcc-4.5
NVCC = nvcc
FORT = gfortran-4.5
ARCH = ar
ARCHFLAGS = cr
RANLIB = ranlib
OPTS = -O3 -DADD_
F77OPTS = -O3 -DADD_
FOPTS = -O3 -DADD_ -x f95-cpp-input
NVOPTS = -O3 -DADD_ --compiler-options -fno-strict-aliasing -DUNIX
LDOPTS = -fPIC -Xlinker -zmuldefs
LIB = -lblas -lgfortran -lgoto2 -lpthread -lcublas -lcudart -llapack -lm -ldl -lstdc++
CUDADIR = /usr/local/cuda
LIBDIR = -L/usr/local/cuda/lib64 -L/usr/lib64
INC = -I$(CUDADIR)/include -I/usr/include
                                                   
5. The last things is that for some reason, the /usr/local/cuda-5.0/src/fortran_common.h skipped
defining micro CUBLAS_GFORTRAN for linux based machine so it breaks the compilation for
test files. I added few lines at lines 61 to define the micro CUBLAS_GFORTRAN as the following,
#if defined(_WIN32)
#ifndef CUBLAS_INTEL_FORTRAN
#define CUBLAS_INTEL_FORTRAN
#endif
#elif defined(__linux)
#ifndef CUBLAS_GFORTRAN
#define CUBLAS_GFORTRAN
#endif
#endif
I'm not sure if everybody needs this step, because I suspect myself might havedone something to lead the CUDA 5 installation run script to skip Fortran option a while ago.
If you are following my steps, you should be now good to go. I'm leaving work now to ...hopefully see Stanford get the Pack12 Championship, but this is the the
speed up from a Tesla C1060 and nForce 980a/780a equipped old machine (my playground :p),

  N     CPU Time(s)    GPU Time(s)
===================================
 1024       2.12           0.64
 2048      17.00           1.22
 3072      56.24           3.31
 4032     126.69           6.43
 5184     279.86          12.52



I'm already excited about the speedup. Good luck!




  

Tuesday, June 28, 2011

Wow chroma does make sense


The above are the chromas based on the acoustic chord transcription and key extraction using Kyogu's paper. The chromas are from a mid file and a sound track of song "Crazy Little Thing Called Love". The chroma form mid file is clearly align with the wav file. Awesome! I see the direction where this project is going. :)



The above Chormas are based on a mid and a sound track of the song "Not in Love". The interesting part is that we can see the pattern somehow align with each other but with a shift. This brings out an important feature of a cover song. Most of the cover song does not follow the original song exactly, for instant, my music band would measure the highest key of a song that I am comfortable with and shift the key of the whole song when we do the cover version.  The other point is that we can see the wrap around in the mid file comparing to the wav file, but still captures the pattern of a song.

 By the way, the chromas here are extract from full songs, with

Sample rate: 5512.00 Hz
Duration:  (the number of chroma of each song + 1)* hop size
Hop size: 1024
FFT frame size: 2048

Wednesday, January 19, 2011

Quick note for myself

"If any woman can steal a guy away from me, then she can have him because I wouldn't want him anymore."

Sunday, April 4, 2010

The History of Operating Systems

"As an interesting historical aside,  Babbage realized that he would need software for his analytical engine, so he hired a young woman named Ada Lovelace, who was the daughter of the famed British poet Lord Byron, as the world's first programmer. The programming language Ada is named after her."[1]



Cited
1. Tanenbaum, Andrew S. Modern Operating Systems. New Jersey: Prentice Hall, 2002. Print.


Monday, March 8, 2010

Feeling

Now the feeling is so true to me. It is not a feeling whether I am accepted to Stanford, but a feeling feeling the need for God. And he is so responsive that I can feel so warm, I am still worried about my acceptance to Stanford, even though everything happened to me is so magic recently. But I got a strong feeling that God is filling my heart that I am almost crying.

Last time, I experienced this feeling when I was with other saints camping somewhere in CA. I was asking the existence  of God in my prayer, and soddenly I just felt warm and overloaded by a flow to my heart. I felt a flow now telling me no need to worry, and I am loved by him.

The feeling of flow if like a smile from mom said don't worry in the morning before I said good bye for school, and it is strong like support from father when I am weak. I know overall I am human, I switched back and forth, and I am weak. But here is a backbone always there open to me. He is telling me, don't treat yourself so hard, you don't have to try to be tough all by yourself. Come here, relax, I am here all for you. Just rely on me.

This is so sweet. Lord, I know you are with me. And I am in the process of learning to worship your ways on me. Right now I just want to say Amen to you.


 "Come to Me all who toil and are burdened, and I will give you rest." Matthew 11:28

Sydney 2010/3/8 01:56 PM