0

I have already written C++ layer which is using CPU, I want to plugin chainer framework, How to do that ? Can chainer mix of CPU and GPU layers together?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
machen
  • 283
  • 2
  • 10

1 Answers1

0

You can use Cython, pybind11, or whatever tool to call C++ code from Python to embed your C++ layer into Chainer. You have to write a little bit of glue code to do that (e.g. converting NumPy array buffer from/to the data format used in the layer written in C++ and converting the interface of you layer into Chainer style Function; the latter should be easily done by writing a small Python class).

In order to mix CPU and GPU in your forward/backward computations, you can use F.copy(); it supports backprop (see https://docs.chainer.org/en/stable/reference/generated/chainer.functions.copy.html?highlight=copy).

Seiya Tokui
  • 341
  • 2
  • 3
  • You said: converting the interface of you layer into Chainer style Function? How to write C++ layer interface like chainer style function?? do not understand about this sentence. – machen Aug 23 '17 at 08:01
  • oh , I understand, You mean modify C++ code to function, and chainer link call the C++ function? (not C++ layer?) – machen Aug 23 '17 at 08:03
  • Yes. It would be very complicated to make C++ code manage parameters of Chainer. It's much simpler to write a Function that internally calls the C++ code (some modifications to the C++ code would be needed to align the interface) and to write Link that calls the Function. – Seiya Tokui Aug 28 '17 at 00:41