-
Notifications
You must be signed in to change notification settings - Fork 35
WIP: Add a non-forking compiler option #614
base: master
Are you sure you want to change the base?
Conversation
The reasoning is that things like CFLAGS have no obvious default so make little sense here.
Cool. There are a bunch of other places where we (possibly without knowing) fork subprocesses. e.g the |
I've done a lot of reading about different ways that we could compile the code without forking and I've found 3 approaches that might work:
Before going any further I have two questions:
|
Wrapper code that calls PETSc needs to link against MPI (and find the MPI headers) so I think yes. I think firedrake can grab them out of the petscvariables configuration like it does for Eigen include paths (see firedrake/slate/slac/compiler.py)
I think that GCC and Clang have the same C ABI, but maybe not. As to the C++ void strictness, I would have assumed (but maybe I am wrong) that with these approaches we no longer use the ctypes interface to call compiled code? |
Clang JIT and GCC are mostly compatible, assuming you hand them the same compiler flags (esp. the math options, so most definitely your point 1. is something that you will want to look into) and same standard header files. There are corner cases, e.g. thread local storage and OTOH, cppyy munches ctypes.c_voidp just fine. Try this:
Not b/c it's "permissive", but b/c The larger problem with it and MPI though, is that many "constants" in MPI are in fact preprocessor macro's and thus not available automatically through cppyy in Python-land (they're still fine to use in JIT-ed code, of course). Is the use case for compiling programs locally when running under MPI public information? In a different context, we're advocating for more JIT-ing (and hence the need for better support) in HPC. It'd be useful for us to add another use case to the growing list. |
@wlav thank you for joining the discussion! We definitely appreciate your expertise.
That sounds sensible. What would the versioning stuff be replaced with?
Yep this will work.
We definitely still use ctypes. The @wlav the issue is that we want to cast these void wrap_expression_kernel(int32_t const start, int32_t const end, double *__restrict__ dat1, double const *__restrict__ dat0, int32_t const *__restrict__ map0) I think getting this to work is just a case of being a bit less lazy about how we track the argument types.
PyOP2 is used by Firedrake so I would say that yes the use case is public information 👍. Yesterday I spent some time playing with DragonFFI and TinyCC and I've come to the conclusion that neither is really feature complete. I couldn't figure out how to pass pointers into a DragonFFI function and TinyCC doesn't support complex numbers. cppyy might well be the way to go. |
I have this feeling that it may help here to think of the bindings and the JIT-ing separately. Both to preserve the current Below is an example of what I mean: it uses
|
We're kind of willing to invest some effort to do the right thing. For example, I know that cffi has lower cross-calling overheads than ctypes (which in the limit case is not the biggest deal, but every little helps), what's the "right" way to call stuff via cpppy in that sense? |
The "right" way depends on use. Assuming for example that all types are known and correct, it's pretty straightforward:
If the buffers don't come from python, but from C++, cppyy will create Run-time CPU overhead of cppyy is close to cffi (C++ has some complications, such as overloads, that one doesn't have to deal with in C), but memory overhead is higher b/c of the presence of Clang/LLVM for the JIT (b/c of C++ being a much larger language). Maybe this notebook from Matti is of value: https://github.com/mattip/c_from_python/blob/master/c_from_python.ipynb (the actual presentation is on youtube). |
This PR:
compilation.py
I've fiddled with the environment variables a bit too. For example it now uses
PYOP2_CC
to determine the compiler instead ofCC
and I've movedPYOP2_CFLAGS
andPYOP2_LDFLAGS
out ofconfiguration.py
because they made little sense there.