Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AOT or Jit run the daphne DSL in c++ server as function library #937

Open
hudengjunai opened this issue Jan 6, 2025 · 1 comment
Open

Comments

@hudengjunai
Copy link

can daphne aot or jit compile or run in c++ application as function and shared library?

@pdamme
Copy link
Collaborator

pdamme commented Jan 8, 2025

Hi @hudengjunai! DAPHNE JIT-compiles DaphneDSL scripts and executes them immediately. The AOT compilation of DaphneDSL scripts is not supported (maybe we will add that later, but there are no concrete plans yet). Furthermore, DAPHNE is intended to be used either as a stand-alone executable (for local or distributed execution) or through a Python API (the so-called DaphneLib).

DAPHNE is not explicitly designed to be invoked like a library from a C++ program. However, if you want to use DAPHNE in a C++ program, two options come to my mind:

  1. Create a child process that executes the daphne executable (the well-known fork()+exec() approach). With that approach, you would need to store the DaphneDSL script in a file and pass the path to that file as an argument to daphne (just like when you run daphne in a terminal). Any data that you process in DAPHNE would need to be read from files or be generated in DaphneDSL, since DAPHNE would run in a separate process.
  2. Link DAPHNE as a shared library into your C++ program. You could try using the target daphnelib (build with ./build.sh --target daphnelib); the compiled library resides in lib/libdaphnelib.so. This is the shared library used underneath DaphneLib (DAPHNE's Python API). Internally, DaphneLib dynamically links libdaphnelib.so into the python3 process via Python's ctypes library. Probably, you could also link this shared library into any C++ program to use DAPHNE from C++. However, note that the interface of this shared library is quite narrow (see src/api/daphnelib/daphnelib.cpp). It basically offers a daphne() function that accepts the path to a DaphneDSL script file (supporting the same arguments as the daphne executable is an open issue DAPHNE arguments in DaphneLib #719). That means, you still need to create a file for the DaphneDSL script to execute. However, as DAPHNE would run in the same process and virtual address space as your C++ program, you could benefit from zero-copy data transfer via shared memory. You could look at how we accomplish that for the data transfer with numpy in DaphneLib (feel free to ask specific questions). By reusing DaphneDSL built-in functions like receiveFromNumpy() (see src/parser/daphnedsl/DaphneDSLBuiltins.cpp) and getResult() from libdaphnelib.so you could probably build a solution for data transfer with you C++ program. However, so far we have focused on efficient data transfer only in the context of the Python API (not for arbitrary C++ programs) and do not support arbitrary protobuf tensors or lists as inputs yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants