Conversation
Yurlungur
commented
Apr 20, 2026
| // Helper function to convert lambda numpy array to double* buffer | ||
| // With std::optional we would add support for a default value of lambda=None | ||
| template<typename T, PORTABLE_FUNCTION Real(T::*Func)(const Real, const Real, Real*&&) const> | ||
| template<typename T, Real(T::*Func)(const Real, const Real, Real*&&) const> |
Collaborator
Author
There was a problem hiding this comment.
These decorators just aren't allowed in the template arguments. They also don't seem to be necessary.
Comment on lines
+51
to
+54
| LambdaHelper(py::array_t<Real> & lambdas) | ||
| : data_(lambdas.mutable_data(0,0)) | ||
| , stride_(lambdas.mutable_data(1,0) - lambdas.mutable_data(0,0)) | ||
| {} |
Collaborator
Author
There was a problem hiding this comment.
This stride trick should work for any non-ragged lambda array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR Summary
This MR supersedes #634 . The issue is that, despite Python calling only host code (thanks to #630 ), the loops are still marked with
PORTABLE_LAMBDAs which means the compiler detects that host only code (numpy arraysoperator[]) is called from a function marked__host__ __device__(the portable lambda). #634 fixed this by adding a switch on the lambda making it eitherPORTABLE_LAMBDAor[=]depending on execution space.This MR instead wraps
numpyarrays in a very thin wrapper. @jdolence and I actually already wrote this wrapper for a prior MR, so almost no changes needed to be made. The wrapper lies to the compiler by marking theoperator[]asPORTABLE_INLINE_FUNCTIONdespite the memory always being host memory. Nevertheless, this is safe, because we always call the python explicitly on host.This MR eliminates warnings on GPU architectures related to calling host functions from device. It also is required for the python code to compile on AMD GPU architectures, if a non-host backend is active.
PR Checklist
make formatcommand after configuring withcmake.plan_historiesfolder, with a filename the same as the MR number.If preparing for a new release, in addition please check the following: