GComputation::compile() does not set internal cached GCompiled object of GComputation instance

Hello,

TL;DR:
Am I just holding it wrong? It seems, like GComputation::compile() should just actually set the m_priv->m_lastCompiled member of GComputation, like GComputation::apply() does.

I have a scenario where I’d like to specify a GAPI computation before the first actual frame is processed. Think of it as initializing the application and then, after initialization, let it run as fast as possible from the first frame of actual input.
The user should have the option to offload GComputation::compile() to non-critical time slots.

From the GAPI documentation, it felt natural to call the compile() method on a cached GComputation object during initialization and let it run, precompiled, using the apply() method later when the data arrives.

However, compile() just generates a new GCompiled object for the caller to use, instead of actually replacing the GCompiled object that is used by the GComputation instance. Thus, I can see no obvious way of preinitializing my GComputation object as soon as the data specs are known without having it actually run the computation in a call to it’s apply() method.

I want to do:

Mat in, out;
GMat gin, gout; // Graph definition left out for brevity. Those are the in- and outputs.

GComputation computation(gin, gout);
computation.compile(/* args */);

while(true) {
    read_input(in);
    computation.apply(in, out /*, args */); // Never compiles again.
    write_output(out);
}

but I have to do either option 1:

Mat in, out;
GMat gin, gout; // Graph definition left out for brevity. Those are the in- and outputs.

GComputation computation(gin, gout);

while(true) {
    read_input(in);
    computation.apply(in, out /*, args */); // Compiles once (first fame "lags"), checks args and input every iteration.
    write_output(out);
}

or option 2:

Mat in, out;
GMat gin, gout; // Graph definition left out for brevity. Those are the in- and outputs.

GComputation computation(gin, gout);
auto compiled = computation.compile(/* args */);

while(true) {
    read_input(in);
    compiled (in, out); // Never compiles again.
    write_output(out);
}

Option 2 lets it look to me, as if the GComputation is not necessary, but the gimpl::GCompiler::GCompiler object that is used in GComputation::compile() takes a reference to the GComputation object to get the graph.

1 Like

Hello!

compile() isn’t supposed to cache the GCompiled’s, it is assumed as a “pure function”. Only apply() does so.

Please note once you called compile(), you get its return value – a GCompiled object - and you should use that one going forward. It is not connected with a GComputation in any way so you can safely destroy the GComputation, too (if you don’t need any recompilation, though).

Can you just use a GCompiled object in your case? You can consider this is a “compiled function ready to use”.

1 Like