Alpine-DAV / ascent

A flyweight in situ visualization and analysis runtime for multi-physics HPC simulations
https://alpine-dav.github.io/ascent/
Other
189 stars 65 forks source link

OCCA incorrectly interprets expressions with field names containing dashes #1182

Open BenWibking opened 1 year ago

BenWibking commented 1 year ago

The JIT expression compiler incorrectly interprets field names containing dashes (e.g. field('x-GasMomentum')) in expressions and can't compile them:

[Error] Ascent::execute
file: /Users/benwibking/ascent_build/ascent/src/libs/ascent/runtimes/ascent_expression_eval.cpp
line: 1543
message:
Error while executing expression 'field('x-GasMomentum') / field('gasDensity')':
file: /Users/benwibking/ascent_build/ascent/src/libs/ascent/runtimes/expressions/ascent_expression_jit_filters.cpp
line: 652
message:
Jit errors:
- "\nfile: /Users/benwibking/ascent_build/ascent/src/libs/ascent/runtimes/expressions/ascent_derived_jit.cpp\nline: 1014\nmessage: \nJit errors: \n- \"\\nfile: /Users/benwibking/ascent_build/ascent/src/libs/ascent/runtimes/expressions/ascent_derived_jit.cpp\\nline: 926\\nmessage: \\nJitable: Expression compilation failed:\\n\\n---[ Error ]--------------------------------------------------------------------\\n    File     : /Users/benwibking/ascent_build/occa/src/occa/internal/modes/serial/device.cpp\\n    Line     : 373\\n    Function : operator()\\n    Message  : Error compiling [map], Command: [g++ -O3 -std=c++11 -fPIC -shared /Users/benwibking/quokka/tests/.occa/cache/60a700efcc0c8883/source.cpp -o /Users/benwibking/quokka/tests/.occa/cache/60a700efcc0c8883/9a546136508e891b.binary -I/Users/benwibking/ascent_build/occa/include -I/Users/benwibking/ascent_build/occa/include -L/Users/benwibking/ascent_build/occa/lib -locca  2>&1]\\n               Output:\\n               \\n               /Users/benwibking/quokka/tests/.occa/cache/60a700efcc0c8883/source.cpp:17:29: error: use of undeclared identifier 'GasMomentum'\\n                       output[item] = (x - GasMomentum[item] / gasDensity[item]);\\n                                           ^\\n               1 error generated.\\n               \\n    Stack\\n      21 libocca.dylib       std::__1::__function::__func<occa::serial::device::buildKernel(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, occa::hash_t, occa::json const&, bool)::$_1, std::__1::allocator<occa::serial::device::buildKernel(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, occa::hash_t, occa::json const&, bool)::$_1>, bool (std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)>::operator()(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)\\n      20 libocca.dylib       occa::io::stageFiles(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&, bool, std::__1::function<bool (std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>> const&)>)\\n      19 libocca.dylib       occa::io::stageFile(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, bool, std::__1::function<bool (std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)>)\\n      18 libocca.dylib       occa::serial::device::buildKernel(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, occa::hash_t, occa::json const&, bool)\\n      17 libocca.dylib       occa::serial::device::buildKernel(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, occa::hash_t, occa::json const&)\\n      16 libocca.dylib       occa::device::buildKernel(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, occa::json const&) const\\n      15 libocca.dylib       occa::device::buildKernelFromString(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&, occa::json const&) const\\n      14 libascent_mpi.dylib ascent::runtime::expressions::Jitable::execute(conduit::Node&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>> const&)\\n      13 libascent_mpi.dylib ascent::runtime::expressions::JitFilter::execute()\\n      12 libascent_flow.dylibflow::Workspace::execute()                        \\n      11 libascent_mpi.dylib ascent::runtime::expressions::ExpressionEval::evaluate(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>)\\n      10 libascent_mpi.dylib ascent::runtime::filters::FilterQuery::execute()  \\n       9 libascent_flow.dylibflow::Workspace::execute()                        \\n       8 libascent_mpi.dylib ascent::AscentRuntime::Execute(conduit::Node const&)\\n       7 libascent_mpi.dylib ascent::Ascent::execute(conduit::Node const&)     \\n       6 shock_cloud         AMRSimulation<ShockCloud>::AscentCustomActions(conduit::Node const&)\\n       5 shock_cloud         AMRSimulation<ShockCloud>::RenderAscent()         \\n       4 shock_cloud         AMRSimulation<ShockCloud>::setInitialConditions() \\n       3 shock_cloud         problem_main()                                    \\n       2 shock_cloud         main                                              \\n       1 dyld                start                                             \\n================================================================================\\n\\n\\n@kernel void map(double *output,\\n                 const double *x-GasMomentum,\\n                 const double *gasDensity,\\n                 const int entries)\\n{\\n  for (int group = 0; group < entries; group += 128; @outer)\\n  {\\n    for (int item = group; item < (group + 128); ++item; @inner)\\n    {\\n      if (item < entries)\\n      {\\n        output[item] = (x-GasMomentum[item] / gasDensity[item]);\\n      }\\n    }\\n  }\\n}\\n\\n\"\n\n"

The relevant part of the error message is:

/Users/benwibking/quokka/tests/.occa/cache/60a700efcc0c8883/source.cpp:17:29: error: use of undeclared identifier 'GasMomentum'
output[item] = (x - GasMomentum[item] / gasDensity[item])

Is there a workaround for this? Or do I need to rename my fields so they don't contain dashes?

cyrush commented 1 year ago

Interesting, the expression lang takes these as a string arg to field function to avoid this very issue.

But it sounds like we have a bug where we aren't sanitizing the name in the generated OCCA C++ code.

I don't have workaround, I'll need to explore a fix for you in the OCCA code generation.