pytorch
pytorch copied to clipboard
Generator: when I want to use a new backend, how to create a Generator with the new backend?
🐛 Describe the bug
I want to add a new backend, so I add my backend by referring to this tutorial. https://github.com/bdhirsh/pytorch_open_registration_example
But how to create a Generator with my new backend ? I see the code related to 'Generator' is in the file, https://github.com/pytorch/pytorch/blob/master/torch/csrc/Generator.cpp
static PyObject* THPGenerator_pynew( PyTypeObject* type, PyObject* args, PyObject* kwargs) { HANDLE_TH_ERRORS static torch::PythonArgParser parser({"Generator(Device device=None)"}); torch::ParsedArgs<1> parsed_args; auto r = parser.parse(args, kwargs, parsed_args); auto device = r.deviceWithDefault(0, at::Device(at::kCPU));
THPGeneratorPtr self((THPGenerator*)type->tp_alloc(type, 0)); if (device.type() == at::kCPU) { self->cdata = make_generator<CPUGeneratorImpl>(); } #ifdef USE_CUDA else if (device.type() == at::kCUDA) { self->cdata = make_generator<CUDAGeneratorImpl>(device.index()); } #elif USE_MPS else if (device.type() == at::kMPS) { self->cdata = make_generator<MPSGeneratorImpl>(); } #endif else { AT_ERROR( "Device type ", c10::DeviceTypeName(device.type()), " is not supported for torch.Generator() api."); } return (PyObject*)self.release(); END_HANDLE_TH_ERRORS }
So how to create a Generator with my new backend named "privateuseone" ?
Versions
new backend python:3.7.5 pytorch: 2.0.0 CUDA: None