pytorch/torch/csrc/cuda/utils.cpp
Peter Goldsborough 7ddc6f84c4 NULL -> nullptr (#11047)
Summary:
How did we get so many uses of `NULL` again?

ezyang
Pull Request resolved: https://github.com/pytorch/pytorch/pull/11047

Differential Revision: D9566799

Pulled By: goldsborough

fbshipit-source-id: 83469f352ac69aa65bdaf1a1a21f922d892e0db3
2018-08-30 16:25:42 -07:00

38 lines
1.1 KiB
C++

#include "torch/csrc/python_headers.h"
#include <stdarg.h>
#include <string>
#include "THCP.h"
#include "override_macros.h"
#define THC_GENERIC_FILE "torch/csrc/generic/utils.cpp"
#include <THC/THCGenerateAllTypes.h>
#ifdef USE_CUDA
std::vector <THCStream*> THPUtils_PySequence_to_THCStreamList(PyObject *obj) {
if (!PySequence_Check(obj)) {
throw std::runtime_error("Expected a sequence in THPUtils_PySequence_to_THCStreamList");
}
THPObjectPtr seq = THPObjectPtr(PySequence_Fast(obj, nullptr));
if (seq.get() == nullptr) {
throw std::runtime_error("expected PySequence, but got " + std::string(THPUtils_typename(obj)));
}
std::vector<THCStream*> streams;
Py_ssize_t length = PySequence_Fast_GET_SIZE(seq.get());
for (Py_ssize_t i = 0; i < length; i++) {
PyObject *stream = PySequence_Fast_GET_ITEM(seq.get(), i);
if (PyObject_IsInstance(stream, THCPStreamClass)) {
streams.push_back( ((THCPStream *)stream)->cdata);
} else if (stream == Py_None) {
streams.push_back(nullptr);
} else {
std::runtime_error("Unknown data type found in stream list. Need THCStream or None");
}
}
return streams;
}
#endif