EventDrivenGP.hpp

TODO.

Typedefs

using EventDrivenGP = EventDrivenGP_AW<8>

A convenient shortcut for using EventDrivenGP_AW class with affinity width set to a default of 8.

template<size_t AFFINITY_WIDTH, typename TRAIT_T = vector<double>, typename MATCHBIN_T = MatchBin<size_t, HammingMetric<AFFINITY_WIDTH>, RankedSelector<std::ratio<1, 2>>, MultiplicativeCountdownRegulator<>>>
class EventDrivenGP_AW
#include <EventDrivenGP.hpp>

A linear GP (inspired by AvidaGP) virtual hardware CPU that supports an event-driven programming paradigm.

The EventDrivenGP virtual hardware runs programs where each program is a set of named functions. Function names are mutable bit strings, or affinities, and each function consists of a sequence of instructions. Functions are called by name, and can be called from within the hardware (via Call instructions) or from outside the hardware (via Events).

The EventDrivenGP virtual hardware CPU is capable of multi-core/parallel processing. This hardware maintains a (bounded) set of cores. Each core maintains its own program call stack that stores information about the active functions on that core. Cores execute in simulated parallel. For every single CPU cycle (see SingleProcess function) given to the virtual hardware, each core is given the opportunity to advance by a single cycle.

When functions are called from within the hardware (via Call instructions), a new call state is pushed onto the program call stack on the core from which the function was called. No new core is spawned (unless using a non-standard Call instruction). When functions are called from outside the hardware (via Events), if there is an available inactive core, an inactive core will be made active with the called function.

Affinity matching/binding is used to determine which functions should be called by events or by Call instructions. The hardware looks at the event/instruction’s associated affinity and finds the best match (using a simple matching coefficient) among function affinities in the hardware’s program. The best match must be better than a given minimum threshold (min_bind_thresh) for that function to be called. If there are not functions that meet the minimum threshold, no function is called. If two or more functions are tied for best match and are above the minimum threshold, one is selected randomly to be called; otherwise, if there is no tie, the best matching function is called.

Terminology:

  • Programs

    • The EventDrivenGP virtual hardware runs programs of type EventDrivenGP::Program. These programs are a set of named functions.

  • Functions

    • Functions in EventDrivenGP programs are named and consist of a sequence of instructions. Function names, or affinities, are bit strings whose length are defined by AFFINITY_WIDTH.

  • Instructions

    • EventDrivenGP hardware instructions are managed by an instruction library (InstLib.h).

    • Instructions have IDs, affinities, arguments, and properties.

  • Affinity

    • An affinity is a sequence of bits whose length is determined by AFFINITY_WIDTH (by default, 8).

  • Core

    • A core is a single program call stack where the call stack stores information about the active functions running on the core.

  • Call State

    • Local state information relative to a particular function call. Each call state consists of: Local memory, Input memory, Output memory, a Code Block Stack, a function pointer, and an instruction pointer.

  • Events

    • Events are defined and managed through the an event library (EventLib.h). Events are flexible packages of information that can be used to interact with EventDrivenGP hardware. Events are minimally defined by default as they are heavily dependent on the context of where/how the EventDrivenGP hardware is being used.

    • Events have an associated ID (managed by the event library), an affinity, a memory map, and a set of properties (string set).

    • When an event is triggered the set of dispatcher functions that are registered to that particular event’s type (managed by the event library) are called. Events events are often triggered by instructions or by external processes. For example, the default SendMsg instruction triggers a Message type event which causes all of the Message event dispatchers registered to the hardware’s event library to be called.

    • Each event type has a registered event handler that gets called to handle a dispatched event.

Note

The terminology used throughout this class is out of date. EventDrivenGP will eventually change to ‘SignalGP’, and our terminology will be updated throughout.

Public Types

enum class BlockType

Currently only 3 Block types:

  • NONE: Not a block.

  • BASIC: Anything that’s not a loop. Once closed/at end of block, execution can just continue.

  • LOOP: Once closed/at end of block, execution needs to jump back to beginning of block.

Values:

enumerator NONE
enumerator BASIC
enumerator LOOP
using EventDrivenGP_t = EventDrivenGP_AW<AFFINITY_WIDTH, TRAIT_T, MATCHBIN_T>
using mem_key_t = int
using mem_val_t = double
using memory_t = std::unordered_map<mem_key_t, mem_val_t>
using arg_t = int
using arg_set_t = array<arg_t, MAX_INST_ARGS>
using affinity_t = BitSet<AFFINITY_WIDTH>
using properties_t = std::unordered_set<std::string>
using trait_t = TRAIT_T
using matchbin_t = MATCHBIN_T
using inst_t = Instruction
using inst_seq_t = vector<inst_t>
using event_t = Event
using inst_lib_t = InstLib<EventDrivenGP_t>
using event_lib_t = EventLib<EventDrivenGP_t>
using program_t = Program
using exec_stk_t = vector<State>
using fun_event_handler_t = std::function<void(EventDrivenGP_t&, const event_t&)>

Event handler function type alias.

using trait_printer_t = std::function<void(std::ostream &os, TRAIT_T t)>

Public Functions

inline EventDrivenGP_AW(Ptr<const inst_lib_t> _ilib, Ptr<const event_lib_t> _elib, Ptr<Random> rnd = nullptr)

EventDrivenGP constructor. Give instance variables reasonable defaults. Allow for configuration post-construction.

inline EventDrivenGP_AW(const inst_lib_t &_ilib, const event_lib_t &_elib, Ptr<Random> rnd = nullptr)
inline EventDrivenGP_AW(Ptr<const event_lib_t> _elib, Ptr<Random> rnd = nullptr)
inline EventDrivenGP_AW(Ptr<Random> rnd = nullptr)
inline EventDrivenGP_AW(EventDrivenGP_t &&in)
inline EventDrivenGP_AW(const EventDrivenGP_t &in)
inline ~EventDrivenGP_AW()
inline void Reset()

Reset everything, including program. Not allowed to Reset during execution.

inline void ResetProgram()

clear program, this also requires resetting hardware

inline void ResetHardware()

Reset only hardware, not program. Not allowed to reset hardware during execution.

inline void SpawnCore(const affinity_t &affinity, double threshold, const memory_t &input_mem = memory_t(), bool is_main = false)

Spawn core with function that has best match to provided affinity. Do nothing if no functions match above the provided threshold. Initialize function state with provided input memory. Will fail if no inactive cores to claim.

inline void SpawnCore(size_t fID, const memory_t &input_mem = memory_t(), bool is_main = false)

Spawn core with function specified by fID. Initialize function state with provided input memory. Will fail if no inactive cores to claim.

inline Ptr<const inst_lib_t> GetInstLib() const

Get instruction library associated with hardware’s program.

inline Ptr<const event_lib_t> GetEventLib() const

Get event library associated with hardware.

inline Random &GetRandom()

Get reference to random number generator used by this hardware.

inline Ptr<Random> GetRandomPtr()

Get pointer to random number generator used by this hardware.

inline const program_t &GetConstProgram() const

Get program loaded on this hardware.

inline program_t &GetProgram()
inline const Function &GetFunction(size_t fID) const

Get reference to a particular function in hardware’s program.

inline const inst_t &GetInst(size_t fID, size_t pos) const

Get reference to particular instruction in hardware’s program given function ID and instruction position.

inline TRAIT_T &GetTrait()

Get the stored trait in hardware’s program.

inline const TRAIT_T &GetTrait() const

Get the stored trait in hardware’s program.

inline size_t GetNumErrors() const

Get current number of errors committed by this hardware.

inline double GetMinBindThresh() const

Get hardware’s minimum binding threshold (threshold used to determine if two affinities are close enough to bind).

inline size_t GetMaxCores() const

Get the maximum number of cores allowed to run simultaneously on this hardware object.

inline size_t GetMaxCallDepth() const

Get the maximum call depth allowed on this hardware object (max call states allowed on a single core’s call stack at a time).

inline mem_val_t GetDefaultMemValue() const

Get the default memory value for local/shared/input/output memory maps.

inline bool IsStochasticFunCall() const

Is this hardware object configured to allow stochasticity in function calling? Hardware is only stochastic when calling/event affinity is equidistant from two or more functions.

inline vector<exec_stk_t> &GetCores()

Get all hardware cores. NOTE: use responsibly!

inline const vector<exec_stk_t> &GetCores() const

Get all hardware cores. NOTE: use responsibly!

inline size_t GetCurCoreID()

Get the currently executing core ID. If hardware is not in the middle of an execution cycle (the SingleProcess function), this will return the first core ID in active_cores, which will typically be the core on which main is running.

inline exec_stk_t &GetCurCore()

Get a reference to the current core/execution stack.

inline State &GetCurState()

Get a reference to the current local call state.

inline memory_t &GetSharedMem()

Get a reference to hardware’s shared memory map.

inline mem_val_t GetShared(mem_key_t key) const

Get a particular value in shared memory map stored @ location indicated by key. If key cannot be found, return the default memory value.

inline mem_val_t &AccessShared(mem_key_t key)

Get a reference to a location in the shared memory map as indicated by key. If key cannot be found, add key:default_mem_value to map and return newly added location.

inline void SetMinBindThresh(double val)

Set minimum binding threshold. Requirement: minimum binding threshold >= 0.0

inline void SetMaxCores(size_t val)

Set the maximum number of cores that are allowed to be running/active simultaneously on this hardware object. Warning: If you decrease max cores, you may kill actively running cores. Warning: If you decrease max cores, we make no guarantees about which particular cores are killed. This could have adverse effects. Requirement: Must have max cores > 0 and cannot set max cores while executing (while in SingleProcess function). To sum up, be careful if you’re going to decreasing max cores after you’ve run the hardware.

inline void SetMaxCallDepth(size_t val)

Configure max call depth. Warning: will not retroactively enforce new max call depth. Requirement: max call depth must be > 0.

inline void SetDefaultMemValue(mem_val_t val)

Configure the default memory value.

inline void SetStochasticFunCall(bool val)

Configure whether or not function calls should be stochastic if we have two or more matches that are equidistant from caller/event affinity.

inline void SetTrait(TRAIT_T t)

Set trait in traits vector given by id to value given by val. Will resize traits vector if given id is greater than current traits vector size.

inline void SetInst(size_t fID, size_t pos, const inst_t &inst)

Shortcut to this hardware object’s program’s SetInst function of the same signature.

inline void SetInst(size_t fID, size_t pos, size_t id, arg_t a0 = 0, arg_t a1 = 0, arg_t a2 = 0, const affinity_t &aff = affinity_t())

Shortcut to this hardware object’s program’s SetInst function of the same signature.

inline void SetProgram(const program_t &_program)

Set program for this hardware object.

inline void PushFunction(const Function &_function)

Shortcut to this hardware object’s program’s PushFunction operation of the same signature.

inline void PushFunction(const affinity_t &_aff = affinity_t(), const inst_seq_t &_seq = inst_seq_t())

Shortcut to this hardware object’s program’s PushFunction operation of the same signature.

inline void PushInst(size_t id, arg_t a0 = 0, arg_t a1 = 0, arg_t a2 = 0, const affinity_t &aff = affinity_t(), int fID = -1)

Push new instruction to program. If no function pointer is provided and no functions exist yet, add new function to program and push to that. If no function pointer is provided and functions exist, push to last function in program. If function pointer is provided, push to that function.

inline void PushInst(const std::string &name, arg_t a0 = 0, arg_t a1 = 0, arg_t a2 = 0, const affinity_t &aff = affinity_t(), int fID = -1)

Push new instruction to program. If no function pointer is provided and no functions exist yet, add new function to program and push to that. If no function pointer is provided and functions exist, push to last function in program. If function pointer is provided, push to that function.

inline void PushInst(const inst_t &inst, int fID = -1)

Push new instruction to program. If no function pointer is provided and no functions exist yet, add new function to program and push to that. If no function pointer is provided and functions exist, push to last function in program. If function pointer is provided, push to that function.

inline void Load(std::istream &input)

Load entire program from input stream. Warning: This function accepts a slightly different than what the Program’s PrintProgram function prints out (for now, will add a PrintProgram variant that prints in this load function’s accepted format). Program format: Fn-AFFINITY: INST_NAMEAFFINITY … Fn-AFFINITY: …

inline void NewRandom(int seed = -1)

Generate new random number generator for this hardware object with the given seed value.

inline bool ValidPosition(size_t fID, size_t pos) const

Is program position defined by the given function ID (fID) and instruction position (pos) a valid position in this hardware object’s program?

inline bool ValidFunction(size_t fID) const

Is the function given by function ID (fID) a valid function in this hardware object’s program?

inline void SetShared(mem_key_t key, mem_val_t value)

Set given shared memory map location (key) to given value.

inline size_t FindEndOfBlock(size_t fp, size_t ip)

Given valid function pointer and instruction pointer, find next end of block (at current block level). This is not guaranteed to return a valid IP. At worst, it’ll return an IP == function.inst_seq.size().

inline void CloseBlock()

Close current block in the current local program state if there is one to close. If not, do nothing. Handles closure of known, special block types appropriately:

  • LOOPS - set cur_state’s IP to beginning of block.

inline void OpenBlock(size_t begin, size_t end, BlockType type)

Open a block in the current local program state as specified by begin, end, and type.

inline void BreakBlock()

If there’s a block to break out of in current local program state, break out (to eob). Otherwise, do nothing.

inline vector<size_t> FindBestFuncMatch(const affinity_t &affinity)

Find best matching functions (by ID) given affinity.

inline MATCHBIN_T &GetMatchBin()
inline const MATCHBIN_T &GetMatchBin() const
inline void RefreshMatchBin()
inline void CallFunction(const affinity_t &affinity, double threshold)

Call function with best affinity match above threshold. If not candidate functions found, do nothing.

inline void CallFunction(size_t fID)

Call function specified by fID. REQ: core must be active (must have a local state on execution stack).

inline void ReturnFunction()

Return from current function call (cur_state) in current core (cur_core). Upon returning, put values in output memory of returning state into local memory of caller state.

inline void ProcessInst(const inst_t &inst)

Process a single instruction, provided by the caller.

inline void HandleEvent(const event_t &event)

Handle an event (on this hardware).

inline void TriggerEvent(const event_t &event)

Trigger an event (from this hardware).

inline void TriggerEvent(const std::string &name, const affinity_t &affinity = affinity_t(), const memory_t &msg = memory_t(), const properties_t &properties = properties_t())

Trigger an event (from this hardware).

inline void TriggerEvent(size_t id, const affinity_t &affinity = affinity_t(), const memory_t &msg = memory_t(), const properties_t &properties = properties_t())

Trigger an event (from this hardware).

inline void QueueEvent(const event_t &event)

Queue an event (to be handled by this hardware).

inline void QueueEvent(const std::string &name, const affinity_t &affinity = affinity_t(), const memory_t &msg = memory_t(), const properties_t &properties = properties_t())

Queue event by name.

inline void QueueEvent(size_t id, const affinity_t &affinity = affinity_t(), const memory_t &msg = memory_t(), const properties_t &properties = properties_t())

Queue event by id.

inline void SingleProcess()

Advance hardware by single instruction.

inline void Process(size_t num_inst)

Advance hardware by some arbitrary number instructions.

inline void PrintEvent(const event_t &event, std::ostream &os = std::cout)

Print given event using given output stream (default = std::cout).

inline void PrintInst(const inst_t &inst, std::ostream &os = std::cout)

Print given instruction using given output stream (default = std::cout).

inline void PrintTraits(std::ostream &os = std::cout)

Print hardware traits using given output stream (default = std::cout).

inline void SetTraitPrintFun(const trait_printer_t &t)
inline void PrintProgram(std::ostream &os = std::cout)

Print out entire program using given output stream (default = std::cout).

inline void PrintProgramFull(std::ostream &os = std::cout)

Print out entire program using given output stream (default = std::cout).

inline void PrintState(std::ostream &os = std::cout)

Print out current state (full) of virtual hardware using given output stream (default = std::cout).

Public Static Functions

static inline void Inst_Inc(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Inc Number arguments: 1 Description: Increment value in local memory[Arg1].

static inline void Inst_Dec(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Dec Number of arguments: 1 Description: Decrement value in local memory[Arg1].

static inline void Inst_Not(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Not Number of arguments: 1 Description: Logically toggle value in Local[Arg1].

static inline void Inst_Add(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Add Number of arguments: 3 Description: Local[Arg3] = Local[Arg1] + Local[Arg2]

static inline void Inst_Sub(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Sub Number of arguments: 3 Description: Local[Arg3] = Local[Arg1] - Local[Arg2]

static inline void Inst_Mult(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Mult Number of arguments: 3 Description: Local[Arg3] = Local[Arg1] * Local[Arg2]

static inline void Inst_Div(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Div Number of arguments: 3 Description: Local[Arg3] = Local[Arg1] / Local[Arg2] If Local[Arg2] == 0, division fails and increment hardware errors.

static inline void Inst_Mod(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Mod Number of arguments: 3 Description: Local[Arg3] = Local[Arg1] % Local[Arg2] If Local[Arg2] == 0, modulus fails and increment hardware errors.

static inline void Inst_TestEqu(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: TestEqu Number of arguments: 3 Description: Local[Arg3] = Local[Arg1] == Local[Arg2]

static inline void Inst_TestNEqu(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: TestNEqu Number of arguments: 3 Description: Local[Arg3] = Local[Arg1] != Local[Arg2]

static inline void Inst_TestLess(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: TestLess Number of arguments: 3 Description: Local[Arg3] = Local[Arg1] < Local[Arg2]

static inline void Inst_If(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: If Number of arguments: 1 Description: If (Local[Arg1] != 0) { execute block } else { skip block }

static inline void Inst_While(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: While Number of arguments: 1 Description: While (Local[Arg1] != 0) { execute block }

static inline void Inst_Countdown(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Countdown Number of arguments: 1 Description: While (Local[Arg1] != 0) { Local[Arg1]&#8212; then execute block }

static inline void Inst_Break(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Break Number of arguments: 0 Description: Break out of current block if there’s a block to close.

static inline void Inst_Close(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Close Number of arguments: 0 Description: Marks the end of a block.

static inline void Inst_Call(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Call Number of arguments: 0 Description: Call function with the strongest affinity match to call affinity.

static inline void Inst_Return(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Return Number of arguments: 0 Description: Return from current function call unless in main function call.

static inline void Inst_SetMem(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: SetMem Number of arguments: 2 Description: Local[Arg1] = ValueOf(Arg2)

static inline void Inst_CopyMem(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: CopyMem Number of arguments: 2 Description: Local[Arg2] = Local[Arg1]

static inline void Inst_SwapMem(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: SwapMem Number of arguments: 2 Description: Swap(Local[Arg1], Local[Arg2])

static inline void Inst_Input(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Input Number of arguments: 2 Description: Local[Arg2] = Input[Arg1]

static inline void Inst_Output(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Output Number of arguments: 2 Description: Output[Arg2] = Local[Arg1]

static inline void Inst_Commit(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Commit Number of arguments: 2 Description: Shared[Arg2] = Local[Arg1]

static inline void Inst_Pull(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Pull Number of arguments: 2 Description: Local[Arg2] = Shared[Arg1]

static inline void Inst_Fork(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Fork Number of instruction arguments: 0 Description: Self-signal. Fork a new thread, using tag-based referencing to determine the appropriate function to call on the new thread.

static inline void Inst_Terminate(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Terminate Number of instruction arguments: 0 Description: Terminate the thread that executes this instruction. WARNING: This instruction does not respect any ‘main’ function calls. Any thread where this is called is terminated.

static inline void Inst_Nop(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: Nop Number of arguments: 0 Description: No operation.

static inline void Inst_BroadcastMsg(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: BroadcastMsg Number of arguments: 0 Description: Trigger a Message event where the event’s affinity is equal to this instructions affinity and the event’s message payload is equal to the current local program state output buffer. Event properties will indicate that this is a broadcast.

static inline void Inst_SendMsg(EventDrivenGP_t &hw, const inst_t &inst)

Default instruction: SendMsg Number of arguments: 0 Description: Trigger a Message event where the event’s affinity is equal to this instructions affinity and the event’s message payload is equal to the current local program state output buffer. Event properties will indicate that this is a send.

static inline void Inst_RngDouble(EventDrivenGP_t &hw, const inst_t &inst)

Non-default instruction: RngDouble Number of arguments: 1 Description: Draw a value between 0 and 1 from the onboard RNG and store it in Local[Arg1]

static inline void Inst_SetRegulator(EventDrivenGP_t &hw, const inst_t &inst)

Non-default instruction: SetRegulator Number of arguments: 2 Description: Sets the regulator of a tag in the matchbin.

static inline void Inst_SetOwnRegulator(EventDrivenGP_t &hw, const inst_t &inst)

Non-default instruction: SetOwnRegulator Number of arguments: 2 Description: Sets the regulator of the currently executing function.

static inline void Inst_AdjRegulator(EventDrivenGP_t &hw, const inst_t &inst)

Non-default instruction: AdjRegulator Number of arguments: 3 Description: adjusts the regulator of a tag in the matchbin towards a goal.

static inline void Inst_AdjOwnRegulator(EventDrivenGP_t &hw, const inst_t &inst)

Non-default instruction: AdjOwnRegulator Number of arguments: 3 Description: adjusts the regulator of a tag in the matchbin towards a target.

static inline void Inst_ExtRegulator(EventDrivenGP_t &hw, const inst_t &inst)

Non-default instruction: ExtRegulator Number of arguments: 1 Description: extends the decay counter of a regulator of a tag in the matchbin.

static inline void Inst_ExtOwnRegulator(EventDrivenGP_t &hw, const inst_t &inst)

Non-default instruction: ExtOwnRegulator Number of arguments: 1 Description: extends the decay counter of a regulator of a tag in the matchbin.

static inline void Inst_SenseRegulator(EventDrivenGP_t &hw, const inst_t &inst)

Non-default instruction: SenseRegulator Number of arguments: 1 Description: senses the value of the regulator of another function.

static inline void Inst_SenseOwnRegulator(EventDrivenGP_t &hw, const inst_t &inst)

Non-default instruction: SenseOwnRegulator Number of arguments: 1 Description: senses the value of the regulator the current function.

template<typename MaxRatio = std::ratio<1>, typename MinRatio = std::ratio<0>>
static inline void Inst_Terminal(EventDrivenGP_t &hw, const inst_t &inst)

Non-default instruction: Terminal Number of arguments: 1 Description: writes a genetically-encoded value into a register.

static inline Ptr<const InstLib<EventDrivenGP_t>> DefaultInstLib()

Get a pointer to const default instruction library. Will only construct the default instruction library once.

static inline void HandleEvent_Message(EventDrivenGP_t &hw, const event_t &event)

Default event handler: Message Description: Handle a message by spawning a new core (if we’re not already maxed out) with the function that best matches the messages affinity. Set the function’s input buffer to be equal to the contents of the message event’s message contents.

static inline Ptr<const EventLib<EventDrivenGP_t>> DefaultEventLib()

Get a pointer to const default event library. Will only construct the default event library once. Note: the default event library does not construct any default dispatch functions. This is the responsibility of whatever is using the EventDrivenGP hardware.

Public Static Attributes

static constexpr size_t MAX_INST_ARGS = 3

Maximum number of instruction arguments. Currently hardcoded. At some point, will make flexible.

static constexpr size_t affinity_width = AFFINITY_WIDTH
static constexpr size_t DEFAULT_MAX_CORES = 8
static constexpr size_t DEFAULT_MAX_CALL_DEPTH = 128
static constexpr mem_val_t DEFAULT_MEM_VALUE = 0.0
static constexpr double DEFAULT_MIN_BIND_THRESH = 0.5

Protected Attributes

Ptr<const event_lib_t> event_lib
Ptr<Random> random_ptr
bool random_owner
program_t program
memory_t shared_mem
std::deque<event_t> event_queue
TRAIT_T traits
size_t errors
size_t max_cores
size_t max_call_depth
double default_mem_value
double min_bind_thresh
bool stochastic_fun_call
vector<exec_stk_t> cores
vector<size_t> active_cores
vector<size_t> inactive_cores
std::deque<size_t> pending_cores
size_t exec_core_id
bool is_executing
MATCHBIN_T matchBin
struct Block
#include <EventDrivenGP.hpp>

Struct to store information relevant to a ‘code block’ (e.g. if statements, while loops, etc). Maintains the beginning, end, and type of block.

Public Functions

inline Block(size_t _begin = 0, size_t _end = 0, BlockType _type = BlockType::BASIC)

Public Members

size_t begin
size_t end
BlockType type
struct Event
#include <EventDrivenGP.hpp>

Struct to represent an instance of an Event. Events have an associated ID, affinity, message, and set of properties.

Public Functions

inline Event(size_t _id = 0, const affinity_t &aff = affinity_t(), const memory_t &_msg = memory_t(), const properties_t &_properties = properties_t())
Event(const Event&) = default
Event(Event&&) = default
Event &operator=(const Event&) = default
Event &operator=(Event&&) = default
inline bool operator<(const Event &other) const

Compares two events, only taking into account ID and affinity. Message and properties aren’t compared due to performance considerations. Returns true if rhs is ‘larger’ than lhs.

inline bool operator==(const Event &other) const

Compares two events, only taking into account ID and affinity. Message and properties aren’t compared due to performance considerations. Returns true if events are ‘equal.’

inline bool HasProperty(std::string property) const

Does event object have given property?

template<class Archive>
inline void serialize(Archive &ar)

Cereal serialization interface.

Public Members

size_t id
affinity_t affinity
memory_t msg
properties_t properties
class Function
#include <EventDrivenGP.hpp>

Function struct. Defines an EventDrivenGP function. Each function has an associated:

  • affinity: Function affinity. Analogous to the function’s name.

  • inst_seq: Instruction sequence. Sequence of instructions that make up the function.

Public Functions

inline Function(const affinity_t &_aff = affinity_t(), const inst_seq_t &_seq = inst_seq_t(), std::function<void()> _fun_matchbin_refresh)
inline Function &operator=(const Function &other)
inline inst_t &operator[](size_t id)
inline const inst_t &operator[](size_t id) const
inline bool operator==(const Function &in) const
inline bool operator!=(const Function &in) const
inline bool operator<(const Function &other) const
inline size_t GetSize() const
inline void SetMatchBinRefreshFun(std::function<void()> fun)

If this function is loaded onto hardware, we need to refresh the MatchBin whenever we make certain changes here

inline const affinity_t &GetAffinity() const
inline void SetAffinity(const affinity_t &aff)
inline void PushInst(size_t id, arg_t a0, arg_t a1, arg_t a2, const affinity_t &aff)
inline void PushInst(const inst_t &inst)
inline void SetInst(size_t pos, size_t id, arg_t a0, arg_t a1, arg_t a2, const affinity_t &aff)
inline void SetInst(size_t pos, const inst_t &inst)
template<class Archive>
inline void serialize(Archive &ar)

Public Members

inst_seq_t inst_seq

Private Members

affinity_t affinity
std::function<void()> fun_matchbin_refresh
struct Instruction
#include <EventDrivenGP.hpp>

Struct to maintain EventDrivenGP Instruction information. Each instruction has an associated:

  • id: Instruction ID. Used to lookup instruction type using an instruction library.

  • args: Instruction arguments. Currently hardcoded maximum of 3.

  • affinity: Instruction affinity.

Public Functions

inline Instruction(size_t _id = 0, arg_t a0 = 0, arg_t a1 = 0, arg_t a2 = 0, const affinity_t &_aff = affinity_t())
Instruction(const Instruction&) = default
Instruction(Instruction&&) = default
Instruction &operator=(const Instruction&) = default
Instruction &operator=(Instruction&&) = default
inline void Set(size_t _id, arg_t _a0 = 0, arg_t _a1 = 0, arg_t _a2 = 0, const affinity_t &_aff = affinity_t())
inline void Set(const Instruction &other)
inline bool operator==(const Instruction &in) const
inline bool operator!=(const Instruction &in) const
inline bool operator<(const Instruction &other) const
template<class Archive>
inline void serialize(Archive &ar)
inline size_t GetIndex() const

Public Members

size_t id
arg_set_t args
affinity_t affinity
class Program
#include <EventDrivenGP.hpp>

Program struct. Defines an EventDrivenGP program. A programs consists of a set of functions where each function is a named sequence of instructions. Function names are bit strings (stored as a BitSet). Programs require an associated instruction library to give meaning to the instructions that make up their functions.

Public Functions

inline Program(Ptr<const inst_lib_t> _ilib, const program_t &_prgm = program_t())
Program(const Program&) = default
inline auto begin()
inline auto end()
inline auto cbegin() const
inline auto cend() const
inline void Clear()
inline Function &operator[](size_t id)
inline const Function &operator[](size_t id) const
inline bool operator==(const Program &in) const
inline bool operator!=(const Program &in) const
inline bool operator<(const Program &other) const
inline size_t GetSize() const

Get number of functions that make up this program.

inline size_t GetInstCnt() const

Get the total number of instructions across all functions that make up this program.

inline Ptr<const inst_lib_t> GetInstLib() const
inline bool ValidPosition(size_t fID, size_t pos) const
inline bool ValidFunction(size_t fID) const
inline void SetMatchBinRefreshFun(std::function<void()> fun)

If this program is loaded onto hardware, we need to refresh the MatchBin whenever we make certain changes here

inline void SetInstLib(const Ptr<const inst_lib_t> in)
inline void SetProgram(const program_t &_program)
inline void PushFunction(const Function &_function)
inline void DeleteFunction(const size_t fID)
inline void PushFunction(const affinity_t &_aff = affinity_t(), const inst_seq_t &_seq = inst_seq_t())
inline void PushInst(size_t id, arg_t a0 = 0, arg_t a1 = 0, arg_t a2 = 0, const affinity_t &aff = affinity_t(), int fID = -1)

Push new instruction to program. If no function pointer is provided and no functions exist yet, add new function to program and push to that. If no function pointer is provided and functions exist, push to last function in program. If function pointer is provided, push to that function.

inline void PushInst(const std::string &name, arg_t a0 = 0, arg_t a1 = 0, arg_t a2 = 0, const affinity_t &aff = affinity_t(), int fID = -1)

Push new instruction to program. If no function pointer is provided and no functions exist yet, add new function to program and push to that. If no function pointer is provided and functions exist, push to last function in program. If function pointer is provided, push to that function.

inline void PushInst(const inst_t &inst, int fID = -1)

Push new instruction to program. If no function pointer is provided and no functions exist yet, add new function to program and push to that. If no function pointer is provided and functions exist, push to last function in program. If function pointer is provided, push to that function.

inline void SetInst(size_t fID, size_t pos, size_t id, arg_t a0 = 0, arg_t a1 = 0, arg_t a2 = 0, const affinity_t &aff = affinity_t())
inline void SetInst(size_t fID, size_t pos, const inst_t &inst)
inline void Load(std::istream &input)

Load entire program from input stream. Warning: This function accepts a slightly different than what the Program’s PrintProgram function prints out (for now, will add a PrintProgram variant that prints in this load function’s accepted format). Program format: Fn-AFFINITY: INST_NAMEAFFINITY … Fn-AFFINITY: …

inline void PrintInst(const inst_t &inst, std::ostream &os = std::cout) const

Print out a single instruction with its arguments.

inline void PrintInstFull(const inst_t &inst, std::ostream &os = std::cout) const

Fully print out a single instruction with its arguments/affinity.

inline void PrintProgram(std::ostream &os = std::cout) const

Print out entire program.

inline void PrintProgramFull(std::ostream &os = std::cout) const

Print out entire program.

template<class Archive>
inline void serialize(Archive &ar)

Protected Types

using program_t = vector<Function>

Protected Attributes

Ptr<const inst_lib_t> inst_lib
program_t program
std::function<void()> fun_matchbin_refresh
struct State
#include <EventDrivenGP.hpp>

Struct to maintain local program state for a given function call. A local program state has an associated: local memory map, input memory map, output memory map, function pointer, instruction pointer, and block stack.

Public Functions

inline State(mem_val_t _default_mem_val = 0.0, bool _is_main = false)
State(const State&) = default
State(State&&) = default
inline void Reset()

Reset state object.

inline size_t GetFP() const

Get function pointer.

inline size_t GetIP() const

Get instruction pointer.

inline mem_val_t GetDefaultMemValue() const

Get default memory value.

inline void SetIP(size_t ip)

Set instruction pointer to given value, ip.

inline void SetFP(size_t fp)

Set function pointer to given value, fp.

inline void SetDefaultMemValue(mem_val_t val)

Set default memory value to given value, val.

inline void AdvanceIP(size_t inc = 1)

Advance instruction pointer by amount given by inc.

inline bool IsMain() const

Is this a main state?

inline memory_t &GetLocalMemory()

Get a reference to the local memory map for this state.

inline memory_t &GetInputMemory()

Get a reference to the input memory map for this state.

inline memory_t &GetOutputMemory()

Get a reference to the output memory map for this state.

inline mem_val_t GetLocal(mem_key_t key) const

Get value at requested local memory location (key) if that memory location exists. Otherwise, return default memory value.

inline mem_val_t GetInput(mem_key_t key) const

Get value at requested input memory location (key) if that memory location exists. Otherwise, return default memory value.

inline mem_val_t GetOutput(mem_key_t key) const

Get value at requested output memory location (key) if that memory location exists. Otherwise, return default memory value.

inline void SetLocal(mem_key_t key, mem_val_t value)

Set local memory specified by key to value.

inline void SetInput(mem_key_t key, mem_val_t value)

Set input memory specified by key to value.

inline void SetOutput(mem_key_t key, mem_val_t value)

Set output memory specified by key to value.

inline mem_val_t &AccessLocal(mem_key_t key)

Access local memory. This function returns a reference to memory location value if that location exists. If the location does not exist, set to default memory value and return reference to memory location value.

inline mem_val_t &AccessInput(mem_key_t key)

Access input memory. This function returns a reference to memory location value if that location exists. If the location does not exist, set to default memory value and return reference to memory location value.

inline mem_val_t &AccessOutput(mem_key_t key)

Access output memory. This function returns a reference to memory location value if that location exists. If the location does not exist, set to default memory value and return reference to memory location value.

Public Members

memory_t local_mem
memory_t input_mem
memory_t output_mem
double default_mem_val
size_t func_ptr
size_t inst_ptr
vector<Block> block_stack
bool is_main