GithubHelp home page GithubHelp logo

Comments (10)

pressenna avatar pressenna commented on June 22, 2024

Hi, can I tackle this one?

from heavydb.

billmaimone avatar billmaimone commented on June 22, 2024

Yes, good one for you.

from heavydb.

asuhan avatar asuhan commented on June 22, 2024

@psockali You can use ScalarExprVisitor to build a constant-collecting visitor. There's a pitfall though: we don't know all constants upfront when sub-queries are involved. Have a look at RelAlgTranslator::translateInOper. We can use a hybrid approach: collect and generate all the other constants upfront and leave the current handling in place (and keep LICM). Alternatively, we can reorganize the compiler to do a full pass first without emitting any IR, which we know we'll eventually have to do for other reasons as well. Going for the first approach won't hurt our ability to achieve the second and the code should be fully reusable once we have the full solution in place, so I recommend going for it as an incremental, nearly-complete solution.

from heavydb.

pressenna avatar pressenna commented on June 22, 2024

Hi @asuhan , I will do so.
Am I correct in assuming that only runtime constants (within the scope of a block) shall be hoisted, but literals can remain as they are?

from heavydb.

pressenna avatar pressenna commented on June 22, 2024

Hey @asuhan

I think I need to be much more clearer when addressing things in mapd. (e.g. literal in LLVM IR, literal in REX, literal in Analyzer::Exp, etc...).

Finally managed to look at this in more detail and it turns out that Analyzer::Constant literals are hoisted in Executor::codegenHoistedConstants into a memory buffer. And each unoptimized access to the literal requires a memory read from that buffer. As you have pointed out RelAlgTranslator::translateInOper is creating Analyzer::Constant dynamically, so scanning early on, right after translating from REX, is not very promising.

Currently I would propose to scan for Analyzer::Constant via an ScalarExprVisitor before the actual LLVM IR generation (somewhere in Executor::compileWorkUnit) and also extend the Constant class to hold a few more attributes required for this extra step.

I would then generate the memory load for each literal in @query_group_by_template and pass them as arguments to the always inlined @row_func , which also needs to be extended to take these new parameters.

I would also make this, in effect, a configurable behaviour and would probably introduce a new compiler option flag.

I hope to start tomorrow on it, if there are no objections to the above approach.

from heavydb.

shtilman avatar shtilman commented on June 22, 2024

Hi @psockali, your approach sounds reasonable. Add a constant scanning visitor, generate corresponding literal loads in the first block of the query func and feed these values to the always_inlined @row_func. Not sure if any Constant extensions are necessary but let's see if your motivation can be justified. No need to make this behavior configurable - we're just putting some literal loads where they should have been generated from the get go, instead of relying on LICM to move them there.

You mentioned @query_group_by_template, note that it's just one of the templates that the query func can be built from, the other one is @query_template.

from heavydb.

pressenna avatar pressenna commented on June 22, 2024

Hey @shtilman, as usual: theory does not reflect reality.

It turns out that during LLVM IR generation Analyzer::Constant nodes are created on the fly and sometimes the original Constant node is translated.
See Executor::codegenRowId, Executor::codegenCmpDecimalConst and Executor::codegenOuterJoinNullPlaceholder.

This invalidates the proposed approach, because scanning the source Analyzer::Exp tree will not be reliable nor sufficient.

I have to rethink .. please bear with me.

from heavydb.

pressenna avatar pressenna commented on June 22, 2024

Hey @shtilman,

@asuhan mentioned two approaches:

  • Hybrid:
    Currently this is the approach I am going for.
  • Full Pass without IR generation:
    I am not confident enough at this stage to make such a central change to the compiler as I am not sure what state(s) the compiler currently maintains and how I would reset it correctly.

I think there is an alternative way, but it would require to clone the row_function (in order to correct the function type with the hoisted variable).

Either way, let me first try the hybrid approach, it probably will be complicated enough.

from heavydb.

pressenna avatar pressenna commented on June 22, 2024

Hi @shtilman / @asuhan
I committed an initial version of the hybrid solution. the PR is #145 .
Please let me know if this approach is OK for now as I fear that it does not capture all the cases.

from heavydb.

shtilman avatar shtilman commented on June 22, 2024

Comments and discussion are in #145 PR.

from heavydb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.