Caffe2 - C++ API
A deep learning, cross platform ML framework
Related Pages
Modules
Data Structures
Files
C++ API
Python API
GitHub
File List
Globals
torch
csrc
utils
cuda_lazy_init.cpp
1
#include <torch/csrc/utils/cuda_lazy_init.h>
2
3
#include <torch/csrc/python_headers.h>
4
#include <mutex>
5
6
#include <torch/csrc/Exceptions.h>
7
#include <torch/csrc/utils/object_ptr.h>
8
9
namespace
torch
{
10
namespace
utils {
11
12
void
cuda_lazy_init() {
13
AutoGIL
g;
14
// Protected by the GIL. We don't use call_once because under ASAN it
15
// has a buggy implementation that deadlocks if an instance throws an
16
// exception. In any case, call_once isn't necessary, because we
17
// have taken a lock.
18
static
bool
run_yet =
false
;
19
if
(!run_yet) {
20
auto
module =
THPObjectPtr
(PyImport_ImportModule(
"torch.cuda"
));
21
if
(!module)
throw
python_error
();
22
auto
res =
THPObjectPtr
(PyObject_CallMethod(module.get(),
"_lazy_init"
,
""
));
23
if
(!res)
throw
python_error
();
24
run_yet =
true
;
25
}
26
}
27
28
}
29
}
AutoGIL
Definition:
auto_gil.h:8
THPPointer< PyObject >
torch
Definition:
jit_type.h:17
python_error
Definition:
Exceptions.h:47
Generated on Thu Mar 21 2019 13:06:24 for Caffe2 - C++ API by
1.8.11