Spinscale: PuppetComponent takes PuppetApplication&
This commit is contained in:
@@ -5,10 +5,10 @@
|
|||||||
#include <memory>
|
#include <memory>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/callback.h>
|
||||||
|
#include <spinscale/puppetApplication.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
|
|
||||||
class Mind;
|
|
||||||
class ComponentThread;
|
class ComponentThread;
|
||||||
|
|
||||||
class Component
|
class Component
|
||||||
@@ -27,11 +27,13 @@ class PuppetComponent
|
|||||||
: public Component
|
: public Component
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PuppetComponent(Mind &parent, const std::shared_ptr<ComponentThread> &thread);
|
PuppetComponent(
|
||||||
|
PuppetApplication &parent,
|
||||||
|
const std::shared_ptr<ComponentThread> &thread);
|
||||||
~PuppetComponent() = default;
|
~PuppetComponent() = default;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Mind &parent;
|
PuppetApplication &parent;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace smo
|
} // namespace smo
|
||||||
|
|||||||
@@ -31,6 +31,9 @@ public:
|
|||||||
void exitAllPuppetThreadsReq(
|
void exitAllPuppetThreadsReq(
|
||||||
Callback<puppetThreadLifetimeMgmtOpCbFn> callback);
|
Callback<puppetThreadLifetimeMgmtOpCbFn> callback);
|
||||||
|
|
||||||
|
// CPU distribution method
|
||||||
|
void distributeAndPinThreadsAcrossCpus();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Collection of PuppetThread instances
|
// Collection of PuppetThread instances
|
||||||
std::vector<std::shared_ptr<PuppetThread>> componentThreads;
|
std::vector<std::shared_ptr<PuppetThread>> componentThreads;
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
#include <spinscale/component.h>
|
#include <spinscale/component.h>
|
||||||
|
#include <spinscale/puppetApplication.h>
|
||||||
#include <marionette/marionette.h>
|
#include <marionette/marionette.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
@@ -9,7 +10,7 @@ Component::Component(const std::shared_ptr<ComponentThread> &thread)
|
|||||||
}
|
}
|
||||||
|
|
||||||
PuppetComponent::PuppetComponent(
|
PuppetComponent::PuppetComponent(
|
||||||
Mind &parent, const std::shared_ptr<ComponentThread> &thread)
|
PuppetApplication &parent, const std::shared_ptr<ComponentThread> &thread)
|
||||||
: Component(thread),
|
: Component(thread),
|
||||||
parent(parent)
|
parent(parent)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -201,4 +201,21 @@ void PuppetApplication::exitAllPuppetThreadsReq(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PuppetApplication::distributeAndPinThreadsAcrossCpus()
|
||||||
|
{
|
||||||
|
int cpuCount = ComponentThread::getAvailableCpuCount();
|
||||||
|
|
||||||
|
// Distribute and pin threads across CPUs
|
||||||
|
int threadIndex = 0;
|
||||||
|
for (auto& thread : componentThreads)
|
||||||
|
{
|
||||||
|
int targetCpu = threadIndex % cpuCount;
|
||||||
|
thread->pinToCpu(targetCpu);
|
||||||
|
++threadIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << __func__ << ": Distributed " << threadIndex << " threads "
|
||||||
|
<< "across " << cpuCount << " CPUs\n";
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace smo
|
} // namespace smo
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ add_library(smocore STATIC
|
|||||||
# Director
|
# Director
|
||||||
director/director.cpp
|
director/director.cpp
|
||||||
|
|
||||||
|
# Simulator
|
||||||
|
simulator/simulator.cpp
|
||||||
|
|
||||||
# Marionette
|
# Marionette
|
||||||
marionette/main.cpp
|
marionette/main.cpp
|
||||||
marionette/salmanoff.cpp
|
marionette/salmanoff.cpp
|
||||||
|
|||||||
+11
-5
@@ -4,6 +4,7 @@
|
|||||||
#include <spinscale/asynchronousLoop.h>
|
#include <spinscale/asynchronousLoop.h>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/callback.h>
|
||||||
#include <spinscale/callableTracer.h>
|
#include <spinscale/callableTracer.h>
|
||||||
|
#include <spinscale/puppetApplication.h>
|
||||||
#include <body/body.h>
|
#include <body/body.h>
|
||||||
#include <componentThread.h>
|
#include <componentThread.h>
|
||||||
#include <mind.h>
|
#include <mind.h>
|
||||||
@@ -23,14 +24,15 @@ class Body::InitializeReq
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
InitializeReq(
|
InitializeReq(
|
||||||
Mind &parent, const std::shared_ptr<ComponentThread> &caller,
|
PuppetApplication &parent,
|
||||||
|
const std::shared_ptr<ComponentThread> &caller,
|
||||||
Callback<bodyLifetimeMgmtOpCbFn> callback)
|
Callback<bodyLifetimeMgmtOpCbFn> callback)
|
||||||
: PostedAsynchronousContinuation<bodyLifetimeMgmtOpCbFn>(caller, callback),
|
: PostedAsynchronousContinuation<bodyLifetimeMgmtOpCbFn>(caller, callback),
|
||||||
parent(parent)
|
parent(parent)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Mind &parent;
|
PuppetApplication &parent;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void initializeReq1_posted(
|
void initializeReq1_posted(
|
||||||
@@ -54,15 +56,17 @@ public:
|
|||||||
* We used to use Marionette, but there's a strong argument for using
|
* We used to use Marionette, but there's a strong argument for using
|
||||||
* Body instead since it's meant to handle device-management operations.
|
* Body instead since it's meant to handle device-management operations.
|
||||||
*/
|
*/
|
||||||
|
// Upcast to Mind to access Mind-specific members
|
||||||
|
Mind &mind = static_cast<Mind&>(context->parent);
|
||||||
stim_buff::StimBuffApiManager::getInstance()
|
stim_buff::StimBuffApiManager::getInstance()
|
||||||
.loadAllStimBuffApiLibsFromOptions(parent.body.thread);
|
.loadAllStimBuffApiLibsFromOptions(mind.body.thread);
|
||||||
|
|
||||||
/** EXPLANATION:
|
/** EXPLANATION:
|
||||||
* Consider body::initializeReq to have been called if even one of its
|
* Consider body::initializeReq to have been called if even one of its
|
||||||
* operations was executed at all, whether successfully or
|
* operations was executed at all, whether successfully or
|
||||||
* unsuccessfully.
|
* unsuccessfully.
|
||||||
*/
|
*/
|
||||||
context->parent.bodyComponentInitialized = true;
|
mind.bodyComponentInitialized = true;
|
||||||
|
|
||||||
std::cout << stim_buff::StimBuffApiManager::getInstance().stringifyLibs()
|
std::cout << stim_buff::StimBuffApiManager::getInstance().stringifyLibs()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
@@ -176,7 +180,9 @@ void Body::finalizeReq(Callback<bodyLifetimeMgmtOpCbFn> callback)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!parent.bodyComponentInitialized)
|
// Upcast to Mind to access Mind-specific members
|
||||||
|
Mind &mind = static_cast<Mind&>(parent);
|
||||||
|
if (!mind.bodyComponentInitialized)
|
||||||
{
|
{
|
||||||
std::cout << "Mrntt: Body component not initialized. "
|
std::cout << "Mrntt: Body component not initialized. "
|
||||||
<< "Skipping finalization." << "\n";
|
<< "Skipping finalization." << "\n";
|
||||||
|
|||||||
@@ -1,10 +1,16 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <director/director.h>
|
#include <director/director.h>
|
||||||
|
#include <mind.h>
|
||||||
#include <goal.h>
|
#include <goal.h>
|
||||||
|
|
||||||
namespace smo {
|
namespace smo {
|
||||||
namespace director {
|
namespace director {
|
||||||
|
|
||||||
|
Director::Director(Mind &parent, const std::shared_ptr<ComponentThread> &thread)
|
||||||
|
: PuppetComponent(static_cast<PuppetApplication&>(parent), thread)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
void Director::negtrinEventInd(void)
|
void Director::negtrinEventInd(void)
|
||||||
{
|
{
|
||||||
/** EXPLANATION:
|
/** EXPLANATION:
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
#ifndef _BODY_COMPONENT_H
|
#ifndef _BODY_COMPONENT_H
|
||||||
#define _BODY_COMPONENT_H
|
#define _BODY_COMPONENT_H
|
||||||
|
|
||||||
|
#include <spinscale/puppetApplication.h>
|
||||||
#include <spinscale/component.h>
|
#include <spinscale/component.h>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/callback.h>
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define DIRECTOR_H
|
#define DIRECTOR_H
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
#include <spinscale/puppetApplication.h>
|
||||||
#include <spinscale/component.h>
|
#include <spinscale/component.h>
|
||||||
#include <goal.h>
|
#include <goal.h>
|
||||||
#include <lruLifo.h>
|
#include <lruLifo.h>
|
||||||
@@ -17,10 +18,7 @@ class Director
|
|||||||
: public PuppetComponent
|
: public PuppetComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Director(Mind &parent, const std::shared_ptr<ComponentThread> &thread)
|
Director(Mind &parent, const std::shared_ptr<ComponentThread> &thread);
|
||||||
: PuppetComponent(parent, thread)
|
|
||||||
{}
|
|
||||||
|
|
||||||
~Director() = default;
|
~Director() = default;
|
||||||
|
|
||||||
void negtrinEventInd(void);
|
void negtrinEventInd(void);
|
||||||
|
|||||||
@@ -7,8 +7,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <spinscale/callback.h>
|
#include <spinscale/callback.h>
|
||||||
|
|
||||||
#include <spinscale/component.h>
|
|
||||||
#include <spinscale/puppetApplication.h>
|
#include <spinscale/puppetApplication.h>
|
||||||
|
#include <spinscale/component.h>
|
||||||
#include <componentThread.h>
|
#include <componentThread.h>
|
||||||
#include <mindThread.h>
|
#include <mindThread.h>
|
||||||
#include <director/director.h>
|
#include <director/director.h>
|
||||||
@@ -35,9 +35,6 @@ public:
|
|||||||
// Get all this Mind's component threads.
|
// Get all this Mind's component threads.
|
||||||
std::vector<std::shared_ptr<MindThread>> getMindThreads() const;
|
std::vector<std::shared_ptr<MindThread>> getMindThreads() const;
|
||||||
|
|
||||||
// CPU distribution method
|
|
||||||
void distributeAndPinThreadsAcrossCpus();
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
director::Director director;
|
director::Director director;
|
||||||
simulator::Simulator canvas;
|
simulator::Simulator canvas;
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#define SIMULATOR_H
|
#define SIMULATOR_H
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
#include <spinscale/puppetApplication.h>
|
||||||
#include <spinscale/component.h>
|
#include <spinscale/component.h>
|
||||||
#include <simulator/scene.h>
|
#include <simulator/scene.h>
|
||||||
|
|
||||||
@@ -16,10 +17,7 @@ class Simulator
|
|||||||
: public PuppetComponent
|
: public PuppetComponent
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
Simulator(Mind &parent, const std::shared_ptr<ComponentThread> &thread)
|
Simulator(Mind &parent, const std::shared_ptr<ComponentThread> &thread);
|
||||||
: PuppetComponent(parent, thread)
|
|
||||||
{}
|
|
||||||
|
|
||||||
~Simulator() = default;
|
~Simulator() = default;
|
||||||
|
|
||||||
void initialize();
|
void initialize();
|
||||||
|
|||||||
@@ -245,25 +245,4 @@ void Mind::finalizeReq(Callback<mindLifetimeMgmtOpCbFn> callback)
|
|||||||
request.get(), request)));
|
request.get(), request)));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mind::distributeAndPinThreadsAcrossCpus()
|
|
||||||
{
|
|
||||||
int cpuCount = ComponentThread::getAvailableCpuCount();
|
|
||||||
|
|
||||||
if (OptionParser::getOptions().verbose) {
|
|
||||||
std::cout << __func__ << ": Available CPUs: " << cpuCount << "\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Distribute and pin threads across CPUs
|
|
||||||
int threadIndex = 0;
|
|
||||||
for (auto& thread : componentThreads)
|
|
||||||
{
|
|
||||||
int targetCpu = threadIndex % cpuCount;
|
|
||||||
thread->pinToCpu(targetCpu);
|
|
||||||
++threadIndex;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::cout << __func__ << ": Distributed " << threadIndex << " threads "
|
|
||||||
<< "across " << cpuCount << " CPUs\n";
|
|
||||||
}
|
|
||||||
|
|
||||||
} // namespace smo
|
} // namespace smo
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
#include <simulator/simulator.h>
|
||||||
|
#include <mind.h>
|
||||||
|
|
||||||
|
namespace smo {
|
||||||
|
namespace simulator {
|
||||||
|
|
||||||
|
Simulator::Simulator(Mind &parent, const std::shared_ptr<ComponentThread> &thread)
|
||||||
|
: PuppetComponent(static_cast<PuppetApplication&>(parent), thread)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace simulator
|
||||||
|
} // namespace smo
|
||||||
Reference in New Issue
Block a user