|
18 | 18 | * limitations under the License. |
19 | 19 | */ |
20 | 20 |
|
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 | | - |
25 | 21 | /* |
26 | 22 | Support for dynamic loading in Chapel. |
27 | 23 |
|
| 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 | +
|
28 | 30 | This module provides the ability to load a binary at runtime. Procedures |
29 | 31 | contained in a dynamically loaded binary can be retrieved and called on |
30 | 32 | any locale without compile-time knowledge of their names or locations. |
@@ -60,6 +62,54 @@ be ``extern`` and this is reflected in its type. |
60 | 62 | Currently, only procedures can be retrieved from loaded binaries. |
61 | 63 | Support for retrieving references to data stored in a binary could |
62 | 64 | 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. |
63 | 113 | */ |
64 | 114 | @unstable('Dynamic loading support is experimental and unstable.') |
65 | 115 | module DynamicLoading { |
|
0 commit comments