Halide
Halide::GeneratorContext Class Reference

GeneratorContext is a base class that is used when using Generators (or Stubs) directly; it is used to allow the outer context (typically, either a Generator or "top-level" code) to specify certain information to the inner context to ensure that inner and outer Generators are compiled in a compatible way. More...

#include <Generator.h>

Inherited by Halide::Internal::GeneratorBase.

Public Types

using ExternsMap = std::map< std::string, ExternalCode >
 

Public Member Functions

 GeneratorContext (const Target &t, bool auto_schedule=false, const MachineParams &machine_params=MachineParams::generic())
 
virtual ~GeneratorContext ()
 
Target get_target () const
 
bool get_auto_schedule () const
 
MachineParams get_machine_params () const
 
std::shared_ptr< ExternsMapget_externs_map () const
 Generators can register ExternalCode objects onto themselves. More...
 
template<typename T >
std::unique_ptr< T > create () const
 
template<typename T , typename... Args>
std::unique_ptr< T > apply (const Args &... args) const
 

Protected Member Functions

 GeneratorContext ()
 
virtual void init_from_context (const Halide::GeneratorContext &context)
 
std::shared_ptr< Internal::ValueTrackerget_value_tracker () const
 
 GeneratorContext (const GeneratorContext &)=delete
 
void operator= (const GeneratorContext &)=delete
 
 GeneratorContext (GeneratorContext &&)=delete
 
void operator= (GeneratorContext &&)=delete
 

Protected Attributes

GeneratorParam< Targettarget
 
GeneratorParam< bool > auto_schedule
 
GeneratorParam< MachineParamsmachine_params
 
std::shared_ptr< ExternsMapexterns_map
 
std::shared_ptr< Internal::ValueTrackervalue_tracker
 

Detailed Description

GeneratorContext is a base class that is used when using Generators (or Stubs) directly; it is used to allow the outer context (typically, either a Generator or "top-level" code) to specify certain information to the inner context to ensure that inner and outer Generators are compiled in a compatible way.

If you are using this at "top level" (e.g. with the JIT), you can construct a GeneratorContext with a Target:

auto my_stub = MyStub(
// inputs
{ ... },
// generator params
{ ... }
);

Note that all Generators inherit from GeneratorContext, so if you are using a Stub from within a Generator, you can just pass 'this' for the GeneratorContext:

struct SomeGen : Generator<SomeGen> {
void generate() {
...
auto my_stub = MyStub(
this, // GeneratorContext
// inputs
{ ... },
// generator params
{ ... }
);
...
}
};

Definition at line 2856 of file Generator.h.

Member Typedef Documentation

◆ ExternsMap

using Halide::GeneratorContext::ExternsMap = std::map<std::string, ExternalCode>

Definition at line 2858 of file Generator.h.

Constructor & Destructor Documentation

◆ GeneratorContext() [1/4]

Halide::GeneratorContext::GeneratorContext ( const Target t,
bool  auto_schedule = false,
const MachineParams machine_params = MachineParams::generic() 
)
explicit

◆ ~GeneratorContext()

virtual Halide::GeneratorContext::~GeneratorContext ( )
virtual

◆ GeneratorContext() [2/4]

Halide::GeneratorContext::GeneratorContext ( )
inlineprotected

Definition at line 2913 of file Generator.h.

◆ GeneratorContext() [3/4]

Halide::GeneratorContext::GeneratorContext ( const GeneratorContext )
protecteddelete

◆ GeneratorContext() [4/4]

Halide::GeneratorContext::GeneratorContext ( GeneratorContext &&  )
protecteddelete

Member Function Documentation

◆ get_target()

Target Halide::GeneratorContext::get_target ( ) const
inline

◆ get_auto_schedule()

bool Halide::GeneratorContext::get_auto_schedule ( ) const
inline

Definition at line 2868 of file Generator.h.

References auto_schedule.

◆ get_machine_params()

MachineParams Halide::GeneratorContext::get_machine_params ( ) const
inline

Definition at line 2871 of file Generator.h.

References machine_params.

◆ get_externs_map()

std::shared_ptr<ExternsMap> Halide::GeneratorContext::get_externs_map ( ) const
inline

Generators can register ExternalCode objects onto themselves.

The Generator infrastructure will arrange to have this ExternalCode appended to the Module that is finally compiled using the Generator. This allows encapsulating functionality that depends on external libraries or handwritten code for various targets. The name argument should match the name of the ExternalCode block and is used to ensure the same code block is not duplicated in the output. Halide does not do anything other than to compare names for equality. To guarantee uniqueness in public code, we suggest using a Java style inverted domain name followed by organization specific naming. E.g.: com.yoyodyne.overthruster.0719acd19b66df2a9d8d628a8fefba911a0ab2b7

See test/generator/external_code_generator.cpp for example use.

Definition at line 2890 of file Generator.h.

References externs_map.

◆ create()

template<typename T >
std::unique_ptr<T> Halide::GeneratorContext::create ( ) const
inline

Definition at line 2895 of file Generator.h.

Referenced by Halide::Generator< T >::create().

◆ apply()

template<typename T , typename... Args>
std::unique_ptr<T> Halide::GeneratorContext::apply ( const Args &...  args) const
inline

Definition at line 2900 of file Generator.h.

◆ init_from_context()

virtual void Halide::GeneratorContext::init_from_context ( const Halide::GeneratorContext context)
protectedvirtual

◆ get_value_tracker()

std::shared_ptr<Internal::ValueTracker> Halide::GeneratorContext::get_value_tracker ( ) const
inlineprotected

Definition at line 2919 of file Generator.h.

References value_tracker.

◆ operator=() [1/2]

void Halide::GeneratorContext::operator= ( const GeneratorContext )
protecteddelete

◆ operator=() [2/2]

void Halide::GeneratorContext::operator= ( GeneratorContext &&  )
protecteddelete

Member Data Documentation

◆ target

GeneratorParam<Target> Halide::GeneratorContext::target
protected

Definition at line 2907 of file Generator.h.

Referenced by get_target().

◆ auto_schedule

GeneratorParam<bool> Halide::GeneratorContext::auto_schedule
protected

Definition at line 2908 of file Generator.h.

Referenced by get_auto_schedule().

◆ machine_params

GeneratorParam<MachineParams> Halide::GeneratorContext::machine_params
protected

Definition at line 2909 of file Generator.h.

Referenced by get_machine_params().

◆ externs_map

std::shared_ptr<ExternsMap> Halide::GeneratorContext::externs_map
protected

Definition at line 2910 of file Generator.h.

Referenced by get_externs_map().

◆ value_tracker

std::shared_ptr<Internal::ValueTracker> Halide::GeneratorContext::value_tracker
protected

Definition at line 2911 of file Generator.h.

Referenced by get_value_tracker().


The documentation for this class was generated from the following file:
Halide::GeneratorContext::GeneratorContext
GeneratorContext()
Definition: Generator.h:2913
Halide::get_target_from_environment
Target get_target_from_environment()
Return the target that Halide will use.