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

Enhance performacne of cpp msg lib #709

Merged
merged 2 commits into from
Jun 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 11 additions & 2 deletions src/lava/magma/runtime/_c_message_infrastructure/csrc/core/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#endif

#define MAX_ARRAY_DIMS (5)
#define SLEEP_NS (1)
#define SLEEP_MS (1)

#define LAVA_SIZEOF_CHAR (sizeof(char))
#define LAVA_SIZEOF_UCHAR (LAVA_SIZEOF_CHAR)
Expand Down Expand Up @@ -142,11 +142,20 @@ static void Sleep() {
#if defined(ENABLE_MM_PAUSE)
_mm_pause();
#else
std::this_thread::sleep_for(std::chrono::nanoseconds(SLEEP_NS));
std::this_thread::sleep_for(std::chrono::milliseconds(SLEEP_MS));
#endif
}

static void Sleep(int64_t ns) {
#if defined(ENABLE_MM_PAUSE)
_mm_pause();
#else
std::this_thread::sleep_for(std::chrono::nanoseconds(ns));
#endif
}

} // namespace helper

#if defined(DDS_CHANNEL)
// Default Parameters
// Transport
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,14 @@ using RecvPortProxyList = std::vector<RecvPortProxyPtr>;
class Selector {
public:
pybind11::object Select(std::vector<std::tuple<RecvPortProxyPtr,
py::function>> *args) {
py::function>> *args, const int64_t sleep_ns) {
while (true) {
for (auto it = args->begin(); it != args->end(); ++it) {
if (std::get<0>(*it)->Probe()) {
return std::get<1>(*it)();
}
}
helper::Sleep(sleep_ns);
}
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/lava/magma/runtime/message_infrastructure/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,11 @@ def load_library():
AbstractTransferPort, # noqa # nosec
support_grpc_channel,
support_fastdds_channel,
support_cyclonedds_channel,
CPPSelector)
support_cyclonedds_channel)

ChannelQueueSize = 1
SyncChannelBytes = 128
SelectorSleepNs = 1

from .ports import ( # noqa # nosec
SendPort, # noqa # nosec
Expand Down
5 changes: 3 additions & 2 deletions src/lava/magma/runtime/message_infrastructure/ports.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# See: https://spdx.org/licenses/

from lava.magma.runtime.message_infrastructure \
import ChannelQueueSize, CPPSelector
import ChannelQueueSize, SelectorSleepNs
from lava.magma.runtime.message_infrastructure.MessageInfrastructurePywrapper \
import Channel as CppChannel
from lava.magma.runtime.message_infrastructure.MessageInfrastructurePywrapper \
Expand All @@ -14,6 +14,7 @@
support_cyclonedds_channel,
AbstractTransferPort,
ChannelType,
CPPSelector,
RecvPort)

import numpy as np
Expand All @@ -23,7 +24,7 @@

class Selector(CPPSelector):
def select(self, *args: ty.Tuple[RecvPort, ty.Callable[[], ty.Any]]):
return super().select(args)
return super().select(args, SelectorSleepNs)


class SendPort(AbstractTransferPort):
Expand Down