Skip to content

Commit 46be46e

Browse files
authored
Merge branch 'master' into ProjectTemplate
2 parents 52f7918 + e66d680 commit 46be46e

2 files changed

Lines changed: 124 additions & 124 deletions

File tree

source/hardware/EventDrivenGP.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ namespace emp {
3232

3333
/**
3434
* @brief A linear GP (inspired by AvidaGP) virtual hardware CPU that supports an event-driven programming paradigm.
35-
* @note The terminology used throughout this class is out of date. EventDrivenGP will eventually change to 'SignalGP',
36-
* and our terminology will be updated throughout.
35+
* @note The terminology used throughout this class is out of date. EventDrivenGP will eventually change to 'SignalGP',
36+
* and our terminology will be updated throughout.
3737
* @details
3838
* The EventDrivenGP virtual hardware runs programs where each program is a set of named functions.
3939
* Function names are mutable bit strings, or affinities, and each function consists of a sequence
@@ -95,13 +95,13 @@ namespace emp {
9595
* * Each event type has a registered event handler that gets called to handle a dispatched
9696
* event.
9797
*/
98-
template<size_t AFFINITY_WIDTH>
98+
template<size_t AFFINITY_WIDTH, typename TRAIT_TYPE=double>
9999
class EventDrivenGP_AW {
100100
public:
101101
/// Maximum number of instruction arguments. Currently hardcoded. At some point, will make flexible.
102102
static constexpr size_t MAX_INST_ARGS = 3;
103103

104-
using EventDrivenGP_t = EventDrivenGP_AW<AFFINITY_WIDTH>; //< Resolved type for this templated class.
104+
using EventDrivenGP_t = EventDrivenGP_AW<AFFINITY_WIDTH, TRAIT_TYPE>; //< Resolved type for this templated class.
105105
using mem_key_t = int; //< Hardware memory map key type.
106106
using mem_val_t = double; //< Hardware memory map value type.
107107
using memory_t = std::unordered_map<mem_key_t, mem_val_t>; //< Hardware memory map type.
@@ -618,7 +618,7 @@ namespace emp {
618618
program_t program; //< Hardware's associated program (set of functions).
619619
memory_t shared_mem; //< Hardware's shared memory map. All cores have access to the same shared memory.
620620
std::deque<event_t> event_queue; //< Hardware's event queue. Where events go to be handled (in order of reception).
621-
emp::vector<double> traits; //< Generic traits vector. Whatever uses the hardware must define/keep track of what traits mean.
621+
emp::vector<TRAIT_TYPE> traits; //< Generic traits vector. Whatever uses the hardware must define/keep track of what traits mean.
622622
size_t errors; //< Errors committed by hardware while executing. (e.g. divide by 0, etc.)
623623
size_t max_cores; //< Maximum number of parallel execution stacks that can be spawned. Increasing this value drastically slows things down.
624624
size_t max_call_depth; //< Maximum depth of calls per execution stack.
@@ -814,7 +814,7 @@ namespace emp {
814814
}
815815

816816
/// Get a particular trait given its ID.
817-
double GetTrait(size_t id) const { emp_assert(id < traits.size()); return traits[id]; }
817+
TRAIT_TYPE GetTrait(size_t id) const { emp_assert(id < traits.size()); return traits[id]; }
818818

819819
/// Get current number of errors committed by this hardware.
820820
size_t GetNumErrors() const { return errors; }
@@ -837,7 +837,7 @@ namespace emp {
837837
bool IsStochasticFunCall() const { return stochastic_fun_call; }
838838

839839
/// Get all hardware cores.
840-
/// NOTE: use responsibly!
840+
/// NOTE: use responsibly!
841841
emp::vector<exec_stk_t> & GetCores() { return cores; }
842842

843843
/// Get the currently executing core ID. If hardware is not in the middle of an execution cycle
@@ -956,7 +956,7 @@ namespace emp {
956956

957957
/// Set trait in traints vector given by id to value given by val.
958958
/// Will resize traits vector if given id is greater than current traits vector size.
959-
void SetTrait(size_t id, double val) {
959+
void SetTrait(size_t id, TRAIT_TYPE val) {
960960
if (id >= traits.size()) traits.resize(id+1, 0.0);
961961
traits[id] = val;
962962
}
@@ -976,7 +976,7 @@ namespace emp {
976976
}
977977

978978
/// Push a trait onto end of traits vector.
979-
void PushTrait(double val) { traits.emplace_back(val); }
979+
void PushTrait(TRAIT_TYPE val) { traits.emplace_back(val); }
980980

981981
/// Shortcut to this hardware object's program's SetInst function of the same signature.
982982
void SetInst(size_t fID, size_t pos, const inst_t & inst) {
@@ -1617,17 +1617,17 @@ namespace emp {
16171617
/// Default instruction: Fork
16181618
/// Number of instruction arguments: 0
16191619
/// Description: Self-signal. Fork a new thread, using tag-based referencing to determine the appropriate
1620-
/// function to call on the new thread.
1620+
/// function to call on the new thread.
16211621
static void Inst_Fork(EventDrivenGP_t & hw, const inst_t & inst) {
16221622
State & state = hw.GetCurState();
16231623
hw.SpawnCore(inst.affinity, hw.GetMinBindThresh(), state.local_mem, false);
16241624
}
16251625

16261626
/// Default instruction: Terminate
16271627
/// Number of instruction arguments: 0
1628-
/// Description: Terminate the thread that executes this instruction.
1629-
/// WARNING: This instruction does not respect any 'main' function calls.
1630-
/// *Any* thread where this is called is terminated.
1628+
/// Description: Terminate the thread that executes this instruction.
1629+
/// WARNING: This instruction does not respect any 'main' function calls.
1630+
/// *Any* thread where this is called is terminated.
16311631
static void Inst_Terminate(EventDrivenGP_t & hw, const inst_t & inst) {
16321632
// Pop all the call states from current core.
16331633
exec_stk_t & core = hw.GetCurCore();

0 commit comments

Comments
 (0)