multiple instantiation of a (e.g. templated) kernel with “similar” extern shared declaration can become problematic. I’m not suggesting this is identical to your problem; they are obviously somewhat different. But this outlines the general issue.
I don’t know exactly why you are getting multiple instantiations, but its clear that you are from the error message:
Perhaps your compilation process is instantiating it with a template argument of float (that is obviously the case) and also a template argument of some other type. I haven’t unpacked the torch/pybind stuff enough to determine any of that.
I guess I would suggest trying this:
extern __shared__ unsigned char my_smem[];
realtype *share_mem = (realtype *)my_smem;
and see if that makes the error disappear. If it does, you are barking up the right tree.
If that makes the error go away, if it were me, I would probably just proceed with that. However it raises questions around alignment and type-punning. If these are of concern to you, then you would need to come up with another realization.
EDIT: For the benefit of future readers in a time crunch, I have edited my response here to remove an errant usage of __shared__ which is mentioned below.
Another method to avoid this issue is demonstrated in CUDA sample codes eg. here