-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #292 from hexu33/messaging_refactor_develop
Initialize cpp_message_infrastruture folder for development
- Loading branch information
Showing
22 changed files
with
437 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
16
src/lava/magma/runtime/cpp_message_infrastructure/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
13 changes: 13 additions & 0 deletions
13
src/lava/magma/runtime/cpp_message_infrastructure/docs/run_example.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` |
40 changes: 40 additions & 0 deletions
40
src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_actor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
22 changes: 22 additions & 0 deletions
22
src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_channel.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
43 changes: 43 additions & 0 deletions
43
src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
31 changes: 31 additions & 0 deletions
31
src/lava/magma/runtime/cpp_message_infrastructure/include/abstract_port_implementation.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
29 changes: 29 additions & 0 deletions
29
src/lava/magma/runtime/cpp_message_infrastructure/include/multiprocessing.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
16 changes: 16 additions & 0 deletions
16
src/lava/magma/runtime/cpp_message_infrastructure/include/process_model.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
15 changes: 15 additions & 0 deletions
15
src/lava/magma/runtime/cpp_message_infrastructure/include/runtime.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
24
src/lava/magma/runtime/cpp_message_infrastructure/include/shm.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
18 changes: 18 additions & 0 deletions
18
src/lava/magma/runtime/cpp_message_infrastructure/include/shmem_channel.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
22 changes: 22 additions & 0 deletions
22
src/lava/magma/runtime/cpp_message_infrastructure/include/shmem_port.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
22
src/lava/magma/runtime/cpp_message_infrastructure/include/utils.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
export PYTHONPATH=${PWD}/build | ||
export LD_LIBRARY_PATH=${PWD}/build |
29 changes: 29 additions & 0 deletions
29
src/lava/magma/runtime/cpp_message_infrastructure/src/abstract_port_implementation.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
23 changes: 23 additions & 0 deletions
23
src/lava/magma/runtime/cpp_message_infrastructure/src/message_infrastructure_py_wrapper.cc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.