Skip to content

Commit

Permalink
update_2_1_14
Browse files Browse the repository at this point in the history
  • Loading branch information
OlegKonings committed Feb 2, 2014
1 parent 6213b63 commit 3c1c068
Show file tree
Hide file tree
Showing 11 changed files with 306 additions and 298 deletions.
73 changes: 73 additions & 0 deletions GLcuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -391,4 +391,77 @@ extern "C" void z_shrinkage_wrap(float *D_z,const float *x_hat, const float *D_u
//End partition loop, updated vector z by section and got the sum of the norms of Z into d_obj for later use by objective
}

//need norm of x, -z , (x-z), -rho*(z-zold), rho*u
__global__ void _get_norm_all(const float* __restrict__ x, const float * __restrict__ z, const float* __restrict__ zold, const float* __restrict__ u,
float* __restrict__ xnorm, float* __restrict__ znorm, float* __restrict__ xznorm, float* __restrict__ rzznorm,float* __restrict__ runorm,
const int length, const float _rho){

const int offset=threadIdx.x+blockIdx.x*blockDim.x;
const int warp_idx=threadIdx.x%32;

__shared__ float x_sq_sum[2],
z_sq_sum[2],
x_minus_z_sum[2],
neg_rho_zzold_sum[2],
rho_u_sum[2];

float xx=0.0f,zz=0.0f,xz=0.0f, zzold=0.0f,ru=0.0f, tmp=0.0f;

if(offset<length){
xx=x[offset];
zz=z[offset];
xz=(xx-zz)*(xx-zz);//rnorm calc
tmp= -_rho*(zz-zold[offset]);
zzold=tmp*tmp;//snorm calc
xx*=xx;//norm x
zz*=zz;//norm (-z)
ru=_rho*u[offset];
ru*=ru;//norm (rho*u)
}
for(int ii=16;ii>0;ii>>=1){
xx += __shfl(xx, warp_idx + ii);
zz += __shfl(zz, warp_idx + ii);
xz += __shfl(xz, warp_idx + ii);
zzold += __shfl(zzold, warp_idx + ii);
ru += __shfl(ru, warp_idx + ii);

}
if(warp_idx==0){
x_sq_sum[threadIdx.x>>5]=xx;
z_sq_sum[threadIdx.x>>5]=zz;
x_minus_z_sum[threadIdx.x>>5]=xz;
neg_rho_zzold_sum[threadIdx.x>>5]=zzold;
rho_u_sum[threadIdx.x>>5]=ru;
}
__syncthreads();

if(threadIdx.x==0){
atomicAdd(&xnorm[0],(x_sq_sum[0]+x_sq_sum[1]));
atomicAdd(&znorm[0],(z_sq_sum[0]+z_sq_sum[1]));
atomicAdd(&xznorm[0],(x_minus_z_sum[0]+x_minus_z_sum[1]));
atomicAdd(&rzznorm[0],(neg_rho_zzold_sum[0]+neg_rho_zzold_sum[1]));
atomicAdd(&runorm[0],(rho_u_sum[0]+rho_u_sum[1]));

}

}

extern "C" void get_multi_norms(const float *x, const float *z, const float *zold, const float *u,
float *norm_arr,const float _rho, const int length){

_get_norm_all<<<(length+THREADS-1)/THREADS,THREADS>>>(x,z,zold,u,&norm_arr[0], &norm_arr[1], &norm_arr[2],&norm_arr[3],&norm_arr[4], length,_rho);
}

__global__ void update_q(const float* __restrict__ Atb, const float* __restrict__ z, const float* __restrict__ u,
float* __restrict__ q, const float rho, const int length){

const int offset=threadIdx.x+blockIdx.x*blockDim.x;

if(offset<length){
q[offset]= (Atb[offset]+rho*(z[offset]-u[offset]));
}
}
extern "C" void update_vector_q(const float *Atb, const float *z, const float *u, float *q, const float rho,const int length){
update_q<<<(length+THREADS-1)/THREADS,THREADS>>>(Atb,z,u,q,rho,length);

}
311 changes: 140 additions & 171 deletions GLmex.cpp

Large diffs are not rendered by default.

31 changes: 26 additions & 5 deletions GLtest2.m
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
m=int32(1536);
K=int32(20);
m=int32(1968);
K=int32(13);
density=single(100);

[ A,b,partition,lambda ] = GenerateRandomGroupLassoDataSet( m,K,density );
Expand All @@ -23,6 +23,13 @@
u=single(zeros(n,1));
z=single(zeros(n,1));

do_obj=int32(0);
do_lam=int32(0);

lambda_counter=int32(0);
lambda_update_count=int32(10);
lambda_update_thresh=single(10^-5);

AA=A';
disp('partition sum= ');
dd=sum(partition);
Expand All @@ -32,7 +39,7 @@
disp('n=');
disp(n);
tic;
[nxtu,nxtz]=GroupMextest(AA,b,partition,u,z,rho,alpha,lambda,MAX_ITER,ABSTOL,RELTOL);% for this version matrix A must be passed in transpose (CUDA solver uses row major)
[nxtu,nxtz]=GroupMextest(AA,b,partition,u,z,rho,alpha,lambda,MAX_ITER,ABSTOL,RELTOL,do_obj,do_lam);% for this version matrix A must be passed in transpose (CUDA solver uses row major)
toc;
gtime=(toc-tic);
disp(gtime);
Expand Down Expand Up @@ -84,16 +91,30 @@
history.eps_dual(k)= sqrt(single(n))*ABSTOL + RELTOL*norm(rho*u);



if ~QUIET
fprintf('%3d\t%10.4f\t%10.4f\t%10.4f\t%10.4f\t%10.2f\n', k, ...
history.r_norm(k), history.eps_pri(k), ...
history.s_norm(k), history.eps_dual(k), history.objval(k));
end

if (history.r_norm(k) <=history.eps_pri(k) && ...
history.s_norm(k) <=history.eps_dual(k))
if (history.r_norm(k) <history.eps_pri(k) && ...
history.s_norm(k) <history.eps_dual(k))
break;
end
if do_lam && k>1
if abs(history.r_norm(k)-history.r_norm(k-1)) < lambda_update_thresh ...
&& abs(history.s_norm(k)-history.s_norm(k-1)) < lambda_update_thresh

lambda_counter = lambda_counter + 1;
if lambda_counter > lambda_update_count
lambda=lambda*single(0.1);
lambda_counter=0;
end

end

end

end

Expand Down
52 changes: 0 additions & 52 deletions GenerateRandomGroupLassoDataSet.m

This file was deleted.

Binary file modified GroupMextest.mexw64
Binary file not shown.
15 changes: 0 additions & 15 deletions README.md

This file was deleted.

67 changes: 67 additions & 0 deletions ReadMe.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
========================================================================
MICROSOFT FOUNDATION CLASS LIBRARY : GroupMextest Project Overview
========================================================================


AppWizard has created this GroupMextest DLL for you. This DLL not only
demonstrates the basics of using the Microsoft Foundation classes but
is also a starting point for writing your DLL.

This file contains a summary of what you will find in each of the files that
make up your GroupMextest DLL.

GroupMextest.vcxproj
This is the main project file for VC++ projects generated using an Application Wizard.
It contains information about the version of Visual C++ that generated the file, and
information about the platforms, configurations, and project features selected with the
Application Wizard.

GroupMextest.vcxproj.filters
This is the filters file for VC++ projects generated using an Application Wizard.
It contains information about the association between the files in your project
and the filters. This association is used in the IDE to show grouping of files with
similar extensions under a specific node (for e.g. ".cpp" files are associated with the
"Source Files" filter).

GroupMextest.h
This is the main header file for the DLL. It declares the
CGroupMextestApp class.

GroupMextest.cpp
This is the main DLL source file. It contains the class CGroupMextestApp.

GroupMextest.rc
This is a listing of all of the Microsoft Windows resources that the
program uses. It includes the icons, bitmaps, and cursors that are stored
in the RES subdirectory. This file can be directly edited in Microsoft
Visual C++.

res\GroupMextest.rc2
This file contains resources that are not edited by Microsoft
Visual C++. You should place all resources not editable by
the resource editor in this file.

GroupMextest.def
This file contains information about the DLL that must be
provided to run with Microsoft Windows. It defines parameters
such as the name and description of the DLL. It also exports
functions from the DLL.

/////////////////////////////////////////////////////////////////////////////
Other standard files:

StdAfx.h, StdAfx.cpp
These files are used to build a precompiled header (PCH) file
named GroupMextest.pch and a precompiled types file named StdAfx.obj.

Resource.h
This is the standard header file, which defines new resource IDs.
Microsoft Visual C++ reads and updates this file.

/////////////////////////////////////////////////////////////////////////////
Other notes:

AppWizard uses "TODO:" to indicate parts of the source code you
should add to or customize.

/////////////////////////////////////////////////////////////////////////////
10 changes: 0 additions & 10 deletions factor.m

This file was deleted.

11 changes: 0 additions & 11 deletions objective.m

This file was deleted.

30 changes: 0 additions & 30 deletions padd_admm_data.m

This file was deleted.

4 changes: 0 additions & 4 deletions shrinkage.m

This file was deleted.

0 comments on commit 3c1c068

Please sign in to comment.