mxnet icon indicating copy to clipboard operation
mxnet copied to clipboard

advise for implement a C++ layer

Open hanpum opened this issue 9 years ago • 3 comments

hi, I'm writing a NCE loss in C++, the forward is easy, but backward is some hard to me, the formula as below:

ograd[i,j,k] = -y[i,j,k] / ( y[i,j,k] + k*pn[i,j,k] ) ograd[0, :, :] += 1.0

I'm writing with softmax_output as template, using the old style(previous 0.9.0) as here, because the tutorial told little about how to make a loss layer

I'm a newbie to mxnet and cuda&cudnn, and only know 2 possible solution:

  1. using cuda and openmp to write for loop
  2. using mshadow (just guess)

are there any better solution?

where can I find document about how to do this more quickly, or, which can I take as example

thanks for any help

hanpum avatar Jun 29 '17 14:06 hanpum

You can use the kernel::launch mechanism: https://github.com/dmlc/mxnet/blob/master/src/operator/tensor/indexing_op.h#L200

piiswrong avatar Jun 29 '17 18:06 piiswrong

@piiswrong , tks, I'lll have a try

hanpum avatar Jun 30 '17 00:06 hanpum

missing complete

@piiswrong, thanks

hanpum avatar Jun 30 '17 08:06 hanpum