[For Third-party Developers] Migrate from C++ library to C library #2124
njzjz
announced in
Announcement
Replies: 2 comments 5 replies
-
I would prefer preserving the C++ API, because the usage is easier than the C API. |
Beta Was this translation helpful? Give feedback.
1 reply
-
Can we provide an API interface that accepts the pointer address of tensors variables (in CUDA or CPU) as positions input? |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Starting from v2.2.0.b0, DeePMD-kit will add a C library (
libdeepmd_c.so
) along with a header-only C++ API (deepmd/deepmd.hpp
). Meanwhile, a C library binary (libdeepmd_c.tar.gz
) is built and packed with CUDA 11 support (but can fall back to the CPU mode) for each build and will be provided on the release page.Currently, this package can be downloaded from each GitHub Actions build, for example, here.
Advantages
C++ ABI is not stable as it is dependent on C++ standards (e.g., C++11) and the compiler ABI. This means one may need to use the same compiler, the same C++ standard, and the same flag to compile all of the libraries. Otherwise, errors may be thrown. OS platforms use the same compiler environment to build a so-called "release version" and conda is doing a similar thing.
Compared to the C++ ABI, C is ABI stable on almost all platforms, so one can use different compilers and standards to compile different libraries of an application.
Benefiting this feature, it is possible to distribute the C library binary.
libdeepmd_c.tar.gz
is built on CentOS 7 and only relies on the system libraries, including GNU C Library >=2.17 and GNU C++ Library >=6.0.19. One does not need to build the DeePMD-kit by itself.Some C libraries are distributed in the same way, such as TensorFlow C library and cuDNN.
Changes
To migrate from the C++ library to the C library, the following changes should be made:
or do the corresponding changes in the CMake.
4. Any other C++-related flags are not necessary anymore.
- -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -DHIGH_PREC
libdeepmd_c.tar.gz
.To be discussed
It's unclear whether it is necessary to keep compatibility with the old C++ API. The benefits of doing so are not obvious.
Beta Was this translation helpful? Give feedback.
All reactions