Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert CppIn/Out/Ref/Var-Ports #297

Merged
Merged
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
ca90550
Adding preliminary ports
seowwj Aug 9, 2022
a0c10e6
Added CppPort and CppIOPort
seowwj Aug 10, 2022
e50481d
Add preliminary classes for CppInPorts and CppOutPorts
seowwj Aug 10, 2022
9152359
Add preliminary code for CppRefPorts
seowwj Aug 10, 2022
231d591
Added preliminary CppVarPort class
seowwj Aug 10, 2022
3eac075
Add derived classes for CppVarPort
shaline-koh Aug 10, 2022
b1b3cfc
Update namespace naming
seowwj Aug 11, 2022
406fcfb
Merge branch 'messaging_refactor_develop' of https://github.com/lava-…
seowwj Aug 11, 2022
c7cc0e1
Merge branch 'lava-nc-messaging_refactor_develop' into messaging_refa…
seowwj Aug 11, 2022
7fbc060
Merge branch 'messaging_refactor_develop' of https://github.com/lava-…
seowwj Aug 12, 2022
e1a7f43
Merge branch 'lava-nc-messaging_refactor_develop' into messaging_refa…
seowwj Aug 12, 2022
8901ab1
Fix linting issues
seowwj Aug 12, 2022
d65b788
Updated pybind11 for numpy arrays
seowwj Aug 15, 2022
ff915b6
Fixed cpplint issues
seowwj Aug 15, 2022
2cc8c94
Added lambda functions
shaline-koh Aug 15, 2022
6b93ee3
Merge branch 'messaging_refactor_develop' of https://github.com/seoww…
shaline-koh Aug 15, 2022
3cdf7bb
Fix linting issues in Ports.h and Abstract Port cc file
seowwj Aug 15, 2022
c8febba
Added Python wrapper functions
seowwj Aug 15, 2022
bebd2f9
Added Pybind dtype for AbstractPortImplementation
seowwj Aug 15, 2022
cd50a84
Added tranformer header file
shaline-koh Aug 15, 2022
1c348c1
Updated transformers with parameters
seowwj Aug 15, 2022
76eb9d8
Add missing include in PyWrapper
seowwj Aug 16, 2022
0c05fac
Add namespace for ports.cc
seowwj Aug 16, 2022
d719a11
Add different types of Read()
seowwj Aug 16, 2022
33a3107
Add transformer include and null to constants
seowwj Aug 16, 2022
4e8946e
Swap naming of classes in PyWrapper
seowwj Aug 16, 2022
da6df89
Test variant on return types
seowwj Aug 16, 2022
516cc28
Added Python wrapper for transformer class
shaline-koh Aug 16, 2022
c993f19
Comment out Out/Ref/VarPorts for debugging
seowwj Aug 17, 2022
b64393b
Merge branch 'messaging_refactor_develop' of https://github.com/seoww…
seowwj Aug 17, 2022
8f2d512
Merge pull request #3 from lava-nc/messaging_refactor_develop
seowwj Aug 17, 2022
14a0514
Change to use template for Recv and Peek (CppInPort)
seowwj Aug 17, 2022
32fed22
Using pointers for constants
seowwj Aug 18, 2022
babb953
Updated templates for all ports
seowwj Aug 18, 2022
3d58b77
Fixed issue with vectors
seowwj Aug 18, 2022
1164cdb
Fix linting issue
seowwj Aug 18, 2022
3cc2210
Uncomment in PyWrapper
seowwj Aug 18, 2022
ab59e6c
Add AbstractPort, Port and Transformer to CMakeLists
seowwj Aug 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,4 @@ std::vector<int> AbstractPortImplementation::GetShape() {
return this->shape_;
}

std::vector<PortPtr> AbstractPortImplementation::GetPorts() {
return this->ports_;
}

} // namespace message_infrastructure
} // namespace message_infrastrature
seowwj marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class AbstractPortImplementation {
int Start();
int Join();
std::vector<int> GetShape();
std::vector<PortPtr> GetPorts();
virtual std::vector<PortPtr> GetPorts();

DataType dtype_;
seowwj marked this conversation as resolved.
Show resolved Hide resolved
std::vector<int> shape_;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Copyright (C) 2021-22 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#include <ports.h>
#include <vector>

namespace message_infrastructure {

std::vector<PortPtr> AbstractCppIOPort::GetPorts() {
return this->ports_;
}

bool CppInPort::Probe() {
return;
}


}
seowwj marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,211 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#ifndef PORTS_H_
#define PORTS_H_

#include <pybind11/pybind11.h>
#include <pybind11/numpy.h>

#include <vector>

#include "abstract_port_implementation.h"

namespace message_infrastructure {

class AbstractCppPort : public AbstractPortImplementation {
public:
virtual std::vector<PortPtr> GetPorts();

std::vector<PortPtr> ports_;
};


class AbstractCppIOPort : public AbstractCppPort {
public:
std::vector<PortPtr> GetPorts();

std::vector<PortPtr> ports_;
};


class CppInPort : public AbstractCppIOPort {
public:
bool Probe();
virtual std::vector<pybind11::dtype> Peek();
virtual std::vector<pybind11::dtype> Recv();

const CppInPortVectorDense VEC_DENSE;
const CppInPortVectorSparse VEC_SPARSE;
const CppInPortScalarDense SCALAR_DENSE;
const CppInPortScalarSparse SCALAR_SPARSE;

AbstractTransformer transformer_;
};

class CppInPortVectorDense : public CppInPort {
public:
std::vector<pybind11::dtype> Recv();
std::vector<pybind11::dtype> Peek();
};


class CppInPortVectorSparse : public CppInPort {
public:
std::vector<pybind11::dtype> Recv();
std::vector<pybind11::dtype> Peek();
};


class CppInPortScalarDense : public CppInPort {
public:
std::vector<pybind11::dtype> Recv();
std::vector<pybind11::dtype> Peek();
};


class CppInPortScalarSparse : public CppInPort {
public:
std::vector<pybind11::dtype> Recv();
std::vector<pybind11::dtype> Peek();
};


class CppOutPort : public AbstractCppIOPort {
public:
virtual std::vector<pybind11::array_t<pybind11::dtype>> 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<pybind11::array_t<pybind11::dtype>> Send();
};


class CppOutPortVectorSparse : public CppOutPort {
public:
std::vector<pybind11::array_t<pybind11::dtype>> Send();
};


class CppOutPortScalarDense : public CppOutPort {
public:
int Send();
};


class CppOutPortScalarSparse : public CppOutPort {
public:
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<PortPtr> 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<pybind11::dtype> Read();
std::vector<pybind11::dtype> Write();
};


class CppRefPortVectorSparse : public CppRefPort {
public:
std::vector<pybind11::dtype> Read();
std::vector<pybind11::dtype> Write();
};


class CppRefPortScalarDense : public CppRefPort {
public:
int Read();
std::vector<pybind11::dtype> Write();
};


class CppRefPortScalarSparse : public CppRefPort {
public:
std::vector<int> Read();
std::vector<pybind11::dtype> 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<AbstractCspPort> 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_[];
};

class CppVarPortVectorDense : public CppVarPort {
public:
void Service();
};

class CppVarPortVectorSparse : public CppVarPort {
public:
std::vector<pybind11::array_t<pybind11::dtype>> Recv();
std::vector<pybind11::array_t<pybind11::dtype>> Peek();
void Service();
};

class CppVarPortScalarDense : public CppVarPort {
public:
int Recv();
int Peek();
void Service();
};

class CppVarPortScalarSparse : public CppVarPort {
public:
std::vector<int> Recv();
std::vector<int> Peek();
void Service();
};

} // namespace message_infrastructure

#endif // PORTS_H_