Skip to content

Commit

Permalink
Merge pull request #292 from hexu33/messaging_refactor_develop
Browse files Browse the repository at this point in the history
Initialize cpp_message_infrastruture folder for development
  • Loading branch information
hexu33 committed Aug 5, 2022
2 parents 0a608fa + aa2fd5d commit bceccfc
Show file tree
Hide file tree
Showing 22 changed files with 437 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "docs"]
path = docs
url = https://github.com/lava-nc/lava-docs.git
[submodule "src/lava/magma/runtime/cpp_message_infrastructure/pybind11"]
path = src/lava/magma/runtime/cpp_message_infrastructure/pybind11
url = https://github.com/pybind/pybind11.git
16 changes: 16 additions & 0 deletions src/lava/magma/runtime/cpp_message_infrastructure/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
cmake_minimum_required(VERSION 2.8.3)
project(message_passing)

set (CMAKE_CXX_STANDARD 17)
include_directories(include)

file (GLOB MULTI_PROC_SRCS "src/multiprocessing.cc")

file (GLOB PY_WRAPPER "src/message_infrastructure_py_wrapper.cc")

add_subdirectory(pybind11)

add_library(multi_processing SHARED ${MULTI_PROC_SRCS})

pybind11_add_module(MessageInfrastructurePywrapper ${PY_WRAPPER})
target_link_libraries(MessageInfrastructurePywrapper PRIVATE multi_processing)
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# An Example for MessageInfrastructurePywrapper

*Welcome to the messaging refactory project, and this will show how an example run*

```
mkdir build
cd build
cmake ..
make
cd ..
source setenv.sh
python test/test_example.py
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#ifndef ABSTACT_ACTOR_H_
#define ABSTACT_ACTOR_H_

namespace message_infrastrature {

class AbstractActor {
public:
virtual int GetPid() = 0;
virtual int Stop() = 0;
virtual int Pause() = 0;

int pid_;
};

class PosixActor : public AbstractActor {
public:
explicit PosixActor(int pid){
this->pid_ = pid;
}
int GetPid(){
return this->pid_;
};
int Stop(){
return 0;
};
int Pause(){
return 0;
};
};

using ActorPtr = AbstractActor *;
using PosixActorPtr = PosixActor *;

} // namespace message_infrastrature

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#ifndef ABSTACT_CHANNEL_H_
#define ABSTACT_CHANNEL_H_

#include "abstract_port.h"
#include "utils.h"
#include <memory>

namespace message_infrastrature {

class AbstractChannel {
public:
std::shared_ptr<AbstractSendPort> src_port_;
std::shared_ptr<AbstractRecvPort> dst_port_;
};

} // namespace message_infrastrature

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#ifndef ABSTRACT_PORT_H_
#define ABSTRACT_PORT_H_

#include <string>
#include <vector>

#include "shm.h"
#include "utils.h"

namespace message_infrastrature {

class AbstractPort {
public:
virtual int Start() = 0;
virtual int Join() = 0;

std::string name_;
DataType dtype_;
std::vector<int> shape_;
size_t size_;
};

class AbstractSendPort : public AbstractPort {
public:
virtual int Send() = 0;
};

class AbstractRecvPort : public AbstractPort {
public:
virtual int Recv() = 0;
};

using PortPtr = AbstractPort *;
using SendPortPtr = AbstractSendPort *;
using RecvPortPtr = AbstractRecvPort *;

} // namespace message_infrastrature

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#ifndef ABSTRACT_PORT_IMPLEMENTATION_H_
#define ABSTRACT_PORT_IMPLEMENTATION_H_

#include <vector>

#include "abstract_port.h"
#include "process_model.h"

namespace message_infrastrature {

class AbstractPortImplementation {
public:
int Start();
int Join();
std::vector<int> GetShape();
std::vector<PortPtr> GetPorts();

DataType dtype_;
std::vector<int> shape_;
size_t size_;
ProcessModel process_model_;
std::vector<PortPtr> ports_;
};

} // namespace message_infrastrature

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#ifndef MULTIPROCESSING_H_
#define MULTIPROCESSING_H_

#include <vector>
#include <functional>

#include "abstract_actor.h"
#include "shm.h"

namespace message_infrastrature {

class MultiProcessing {
public:
// stop each actor in vector actors;
void Stop();
void BuildActor(std::function<void()>);
void CheckActor();
private:
std::vector<ActorPtr> actors_;
//SharedMemManager shmm_;
};

} // namespace message_infrastrature

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#ifndef PROCESS_MODEL_H_
#define PROCESS_MODEL_H_

namespace message_infrastrature {

class ProcessModel {

};

} // namespace message_infrastrature

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#ifndef RUNTIME_H_
#define RUNTIME_H_

namespace message_infrastrature {

class Runtime {
};

} // namespace message_infrastrature

#endif
24 changes: 24 additions & 0 deletions src/lava/magma/runtime/cpp_message_infrastructure/include/shm.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#ifndef SHM_H_
#define SHM_H_

#include <sys/mman.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/shm.h>
#include <fcntl.h>
#include <semaphore.h>
#include <unistd.h>

namespace message_infrastrature {

class SharedMemory {

};

} // namespace message_infrastrature

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#ifndef SHMEM_CHANNEL_H_
#define SHMEM_CHANNEL_H_

#include "abstract_channel.h"

namespace message_infrastrature {

class ShmemChannel : public AbstractChannel {

};

} // namespace message_infrastrature

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#ifndef SHMEM_PORT_H_
#define SHMEM_PORT_H_

#include "abstract_port.h"

namespace message_infrastrature {

class ShmemSendPort : public AbstractSendPort {

};

class ShmemRecvPort : public AbstractRecvPort {

};

} // namespace message_infrastrature

#endif
22 changes: 22 additions & 0 deletions src/lava/magma/runtime/cpp_message_infrastructure/include/utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#ifndef UTILS_H_
#define UTILS_H_

namespace message_infrastrature {

enum ChannelType {
ShmemChannel = 0,
RpcChannel = 1,
DdsChannel = 2
};

enum DataType {
// dtype
};

} // namespace message_infrastrature

#endif
1 change: 1 addition & 0 deletions src/lava/magma/runtime/cpp_message_infrastructure/pybind11
Submodule pybind11 added at ba5ccd
2 changes: 2 additions & 0 deletions src/lava/magma/runtime/cpp_message_infrastructure/setenv.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export PYTHONPATH=${PWD}/build
export LD_LIBRARY_PATH=${PWD}/build
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

#include "abstract_port_implementation.h"

namespace message_infrastrature {

int AbstractPortImplementation::Start() {
for (auto port : this->ports_){
port->Start();
}
}

int AbstractPortImplementation::Join() {
for (auto port : this->ports_){
port->Join();
}
}

std::vector<int> AbstractPortImplementation::GetShape() {
return this->shape_;
}

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

} // namespace message_infrastrature
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright (C) 2021 Intel Corporation
// SPDX-License-Identifier: BSD-3-Clause
// See: https://spdx.org/licenses/

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

#include "multiprocessing.h"
//#include "abstract_port_implementation.h"

namespace message_infrastrature {

namespace py = pybind11;

PYBIND11_MODULE(MessageInfrastructurePywrapper, m) {
py::class_<MultiProcessing> (m, "MultiProcessing")
.def(py::init<>())
.def("build_actor", &MultiProcessing::BuildActor)
.def("check_actor", &MultiProcessing::CheckActor)
.def("stop", &MultiProcessing::Stop);
}

} // namespace message_infrastrature
Loading

0 comments on commit bceccfc

Please sign in to comment.