Custom Layer with own Cuda code


What is the best way to add a new operator to gluon that uses custom Cuda code for the forward and backward pass?
Are the examples available, I only found examples for custom layers in Python gluon, but not how to call native code.


You should be able to implement an operator in C++ backend and register it. Here is a good tutorial on it: Then you can use your backend operator to create a layer using Block or HybridBlock similar to the way it is shown here : ( . If you want additional examples you can look at Conv2D layer in gluon. For CUDA kernels you can look at specific examples in src/operator/tensor/dot-inl.cuh


Maybe you want to checkout this example of creating custom operators: