Thanks. I agree that solution B sounds better than A as it can avoid redundant code by using template. Otherwise we may need to check gpu/cpu whenever we use the memory or we have to write two pieces of code (one for cpu and one for gpu).
For solution B, the Blob<xpu> class should be carefully modified. 1. it should support function like data() which returns gpu/cpu data depends on the xpu. 2. it should also support cpu_data() and gpu_data() which specify the data type explicitly. Because some Blobs can only be stored on cpu, e.g., the training data is loaded into cpu memory (i.e., Blob<cpu>) firstly. If no other suggestions, let's start with solution B and discuss in details, e.g., how to modify Blob and Layer APIs. regards, Wei On Fri, Jun 19, 2015 at 6:37 PM, 陈海波 <hzchenha...@corp.netease.com> wrote: > Sorry, I make a mistake. we think solution B is better than solution A > > 在2015-06-19 17:54:48,陈海波<hzchenha...@corp.netease.com>写道: > > hi,wang~ > > Two solutions for GPU API: > > solution A) > > In each neural network layer, two menthods(CPU and GPU) are > implemented > > in feedforward propagation and backforward propagation funtcion > module. > > solution B) > > modify Blob class,we add a device template > parameter(CPU/GPU),there may be two choices for parameter: > > 1) use mshadow::cpu/gpu > > 2) declare a global parameter in SINGA > > > > we think solution A is better. > > > > Wang'question: > > We currently use mshadow for maxtrix computation.If we want to > use another matrix libray instead of mshadow,how do we? > > > > I think matrix library can be divided into three levels: > > base level library: > > for GPU computation,cudamaxtrix;for CPU > computation,mkl、openblas、atlas and son on. > > middle level library: > > both cpu and gpu matrix computation,mshadow > > high level library: > > abstract matrix interface which encapsulate some middle level > matrix libraries. > > > > I think it's a hard problem we add many middle level libraries > into SINGA. Because the difference between middle libraries is > > so large that we can't integrate them together effeively. And GPU > function module should be integrated into SINGA in our first step. > > Then If we want to add a new middle level library,the better way is > to design a set of high level interfaces. > > thanks~ > >