Skip to content

Commit 624c3a1

Browse files
Update 'DynamicLoading' docs with section on loading Chapel libraries (#28973)
Add a new section to the `DynamicLoading` module docs that describes how to build and load a Chapel library. Reviewed by @benharsh. Thanks!
2 parents 7009107 + 34f8dc8 commit 624c3a1

1 file changed

Lines changed: 54 additions & 4 deletions

File tree

modules/packages/DynamicLoading.chpl

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
* limitations under the License.
1919
*/
2020

21-
// TODO: Can we make tests out of the code blocks? We'd need to be able to
22-
// add a 'precomp' and 'compopts'.
23-
//
24-
2521
/*
2622
Support for dynamic loading in Chapel.
2723
24+
.. note::
25+
26+
As of the 2.9 release, prototypical support has been added for loading
27+
and executing code from Chapel programs at runtime. See the section
28+
:ref:`Loading_Chapel_Programs_at_Runtime` below.
29+
2830
This module provides the ability to load a binary at runtime. Procedures
2931
contained in a dynamically loaded binary can be retrieved and called on
3032
any locale without compile-time knowledge of their names or locations.
@@ -60,6 +62,54 @@ be ``extern`` and this is reflected in its type.
6062
Currently, only procedures can be retrieved from loaded binaries.
6163
Support for retrieving references to data stored in a binary could
6264
be added in the future.
65+
66+
.. _Loading_Chapel_Programs_at_Runtime:
67+
68+
Loading Chapel Programs at Runtime
69+
----------------------------------
70+
71+
Chapel supports the ability to dynamically load other Chapel programs while
72+
having all loaded Chapel programs utilize a single shared copy of the runtime.
73+
74+
.. warning::
75+
76+
This feature is highly unstable (even more than the rest of this module).
77+
As of the 2.9 release, it is only supported when ``CHPL_COMM=gasnet`` and
78+
``CHPL_LIB_PIC=pic``. Safety checks have not been added yet, so dynamically
79+
loaded code may break in unexpected ways if these constraints are not met.
80+
81+
Additionally, while it should be possible to execute parallel and
82+
distributed code from a loaded Chapel library, it is possible that certain
83+
(combinations of) features may have bugs and fail to work correctly.
84+
85+
To utilize this feature, *both* the Chapel program that is doing the loading
86+
(the "executable") and the Chapel library that is loaded (the "library") must
87+
be compiled with the flag ``--no-builtin-runtime``.
88+
89+
This flag causes a Chapel program to be linked against a shared library
90+
variant of the Chapel runtime rather than to statically link in a copy as has
91+
traditionally been done.
92+
93+
In order to use ``--no-builtin-runtime``, you must make sure your Chapel
94+
configuration was built with ``CHPL_LIB_PIC=pic`` so that the runtime,
95+
executable, and library can be compiled with position-independent code.
96+
97+
Additionally, the library must be compiled with ``--library --dynamic``.
98+
99+
Once compiled, the library can be loaded by the executable using the same
100+
process that is described in the previous sections of this module.
101+
102+
Do note that only ``export`` procedures may be called from the library. This
103+
restriction may be removed in the future.
104+
105+
.. note::
106+
107+
You may get strange link-time errors when trying to run the executable.
108+
If this happens, it is usually because of a bug that occurs when the
109+
dynamic variant of the Chapel runtime library was built.
110+
111+
If you've built Chapel from source, a workaround is to touch a source
112+
file in the Chapel runtime and then rebuild it.
63113
*/
64114
@unstable('Dynamic loading support is experimental and unstable.')
65115
module DynamicLoading {

0 commit comments

Comments
 (0)