CULA GELS problem

General CULA Dense (LAPACK & BLAS) support and troubleshooting. Use this forum if you are having a general problem or have encountered a bug.

CULA GELS problem

Postby huangchbii » Mon Nov 14, 2011 8:31 am

Hi,

I am trying to use GELS to compute min || B - AX ||. The code is as the following:

Code: Select all
   cublasInit();
   culaInitialize();

   float *dA;
   CUDA_CALL(cudaMalloc((void**)&dA, M*N*sizeof(float)));
   CUDA_CALL(cudaMemcpy(dA, A, M*N*sizeof(float), cudaMemcpyHostToDevice));

   const int L = (M>N)? M: N;

   float *dx;
   CUDA_CALL(cudaMalloc((void**)&dx, L*W*sizeof(float)));
   CUDA_CALL(cudaMemcpy(dx, b, M*W*sizeof(float), cudaMemcpyHostToDevice));
   for(int i = 0; i < W; i ++) CUDA_CALL(cudaMemcpy(&dx[i*L], &b[i*M], M*sizeof(float), cudaMemcpyHostToDevice));

   CULA_CALL(culaDeviceSgels('N', M, N, W, dA, M, dx, L));

   CUDA_CALL(cudaMemcpy(dA, A, M*N*sizeof(float), cudaMemcpyHostToDevice));

   float *db;
   CUDA_CALL(cudaMalloc((void**)&db, L*W*sizeof(float)));
   CUDA_CALL(cudaMemcpy(db, b, M*W*sizeof(float), cudaMemcpyHostToDevice));
   for(int i = 0; i < W; i ++) CUDA_CALL(cudaMemcpy(&db[i*L], &b[i*M], M*sizeof(float), cudaMemcpyHostToDevice));

   cublasSgemm('N', 'N', M, W, N, 1, dA, M, dx, L, -1, db, L);

   for(int i = 0; i < W; i ++) CUDA_CALL(cudaMemcpy(&r[i*M], &db[i*L], M*sizeof(float), cudaMemcpyDeviceToHost));

   CUDA_CALL(cudaFree(dA));
   CUDA_CALL(cudaFree(db));
   CUDA_CALL(cudaFree(dx));

   culaFreeBuffers();
   culaShutdown();
   cublasShutdown();


The interesting part is, when the number of columns of A is bigger than number of rows, it works fine. db returned relative small residuals. However, when the number of columns of A is smaller than the number of rows, the result is not correct. According to the document, If TRANS = ‘N’ and m >= n: find the least squares solution of an overdetermined system, i.e., solve the least squares problem minimize || B - A*X ||, but it seems not working?
huangchbii
 
Posts: 15
Joined: Wed Jul 07, 2010 1:27 am

Return to CULA Dense Support

Who is online

Users browsing this forum: No registered users and 2 guests

cron