1 #include <torch/csrc/python_headers.h> 4 #include <torch/csrc/cuda/THCP.h> 6 #include <torch/csrc/cuda/override_macros.h> 8 #define THC_GENERIC_FILE "torch/csrc/generic/utils.cpp" 9 #include <THC/THCGenerateAllTypes.h> 11 #define THC_GENERIC_FILE "torch/csrc/generic/utils.cpp" 12 #include <THC/THCGenerateBoolType.h> 17 std::vector<c10::optional<at::cuda::CUDAStream>> THPUtils_PySequence_to_CUDAStreamList(PyObject *obj) {
18 if (!PySequence_Check(obj)) {
19 throw std::runtime_error(
"Expected a sequence in THPUtils_PySequence_to_CUDAStreamList");
22 if (seq.get() ==
nullptr) {
23 throw std::runtime_error(
"expected PySequence, but got " + std::string(THPUtils_typename(obj)));
26 std::vector<c10::optional<at::cuda::CUDAStream>> streams;
27 Py_ssize_t length = PySequence_Fast_GET_SIZE(seq.get());
28 for (Py_ssize_t i = 0; i < length; i++) {
29 PyObject *stream = PySequence_Fast_GET_ITEM(seq.get(), i);
31 if (PyObject_IsInstance(stream, THCPStreamClass)) {
33 streams.emplace_back( at::cuda::CUDAStream::unpack((reinterpret_cast<THCPStream*>(stream))->cdata) );
34 }
else if (stream == Py_None) {
35 streams.emplace_back();
37 std::runtime_error(
"Unknown data type found in stream list. Need torch.cuda.Stream or None");