提交 519ec8d5 authored 作者: Frederic Bastien's avatar Frederic Bastien

Don't take the lock if the cutil is well compiled.

上级 e552cf70
...@@ -1155,7 +1155,7 @@ class OpWiseCLinker(link.LocalLinker): ...@@ -1155,7 +1155,7 @@ class OpWiseCLinker(link.LocalLinker):
# compilation will be finished. This allow to don't # compilation will be finished. This allow to don't
# require the lock when all c code are already compiled! # require the lock when all c code are already compiled!
keep_lock=True keep_lock=True
orig_n_lock = get_lock.n_lock orig_n_lock = getattr(get_lock,"n_lock",0)
try: try:
env = self.env env = self.env
......
...@@ -10,58 +10,65 @@ if os.path.exists(os.path.join(config.compiledir,'cutils_ext.so')): ...@@ -10,58 +10,65 @@ if os.path.exists(os.path.join(config.compiledir,'cutils_ext.so')):
# Ensure no-one else is currently modifying the content of the compilation # Ensure no-one else is currently modifying the content of the compilation
# directory. This is important to prevent multiple processes from trying to # directory. This is important to prevent multiple processes from trying to
# compile the cutils_ext module simultaneously. # compile the cutils_ext module simultaneously.
get_lock()
try: try:
try: from cutils_ext.cutils_ext import *
from cutils_ext.cutils_ext import * except ImportError:
except ImportError: import cmodule
import cmodule
code = """ get_lock()
#include <Python.h> try:
extern "C"{ try:
static PyObject * # We must retry to import it as some other processs could
run_cthunk(PyObject *self, PyObject *args) # have been compiling it between the first failed import
{ # and when we receive the lock
PyObject *py_cthunk = NULL; from cutils_ext.cutils_ext import *
if(!PyArg_ParseTuple(args,"O",&py_cthunk)) except ImportError:
return NULL; import cmodule
if (!PyCObject_Check(py_cthunk)) { code = """
PyErr_SetString(PyExc_ValueError, #include <Python.h>
"Argument to run_cthunk must be a PyCObject."); extern "C"{
return NULL; static PyObject *
} run_cthunk(PyObject *self, PyObject *args)
void * ptr_addr = PyCObject_AsVoidPtr(py_cthunk); {
int (*fn)(void*) = (int (*)(void*))(ptr_addr); PyObject *py_cthunk = NULL;
void* it = PyCObject_GetDesc(py_cthunk); if(!PyArg_ParseTuple(args,"O",&py_cthunk))
int failure = fn(it); return NULL;
return Py_BuildValue("i", failure); if (!PyCObject_Check(py_cthunk)) {
} PyErr_SetString(PyExc_ValueError,
"Argument to run_cthunk must be a PyCObject.");
return NULL;
}
void * ptr_addr = PyCObject_AsVoidPtr(py_cthunk);
int (*fn)(void*) = (int (*)(void*))(ptr_addr);
void* it = PyCObject_GetDesc(py_cthunk);
int failure = fn(it);
static PyMethodDef CutilsExtMethods[] = { return Py_BuildValue("i", failure);
{"run_cthunk", run_cthunk, METH_VARARGS|METH_KEYWORDS, }
"Run a theano cthunk."},
{NULL, NULL, 0, NULL} /* Sentinel */
};
PyMODINIT_FUNC static PyMethodDef CutilsExtMethods[] = {
initcutils_ext(void) {"run_cthunk", run_cthunk, METH_VARARGS|METH_KEYWORDS,
{ "Run a theano cthunk."},
(void) Py_InitModule("cutils_ext", CutilsExtMethods); {NULL, NULL, 0, NULL} /* Sentinel */
} };
}
"""
loc = os.path.join(config.compiledir, 'cutils_ext') PyMODINIT_FUNC
if not os.path.exists(loc): initcutils_ext(void)
os.mkdir(loc) {
(void) Py_InitModule("cutils_ext", CutilsExtMethods);
}
}
"""
cmodule.gcc_module_compile_str('cutils_ext', code, location=loc) loc = os.path.join(config.compiledir, 'cutils_ext')
from cutils_ext.cutils_ext import * if not os.path.exists(loc):
os.mkdir(loc)
finally: cmodule.gcc_module_compile_str('cutils_ext', code, location=loc)
# Release lock on compilation directory. from cutils_ext.cutils_ext import *
release_lock()
finally:
# Release lock on compilation directory.
release_lock()
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论