Cublas handle for c extension


I was wondering how to use the existing cublas handle defined inside a pytorch backedn for a custom C extension.

For instance, in the ffi c extension example from pytorch website (,

#include <THC/THC.h>

// this symbol will be resolved automatically from PyTorch libs
extern THCState *state;

The THCState if exposed and can be used from a custom ffi extension. I was wondering the cublas handle is also exposed like this. If not, is there a way to pass it through the cffi function?