-
Notifications
You must be signed in to change notification settings - Fork 1
POSIX Shared Memory implementation #115
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
Open
ritvikrao
wants to merge
17
commits into
main
Choose a base branch
from
shmem-xpmem
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+989
−44
Open
Changes from 15 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
5e1b709
add shared memory functions
ritvikrao 515ea50
fix build for reconverse
ritvikrao 373d330
fix build
ritvikrao 83abfa5
newlines
ritvikrao c91cb16
remove import
ritvikrao ac3c958
remove cmishmem.h
ritvikrao 283de73
CldHandlerIndex is Cpv variable
ritvikrao a6c6e28
cthissuspendable
ritvikrao 76b80fe
cmake change
ritvikrao d1c607e
small fix
ritvikrao 7dc9491
Merge remote-tracking branch 'origin' into shmem-xpmem
ritvikrao 054bdc6
fix scheduling and freeing
ritvikrao 75ce038
Merge branch 'main' into shmem-xpmem
ritvikrao 8135256
merge
ritvikrao e03974b
finish merge
ritvikrao 0f6ce95
Update src/cmishm.cpp
ritvikrao d65339c
fix pointers in whichBin
ritvikrao File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,131 @@ | ||
#ifndef CMI_SHMEM_COMMON_HH | ||
#define CMI_SHMEM_COMMON_HH | ||
|
||
#include "converse_internal.h" | ||
|
||
#include <array> | ||
#include <limits> | ||
#include <map> | ||
#include <memory> | ||
#include <vector> | ||
|
||
|
||
namespace cmi { | ||
namespace ipc { | ||
CpvDeclare(std::size_t, kRecommendedCutoff); | ||
} | ||
} // namespace cmi | ||
|
||
CpvStaticDeclare(std::size_t, kSegmentSize); | ||
constexpr std::size_t kDefaultSegmentSize = 8 * 1024 * 1024; | ||
|
||
constexpr std::size_t kNumCutOffPoints = 25; | ||
const std::array<std::size_t, kNumCutOffPoints> kCutOffPoints = { | ||
64, 128, 256, 512, 1024, 2048, 4096, | ||
8192, 16384, 32768, 65536, 131072, 262144, 524288, | ||
1048576, 2097152, 4194304, 8388608, 16777216, 33554432, 67108864, | ||
134217728, 268435456, 536870912, 1073741824}; | ||
|
||
struct ipc_metadata_; | ||
CsvStaticDeclare(CmiNodeLock, sleeper_lock); | ||
|
||
using sleeper_map_t = std::vector<CthThread>; | ||
CsvStaticDeclare(sleeper_map_t, sleepers); | ||
|
||
// the data each pe shares with its peers | ||
// contains pool of free blocks, heap, and receive queue | ||
struct ipc_shared_ { | ||
std::array<std::atomic<std::uintptr_t>, kNumCutOffPoints> free; | ||
std::atomic<std::uintptr_t> queue; | ||
std::atomic<std::uintptr_t> heap; | ||
std::uintptr_t max; | ||
|
||
ipc_shared_(std::uintptr_t begin, std::uintptr_t end) | ||
: queue(cmi::ipc::max), heap(begin), max(end) { | ||
for (auto& f : this->free) { | ||
f.store(cmi::ipc::max); | ||
} | ||
} | ||
}; | ||
|
||
// shared data for each pe | ||
struct ipc_metadata_ { | ||
// maps ranks to shared segments | ||
std::map<int, ipc_shared_*> shared; | ||
// physical node rank | ||
int mine; | ||
// key of this instance | ||
std::size_t key; | ||
// base constructor | ||
ipc_metadata_(std::size_t key_) : mine(CmiMyNode()), key(key_) {} | ||
// virtual destructor may be needed | ||
virtual ~ipc_metadata_() {} | ||
}; | ||
|
||
inline std::size_t whichBin_(std::size_t size); | ||
|
||
inline static void initIpcShared_(ipc_shared_* shared) { | ||
auto begin = (std::uintptr_t)(sizeof(ipc_shared_) + | ||
(sizeof(ipc_shared_) % ALIGN_BYTES)); | ||
ritvikrao marked this conversation as resolved.
Show resolved
Hide resolved
|
||
CmiAssert(begin != cmi::ipc::nil); | ||
auto end = begin + CpvAccess(kSegmentSize); | ||
new (shared) ipc_shared_(begin, end); | ||
} | ||
|
||
inline static ipc_shared_* makeIpcShared_(void) { | ||
auto* shared = (ipc_shared_*)(::operator new(sizeof(ipc_shared_) + | ||
CpvAccess(kSegmentSize))); | ||
initIpcShared_(shared); | ||
return shared; | ||
} | ||
|
||
inline void initSegmentSize_(char** argv) { | ||
using namespace cmi::ipc; | ||
CpvInitialize(std::size_t, kRecommendedCutoff); | ||
CpvInitialize(std::size_t, kSegmentSize); | ||
|
||
CmiInt8 value; | ||
auto flag = | ||
CmiGetArgLongDesc(argv, "++" CMI_IPC_POOL_SIZE_ARG, &value, CMI_IPC_POOL_SIZE_DESC); | ||
CpvAccess(kSegmentSize) = flag ? (std::size_t)value : kDefaultSegmentSize; | ||
CmiEnforceMsg(CpvAccess(kSegmentSize), "segment size must be non-zero!"); | ||
if (CmiGetArgLongDesc(argv, "++" CMI_IPC_CUTOFF_ARG, &value, CMI_IPC_CUTOFF_DESC)) { | ||
auto bin = whichBin_((std::size_t)value); | ||
CmiEnforceMsg(bin < kNumCutOffPoints, "ipc cutoff out of range!"); | ||
CpvAccess(kRecommendedCutoff) = kCutOffPoints[bin]; | ||
} else { | ||
auto max = CpvAccess(kSegmentSize) / kNumCutOffPoints; | ||
auto bin = (std::intptr_t)whichBin_(max) - 1; | ||
CpvAccess(kRecommendedCutoff) = kCutOffPoints[(bin >= 0) ? bin : 0]; | ||
} | ||
} | ||
|
||
inline static void printIpcStartupMessage_(const char* implName) { | ||
using namespace cmi::ipc; | ||
CmiPrintf("Converse> %s pool init'd with %luB segment and %luB cutoff.\n", | ||
implName, CpvAccess(kSegmentSize), | ||
CpvAccess(kRecommendedCutoff)); | ||
} | ||
|
||
inline static void initSleepers_(void) { | ||
if (CmiMyRank() == 0) { | ||
CsvInitialize(sleeper_map_t, sleepers); | ||
CsvAccess(sleepers).resize(CmiMyNodeSize()); | ||
CsvInitialize(CmiNodeLock, sleeper_lock); | ||
CsvAccess(sleeper_lock) = CmiCreateLock(); | ||
} | ||
} | ||
|
||
inline static void putSleeper_(CthThread th) { | ||
CmiLock(CsvAccess(sleeper_lock)); | ||
(CsvAccess(sleepers))[CmiMyRank()] = th; | ||
CmiUnlock(CsvAccess(sleeper_lock)); | ||
} | ||
|
||
static void awakenSleepers_(void); | ||
|
||
using ipc_manager_ptr_ = std::unique_ptr<CmiIpcManager>; | ||
using ipc_manager_map_ = std::vector<ipc_manager_ptr_>; | ||
CsvStaticDeclare(ipc_manager_map_, managers_); | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.