Skip to content

Comments

bugfix: Fix jit_variables associating with incorrect lambdas bug#393

Open
johnbowen42 wants to merge 12 commits intomainfrom
bugfix/bowen/fix-lambda-runtime-const-ordering
Open

bugfix: Fix jit_variables associating with incorrect lambdas bug#393
johnbowen42 wants to merge 12 commits intomainfrom
bugfix/bowen/fix-lambda-runtime-const-ordering

Conversation

@johnbowen42
Copy link
Collaborator

@johnbowen42 johnbowen42 commented Feb 3, 2026

Previously, the lambda value specialization assumed that a lambda with jit_variable in its capture list would be immediately called--which is typically the case for portability layers like RAJA. However, if a user declared multiple lambdas on the stack, and launched them in any order, the first launched lambda would register all calls to jit_variable as its own. This did not create correctness issues, but did result in Proteus failing to specialize for user-provided runtime constants for all but the first declared lambda. lambda_spec_test shows this

This PR is a bugfix, but it significantly changes how our lambda runtime value specialization works. Roughly, ProteusPass now uses use-def analysis to associate a jit_variable call --> class.anon type emitted by clang. We change register_lambda to force an allocation of the same class.anon type. Using this pattern, we can associate jit_variable-->demangled, clang emitted lambda name. Then, we can intercept execution of these lambdas at runtime, using the appropriate runtime values.

@johnbowen42 johnbowen42 marked this pull request as draft February 3, 2026 20:37
@johnbowen42 johnbowen42 force-pushed the bugfix/bowen/fix-lambda-runtime-const-ordering branch from c991f6a to a4b73b5 Compare February 9, 2026 18:16
@github-actions
Copy link
Contributor

github-actions bot commented Feb 9, 2026

Cpp-Linter Report ⚠️

Some files did not pass the configured checks!

clang-format (v18.1.3) reports: 2 file(s) not formatted
  • tests/cpu/lambda_spec_test.cpp
  • tests/gpu/lambda_spec_test.cpp
clang-tidy (v18.1.3) reports: 21 concern(s)
  • src/runtime/CompilerInterfaceHost.cpp:32:1: warning: [readability-identifier-naming]

    invalid case style for function '__jit_register_variable'

       32 | __jit_register_variable(RuntimeConstant RC, const char *LambdaName) {
          | ^~~~~~~~~~~~~~~~~~~~~~~
          | jitRegisterVariable
  • src/runtime/CompilerInterfaceHost.cpp:36:39: warning: [readability-identifier-naming]

    invalid case style for function '__jit_register_lambda'

       36 | extern "C" __attribute__((used)) void __jit_register_lambda(const char *) {}
          |                                       ^~~~~~~~~~~~~~~~~~~~~
          |                                       jitRegisterLambda
  • src/runtime/CompilerInterfaceHost.cpp:47:43: warning: [readability-identifier-naming]

    invalid case style for function '__jit_take_address'

       47 | extern "C" __attribute__((noinline)) void __jit_take_address(void const *) {}
          |                                           ^~~~~~~~~~~~~~~~~~
          |                                           jitTakeAddress
  • tests/cpu/lambda_spec_test.cpp:16:10: warning: [readability-identifier-naming]

    invalid case style for member 'lambda'

       16 |   Lambda lambda;
          |          ^~~~~~
          |          Lambda
       17 |   Abstraction(Lambda&& lam) : lambda(lam) {};
          |                               ~~~~~~
          |                               Lambda
       18 |   auto operator()() {
       19 |     return lambda();
          |            ~~~~~~
          |            Lambda
  • tests/cpu/lambda_spec_test.cpp:17:24: warning: [readability-identifier-naming]

    invalid case style for parameter 'lam'

       17 |   Abstraction(Lambda&& lam) : lambda(lam) {};
          |                        ^~~           ~~~
          |                        Lam           Lam
  • tests/cpu/lambda_spec_test.cpp:27:18: warning: [readability-identifier-naming]

    invalid case style for variable 'abs'

       27 |   Abstraction<T> abs (LB) ;
          |                  ^~~
          |                  Abs
       28 |   run2(abs);
          |        ~~~
          |        Abs
  • tests/cpu/lambda_spec_test.cpp:38:7: warning: [readability-identifier-naming]

    invalid case style for variable 'zero'

       38 |   int zero = 0;
          |       ^~~~
          |       Zero
       39 |   int one = 1;
       40 |   int two = 2;
       41 | 
       42 |   auto zero_lambda = [=, c = proteus::jit_variable(zero)] ()
          |                                                    ~~~~
          |                                                    Zero
  • tests/cpu/lambda_spec_test.cpp:39:7: warning: [readability-identifier-naming]

    invalid case style for variable 'one'

       39 |   int one = 1;
          |       ^~~
          |       One
       40 |   int two = 2;
       41 | 
       42 |   auto zero_lambda = [=, c = proteus::jit_variable(zero)] ()
       43 |                          __attribute__((annotate("jit"))) { printInt(c); };
       44 | 
       45 |   auto one_lambda = [=, c = proteus::jit_variable(one)] ()
          |                                                   ~~~
          |                                                   One
  • tests/cpu/lambda_spec_test.cpp:40:7: warning: [readability-identifier-naming]

    invalid case style for variable 'two'

       40 |   int two = 2;
          |       ^~~
          |       Two
       41 | 
       42 |   auto zero_lambda = [=, c = proteus::jit_variable(zero)] ()
       43 |                          __attribute__((annotate("jit"))) { printInt(c); };
       44 | 
       45 |   auto one_lambda = [=, c = proteus::jit_variable(one)] ()
       46 |                         __attribute__((annotate("jit"))) { printInt(c); };
       47 | 
       48 |   auto two_lambda = [=, c = proteus::jit_variable(two)] ()
          |                                                   ~~~
          |                                                   Two
  • tests/cpu/lambda_spec_test.cpp:42:8: warning: [readability-identifier-naming]

    invalid case style for variable 'zero_lambda'

       42 |   auto zero_lambda = [=, c = proteus::jit_variable(zero)] ()
          |        ^~~~~~~~~~~
          |        ZeroLambda
       43 |                          __attribute__((annotate("jit"))) { printInt(c); };
       44 | 
       45 |   auto one_lambda = [=, c = proteus::jit_variable(one)] ()
       46 |                         __attribute__((annotate("jit"))) { printInt(c); };
       47 | 
       48 |   auto two_lambda = [=, c = proteus::jit_variable(two)] ()
       49 |                         __attribute__((annotate("jit"))) { printInt(c); };
       50 | 
       51 |   run(zero_lambda);
          |       ~~~~~~~~~~~
          |       ZeroLambda
  • tests/cpu/lambda_spec_test.cpp:42:26: warning: [readability-identifier-naming]

    invalid case style for variable 'c'

       42 |   auto zero_lambda = [=, c = proteus::jit_variable(zero)] ()
          |                          ^
          |                          C
       43 |                          __attribute__((annotate("jit"))) { printInt(c); };
          |                                                                      ~
          |                                                                      C
  • tests/cpu/lambda_spec_test.cpp:45:8: warning: [readability-identifier-naming]

    invalid case style for variable 'one_lambda'

       45 |   auto one_lambda = [=, c = proteus::jit_variable(one)] ()
          |        ^~~~~~~~~~
          |        OneLambda
       46 |                         __attribute__((annotate("jit"))) { printInt(c); };
       47 | 
       48 |   auto two_lambda = [=, c = proteus::jit_variable(two)] ()
       49 |                         __attribute__((annotate("jit"))) { printInt(c); };
       50 | 
       51 |   run(zero_lambda);
       52 |   run(one_lambda);
          |       ~~~~~~~~~~
          |       OneLambda
  • tests/cpu/lambda_spec_test.cpp:45:25: warning: [readability-identifier-naming]

    invalid case style for variable 'c'

       45 |   auto one_lambda = [=, c = proteus::jit_variable(one)] ()
          |                         ^
          |                         C
       46 |                         __attribute__((annotate("jit"))) { printInt(c); };
          |                                                                     ~
          |                                                                     C
  • tests/cpu/lambda_spec_test.cpp:48:8: warning: [readability-identifier-naming]

    invalid case style for variable 'two_lambda'

       48 |   auto two_lambda = [=, c = proteus::jit_variable(two)] ()
          |        ^~~~~~~~~~
          |        TwoLambda
       49 |                         __attribute__((annotate("jit"))) { printInt(c); };
       50 | 
       51 |   run(zero_lambda);
       52 |   run(one_lambda);
       53 |   run(two_lambda);
          |       ~~~~~~~~~~
          |       TwoLambda
  • tests/cpu/lambda_spec_test.cpp:48:25: warning: [readability-identifier-naming]

    invalid case style for variable 'c'

       48 |   auto two_lambda = [=, c = proteus::jit_variable(two)] ()
          |                         ^
          |                         C
       49 |                         __attribute__((annotate("jit"))) { printInt(c); };
          |                                                                     ~
          |                                                                     C
  • tests/gpu/lambda_spec_test.cpp:29:7: warning: [readability-identifier-naming]

    invalid case style for variable 'zero'

       29 |   int zero = 0;
          |       ^~~~
          |       Zero
  • tests/gpu/lambda_spec_test.cpp:30:7: warning: [readability-identifier-naming]

    invalid case style for variable 'one'

       30 |   int one = 1;
          |       ^~~
          |       One
  • tests/gpu/lambda_spec_test.cpp:31:7: warning: [readability-identifier-naming]

    invalid case style for variable 'two'

       31 |   int two = 2;
          |       ^~~
          |       Two
  • tests/gpu/lambda_spec_test.cpp:33:8: warning: [readability-identifier-naming]

    invalid case style for variable 'zero_lambda'

       33 |   auto zero_lambda = [=, c = proteus::jit_variable(zero)] __device__()
          |        ^~~~~~~~~~~
          |        ZeroLambda
  • tests/gpu/lambda_spec_test.cpp:36:8: warning: [readability-identifier-naming]

    invalid case style for variable 'one_lambda'

       36 |   auto one_lambda = [=, c = proteus::jit_variable(one)] __device__()
          |        ^~~~~~~~~~
          |        OneLambda
  • tests/gpu/lambda_spec_test.cpp:39:8: warning: [readability-identifier-naming]

    invalid case style for variable 'two_lambda'

       39 |   auto two_lambda = [=, c = proteus::jit_variable(two)] __device__()
          |        ^~~~~~~~~~
          |        TwoLambda

Have any feedback or feature suggestions? Share it here.

@johnbowen42 johnbowen42 marked this pull request as ready for review February 10, 2026 05:05
@johnbowen42 johnbowen42 force-pushed the bugfix/bowen/fix-lambda-runtime-const-ordering branch from 80903af to 74a9798 Compare February 10, 2026 05:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant