From ca90550d8a91e4d8106d90c6325d52ecedcec8a2 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Tue, 9 Aug 2022 08:24:39 +0800 Subject: [PATCH 01/31] Adding preliminary ports --- .../include/ports.h | 41 +++++++++++++++++++ .../cpp_message_infrastructure/src/ports.cc | 25 +++++++++++ 2 files changed, 66 insertions(+) create mode 100644 src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h create mode 100644 src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h new file mode 100644 index 000000000..41fff01c2 --- /dev/null +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h @@ -0,0 +1,41 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: BSD-3-Clause +// See: https://spdx.org/licenses/ + +#ifndef PORTS_H_ +#define PORTS_H_ + +#include + +#include "abstract_port_implementation.h" + +namespace message_infrastrature { + +class AbstractCppPort : public AbstractPortImplementation { + public: + std::vector GetPorts(); +}; + +class AbstractCppIOPort : public AbstractCppPort { + public: + std::vector GetPorts(); +}; + +class CppInPort : public AbstractCppIOPort { + public: + bool Probe(); + void Peek(); + void Recv(); + + const CppInPortVectorDense VEC_DENSE; + const CppInPortVectorSparse VEC_SPARSE; + const CppInPortScalarDense SCALAR_DENSE; + const CppInPortScalarSparse SCALAR_SPARSE; + + AbstractTransformer transformer_; +}; + + +} // namespace message_infrastrature + +#endif \ No newline at end of file diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc b/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc new file mode 100644 index 000000000..71fca2e52 --- /dev/null +++ b/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc @@ -0,0 +1,25 @@ +// Copyright (C) 2021-22 Intel Corporation +// SPDX-License-Identifier: BSD-3-Clause +// See: https://spdx.org/licenses/ + +#include + +std::vector AbstractCppPort::GetShape() { + return this->shape_; +} + +std::vector AbstractCppIOPort::GetShape() { + return this->shape_; +} + +bool CppInPort::Probe() { + return; +} + +void CppInPort::Recv() { +} + +void CppInPort::Peek() { +} + + From a0c10e63daa6e176a6bc18a4d6fa9af92f9a48f2 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Wed, 10 Aug 2022 10:09:48 +0800 Subject: [PATCH 02/31] Added CppPort and CppIOPort --- .../include/abstract_port_implementation.h | 2 +- .../cpp_message_infrastructure/include/ports.h | 8 ++++++-- .../src/abstract_port_implementation.cc | 4 ---- .../runtime/cpp_message_infrastructure/src/ports.cc | 11 +++++------ 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port_implementation.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port_implementation.h index 5df045dcf..c3705cdbf 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port_implementation.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port_implementation.h @@ -17,7 +17,7 @@ class AbstractPortImplementation { int Start(); int Join(); std::vector GetShape(); - std::vector GetPorts(); + virtual std::vector GetPorts(); DataType dtype_; std::vector shape_; diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h index 41fff01c2..100f771db 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h @@ -13,12 +13,16 @@ namespace message_infrastrature { class AbstractCppPort : public AbstractPortImplementation { public: - std::vector GetPorts(); + virtual std::vector GetPorts(); + + std::vector ports_; }; class AbstractCppIOPort : public AbstractCppPort { public: - std::vector GetPorts(); + std::vector GetPorts(); + + std::vector ports_; }; class CppInPort : public AbstractCppIOPort { diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/src/abstract_port_implementation.cc b/src/lava/magma/runtime/cpp_message_infrastructure/src/abstract_port_implementation.cc index a6f849156..18c5cebac 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/src/abstract_port_implementation.cc +++ b/src/lava/magma/runtime/cpp_message_infrastructure/src/abstract_port_implementation.cc @@ -22,8 +22,4 @@ std::vector AbstractPortImplementation::GetShape() { return this->shape_; } -std::vector AbstractPortImplementation::GetPorts() { - return this->ports_; -} - } // namespace message_infrastrature \ No newline at end of file diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc b/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc index 71fca2e52..0a603ff80 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc +++ b/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc @@ -3,13 +3,12 @@ // See: https://spdx.org/licenses/ #include +#include -std::vector AbstractCppPort::GetShape() { - return this->shape_; -} +namespace message_infrastrature { -std::vector AbstractCppIOPort::GetShape() { - return this->shape_; +std::vector AbstractCppIOPort::GetPorts() { + return this->ports_; } bool CppInPort::Probe() { @@ -22,4 +21,4 @@ void CppInPort::Recv() { void CppInPort::Peek() { } - +} From e50481d4f822a84b74b865fa07a19214080050d9 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Wed, 10 Aug 2022 11:20:52 +0800 Subject: [PATCH 03/31] Add preliminary classes for CppInPorts and CppOutPorts --- .../include/ports.h | 68 ++++++++++++++++++- .../cpp_message_infrastructure/src/ports.cc | 5 -- 2 files changed, 66 insertions(+), 7 deletions(-) diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h index 100f771db..b368ba68c 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h @@ -18,6 +18,7 @@ class AbstractCppPort : public AbstractPortImplementation { std::vector ports_; }; + class AbstractCppIOPort : public AbstractCppPort { public: std::vector GetPorts(); @@ -25,11 +26,12 @@ class AbstractCppIOPort : public AbstractCppPort { std::vector ports_; }; + class CppInPort : public AbstractCppIOPort { public: bool Probe(); - void Peek(); - void Recv(); + virtual std::vector<> Peek(); + virtual std::vector<> Recv(); const CppInPortVectorDense VEC_DENSE; const CppInPortVectorSparse VEC_SPARSE; @@ -39,6 +41,68 @@ class CppInPort : public AbstractCppIOPort { AbstractTransformer transformer_; }; +class CppInPortVectorDense : public CppInPort { + public: + std::vector Recv(); + std::vector Peek(); +}; + + +class CppInPortVectorSparse : public CppInPort { + public: + std::vector Recv(); + std::vector Peek(); +}; + + +class CppInPortScalarDense : public CppInPort { + public: + std::vector Recv(); + std::vector Peek(); +}; + + +class CppInPortScalarSparse : public CppInPort { + public: + std::vector Recv(); + std::vector Peek(); +}; + + +class CppOutPort : public AbstractCppIOPort { + public: + virtual std::vector Send(); + virtual void Flush(); + + const CppOutPortVectorDense VEC_DENSE; + const CppOutPortVectorSparse VEC_SPARSE; + const CppOutPortScalarDense SCALAR_DENSE; + const CppOutPortScalarSparse SCALAR_SPARSE; +}; + + +class CppOutPortVectorDense : public CppOutPort { + public: + std::vector Send(); +}; + + +class CppOutPortVectorSparse : public CppOutPort { + public: + std::vector Send(); +}; + + +class CppOutPortScalarDense : public CppOutPort { + public: + int Send(); +}; + + +class CppOutPortScalarSparse : public CppOutPort { + public: + int Send(); +}; } // namespace message_infrastrature diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc b/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc index 0a603ff80..10cb42335 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc +++ b/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc @@ -15,10 +15,5 @@ bool CppInPort::Probe() { return; } -void CppInPort::Recv() { -} - -void CppInPort::Peek() { -} } From 9152359db42763a724f0e91edd6f22fe88597d11 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Wed, 10 Aug 2022 13:56:57 +0800 Subject: [PATCH 04/31] Add preliminary code for CppRefPorts --- .../include/ports.h | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h index b368ba68c..c315720ff 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h @@ -104,6 +104,54 @@ class CppOutPortScalarSparse : public CppOutPort { int Send(); }; +// -------- +// RefPorts +// -------- +// A CppRefPort is a Port connected to a VarPort of a variable Var of another +// Process. It is used to get or set the value of the referenced Var across +// Processes. +class CppRefPort : public AbstractCppPort { + public: + std::vector GetPorts(); + virtual Read(); + virtual Write(); + virtual Wait(); + + const CppRefPortVectorDense VEC_DENSE; + const CppRefPortVectorSparse VEC_SPARSE; + const CppRefPortScalarDense SCALAR_DENSE; + const CppRefPortScalarSparse SCALAR_SPARSE; +}; + + +class CppRefPortVectorDense : public CppRefPort { + public: + std::vector Read(); + std::vector Write(); +}; + + +class CppRefPortVectorSparse : public CppRefPort { + public: + std::vector Read(); + std::vector Write(); +}; + + +class CppRefPortScalarDense : public CppRefPort { + public: + int Read(); + std::vector Write(); +}; + + +class CppRefPortScalarSparse : public CppRefPort { + public: + std::vector Read(); + std::vector Write(); +}; + + } // namespace message_infrastrature #endif \ No newline at end of file From 231d59132979fcb759aa2c1ac4abb47415198284 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Wed, 10 Aug 2022 16:24:24 +0800 Subject: [PATCH 05/31] Added preliminary CppVarPort class --- .../include/ports.h | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h index c315720ff..92040b2a8 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h @@ -151,6 +151,31 @@ class CppRefPortScalarSparse : public CppRefPort { std::vector Write(); }; +// -------- +// VarPorts +// -------- +// A CppVarPort is a Port linked to a variable Var of a Process and might be +// connected to a RefPort of another process. It is used to get or set the +// value of the referenced Var across Processes. A CppVarPort is connected via +// two channels to a CppRefPort. One channel is used to send data from the +// CppRefPort to the CppVarPort and the other is used to receive data from the +// CppVarPort. CppVarPort set or send the value of the linked Var (service()) +// given the command VarPortCmd received by a connected CppRefPort. +class CppVarPort : public AbstractCppPort { + public: + std::vector GetCspPorts(); + virtual void Service(); + + const CppVarPortVectorDense VEC_DENSE; + const CppVarPortVectorSparse VEC_SPARSE; + const CppVarPortScalarDense SCALAR_DENSE; + const CppVarPortScalarSparse SCALAR_SPARSE; + + AbstractTransformer transformer_; + CspSendPort csp_send_port_; + CspRecvPort csp_recv_port_; + char var_name_[]; +}; } // namespace message_infrastrature From 3eac075fa5c3d4759c8413f1d65d1691e12fa15c Mon Sep 17 00:00:00 2001 From: shaline-koh Date: Wed, 10 Aug 2022 16:43:30 +0800 Subject: [PATCH 06/31] Add derived classes for CppVarPort --- .../include/ports.h | 28 ++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h index 92040b2a8..bb16f1ed7 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h @@ -177,6 +177,32 @@ class CppVarPort : public AbstractCppPort { char var_name_[]; }; +class CppVarPortVectorDense : public CppVarPort { + public: + void Service(); +}; + +class CppVarPortVectorSparse : public CppVarPort { + public: + std::vector Recv(); + std::vector Peek(); + void Service(); +}; + +class CppVarPortScalarDense : public CppVarPort { + public: + int Recv(); + int Peek(); + void Service(); +}; + +class CppVarPortScalarSparse : public CppVarPort { + public: + std::vector Recv(); + std::vector Peek(); + void Service(); +}; + } // namespace message_infrastrature -#endif \ No newline at end of file +#endif From b1b3cfc3353edb6d02adcfc96a490a0c481b87b7 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Thu, 11 Aug 2022 13:51:00 +0800 Subject: [PATCH 07/31] Update namespace naming --- .../cpp_message_infrastructure/include/abstract_actor.h | 4 ++-- .../cpp_message_infrastructure/include/abstract_channel.h | 4 ++-- .../cpp_message_infrastructure/include/abstract_port.h | 4 ++-- .../include/abstract_port_implementation.h | 4 ++-- .../cpp_message_infrastructure/include/multiprocessing.h | 4 ++-- .../magma/runtime/cpp_message_infrastructure/include/ports.h | 4 ++-- .../cpp_message_infrastructure/include/process_model.h | 4 ++-- .../runtime/cpp_message_infrastructure/include/runtime.h | 4 ++-- .../magma/runtime/cpp_message_infrastructure/include/shm.h | 4 ++-- .../cpp_message_infrastructure/include/shmem_channel.h | 4 ++-- .../runtime/cpp_message_infrastructure/include/shmem_port.h | 4 ++-- .../magma/runtime/cpp_message_infrastructure/include/utils.h | 4 ++-- .../src/abstract_port_implementation.cc | 4 ++-- .../src/message_infrastructure_py_wrapper.cc | 4 ++-- .../runtime/cpp_message_infrastructure/src/multiprocessing.cc | 4 ++-- .../magma/runtime/cpp_message_infrastructure/src/ports.cc | 2 +- 16 files changed, 31 insertions(+), 31 deletions(-) diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_actor.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_actor.h index c4aeab341..e6849e9b3 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_actor.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_actor.h @@ -5,7 +5,7 @@ #ifndef ABSTACT_ACTOR_H_ #define ABSTACT_ACTOR_H_ -namespace message_infrastrature { +namespace message_infrastructure { class AbstractActor { public: @@ -35,6 +35,6 @@ class PosixActor : public AbstractActor { using ActorPtr = AbstractActor *; using PosixActorPtr = PosixActor *; -} // namespace message_infrastrature +} // namespace message_infrastructure #endif \ No newline at end of file diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_channel.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_channel.h index 80c658066..75eb7f061 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_channel.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_channel.h @@ -9,7 +9,7 @@ #include "utils.h" #include -namespace message_infrastrature { +namespace message_infrastructure { class AbstractChannel { public: @@ -17,6 +17,6 @@ class AbstractChannel { std::shared_ptr dst_port_; }; -} // namespace message_infrastrature +} // namespace message_infrastructure #endif \ No newline at end of file diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port.h index 4739933e6..b9698e2bb 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port.h @@ -11,7 +11,7 @@ #include "shm.h" #include "utils.h" -namespace message_infrastrature { +namespace message_infrastructure { class AbstractPort { public: @@ -38,6 +38,6 @@ using PortPtr = AbstractPort *; using SendPortPtr = AbstractSendPort *; using RecvPortPtr = AbstractRecvPort *; -} // namespace message_infrastrature +} // namespace message_infrastructure #endif \ No newline at end of file diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port_implementation.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port_implementation.h index c3705cdbf..bab4f7c11 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port_implementation.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port_implementation.h @@ -10,7 +10,7 @@ #include "abstract_port.h" #include "process_model.h" -namespace message_infrastrature { +namespace message_infrastructure { class AbstractPortImplementation { public: @@ -26,6 +26,6 @@ class AbstractPortImplementation { std::vector ports_; }; -} // namespace message_infrastrature +} // namespace message_infrastructure #endif \ No newline at end of file diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/multiprocessing.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/multiprocessing.h index 9d6502879..aa7acffaa 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/multiprocessing.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/multiprocessing.h @@ -11,7 +11,7 @@ #include "abstract_actor.h" #include "shm.h" -namespace message_infrastrature { +namespace message_infrastructure { class MultiProcessing { public: @@ -24,6 +24,6 @@ class MultiProcessing { //SharedMemManager shmm_; }; -} // namespace message_infrastrature +} // namespace message_infrastructure #endif diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h index bb16f1ed7..a453c74d8 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/ports.h @@ -9,7 +9,7 @@ #include "abstract_port_implementation.h" -namespace message_infrastrature { +namespace message_infrastructure { class AbstractCppPort : public AbstractPortImplementation { public: @@ -203,6 +203,6 @@ class CppVarPortScalarSparse : public CppVarPort { void Service(); }; -} // namespace message_infrastrature +} // namespace message_infrastructure #endif diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/process_model.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/process_model.h index 5371d6264..e435e951d 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/process_model.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/process_model.h @@ -5,12 +5,12 @@ #ifndef PROCESS_MODEL_H_ #define PROCESS_MODEL_H_ -namespace message_infrastrature { +namespace message_infrastructure { class ProcessModel { }; -} // namespace message_infrastrature +} // namespace message_infrastructure #endif \ No newline at end of file diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/runtime.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/runtime.h index fc5be9c18..0b7009b21 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/runtime.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/runtime.h @@ -5,11 +5,11 @@ #ifndef RUNTIME_H_ #define RUNTIME_H_ -namespace message_infrastrature { +namespace message_infrastructure { class Runtime { }; -} // namespace message_infrastrature +} // namespace message_infrastructure #endif \ No newline at end of file diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/shm.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/shm.h index a4088de67..a4c3c0222 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/shm.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/shm.h @@ -13,12 +13,12 @@ #include #include -namespace message_infrastrature { +namespace message_infrastructure { class SharedMemory { }; -} // namespace message_infrastrature +} // namespace message_infrastructure #endif \ No newline at end of file diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/shmem_channel.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/shmem_channel.h index b68ec6a1e..6f4c65a17 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/shmem_channel.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/shmem_channel.h @@ -7,12 +7,12 @@ #include "abstract_channel.h" -namespace message_infrastrature { +namespace message_infrastructure { class ShmemChannel : public AbstractChannel { }; -} // namespace message_infrastrature +} // namespace message_infrastructure #endif diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/shmem_port.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/shmem_port.h index 0073bf7d4..97f6c1261 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/shmem_port.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/shmem_port.h @@ -7,7 +7,7 @@ #include "abstract_port.h" -namespace message_infrastrature { +namespace message_infrastructure { class ShmemSendPort : public AbstractSendPort { @@ -17,6 +17,6 @@ class ShmemRecvPort : public AbstractRecvPort { }; -} // namespace message_infrastrature +} // namespace message_infrastructure #endif diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/include/utils.h b/src/lava/magma/runtime/cpp_message_infrastructure/include/utils.h index 3f10ee193..3c9bb9ce9 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/include/utils.h +++ b/src/lava/magma/runtime/cpp_message_infrastructure/include/utils.h @@ -5,7 +5,7 @@ #ifndef UTILS_H_ #define UTILS_H_ -namespace message_infrastrature { +namespace message_infrastructure { enum ChannelType { ShmemChannel = 0, @@ -17,6 +17,6 @@ enum DataType { // dtype }; -} // namespace message_infrastrature +} // namespace message_infrastructure #endif \ No newline at end of file diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/src/abstract_port_implementation.cc b/src/lava/magma/runtime/cpp_message_infrastructure/src/abstract_port_implementation.cc index 18c5cebac..40a07bca4 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/src/abstract_port_implementation.cc +++ b/src/lava/magma/runtime/cpp_message_infrastructure/src/abstract_port_implementation.cc @@ -4,7 +4,7 @@ #include "abstract_port_implementation.h" -namespace message_infrastrature { +namespace message_infrastructure { int AbstractPortImplementation::Start() { for (auto port : this->ports_){ @@ -22,4 +22,4 @@ std::vector AbstractPortImplementation::GetShape() { return this->shape_; } -} // namespace message_infrastrature \ No newline at end of file +} // namespace message_infrastructure \ No newline at end of file diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/src/message_infrastructure_py_wrapper.cc b/src/lava/magma/runtime/cpp_message_infrastructure/src/message_infrastructure_py_wrapper.cc index 329663324..96f746ec5 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/src/message_infrastructure_py_wrapper.cc +++ b/src/lava/magma/runtime/cpp_message_infrastructure/src/message_infrastructure_py_wrapper.cc @@ -8,7 +8,7 @@ #include "multiprocessing.h" //#include "abstract_port_implementation.h" -namespace message_infrastrature { +namespace message_infrastructure { namespace py = pybind11; @@ -20,4 +20,4 @@ PYBIND11_MODULE(MessageInfrastructurePywrapper, m) { .def("stop", &MultiProcessing::Stop); } -} // namespace message_infrastrature +} // namespace message_infrastructure diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/src/multiprocessing.cc b/src/lava/magma/runtime/cpp_message_infrastructure/src/multiprocessing.cc index 59c6143bd..b52f1b7e2 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/src/multiprocessing.cc +++ b/src/lava/magma/runtime/cpp_message_infrastructure/src/multiprocessing.cc @@ -8,7 +8,7 @@ #include #include -namespace message_infrastrature { +namespace message_infrastructure { #define CPP_INFO "[CPP_INFO] " @@ -42,4 +42,4 @@ void MultiProcessing::CheckActor() { } } -} // namespace message_infrastrature +} // namespace message_infrastructure diff --git a/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc b/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc index 10cb42335..4b2ba2109 100644 --- a/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc +++ b/src/lava/magma/runtime/cpp_message_infrastructure/src/ports.cc @@ -5,7 +5,7 @@ #include #include -namespace message_infrastrature { +namespace message_infrastructure { std::vector AbstractCppIOPort::GetPorts() { return this->ports_; From 8901ab1e50816588fd437ee7a12921aa57fde63a Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Fri, 12 Aug 2022 15:53:25 +0800 Subject: [PATCH 08/31] Fix linting issues --- .../message_infrastructure/csrc/ports.h | 61 ++++++++++--------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index a453c74d8..398dc11bb 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -2,8 +2,11 @@ // SPDX-License-Identifier: BSD-3-Clause // See: https://spdx.org/licenses/ -#ifndef PORTS_H_ -#define PORTS_H_ +#ifndef INCLUDE_PORTS_H_ +#define INCLUDE_PORTS_H_ + +#include +#include #include @@ -12,7 +15,7 @@ namespace message_infrastructure { class AbstractCppPort : public AbstractPortImplementation { - public: + public: virtual std::vector GetPorts(); std::vector ports_; @@ -20,7 +23,7 @@ class AbstractCppPort : public AbstractPortImplementation { class AbstractCppIOPort : public AbstractCppPort { - public: + public: std::vector GetPorts(); std::vector ports_; @@ -28,7 +31,7 @@ class AbstractCppIOPort : public AbstractCppPort { class CppInPort : public AbstractCppIOPort { - public: + public: bool Probe(); virtual std::vector<> Peek(); virtual std::vector<> Recv(); @@ -42,35 +45,35 @@ class CppInPort : public AbstractCppIOPort { }; class CppInPortVectorDense : public CppInPort { - public: + public: std::vector Recv(); std::vector Peek(); }; class CppInPortVectorSparse : public CppInPort { - public: + public: std::vector Recv(); std::vector Peek(); }; class CppInPortScalarDense : public CppInPort { - public: + public: std::vector Recv(); std::vector Peek(); }; class CppInPortScalarSparse : public CppInPort { - public: + public: std::vector Recv(); std::vector Peek(); }; class CppOutPort : public AbstractCppIOPort { - public: + public: virtual std::vector Send(); virtual void Flush(); @@ -82,25 +85,25 @@ class CppOutPort : public AbstractCppIOPort { class CppOutPortVectorDense : public CppOutPort { - public: + public: std::vector Send(); }; class CppOutPortVectorSparse : public CppOutPort { - public: + public: std::vector Send(); }; class CppOutPortScalarDense : public CppOutPort { - public: + public: int Send(); }; class CppOutPortScalarSparse : public CppOutPort { - public: + public: int Send(); }; @@ -111,7 +114,7 @@ class CppOutPortScalarSparse : public CppOutPort { // Process. It is used to get or set the value of the referenced Var across // Processes. class CppRefPort : public AbstractCppPort { - public: + public: std::vector GetPorts(); virtual Read(); virtual Write(); @@ -125,28 +128,28 @@ class CppRefPort : public AbstractCppPort { class CppRefPortVectorDense : public CppRefPort { - public: + public: std::vector Read(); std::vector Write(); }; class CppRefPortVectorSparse : public CppRefPort { - public: + public: std::vector Read(); std::vector Write(); }; class CppRefPortScalarDense : public CppRefPort { - public: + public: int Read(); std::vector Write(); }; class CppRefPortScalarSparse : public CppRefPort { - public: + public: std::vector Read(); std::vector Write(); }; @@ -162,7 +165,7 @@ class CppRefPortScalarSparse : public CppRefPort { // CppVarPort. CppVarPort set or send the value of the linked Var (service()) // given the command VarPortCmd received by a connected CppRefPort. class CppVarPort : public AbstractCppPort { - public: + public: std::vector GetCspPorts(); virtual void Service(); @@ -178,31 +181,31 @@ class CppVarPort : public AbstractCppPort { }; class CppVarPortVectorDense : public CppVarPort { - public: + public: void Service(); }; class CppVarPortVectorSparse : public CppVarPort { - public: + public: std::vector Recv(); std::vector Peek(); - void Service(); + void Service(); }; class CppVarPortScalarDense : public CppVarPort { - public: + public: int Recv(); int Peek(); - void Service(); + void Service(); }; class CppVarPortScalarSparse : public CppVarPort { - public: + public: std::vector Recv(); std::vector Peek(); - void Service(); + void Service(); }; -} // namespace message_infrastructure +} // namespace message_infrastructure -#endif +#endif // PORTS_H_ From d65b78834764e2fb93d1c05bdd96bc934bbcc042 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Mon, 15 Aug 2022 09:52:55 +0800 Subject: [PATCH 09/31] Updated pybind11 for numpy arrays --- .../message_infrastructure/csrc/ports.h | 42 +++++++++---------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index 398dc11bb..b91e007c5 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -33,8 +33,8 @@ class AbstractCppIOPort : public AbstractCppPort { class CppInPort : public AbstractCppIOPort { public: bool Probe(); - virtual std::vector<> Peek(); - virtual std::vector<> Recv(); + virtual std::vector Peek(); + virtual std::vector Recv(); const CppInPortVectorDense VEC_DENSE; const CppInPortVectorSparse VEC_SPARSE; @@ -46,35 +46,35 @@ class CppInPort : public AbstractCppIOPort { class CppInPortVectorDense : public CppInPort { public: - std::vector Recv(); - std::vector Peek(); + std::vector Recv(); + std::vector Peek(); }; class CppInPortVectorSparse : public CppInPort { public: - std::vector Recv(); - std::vector Peek(); + std::vector Recv(); + std::vector Peek(); }; class CppInPortScalarDense : public CppInPort { public: - std::vector Recv(); - std::vector Peek(); + std::vector Recv(); + std::vector Peek(); }; class CppInPortScalarSparse : public CppInPort { public: - std::vector Recv(); - std::vector Peek(); + std::vector Recv(); + std::vector Peek(); }; class CppOutPort : public AbstractCppIOPort { public: - virtual std::vector Send(); + virtual std::vector> Send(); virtual void Flush(); const CppOutPortVectorDense VEC_DENSE; @@ -86,13 +86,13 @@ class CppOutPort : public AbstractCppIOPort { class CppOutPortVectorDense : public CppOutPort { public: - std::vector Send(); + std::vector> Send(); }; class CppOutPortVectorSparse : public CppOutPort { public: - std::vector Send(); + std::vector> Send(); }; @@ -129,29 +129,29 @@ class CppRefPort : public AbstractCppPort { class CppRefPortVectorDense : public CppRefPort { public: - std::vector Read(); - std::vector Write(); + std::vector Read(); + std::vector Write(); }; class CppRefPortVectorSparse : public CppRefPort { public: - std::vector Read(); - std::vector Write(); + std::vector Read(); + std::vector Write(); }; class CppRefPortScalarDense : public CppRefPort { public: int Read(); - std::vector Write(); + std::vector Write(); }; class CppRefPortScalarSparse : public CppRefPort { public: std::vector Read(); - std::vector Write(); + std::vector Write(); }; // -------- @@ -187,8 +187,8 @@ class CppVarPortVectorDense : public CppVarPort { class CppVarPortVectorSparse : public CppVarPort { public: - std::vector Recv(); - std::vector Peek(); + std::vector> Recv(); + std::vector> Peek(); void Service(); }; From ff915b6fdba9ecbc1e1c5a2a7f9af2177830db8d Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Mon, 15 Aug 2022 10:05:58 +0800 Subject: [PATCH 10/31] Fixed cpplint issues --- .../message_infrastructure/csrc/ports.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index b91e007c5..041e9aa85 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -2,8 +2,8 @@ // SPDX-License-Identifier: BSD-3-Clause // See: https://spdx.org/licenses/ -#ifndef INCLUDE_PORTS_H_ -#define INCLUDE_PORTS_H_ +#ifndef PORTS_H_ +#define PORTS_H_ #include #include From 2cc8c94ddd3f490f6daf6df952318c09f48c24ee Mon Sep 17 00:00:00 2001 From: shaline-koh Date: Mon, 15 Aug 2022 14:21:02 +0800 Subject: [PATCH 11/31] Added lambda functions --- .../message_infrastructure/include/ports.h | 8 +++--- .../message_infrastructure/src/ports.cc | 27 ++++++++++++++++++- 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/include/ports.h b/src/lava/magma/runtime/message_infrastructure/include/ports.h index a453c74d8..05c63b6f1 100644 --- a/src/lava/magma/runtime/message_infrastructure/include/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/include/ports.h @@ -57,15 +57,15 @@ class CppInPortVectorSparse : public CppInPort { class CppInPortScalarDense : public CppInPort { public: - std::vector Recv(); - std::vector Peek(); + int Recv(); + int Peek(); }; class CppInPortScalarSparse : public CppInPort { public: - std::vector Recv(); - std::vector Peek(); + std::vector Recv(); + std::vector Peek(); }; diff --git a/src/lava/magma/runtime/message_infrastructure/src/ports.cc b/src/lava/magma/runtime/message_infrastructure/src/ports.cc index 4b2ba2109..ec371542f 100644 --- a/src/lava/magma/runtime/message_infrastructure/src/ports.cc +++ b/src/lava/magma/runtime/message_infrastructure/src/ports.cc @@ -11,9 +11,34 @@ std::vector AbstractCppIOPort::GetPorts() { return this->ports_; } +ndarray AbstractTransformer::Transform(ndarray data){ + +} bool CppInPort::Probe() { - return; + auto lambda = [&](int acc, int port){return acc && port->Probe();}; + return std::accumulate(ports_.begin(), ports_.end(), true, lambda); +} + //TODO: Implement transform and change ndarray type +ndarray CppInPortVectorDense::Recv(){ + auto lambda = [&](int acc, int port){return acc + port->Transform();} +} + +int CppInPortScalarDense::Recv() { +} + +int CppInPortScalarDense::Peek() { +} + +std::vector CppInPortScalarSparse::Recv(){ } +std::vector CppInPortScalarSparse::Peek(){ +} + +std::vector CppOutPortVectorDense::Send(ndarray data){ + for (auto port : this->ports_){ + port->Send(data); + } +} } From 3cdf7bb465a31c298e8f29422ecde8870f3306f0 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Mon, 15 Aug 2022 14:45:40 +0800 Subject: [PATCH 12/31] Fix linting issues in Ports.h and Abstract Port cc file --- .../csrc/abstract_port_implementation.cc | 2 +- .../message_infrastructure/csrc/ports.h | 16 ++-------------- 2 files changed, 3 insertions(+), 15 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/abstract_port_implementation.cc b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/abstract_port_implementation.cc index 3d150ff5d..6b32f0559 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/abstract_port_implementation.cc +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/abstract_port_implementation.cc @@ -22,4 +22,4 @@ std::vector AbstractPortImplementation::GetShape() { return this->shape_; } -} // namespace message_infrastrature \ No newline at end of file +} // namespace message_infrastrature \ No newline at end of file diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index a86e7c6d2..9db5d37bf 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -59,28 +59,16 @@ class CppInPortVectorSparse : public CppInPort { class CppInPortScalarDense : public CppInPort { -<<<<<<< HEAD:src/lava/magma/runtime/message_infrastructure/include/ports.h - public: + public: int Recv(); int Peek(); -======= - public: - std::vector Recv(); - std::vector Peek(); ->>>>>>> ff915b6fdba9ecbc1e1c5a2a7f9af2177830db8d:src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h }; class CppInPortScalarSparse : public CppInPort { -<<<<<<< HEAD:src/lava/magma/runtime/message_infrastructure/include/ports.h - public: + public: std::vector Recv(); std::vector Peek(); -======= - public: - std::vector Recv(); - std::vector Peek(); ->>>>>>> ff915b6fdba9ecbc1e1c5a2a7f9af2177830db8d:src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h }; From c8febba83da0bb15523ca9907f0f9a00b1468c05 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Mon, 15 Aug 2022 15:35:35 +0800 Subject: [PATCH 13/31] Added Python wrapper functions --- .../csrc/message_infrastructure_py_wrapper.cc | 84 ++++++++++++++++++- .../message_infrastructure/csrc/ports.h | 6 +- 2 files changed, 86 insertions(+), 4 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc index fed050245..74db29d52 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc @@ -42,7 +42,89 @@ PYBIND11_MODULE(MessageInfrastructurePywrapper, m) { .def("get_dstport", &ShmemChannel::GetDstPort, return_value_policy::reference); m.def("get_shmemchannel", &GetShmemChannel, return_value_policy::reference); */ + + py::class_ (m, "AbstractCppPort") + .def(py::init<>()); + + py::class_ (m, "AbstractCppIOPort") + .def("ports", &AbstractCppIOPort::GetPorts); + + py::class_ (m, "CppInPort") + .def("probe", &CppInPort::Probe); + + py::class_ (m, "CppInPortVectorDense") + .def("recv", &CppInPortVectorDense::Recv) + .def("peek", &CppInPortVectorDense::Peek); + + py::class_ (m, "CppInPortVectorSparse") + .def("recv", &CppInPortVectorSparse::Recv) + .def("peek", &CppInPortVectorSparse::Peek); + + py::class_ (m, "CppInPortScalarDense") + .def("recv", &CppInPortScalarDense::Recv) + .def("peek", &CppInPortScalarDense::Peek); + + py::class_ (m, "CppInPortScalarSparse") + .def("recv", &CppInPortScalarSparse::Recv) + .def("peek", &CppInPortScalarSparse::Peek); + + py::class_ (m, "CppOutPort") + .def(py::init<>()); + + py::class_ (m, "CppOutPortVectorDense") + .def("send", &CppOutPortVectorDense::Send); + + py::class_ (m, "CppOutPortVectorSparse") + .def("send", &CppOutPortVectorSparse::Send); + + py::class_ (m, "CppOutPortScalarDense") + .def("send", &CppOutPortScalarDense::Send); + + py::class_ (m, "CppOutPortScalarSparse") + .def("send", &CppOutPortScalarSparse::Send); + + py::class_ (m, "CppRefPort") + .def(py::init<>()) + .def("ports", &CppRefPort::GetPorts); + + py::class_ (m, "CppRefPortVectorDense") + .def("read", &CppRefPortVectorDense::Read) + .def("write", &CppRefPortVectorDense::Write); + + py::class_ (m, "CppRefPortVectorSparse") + .def("read", &CppRefPortVectorSparse::Read) + .def("write", &CppRefPortVectorSparse::Write); + + py::class_ (m, "CppRefPortScalarDense") + .def("read", &CppRefPortScalarDense::Read) + .def("write", &CppRefPortScalarDense::Write); + + py::class_ (m, "CppRefPortScalarSparse") + .def("read", &CppRefPortScalarSparse::Read) + .def("write", &CppRefPortScalarSparse::Write); + + py::class_ (m, "CppVarPort") + .def(py::init<>()) + .def("csp_ports", &CppVarPort::GetCspPorts); + + py::class_ (m, "CppVarPortVectorDense") + .def("service", &CppVarPortVectorDense::Service); + + py::class_ (m, "CppVarPortVectorSparse") + .def("recv", &CppVarPortVectorSparse::Recv) + .def("peek", &CppVarPortVectorSparse::Peek) + .def("service", &CppVarPortVectorSparse::Service); + + py::class_ (m, "CppVarPortScalarDense") + .def("recv", &CppVarPortScalarDense::Recv) + .def("peek", &CppVarPortScalarDense::Peek) + .def("service", &CppVarPortScalarDense::Service); + + py::class_ (m, "CppVarPortScalarSparse") + .def("recv", &CppVarPortScalarSparse::Recv) + .def("peek", &CppVarPortScalarSparse::Peek) + .def("service", &CppVarPortScalarSparse::Service); } -} // namespace message_infrastructure +} // namespace message_infrastructure diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index 9db5d37bf..52ed3d217 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -116,9 +116,9 @@ class CppOutPortScalarSparse : public CppOutPort { class CppRefPort : public AbstractCppPort { public: std::vector GetPorts(); - virtual Read(); - virtual Write(); - virtual Wait(); + virtual std::vector Read(); + virtual std::vector Write(); + virtual void Wait(); const CppRefPortVectorDense VEC_DENSE; const CppRefPortVectorSparse VEC_SPARSE; From bebd2f95099dbe4bd3f1845c12ae501c3c88acb7 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Mon, 15 Aug 2022 15:43:21 +0800 Subject: [PATCH 14/31] Added Pybind dtype for AbstractPortImplementation --- .../csrc/abstract_port_implementation.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/abstract_port_implementation.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/abstract_port_implementation.h index a16baef74..2c344ed17 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/abstract_port_implementation.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/abstract_port_implementation.h @@ -5,6 +5,9 @@ #ifndef ABSTRACT_PORT_IMPLEMENTATION_H_ #define ABSTRACT_PORT_IMPLEMENTATION_H_ +#include +#include + #include #include "abstract_port.h" @@ -19,7 +22,7 @@ class AbstractPortImplementation { std::vector GetShape(); virtual std::vector GetPorts(); - DataType dtype_; + pybind11::dtype dtype_; std::vector shape_; size_t size_; ProcessModel process_model_; From cd50a84c6b3c6d7ac68c0feaad5bd264081ec0a4 Mon Sep 17 00:00:00 2001 From: shaline-koh Date: Mon, 15 Aug 2022 16:03:37 +0800 Subject: [PATCH 15/31] Added tranformer header file --- .../message_infrastructure/csrc/transformer.h | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/transformer.h diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/transformer.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/transformer.h new file mode 100644 index 000000000..2d56593c9 --- /dev/null +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/transformer.h @@ -0,0 +1,35 @@ +// Copyright (C) 2021 Intel Corporation +// SPDX-License-Identifier: BSD-3-Clause +// See: https://spdx.org/licenses/ + +#ifndef TRANSFORMER_H_ +#define TRANSFORMER_H_ + +#include +#include + +#include + +#include "abstract_port_implementation.h" + +namespace message_infrastructure { + +class AbstractTransformer{ + public: + virtual std::vector> Transform(); +}; + +class IdentityTransformer: public AbstractTransformer { + public: + std::vector> Transform(); +}; + +class VirtualPortTransformer: public AbstractTransformer { + public: + std::vector> Transform(); + std::vector> _Get_Transform(); +}; + +} // namespace message_infrastructure + +#endif // TRANSFORMER_H_ From 1c348c1b8238ffd0988a4f321ca68b8934a6e8ad Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Mon, 15 Aug 2022 16:12:01 +0800 Subject: [PATCH 16/31] Updated transformers with parameters --- .../message_infrastructure/csrc/ports.cc | 3 --- .../message_infrastructure/csrc/transformer.cc | 15 +++++++++++++++ .../message_infrastructure/csrc/transformer.h | 9 ++++++--- 3 files changed, 21 insertions(+), 6 deletions(-) create mode 100644 src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/transformer.cc diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.cc b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.cc index ec371542f..f0637a33e 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.cc +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.cc @@ -11,9 +11,6 @@ std::vector AbstractCppIOPort::GetPorts() { return this->ports_; } -ndarray AbstractTransformer::Transform(ndarray data){ - -} bool CppInPort::Probe() { auto lambda = [&](int acc, int port){return acc && port->Probe();}; return std::accumulate(ports_.begin(), ports_.end(), true, lambda); diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/transformer.cc b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/transformer.cc new file mode 100644 index 000000000..1a03435e9 --- /dev/null +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/transformer.cc @@ -0,0 +1,15 @@ +// Copyright (C) 2021-22 Intel Corporation +// SPDX-License-Identifier: BSD-3-Clause +// See: https://spdx.org/licenses/ + +#include + +namespace message_infrastructure { + +// IdentityTransformer +std::vector> + IdentityTransformer::Transform(pybind11::array_t data) { + return data; +} + +} // namespace message_infrastructure \ No newline at end of file diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/transformer.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/transformer.h index 2d56593c9..d86c2f71e 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/transformer.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/transformer.h @@ -16,17 +16,20 @@ namespace message_infrastructure { class AbstractTransformer{ public: - virtual std::vector> Transform(); + virtual std::vector> + Transform(pybind11::array_t data); }; class IdentityTransformer: public AbstractTransformer { public: - std::vector> Transform(); + std::vector> + Transform(pybind11::array_t data); }; class VirtualPortTransformer: public AbstractTransformer { public: - std::vector> Transform(); + std::vector> + Transform(pybind11::array_t data); std::vector> _Get_Transform(); }; From 76eb9d825eeb65bb29f7e204e1848adeb82bb8ff Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Tue, 16 Aug 2022 09:14:39 +0800 Subject: [PATCH 17/31] Add missing include in PyWrapper --- .../csrc/message_infrastructure_py_wrapper.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc index 74db29d52..df5e9b0f7 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc @@ -9,6 +9,8 @@ // #include "shm.h" // #include "shmem_channel.h" // #include "shmem_port.h" +#include "ports.h" +#include "transformer.h" namespace message_infrastructure { From 0c05fac912bb43809f2e6afc6e1155daed921a26 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Tue, 16 Aug 2022 09:15:29 +0800 Subject: [PATCH 18/31] Add namespace for ports.cc --- .../message_infrastructure/message_infrastructure/csrc/ports.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.cc b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.cc index f0637a33e..bc0d94584 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.cc +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.cc @@ -38,4 +38,4 @@ std::vector CppOutPortVectorDense::Send(ndarray data){ } } -} +} // namespace message_infrastructure From d719a11a46e8448540c62425b363fdfc4422920c Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Tue, 16 Aug 2022 09:49:27 +0800 Subject: [PATCH 19/31] Add different types of Read() --- .../message_infrastructure/message_infrastructure/csrc/ports.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index 52ed3d217..e4812e3ce 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -117,6 +117,8 @@ class CppRefPort : public AbstractCppPort { public: std::vector GetPorts(); virtual std::vector Read(); + virtual int Read(); + virtual std::vector Read(); virtual std::vector Write(); virtual void Wait(); From 33a31075c0563e88fcb67a6d340f841628d585a3 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Tue, 16 Aug 2022 09:53:34 +0800 Subject: [PATCH 20/31] Add transformer include and null to constants --- .../message_infrastructure/csrc/ports.h | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index e4812e3ce..b944c4421 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -11,6 +11,7 @@ #include #include "abstract_port_implementation.h" +#include "transformer.h" namespace message_infrastructure { @@ -77,10 +78,10 @@ class CppOutPort : public AbstractCppIOPort { virtual std::vector> Send(); virtual void Flush(); - const CppOutPortVectorDense VEC_DENSE; - const CppOutPortVectorSparse VEC_SPARSE; - const CppOutPortScalarDense SCALAR_DENSE; - const CppOutPortScalarSparse SCALAR_SPARSE; + const CppOutPortVectorDense VEC_DENSE = NULL; + const CppOutPortVectorSparse VEC_SPARSE = NULL; + const CppOutPortScalarDense SCALAR_DENSE = NULL; + const CppOutPortScalarSparse SCALAR_SPARSE = NULL; }; @@ -122,10 +123,10 @@ class CppRefPort : public AbstractCppPort { virtual std::vector Write(); virtual void Wait(); - const CppRefPortVectorDense VEC_DENSE; - const CppRefPortVectorSparse VEC_SPARSE; - const CppRefPortScalarDense SCALAR_DENSE; - const CppRefPortScalarSparse SCALAR_SPARSE; + const CppRefPortVectorDense VEC_DENSE = NULL; + const CppRefPortVectorSparse VEC_SPARSE = NULL; + const CppRefPortScalarDense SCALAR_DENSE = NULL; + const CppRefPortScalarSparse SCALAR_SPARSE = NULL; }; @@ -171,10 +172,10 @@ class CppVarPort : public AbstractCppPort { std::vector GetCspPorts(); virtual void Service(); - const CppVarPortVectorDense VEC_DENSE; - const CppVarPortVectorSparse VEC_SPARSE; - const CppVarPortScalarDense SCALAR_DENSE; - const CppVarPortScalarSparse SCALAR_SPARSE; + const CppVarPortVectorDense VEC_DENSE = NULL; + const CppVarPortVectorSparse VEC_SPARSE = NULL; + const CppVarPortScalarDense SCALAR_DENSE = NULL; + const CppVarPortScalarSparse SCALAR_SPARSE = NULL; AbstractTransformer transformer_; CspSendPort csp_send_port_; From 4e8946e15ba69a1a6cba1b736773e434a9e2e488 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Tue, 16 Aug 2022 10:31:02 +0800 Subject: [PATCH 21/31] Swap naming of classes in PyWrapper --- .../csrc/message_infrastructure_py_wrapper.cc | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc index df5e9b0f7..6d26e6efa 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc @@ -45,84 +45,84 @@ PYBIND11_MODULE(MessageInfrastructurePywrapper, m) { m.def("get_shmemchannel", &GetShmemChannel, return_value_policy::reference); */ - py::class_ (m, "AbstractCppPort") + py::class_ (m, "AbstractPyPort") .def(py::init<>()); - py::class_ (m, "AbstractCppIOPort") + py::class_ (m, "AbstractPyIOPort") .def("ports", &AbstractCppIOPort::GetPorts); - py::class_ (m, "CppInPort") + py::class_ (m, "PyInPort") .def("probe", &CppInPort::Probe); - py::class_ (m, "CppInPortVectorDense") + py::class_ (m, "PyInPortVectorDense") .def("recv", &CppInPortVectorDense::Recv) .def("peek", &CppInPortVectorDense::Peek); - py::class_ (m, "CppInPortVectorSparse") + py::class_ (m, "PyInPortVectorSparse") .def("recv", &CppInPortVectorSparse::Recv) .def("peek", &CppInPortVectorSparse::Peek); - py::class_ (m, "CppInPortScalarDense") + py::class_ (m, "PyInPortScalarDense") .def("recv", &CppInPortScalarDense::Recv) .def("peek", &CppInPortScalarDense::Peek); - py::class_ (m, "CppInPortScalarSparse") + py::class_ (m, "PyInPortScalarSparse") .def("recv", &CppInPortScalarSparse::Recv) .def("peek", &CppInPortScalarSparse::Peek); - py::class_ (m, "CppOutPort") + py::class_ (m, "PyOutPort") .def(py::init<>()); - py::class_ (m, "CppOutPortVectorDense") + py::class_ (m, "PyOutPortVectorDense") .def("send", &CppOutPortVectorDense::Send); - py::class_ (m, "CppOutPortVectorSparse") + py::class_ (m, "PyOutPortVectorSparse") .def("send", &CppOutPortVectorSparse::Send); - py::class_ (m, "CppOutPortScalarDense") + py::class_ (m, "PyOutPortScalarDense") .def("send", &CppOutPortScalarDense::Send); - py::class_ (m, "CppOutPortScalarSparse") + py::class_ (m, "PyOutPortScalarSparse") .def("send", &CppOutPortScalarSparse::Send); - py::class_ (m, "CppRefPort") + py::class_ (m, "PyRefPort") .def(py::init<>()) .def("ports", &CppRefPort::GetPorts); - py::class_ (m, "CppRefPortVectorDense") + py::class_ (m, "PyRefPortVectorDense") .def("read", &CppRefPortVectorDense::Read) .def("write", &CppRefPortVectorDense::Write); - py::class_ (m, "CppRefPortVectorSparse") + py::class_ (m, "PyRefPortVectorSparse") .def("read", &CppRefPortVectorSparse::Read) .def("write", &CppRefPortVectorSparse::Write); - py::class_ (m, "CppRefPortScalarDense") + py::class_ (m, "PyRefPortScalarDense") .def("read", &CppRefPortScalarDense::Read) .def("write", &CppRefPortScalarDense::Write); - py::class_ (m, "CppRefPortScalarSparse") + py::class_ (m, "PyRefPortScalarSparse") .def("read", &CppRefPortScalarSparse::Read) .def("write", &CppRefPortScalarSparse::Write); - py::class_ (m, "CppVarPort") + py::class_ (m, "PyVarPort") .def(py::init<>()) .def("csp_ports", &CppVarPort::GetCspPorts); - py::class_ (m, "CppVarPortVectorDense") + py::class_ (m, "PyVarPortVectorDense") .def("service", &CppVarPortVectorDense::Service); - py::class_ (m, "CppVarPortVectorSparse") + py::class_ (m, "PyVarPortVectorSparse") .def("recv", &CppVarPortVectorSparse::Recv) .def("peek", &CppVarPortVectorSparse::Peek) .def("service", &CppVarPortVectorSparse::Service); - py::class_ (m, "CppVarPortScalarDense") + py::class_ (m, "PyVarPortScalarDense") .def("recv", &CppVarPortScalarDense::Recv) .def("peek", &CppVarPortScalarDense::Peek) .def("service", &CppVarPortScalarDense::Service); - py::class_ (m, "CppVarPortScalarSparse") + py::class_ (m, "PyVarPortScalarSparse") .def("recv", &CppVarPortScalarSparse::Recv) .def("peek", &CppVarPortScalarSparse::Peek) .def("service", &CppVarPortScalarSparse::Service); From da6df89a77e313fde60146f68a9dc4daf942953c Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Tue, 16 Aug 2022 10:44:12 +0800 Subject: [PATCH 22/31] Test variant on return types --- .../message_infrastructure/csrc/ports.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index b944c4421..8c474b35a 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -9,6 +9,7 @@ #include #include +#include #include "abstract_port_implementation.h" #include "transformer.h" @@ -34,7 +35,8 @@ class AbstractCppIOPort : public AbstractCppPort { class CppInPort : public AbstractCppIOPort { public: bool Probe(); - virtual std::vector Peek(); + virtual std::variant, int> Peek(); + // virtual std::vector Peek(); virtual std::vector Recv(); const CppInPortVectorDense VEC_DENSE; From 516cc28bdd70114d814a4c0291e612b4be372ce6 Mon Sep 17 00:00:00 2001 From: shaline-koh Date: Tue, 16 Aug 2022 13:57:58 +0800 Subject: [PATCH 23/31] Added Python wrapper for transformer class --- .../csrc/message_infrastructure_py_wrapper.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc index 6d26e6efa..9d59a2f60 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc @@ -126,7 +126,16 @@ PYBIND11_MODULE(MessageInfrastructurePywrapper, m) { .def("recv", &CppVarPortScalarSparse::Recv) .def("peek", &CppVarPortScalarSparse::Peek) .def("service", &CppVarPortScalarSparse::Service); -} + py::class_ (m, "AbstractTransformer") + .def("transform", &AbstractTransformer::Transform); + + py::class_ (m, "IdentityTransformer") + .def("transform", &IdentityTransformer::Transform); + + py::class_ (m, "VirtualPortTransformer") + .def("transform", &VirtualPortTransformer::Transform) + .def("_get_transform", &VirtualPortTransformer::_Get_Transform); +} } // namespace message_infrastructure From c993f193f2d04982f8935d7e4f74b3905306fa97 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Wed, 17 Aug 2022 11:25:06 +0800 Subject: [PATCH 24/31] Comment out Out/Ref/VarPorts for debugging --- .../csrc/message_infrastructure_py_wrapper.cc | 3 ++- .../message_infrastructure/csrc/ports.h | 27 +++++++++++++------ 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc index 6d26e6efa..e68d0114d 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc @@ -69,7 +69,7 @@ PYBIND11_MODULE(MessageInfrastructurePywrapper, m) { py::class_ (m, "PyInPortScalarSparse") .def("recv", &CppInPortScalarSparse::Recv) .def("peek", &CppInPortScalarSparse::Peek); - + /* py::class_ (m, "PyOutPort") .def(py::init<>()); @@ -126,6 +126,7 @@ PYBIND11_MODULE(MessageInfrastructurePywrapper, m) { .def("recv", &CppVarPortScalarSparse::Recv) .def("peek", &CppVarPortScalarSparse::Peek) .def("service", &CppVarPortScalarSparse::Service); + */ } diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index 8c474b35a..441247216 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -31,18 +31,25 @@ class AbstractCppIOPort : public AbstractCppPort { std::vector ports_; }; +// Forward definition of Vector/Scalar classes +// class CppInPortVectorDense; +// class CppInPortVectorSparse; +// class CppInPortScalarDense; +// class CppInPortScalarSparse; + class CppInPort : public AbstractCppIOPort { public: bool Probe(); - virtual std::variant, int> Peek(); - // virtual std::vector Peek(); - virtual std::vector Recv(); + virtual std::variant, int> Recv(); + // virtual std::variant, int> Peek(); + virtual std::vector Peek(); + // virtual std::vector Recv(); - const CppInPortVectorDense VEC_DENSE; - const CppInPortVectorSparse VEC_SPARSE; - const CppInPortScalarDense SCALAR_DENSE; - const CppInPortScalarSparse SCALAR_SPARSE; + // const CppInPortVectorDense *VEC_DENSE; + // const CppInPortVectorSparse *VEC_SPARSE; + // const CppInPortScalarDense *SCALAR_DENSE; + // const CppInPortScalarSparse *SCALAR_SPARSE; AbstractTransformer transformer_; }; @@ -64,7 +71,8 @@ class CppInPortVectorSparse : public CppInPort { class CppInPortScalarDense : public CppInPort { public: int Recv(); - int Peek(); + std::variant, int> Peek(); + std::vector Peek(); }; @@ -75,6 +83,8 @@ class CppInPortScalarSparse : public CppInPort { }; + +/* class CppOutPort : public AbstractCppIOPort { public: virtual std::vector> Send(); @@ -210,6 +220,7 @@ class CppVarPortScalarSparse : public CppVarPort { std::vector Peek(); void Service(); }; +*/ } // namespace message_infrastructure From 14a051476aa730c0948addf5e3427d32e749f81c Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Wed, 17 Aug 2022 23:29:38 +0800 Subject: [PATCH 25/31] Change to use template for Recv and Peek (CppInPort) --- .../message_infrastructure/csrc/ports.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index 441247216..2a7427403 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -41,17 +41,19 @@ class AbstractCppIOPort : public AbstractCppPort { class CppInPort : public AbstractCppIOPort { public: bool Probe(); - virtual std::variant, int> Recv(); - // virtual std::variant, int> Peek(); - virtual std::vector Peek(); - // virtual std::vector Recv(); + + template + T Recv() {} + + template + T Peek() {} // const CppInPortVectorDense *VEC_DENSE; // const CppInPortVectorSparse *VEC_SPARSE; // const CppInPortScalarDense *SCALAR_DENSE; // const CppInPortScalarSparse *SCALAR_SPARSE; - AbstractTransformer transformer_; + // AbstractTransformer transformer_; }; class CppInPortVectorDense : public CppInPort { @@ -71,8 +73,7 @@ class CppInPortVectorSparse : public CppInPort { class CppInPortScalarDense : public CppInPort { public: int Recv(); - std::variant, int> Peek(); - std::vector Peek(); + int Peek(); }; From 32fed226b4caecc39db9563f5b44a3873af3cd4e Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Thu, 18 Aug 2022 09:31:48 +0800 Subject: [PATCH 26/31] Using pointers for constants --- .../message_infrastructure/csrc/ports.h | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index 2a7427403..b0facadf6 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -32,10 +32,10 @@ class AbstractCppIOPort : public AbstractCppPort { }; // Forward definition of Vector/Scalar classes -// class CppInPortVectorDense; -// class CppInPortVectorSparse; -// class CppInPortScalarDense; -// class CppInPortScalarSparse; +class CppInPortVectorDense; +class CppInPortVectorSparse; +class CppInPortScalarDense; +class CppInPortScalarSparse; class CppInPort : public AbstractCppIOPort { @@ -48,10 +48,10 @@ class CppInPort : public AbstractCppIOPort { template T Peek() {} - // const CppInPortVectorDense *VEC_DENSE; - // const CppInPortVectorSparse *VEC_SPARSE; - // const CppInPortScalarDense *SCALAR_DENSE; - // const CppInPortScalarSparse *SCALAR_SPARSE; + const CppInPortVectorDense *kVecDense; + const CppInPortVectorSparse *kVecSparse; + const CppInPortScalarDense *kScalarDense; + const CppInPortScalarSparse *kScalarSparse; // AbstractTransformer transformer_; }; @@ -84,7 +84,6 @@ class CppInPortScalarSparse : public CppInPort { }; - /* class CppOutPort : public AbstractCppIOPort { public: From babb953fbf230dd97ceca290cb58420f8f69ebb7 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Thu, 18 Aug 2022 14:11:13 +0800 Subject: [PATCH 27/31] Updated templates for all ports --- .../message_infrastructure/csrc/ports.h | 83 +++++++++++++------ 1 file changed, 57 insertions(+), 26 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index b0facadf6..9324d82d6 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -83,29 +83,35 @@ class CppInPortScalarSparse : public CppInPort { std::vector Peek(); }; +// Forward definition of Vector/Scalar classes +class CppOutPortVectorDense; +class CppOutPortVectorSparse; +class CppOutPortScalarDense; +class CppOutPortScalarSparse; -/* class CppOutPort : public AbstractCppIOPort { public: - virtual std::vector> Send(); + template + T Send() {} + virtual void Flush(); - const CppOutPortVectorDense VEC_DENSE = NULL; - const CppOutPortVectorSparse VEC_SPARSE = NULL; - const CppOutPortScalarDense SCALAR_DENSE = NULL; - const CppOutPortScalarSparse SCALAR_SPARSE = NULL; + const CppOutPortVectorDense *kVecDense; + const CppOutPortVectorSparse *kVecSparse; + const CppOutPortScalarDense *kScalarDense; + const CppOutPortScalarSparse *KScalarSparse; }; class CppOutPortVectorDense : public CppOutPort { public: - std::vector> Send(); + pybind11::array_t Send(); }; class CppOutPortVectorSparse : public CppOutPort { public: - std::vector> Send(); + pybind11::array_t Send(); }; @@ -126,19 +132,27 @@ class CppOutPortScalarSparse : public CppOutPort { // A CppRefPort is a Port connected to a VarPort of a variable Var of another // Process. It is used to get or set the value of the referenced Var across // Processes. + +// Forward definition of Vector/Scalar classes +class CppRefPortVectorDense; +class CppRefPortVectorSparse; +class CppRefPortScalarDense; +class CppRefPortScalarSparse; + class CppRefPort : public AbstractCppPort { public: std::vector GetPorts(); - virtual std::vector Read(); - virtual int Read(); - virtual std::vector Read(); + + template + T Read() {} + virtual std::vector Write(); virtual void Wait(); - const CppRefPortVectorDense VEC_DENSE = NULL; - const CppRefPortVectorSparse VEC_SPARSE = NULL; - const CppRefPortScalarDense SCALAR_DENSE = NULL; - const CppRefPortScalarSparse SCALAR_SPARSE = NULL; + const CppRefPortVectorDense *kVecDense; + const CppRefPortVectorSparse *kVecSparse; + const CppRefPortScalarDense *kScalarDense; + const CppRefPortScalarSparse *kScalarSparse; }; @@ -179,34 +193,50 @@ class CppRefPortScalarSparse : public CppRefPort { // CppRefPort to the CppVarPort and the other is used to receive data from the // CppVarPort. CppVarPort set or send the value of the linked Var (service()) // given the command VarPortCmd received by a connected CppRefPort. + +// Forward declaration of Vector/Sparse classes +class CppVarPortVectorDense; +class CppVarPortVectorSparse; +class CppVarPortScalarDense; +class CppVarPortScalarSparse; + class CppVarPort : public AbstractCppPort { public: - std::vector GetCspPorts(); + // std::vector GetCspPorts(); virtual void Service(); - const CppVarPortVectorDense VEC_DENSE = NULL; - const CppVarPortVectorSparse VEC_SPARSE = NULL; - const CppVarPortScalarDense SCALAR_DENSE = NULL; - const CppVarPortScalarSparse SCALAR_SPARSE = NULL; + template + T Recv() {} + + template + T Peek() {} + + const CppVarPortVectorDense *kVecDense; + const CppVarPortVectorSparse *kVecSparse; + const CppVarPortScalarDense *kScalarDense; + const CppVarPortScalarSparse *kScalarSparse; - AbstractTransformer transformer_; - CspSendPort csp_send_port_; - CspRecvPort csp_recv_port_; + // AbstractTransformer transformer_; + // CspSendPort csp_send_port_; + // CspRecvPort csp_recv_port_; char var_name_[]; }; + class CppVarPortVectorDense : public CppVarPort { public: void Service(); }; + class CppVarPortVectorSparse : public CppVarPort { public: - std::vector> Recv(); - std::vector> Peek(); + pybind11::array_t Recv(); + pybind11::array_t Peek(); void Service(); }; + class CppVarPortScalarDense : public CppVarPort { public: int Recv(); @@ -214,13 +244,14 @@ class CppVarPortScalarDense : public CppVarPort { void Service(); }; + class CppVarPortScalarSparse : public CppVarPort { public: std::vector Recv(); std::vector Peek(); void Service(); }; -*/ + } // namespace message_infrastructure From 3d58b774d14833ef5cb3f3a62f0b5d1eb028face Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Thu, 18 Aug 2022 14:15:50 +0800 Subject: [PATCH 28/31] Fixed issue with vectors --- .../message_infrastructure/csrc/ports.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index 9324d82d6..ec8a8f1cc 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -105,13 +105,13 @@ class CppOutPort : public AbstractCppIOPort { class CppOutPortVectorDense : public CppOutPort { public: - pybind11::array_t Send(); + std::vector Send(); }; class CppOutPortVectorSparse : public CppOutPort { public: - pybind11::array_t Send(); + std::vector Send(); }; @@ -231,8 +231,8 @@ class CppVarPortVectorDense : public CppVarPort { class CppVarPortVectorSparse : public CppVarPort { public: - pybind11::array_t Recv(); - pybind11::array_t Peek(); + std::vector Recv(); + std::vector Peek(); void Service(); }; From 1164cdb2c1d7516cfbfe59b95fec78150d65592b Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Thu, 18 Aug 2022 14:24:00 +0800 Subject: [PATCH 29/31] Fix linting issue --- .../message_infrastructure/message_infrastructure/csrc/ports.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h index ec8a8f1cc..c469b0844 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/ports.h @@ -145,7 +145,7 @@ class CppRefPort : public AbstractCppPort { template T Read() {} - + virtual std::vector Write(); virtual void Wait(); From 3cc221007272e2e3c648572e03496f1c0d554680 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Thu, 18 Aug 2022 14:24:22 +0800 Subject: [PATCH 30/31] Uncomment in PyWrapper --- .../csrc/message_infrastructure_py_wrapper.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc index 5ab4a9bd4..b5acc2051 100644 --- a/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc +++ b/src/lava/magma/runtime/message_infrastructure/message_infrastructure/csrc/message_infrastructure_py_wrapper.cc @@ -87,7 +87,7 @@ PYBIND11_MODULE(MessageInfrastructurePywrapper, m) { py::class_ (m, "PyInPortScalarSparse") .def("recv", &CppInPortScalarSparse::Recv) .def("peek", &CppInPortScalarSparse::Peek); - /* + py::class_ (m, "PyOutPort") .def(py::init<>()); @@ -124,8 +124,8 @@ PYBIND11_MODULE(MessageInfrastructurePywrapper, m) { .def("write", &CppRefPortScalarSparse::Write); py::class_ (m, "PyVarPort") - .def(py::init<>()) - .def("csp_ports", &CppVarPort::GetCspPorts); + .def(py::init<>()); + // .def("csp_ports", &CppVarPort::GetCspPorts); py::class_ (m, "PyVarPortVectorDense") .def("service", &CppVarPortVectorDense::Service); @@ -144,7 +144,9 @@ PYBIND11_MODULE(MessageInfrastructurePywrapper, m) { .def("recv", &CppVarPortScalarSparse::Recv) .def("peek", &CppVarPortScalarSparse::Peek) .def("service", &CppVarPortScalarSparse::Service); - */ + + + /* py::class_ (m, "AbstractTransformer") .def("transform", &AbstractTransformer::Transform); @@ -154,6 +156,7 @@ PYBIND11_MODULE(MessageInfrastructurePywrapper, m) { py::class_ (m, "VirtualPortTransformer") .def("transform", &VirtualPortTransformer::Transform) .def("_get_transform", &VirtualPortTransformer::_Get_Transform); + */ } } // namespace message_infrastructure From ab59e6cbd946aea2144aefcf3f8f4d693192b984 Mon Sep 17 00:00:00 2001 From: "Seow, Wen Jie" Date: Thu, 18 Aug 2022 14:30:04 +0800 Subject: [PATCH 31/31] Add AbstractPort, Port and Transformer to CMakeLists --- .../runtime/message_infrastructure/CMakeLists.txt | 12 ++++++++++++ .../magma/runtime/message_infrastructure/pybind11 | 1 + 2 files changed, 13 insertions(+) create mode 160000 src/lava/magma/runtime/message_infrastructure/pybind11 diff --git a/src/lava/magma/runtime/message_infrastructure/CMakeLists.txt b/src/lava/magma/runtime/message_infrastructure/CMakeLists.txt index 0c8a56eab..ee988c9c6 100644 --- a/src/lava/magma/runtime/message_infrastructure/CMakeLists.txt +++ b/src/lava/magma/runtime/message_infrastructure/CMakeLists.txt @@ -9,6 +9,18 @@ set(MULTI_PROC_SRCS "message_infrastructure/csrc/posix_actor.cc" ) +set(ABSTRACT_PORT_SRCS + "message_infrastructure/csrc/abstract_port_implementation.cc" +) + +set(PORT_SRCS + "message_infrastructure/csrc/ports.cc" +) + +set(TRANSFORMER_SRCS + "message_infrastructure/csrc/transformer.cc" +) + file (GLOB PY_WRAPPER "message_infrastructure/csrc/message_infrastructure_py_wrapper.cc") find_package(pybind11 CONFIG) diff --git a/src/lava/magma/runtime/message_infrastructure/pybind11 b/src/lava/magma/runtime/message_infrastructure/pybind11 new file mode 160000 index 000000000..ba5ccd845 --- /dev/null +++ b/src/lava/magma/runtime/message_infrastructure/pybind11 @@ -0,0 +1 @@ +Subproject commit ba5ccd845a2261e538df651e3d528dc1bece094d