-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0581ef2
commit b5b8123
Showing
15 changed files
with
378 additions
and
243 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
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,49 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <vector> | ||
|
||
namespace faabric::mpi { | ||
|
||
enum MpiMessageType : int32_t | ||
{ | ||
NORMAL = 0, | ||
BARRIER_JOIN = 1, | ||
BARRIER_DONE = 2, | ||
SCATTER = 3, | ||
GATHER = 4, | ||
ALLGATHER = 5, | ||
REDUCE = 6, | ||
SCAN = 7, | ||
ALLREDUCE = 8, | ||
ALLTOALL = 9, | ||
SENDRECV = 10, | ||
BROADCAST = 11, | ||
}; | ||
|
||
struct MpiMessage | ||
{ | ||
int32_t id; | ||
int32_t worldId; | ||
int32_t sendRank; | ||
int32_t recvRank; | ||
int32_t typeSize; | ||
int32_t count; | ||
MpiMessageType messageType; | ||
void* buffer; | ||
}; | ||
|
||
inline size_t payloadSize(const MpiMessage& msg) | ||
{ | ||
return msg.typeSize * msg.count; | ||
} | ||
|
||
inline size_t msgSize(const MpiMessage& msg) | ||
{ | ||
return sizeof(MpiMessage) + payloadSize(msg); | ||
} | ||
|
||
void serializeMpiMsg(std::vector<uint8_t>& buffer, const MpiMessage& msg); | ||
|
||
void parseMpiMsg(const std::vector<uint8_t>& bytes, MpiMessage* msg); | ||
} |
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
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
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
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
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,36 @@ | ||
#include <faabric/mpi/MpiMessage.h> | ||
#include <faabric/util/memory.h> | ||
|
||
#include <cassert> | ||
#include <cstdint> | ||
#include <cstring> | ||
|
||
namespace faabric::mpi { | ||
|
||
void parseMpiMsg(const std::vector<uint8_t>& bytes, MpiMessage* msg) | ||
{ | ||
assert(msg != nullptr); | ||
assert(bytes.size() >= sizeof(MpiMessage)); | ||
std::memcpy(msg, bytes.data(), sizeof(MpiMessage)); | ||
size_t thisPayloadSize = bytes.size() - sizeof(MpiMessage); | ||
assert(thisPayloadSize == payloadSize(*msg)); | ||
|
||
if (thisPayloadSize == 0) { | ||
msg->buffer = nullptr; | ||
return; | ||
} | ||
|
||
msg->buffer = faabric::util::malloc(thisPayloadSize); | ||
std::memcpy( | ||
msg->buffer, bytes.data() + sizeof(MpiMessage), thisPayloadSize); | ||
} | ||
|
||
void serializeMpiMsg(std::vector<uint8_t>& buffer, const MpiMessage& msg) | ||
{ | ||
std::memcpy(buffer.data(), &msg, sizeof(MpiMessage)); | ||
size_t payloadSz = payloadSize(msg); | ||
if (payloadSz > 0 && msg.buffer != nullptr) { | ||
std::memcpy(buffer.data() + sizeof(MpiMessage), msg.buffer, payloadSz); | ||
} | ||
} | ||
} |
Oops, something went wrong.