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

llvm; Refactor ExecutionMode handling #3182

Merged
merged 9 commits into from
Feb 1, 2025

Conversation

jvesely
Copy link
Collaborator

@jvesely jvesely commented Feb 1, 2025

Make most compiled modes private for test/development use only.
Introduce a new _LLVMPerNode execution mode.
Do not fall back to per-node mode in automatic fallback.
Use ExecutionMode helper methods rather than COMPILED mask to determine compiled mode.

This mode is not supposed to be used outside of its combination
in PTXRun.

Signed-off-by: Jan Vesely <[email protected]>
This mode should not be used outside development or testing.

Signed-off-by: Jan Vesely <[email protected]>
It does not support non-trivial scheduling.

Signed-off-by: Jan Vesely <[email protected]>
Explicitly list composition compilation mode.
Make the new mode private. Only used by developers and tests.

Signed-off-by: Jan Vesely <[email protected]>
Use them instead of the COMPILED mask.

Signed-off-by: Jan Vesely <[email protected]>
Move compiled execution of output_CIM to the same place as Python
execution.
Do not report end of trial twice in _LLVMPerNode execution mode.

Signed-off-by: Jan Vesely <[email protected]>
Enum members are singletons.

Signed-off-by: Jan Vesely <[email protected]>
@jvesely jvesely added the compiler Runtime Compiler label Feb 1, 2025
@jvesely jvesely linked an issue Feb 1, 2025 that may be closed by this pull request
Copy link

github-actions bot commented Feb 1, 2025

This PR causes the following changes to the html docs (ubuntu-latest-3.11):

diff -r docs-base/AutodiffComposition.html docs-head/AutodiffComposition.html
364c364
< <li><p>Specifying <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVM" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVM"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVM</span></code></a> or <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PyTorch" title="psyneulink.core.llvm.__init__.ExecutionMode.PyTorch"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PyTorch</span></code></a> in the learn() method of a standard
---
> <li><p>Specifying <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMRun</span></code></a> or <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PyTorch" title="psyneulink.core.llvm.__init__.ExecutionMode.PyTorch"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PyTorch</span></code></a> in the learn() method of a standard
380c380
< <p>Specifying <code class="xref any docutils literal notranslate"><span class="pre">ExecutionMode.LLVMRUn</span></code> in either the <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.learn" title="psyneulink.core.compositions.composition.Composition.learn"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">learn</span></code></a> and <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.run" title="psyneulink.core.compositions.composition.Composition.run"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">run</span></code></a>
---
> <p>Specifying <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMRun</span></code></a> in either the <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.learn" title="psyneulink.core.compositions.composition.Composition.learn"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">learn</span></code></a> and <a class="reference internal" href="Composition.html#psyneulink.core.compositions.composition.Composition.run" title="psyneulink.core.compositions.composition.Composition.run"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">run</span></code></a>
diff -r docs-base/Compilation.html docs-head/Compilation.html
237,238c237,238
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVM" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVM"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVM</span></code></a>: Compile and execute individual nodes. The scheduling loop still runs in Python. If any of the nodes fails to compile, an error is raised. <em>NOTE:</em> Schedules that require access to node data will not work correctly.</p></li>
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMExec</span></code></a>: Execution of <code class="xref any docutils literal notranslate"><span class="pre">Composition.exec</span></code> is replaced by a compiled equivalent. If the <a class="reference internal" href="Composition.html"><span class="doc">Composition</span></a> fails to compile, an error is raised.</p></li>
---
> <li><p><code class="xref any docutils literal notranslate"><span class="pre">ExecutionMode._LLVMPerNode</span></code>: Compile and execute individual nodes. The scheduling loop still runs in Python. If any of the nodes fails to compile, an error is raised. <em>NOTE:</em> Schedules that require access to node data will not work correctly.</p></li>
> <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec" title="psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode._LLVMExec</span></code></a>: Execution of <code class="xref any docutils literal notranslate"><span class="pre">Composition.exec</span></code> is replaced by a compiled equivalent. If the <a class="reference internal" href="Composition.html"><span class="doc">Composition</span></a> fails to compile, an error is raised.</p></li>
diff -r docs-base/Composition.html docs-head/Composition.html
1243c1243
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVM" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVM"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVM</span></code></a> and <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PyTorch" title="psyneulink.core.llvm.__init__.ExecutionMode.PyTorch"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PyTorch</span></code></a> can only be used in the <a class="reference internal" href="AutodiffComposition.html#psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.learn" title="psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.learn"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">learn</span></code></a>
---
> <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMRun"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMRun</span></code></a> and <a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PyTorch" title="psyneulink.core.llvm.__init__.ExecutionMode.PyTorch"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PyTorch</span></code></a> can only be used in the <a class="reference internal" href="AutodiffComposition.html#psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.learn" title="psyneulink.library.compositions.autodiffcomposition.AutodiffComposition.learn"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">learn</span></code></a>
1964,1965c1964,1965
< <li><p><em>True</em> – try to use the one that yields the greatesst improvement, progressively reverting to less powerful
< but more forgiving modes, in the order listed below, for each that fails;</p></li>
---
> <li><p><em>True</em> – try to use the one that yields the greatest improvement, progressively reverting to less powerful
> but more forgiving modes, trying LLVMRun, _LLVMExec, and Python.</p></li>
1969c1969
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVMExec</span></code></a> – compile and run each <a class="reference internal" href="Time.html#psyneulink.core.scheduling.time.TimeScale.TRIAL" title="psyneulink.core.scheduling.time.TimeScale.TRIAL"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">TRIAL</span></code></a>, using the Python interpreter
---
> <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec" title="psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode._LLVMExec</span></code></a> – compile and run each <a class="reference internal" href="Time.html#psyneulink.core.scheduling.time.TimeScale.TRIAL" title="psyneulink.core.scheduling.time.TimeScale.TRIAL"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">TRIAL</span></code></a>, using the Python interpreter
1971,1972c1971,1973
< equivalent the execution of the <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.execute" title="psyneulink.core.compositions.composition.Composition.execute"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">execute</span></code></a> method using the Python interpreter;</p></li>
< <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVM" title="psyneulink.core.llvm.__init__.ExecutionMode.LLVM"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.LLVM</span></code></a> – compile and run <a class="reference internal" href="#composition-nodes"><span class="std std-ref">Node</span></a> of the <a class="reference internal" href="#"><span class="doc">Composition</span></a> and their <a class="reference internal" href="Projection.html"><span class="doc">Projections</span></a>, using the Python interpreter to call the Composition’s <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.scheduler" title="psyneulink.core.compositions.composition.Composition.scheduler"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">scheduler</span></code></a>,
---
> equivalent the execution of the <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.execute" title="psyneulink.core.compositions.composition.Composition.execute"><code class="xref any py py-meth docutils literal notranslate"><span class="pre">execute</span></code></a> method using the Python interpreter;
> This mode does not support Trial scope scheduling rules and should not be used outside of development or testing.</p></li>
> <li><p><code class="xref any docutils literal notranslate"><span class="pre">ExecutionMode._LLVMPerNode</span></code> – compile and run <a class="reference internal" href="#composition-nodes"><span class="std std-ref">Node</span></a> of the <a class="reference internal" href="#"><span class="doc">Composition</span></a> and their <a class="reference internal" href="Projection.html"><span class="doc">Projections</span></a>, using the Python interpreter to call the Composition’s <a class="reference internal" href="#psyneulink.core.compositions.composition.Composition.scheduler" title="psyneulink.core.compositions.composition.Composition.scheduler"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">scheduler</span></code></a>,
1974c1975
< <a class="reference internal" href="Condition.html"><span class="doc">Conditions</span></a> that rely on Node <a class="reference internal" href="Parameters.html"><span class="doc">Parameters</span></a> is not supported;</p></li>
---
> <a class="reference internal" href="Condition.html"><span class="doc">Conditions</span></a> that rely on Node <a class="reference internal" href="Parameters.html"><span class="doc">Parameters</span></a> are not supported;</p></li>
1987c1988
< <li><p><code class="xref any docutils literal notranslate"><span class="pre">ExecutionMode.PTXrun</span></code> – compile multiple <a class="reference internal" href="Time.html#psyneulink.core.scheduling.time.TimeScale.TRIAL" title="psyneulink.core.scheduling.time.TimeScale.TRIAL"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">TRIAL</span></code></a>s  for execution on GPU
---
> <li><p><a class="reference internal" href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.PTXRun" title="psyneulink.core.llvm.__init__.ExecutionMode.PTXRun"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">ExecutionMode.PTXRun</span></code></a> – compile multiple <a class="reference internal" href="Time.html#psyneulink.core.scheduling.time.TimeScale.TRIAL" title="psyneulink.core.scheduling.time.TimeScale.TRIAL"><code class="xref any py py-attr docutils literal notranslate"><span class="pre">TRIAL</span></code></a>s  for execution on GPU
diff -r docs-base/LLVM.html docs-head/LLVM.html
222,223c222,223
< <dt class="sig sig-object py" id="psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec">
< <span class="sig-name descname"><span class="pre">LLVMExec</span></span><a class="headerlink" href="#psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec" title="Permalink to this definition">¶</a></dt>
---
> <dt class="sig sig-object py" id="psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec">
> <span class="sig-name descname"><span class="pre">_LLVMExec</span></span><a class="headerlink" href="#psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec" title="Permalink to this definition">¶</a></dt>
diff -r docs-base/_sources/Compilation.rst.txt docs-head/_sources/Compilation.rst.txt
36,37c36,37
<   * `ExecutionMode.LLVM`: Compile and execute individual nodes. The scheduling loop still runs in Python. If any of the nodes fails to compile, an error is raised. *NOTE:* Schedules that require access to node data will not work correctly.
<   * `ExecutionMode.LLVMExec`: Execution of `Composition.exec` is replaced by a compiled equivalent. If the `Composition` fails to compile, an error is raised.
---
>   * `ExecutionMode._LLVMPerNode`: Compile and execute individual nodes. The scheduling loop still runs in Python. If any of the nodes fails to compile, an error is raised. *NOTE:* Schedules that require access to node data will not work correctly.
>   * `ExecutionMode._LLVMExec`: Execution of `Composition.exec` is replaced by a compiled equivalent. If the `Composition` fails to compile, an error is raised.
diff -r docs-base/genindex.html docs-head/genindex.html
825a826,827
>       <li><a href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode._LLVMExec">_LLVMExec (psyneulink.core.llvm.__init__.ExecutionMode attribute)</a>
> </li>
3321,3322d3322
< </li>
<       <li><a href="LLVM.html#psyneulink.core.llvm.__init__.ExecutionMode.LLVMExec">LLVMExec (psyneulink.core.llvm.__init__.ExecutionMode attribute)</a>
Binary files docs-base/objects.inv and docs-head/objects.inv differ
diff -r docs-base/searchindex.js docs-head/searchindex.js
1c1
< Search.setIndex({docnames:["AGT","AGTControlMechanism","AutoAssociativeLearningMechanism","AutoAssociativeProjection","AutodiffComposition","BasicsAndPrimer","BeukersNBackModel","BeukersNBackModel_NB","BotvinickConflictMonitoringModel","BustamanteStroopXORLVOCModel","Cohen_HustonModel","ComparatorMechanism","Compilation","Component","Components","Composition","CompositionFunctionApproximator","CompositionInterfaceMechanism","Compositions","Condition","Context","ContrastiveHebbianMechanism","ContributorsGuide","ControlMechanism","ControlMechanisms","ControlProjection","ControlProjections","ControlSignal","ConventionsAndDefinitions","Core","DDM","DefaultControlMechanism","Defaults","DistributionFunctions","EMComposition","EVC","EVCAuxiliary","EVCControlMechanism","EpisodicMemoryMechanism","Function","Functions","GatingMechanism","GatingMechanisms","GatingProjection","GatingProjections","GatingSignal","GilzenratModel","InputPort","IntegratorFunctions","IntegratorMechanism","IntegratorMechanisms","KWTAMechanism","Keywords","KohonenMechanism","LCAMechanism","LCControlMechanism","LCMechanism","LLVM","LeabraMechanism","LearningFunctions","LearningMechanism","LearningMechanisms","LearningProjection","LearningProjections","LearningSignal","Library","Log","MappingProjection","MaskedMappingProjection","Mechanism","Mechanisms","MemoryFunctions","Models","ModulatoryMechanism","ModulatoryMechanisms","ModulatoryProjection","ModulatoryProjections","ModulatorySignal","MontagueModel","NieuwenhuisModel","NonStatefulFunctions","ObjectiveFunctions","ObjectiveMechanism","ObjectiveMecha
...

See CI logs for the full diff.

@jvesely jvesely merged commit 30c89d5 into PrincetonUniversity:devel Feb 1, 2025
33 checks passed
@jvesely jvesely deleted the devel-mode branch February 1, 2025 02:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler Runtime Compiler
Projects
Development

Successfully merging this pull request may close these issues.

Bug in LLVM mode when executing LCA on multiple trials
1 participant