diff --git a/examples/memcpy/local/source/pthreads.cpp b/examples/memcpy/local/source/pthreads.cpp index 92328385..b78f9318 100644 --- a/examples/memcpy/local/source/pthreads.cpp +++ b/examples/memcpy/local/source/pthreads.cpp @@ -17,6 +17,7 @@ #include "include/telephoneGame.hpp" #include #include +#include #include int main(int argc, char **argv) @@ -33,8 +34,12 @@ int main(int argc, char **argv) // Instantiating host (CPU) memory manager HiCR::backend::hwloc::MemoryManager m(&topology); + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // Instantiating host (CPU) communication manager - HiCR::backend::pthreads::CommunicationManager c; + HiCR::backend::pthreads::CommunicationManager c(sharedMemory); // Asking backend to check the available devices const auto t = dm.queryTopology(); diff --git a/examples/neuralNetwork/source/pthreads.cpp b/examples/neuralNetwork/source/pthreads.cpp index e3442f2e..e044b22b 100644 --- a/examples/neuralNetwork/source/pthreads.cpp +++ b/examples/neuralNetwork/source/pthreads.cpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "./include/network.hpp" @@ -27,10 +28,14 @@ int main(int argc, char **argv) hwloc_topology_t hwlocTopology; hwloc_topology_init(&hwlocTopology); + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // Instantiating HWLoc-based host (CPU) topology manager HiCR::backend::hwloc::TopologyManager topologyManager(&hwlocTopology); HiCR::backend::hwloc::MemoryManager memoryManager(&hwlocTopology); - HiCR::backend::pthreads::CommunicationManager communicationManager; + HiCR::backend::pthreads::CommunicationManager communicationManager(sharedMemory); HiCR::backend::pthreads::ComputeManager computeManager; // Asking backend to check the available devices diff --git a/examples/objectStore/singleInstance/source/main.cpp b/examples/objectStore/singleInstance/source/main.cpp index dedd7792..58f443fe 100644 --- a/examples/objectStore/singleInstance/source/main.cpp +++ b/examples/objectStore/singleInstance/source/main.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -32,8 +33,12 @@ int main(int argc, char **argv) // Reserving memory for hwloc hwloc_topology_init(&topology); + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // Using default instance, communication and memory manager for single instance - auto communicationManager = std::make_unique(); + auto communicationManager = std::make_unique(sharedMemory); auto memoryManager = std::make_unique(&topology); // Using HWLoc as topology managers diff --git a/include/hicr/backends/mpi/communicationManager.hpp b/include/hicr/backends/mpi/communicationManager.hpp index 892616ae..40d2611c 100644 --- a/include/hicr/backends/mpi/communicationManager.hpp +++ b/include/hicr/backends/mpi/communicationManager.hpp @@ -163,14 +163,14 @@ class CommunicationManager : public HiCR::CommunicationManager { globalSlotPointers[i] = nullptr; globalSourceSlots[i] = nullptr; - globalMemorySpaces[i] = nullptr; + globalMemorySpaces[i] = nullptr; } else { const auto memorySlot = memorySlots[localPointerPos++].second; globalSlotPointers[i] = &memorySlot->getPointer(); globalSourceSlots[i] = memorySlot; - globalMemorySpaces[i] = memorySlot->getMemorySpace(); + globalMemorySpaces[i] = memorySlot->getMemorySpace(); } } @@ -201,7 +201,7 @@ class CommunicationManager : public HiCR::CommunicationManager // Freeing up memory of the old local memory slot // Commented out: it is the user who must free up this local memory slot - // MPI_Free_mem(*(globalSlotPointers[i])); + // MPI_Free_mem(*(globalSlotPointers[i])); // Swapping pointers *(globalSlotPointers[i]) = ptr; diff --git a/include/hicr/backends/pthreads/communicationManager.hpp b/include/hicr/backends/pthreads/communicationManager.hpp index 6a143597..2deecdd3 100644 --- a/include/hicr/backends/pthreads/communicationManager.hpp +++ b/include/hicr/backends/pthreads/communicationManager.hpp @@ -24,11 +24,14 @@ #pragma once #include -#include "pthread.h" +#include + #include #include #include +#include "sharedMemory.hpp" + namespace HiCR::backend::pthreads { @@ -42,43 +45,24 @@ class CommunicationManager final : public HiCR::CommunicationManager public: /** - * Constructor for the memory manager class for the Pthreads backend + * Constructor for the communication manager class for the pthreads backend * - * \param[in] fenceCount Specifies how many times a fence has to be called for it to release callers + * \param[in] sharedMemory the shared memory used to exchange global slots among other threads */ - CommunicationManager(const size_t fenceCount = 1) - : HiCR::CommunicationManager() - { - // Initializing barrier for fence operation - pthread_barrier_init(&_barrier, nullptr, fenceCount); - - // Initializing mutex object - pthread_mutex_init(&_mutex, nullptr); - } + CommunicationManager(SharedMemory &sharedMemory) + : HiCR::CommunicationManager(), + _sharedMemory(sharedMemory) + {} /** * The destructor deletes all created barrier/mutex locks */ - ~CommunicationManager() override - { - // Freeing barrier memory - pthread_barrier_destroy(&_barrier); - - // Freeing mutex memory - pthread_mutex_destroy(&_mutex); - } + ~CommunicationManager() = default; __INLINE__ std::shared_ptr getGlobalMemorySlotImpl(const HiCR::backend::hwloc::GlobalMemorySlot::tag_t tag, const HiCR::backend::hwloc::GlobalMemorySlot::globalKey_t globalKey) override { - if (_shadowMap.find(tag) != _shadowMap.end()) - { - if (_shadowMap[tag].find(globalKey) != _shadowMap[tag].end()) - return _shadowMap[tag][globalKey]; - else - return nullptr; - } - else { return nullptr; } + return _sharedMemory.get(tag, globalKey); } /** @@ -110,21 +94,8 @@ class CommunicationManager final : public HiCR::CommunicationManager private: - /** - * Stores a barrier object to check on a barrier operation - */ - pthread_barrier_t _barrier{}; - - /** - * A mutex to make sure threads do not bother each other during certain operations - */ - pthread_mutex_t _mutex{}; - __INLINE__ void exchangeGlobalMemorySlotsImpl(const HiCR::GlobalMemorySlot::tag_t tag, const std::vector &memorySlots) override { - // Synchronize all intervening threads in this call - barrier(); - // Simply adding local memory slots to the global map for (const auto &entry : memorySlots) { @@ -139,11 +110,10 @@ class CommunicationManager final : public HiCR::CommunicationManager // Registering memory slot registerGlobalMemorySlot(globalMemorySlot); - _shadowMap[tag][globalKey] = globalMemorySlot; - } - // Do not allow any thread to continue until the exchange is made - barrier(); + // Push it to shared memory + _sharedMemory.insert(tag, globalKey, globalMemorySlot); + } } __INLINE__ void queryMemorySlotUpdatesImpl(std::shared_ptr memorySlot) override @@ -151,17 +121,12 @@ class CommunicationManager final : public HiCR::CommunicationManager // This function should check and update the abstract class for completed memcpy operations } - /** - * A barrier implementation that synchronizes all threads in the HiCR instance - */ - __INLINE__ void barrier() { pthread_barrier_wait(&_barrier); } - /** * Implementation of the fence operation for the pthreads backend. In this case, nothing needs to be done, as * the system's memcpy operation is synchronous. This means that it's mere execution (whether immediate or deferred) * ensures its completion. */ - __INLINE__ void fenceImpl(const HiCR::GlobalMemorySlot::tag_t tag) override { barrier(); } + __INLINE__ void fenceImpl(const HiCR::GlobalMemorySlot::tag_t tag) override { _sharedMemory.barrier(); } __INLINE__ void memcpyImpl(const std::shared_ptr &destination, const size_t dst_offset, @@ -193,7 +158,7 @@ class CommunicationManager final : public HiCR::CommunicationManager */ __INLINE__ void destroyGlobalMemorySlotImpl(std::shared_ptr memorySlot) override { - // Nothing to do here + _sharedMemory.remove(memorySlot->getGlobalTag(), memorySlot->getGlobalKey()); } __INLINE__ void memcpyImpl(const std::shared_ptr &destination, @@ -202,17 +167,11 @@ class CommunicationManager final : public HiCR::CommunicationManager const size_t src_offset, const size_t size) override { - // Getting up-casted pointer for the execution unit - auto dst = dynamic_pointer_cast(destination); - - // Checking whether the execution unit passed is compatible with this backend - if (dst == nullptr) HICR_THROW_LOGIC("The passed destination memory slot is not supported by this backend\n"); - // Checking whether the memory slot is local. This backend only supports local data transfers - if (dst->getSourceLocalMemorySlot() == nullptr) HICR_THROW_LOGIC("The passed destination memory slot is not local (required by this backend)\n"); + if (destination->getSourceLocalMemorySlot() == nullptr) HICR_THROW_LOGIC("The passed destination memory slot is not local (required by this backend)\n"); // Executing actual memcpy - memcpy(dst->getSourceLocalMemorySlot(), dst_offset, source, src_offset, size); + memcpy(destination->getSourceLocalMemorySlot(), dst_offset, source, src_offset, size); // Increasing message received/sent counters for both memory slots increaseMessageRecvCounter(*destination->getSourceLocalMemorySlot()); @@ -225,17 +184,11 @@ class CommunicationManager final : public HiCR::CommunicationManager const size_t src_offset, const size_t size) override { - // Getting up-casted pointer for the execution unit - auto src = dynamic_pointer_cast(source); - - // Checking whether the memory slot is compatible with this backend - if (src == nullptr) HICR_THROW_LOGIC("The passed source memory slot is not supported by this backend\n"); - // Checking whether the memory slot is local. This backend only supports local data transfers - if (src->getSourceLocalMemorySlot() == nullptr) HICR_THROW_LOGIC("The passed source memory slot is not local (required by this backend)\n"); + if (source->getSourceLocalMemorySlot() == nullptr) HICR_THROW_LOGIC("The passed source memory slot is not local (required by this backend)\n"); // Executing actual memcpy - memcpy(destination, dst_offset, src->getSourceLocalMemorySlot(), src_offset, size); + memcpy(destination, dst_offset, source->getSourceLocalMemorySlot(), src_offset, size); // Increasing message received/sent counters for both memory slots increaseMessageRecvCounter(*destination); @@ -266,24 +219,12 @@ class CommunicationManager final : public HiCR::CommunicationManager m->unlock(); } - __INLINE__ void lock() - { - // Locking the pthread mutex - pthread_mutex_lock(&_mutex); - } - - __INLINE__ void unlock() - { - // Locking the pthread mutex - pthread_mutex_unlock(&_mutex); - } - private: - // this map shadows the core HiCR map _globalMemorySlotTagKeyMap - // to support getGlobalMemorySlot implementation - // for this backend - globalMemorySlotTagKeyMap_t _shadowMap; + /** + * Shared Memory to exchange slots + */ + SharedMemory &_sharedMemory; }; } // namespace HiCR::backend::pthreads diff --git a/include/hicr/backends/pthreads/sharedMemory.hpp b/include/hicr/backends/pthreads/sharedMemory.hpp new file mode 100644 index 00000000..99e7793e --- /dev/null +++ b/include/hicr/backends/pthreads/sharedMemory.hpp @@ -0,0 +1,179 @@ +/* + * Copyright 2025 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file sharedMemory.hpp + * @brief This file implements the shared memory mechanism to exchange slots for the pthreads backend + * @author L. Terracciano + * @date 30/9/2025 + */ + +#pragma once + +#include + +#include + +namespace HiCR::backend::pthreads +{ + +/** + * Break circular dependency + */ +class SharedMemoryFactory; + +/** + * Implementation of the Pthreads shared memory space to exchange global memory slots among HiCR instances. + * It holds a shared space among threads involved in the communication where one can exchange, retrieve, and destroy global memory slots + * It can be created only by \ref SharedMemoryFactory + * + * This backend uses pthread-based mutexes and barriers to prevent concurrent access violations + */ +class SharedMemory +{ + /** + * The factory is a friend class that can call the constructor + */ + friend class SharedMemoryFactory; + + public: + + ~SharedMemory() + { + // Destroy barrier + pthread_barrier_destroy(&_barrier); + + // Destroy mutex + pthread_mutex_destroy(&_mutex); + } + + SharedMemory(const SharedMemory &) = delete; + SharedMemory &operator=(const SharedMemory &) = delete; + SharedMemory(SharedMemory &&) = delete; + SharedMemory &operator=(SharedMemory &&) = delete; + + /** + * Add an element into the shared memory space + * + * \param[in] tag slot tag + * \param[in] key slot key + * \param[in] slot global memory slot + */ + __INLINE__ void insert(const GlobalMemorySlot::tag_t tag, const GlobalMemorySlot::globalKey_t key, const std::shared_ptr &slot) + { + // Lock the resource + pthread_mutex_lock(&_mutex); + + // Add the memory slot + _globalMemorySlots[tag][key] = slot; + + // Unlock the resource + pthread_mutex_unlock(&_mutex); + } + + /** + * Retrieve a global memory slot + * + * \param[in] tag slot tag + * \param[in] key slot key + * + * \return shared pointer to global memory slot if present, nullptr otherwise + */ + __INLINE__ std::shared_ptr get(const GlobalMemorySlot::tag_t tag, const GlobalMemorySlot::globalKey_t key) + { + std::shared_ptr value = nullptr; + + // Lock the resource + pthread_mutex_lock(&_mutex); + + // Look for the tag + if (_globalMemorySlots.find(tag) != _globalMemorySlots.end()) + { + // Look for the key + if (_globalMemorySlots[tag].find(key) != _globalMemorySlots[tag].end()) { value = _globalMemorySlots[tag][key]; } + } + + // Unlock the resource + pthread_mutex_unlock(&_mutex); + + return value; + } + + /** + * Removes a global memory slot from the shared memory if present + * + * \param[in] tag slot tag + * \param[in] key slot key + */ + __INLINE__ void remove(const GlobalMemorySlot::tag_t tag, const GlobalMemorySlot::globalKey_t globalKey) + { + // Lock the resource + pthread_mutex_lock(&_mutex); + + // Look for the tag + if (_globalMemorySlots.find(tag) != _globalMemorySlots.end()) + { + // Look for the key + if (_globalMemorySlots[tag].find(globalKey) != _globalMemorySlots[tag].end()) { _globalMemorySlots[tag].erase(globalKey); } + } + + // Unlock the resource + pthread_mutex_unlock(&_mutex); + } + + /** + * A barrier implementation that synchronizes all threads in the HiCR instance + */ + __INLINE__ void barrier() { pthread_barrier_wait(&_barrier); } + + private: + + /** + * Private constructor. Can be called only by \ref SharedMemoryFactory + * + * \param[in] fenceCount barrier size. Indicates how many threads should reach the barrier before continuing + */ + SharedMemory(const size_t fenceCount) + : _fenceCount(fenceCount) + { + // Init barrier + pthread_barrier_init(&_barrier, nullptr, _fenceCount); + + // Init mutex + pthread_mutex_init(&_mutex, nullptr); + } + + /** + * Stores a barrier object to check on a barrier operation + */ + pthread_barrier_t _barrier{}; + + /** + * A mutex to make sure threads do not bother each other during certain operations + */ + pthread_mutex_t _mutex{}; + + /** + * How many threads should reach the fence before proceeding + */ + const size_t _fenceCount; + + /** + * Map to track the exchanged slots among different threads + */ + CommunicationManager::globalMemorySlotTagKeyMap_t _globalMemorySlots; +}; +} // namespace HiCR::backend::pthreads diff --git a/include/hicr/backends/pthreads/sharedMemoryFactory.hpp b/include/hicr/backends/pthreads/sharedMemoryFactory.hpp new file mode 100644 index 00000000..4240d84f --- /dev/null +++ b/include/hicr/backends/pthreads/sharedMemoryFactory.hpp @@ -0,0 +1,109 @@ +/* + * Copyright 2025 Huawei Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +/** + * @file sharedMemoryFactory.hpp + * @brief This file implements the factory to create shared memories to be used for the pthread communication manager + * @author L. Terracciano + * @date 30/9/2025 + */ + +#pragma once + +#include + +#include "sharedMemory.hpp" + +namespace HiCR::backend::pthreads +{ + +/** + * Identifier for shared memory +*/ +using sharedMemoryId_t = uint64_t; + +/** + * Shared memory factory class that creates and holds Shared Memory objects + * + * This backend uses pthread-based mutexes and barriers to prevent concurrent access violations + */ +class SharedMemoryFactory +{ + public: + + /** + * Constructor + */ + SharedMemoryFactory() { pthread_mutex_init(&_mutex, nullptr); } + + /** + * Destructor +*/ + ~SharedMemoryFactory() { pthread_mutex_destroy(&_mutex); } + + /** + * Get a shared memory by its id. If not present, it will create one with the specifiec fence count + * + * \param[in] id shared memory id + * \param[in] fenceCount fence count + * + * \return a shared memory reference + */ + __INLINE__ SharedMemory &get(const sharedMemoryId_t id, const size_t fenceCount) + { + // Lock the resource + pthread_mutex_lock(&_mutex); + + // Find the shared memory + auto it = _sharedMemoryMap.find(id); + + // If there is none + if (it == _sharedMemoryMap.end()) + { + // Create a new shared memory + auto sharedMemoryPtr = std::unique_ptr(new SharedMemory(fenceCount)); + auto &sharedMemory = *sharedMemoryPtr; + + // Store it into the global slots map + _sharedMemoryMap.emplace(id, std::move(sharedMemoryPtr)); + + // Unlock the resource + pthread_mutex_unlock(&_mutex); + + // Return the newly created shared memory + return sharedMemory; + } + + // Unlock the resource + pthread_mutex_unlock(&_mutex); + + // Return the already present shared memory + return *it->second; + } + + private: + + /** + * A mutex to make sure threads do not bother each other during certain operations + */ + pthread_mutex_t _mutex{}; + + /** + * Map of shared memory objects + */ + std::unordered_map> _sharedMemoryMap; +}; +} // namespace HiCR::backend::pthreads diff --git a/include/hicr/core/communicationManager.hpp b/include/hicr/core/communicationManager.hpp index 9a2356f4..024eb0d2 100644 --- a/include/hicr/core/communicationManager.hpp +++ b/include/hicr/core/communicationManager.hpp @@ -103,8 +103,10 @@ class CommunicationManager else { // If the requested tag and key are not found, return empty storage - if (_globalMemorySlotTagKeyMap.contains(tag) == false) HICR_THROW_LOGIC("Requesting a global memory slot with key %lu for a tag (%lu) that has not been registered.", globalKey, tag); - if (_globalMemorySlotTagKeyMap.at(tag).contains(globalKey) == false) HICR_THROW_LOGIC("Requesting a global memory slot for a global key (%lu) not registered within the tag (%lu).", globalKey, tag); + if (_globalMemorySlotTagKeyMap.contains(tag) == false) + HICR_THROW_LOGIC("Requesting a global memory slot with key %lu for a tag (%lu) that has not been registered.", globalKey, tag); + if (_globalMemorySlotTagKeyMap.at(tag).contains(globalKey) == false) + HICR_THROW_LOGIC("Requesting a global memory slot for a global key (%lu) not registered within the tag (%lu).", globalKey, tag); // Getting requested memory slot auto value = _globalMemorySlotTagKeyMap.at(tag).at(globalKey); diff --git a/tests/backends/hwloc/memoryManager.cpp b/tests/backends/hwloc/memoryManager.cpp index c2193724..cba25680 100644 --- a/tests/backends/hwloc/memoryManager.cpp +++ b/tests/backends/hwloc/memoryManager.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include TEST(MemoryManager, Construction) @@ -49,10 +50,14 @@ TEST(MemoryManager, Memory) // Creating HWloc topology object hwloc_topology_t topology; + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // Reserving memory for hwloc hwloc_topology_init(&topology); HiCR::backend::hwloc::MemoryManager m(&topology); - HiCR::backend::pthreads::CommunicationManager c; + HiCR::backend::pthreads::CommunicationManager c(sharedMemory); // Initializing hwloc-based topology manager HiCR::backend::hwloc::TopologyManager tm(&topology); diff --git a/tests/frontends/channel/fixedSize/spsc/consumer.cpp b/tests/frontends/channel/fixedSize/spsc/consumer.cpp index fd8d4efb..81f2282b 100644 --- a/tests/frontends/channel/fixedSize/spsc/consumer.cpp +++ b/tests/frontends/channel/fixedSize/spsc/consumer.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #define CHANNEL_TAG 0 @@ -48,8 +49,12 @@ TEST(ConsumerChannel, Construction) // Instantiating HWloc-based host (CPU) memory manager HiCR::backend::hwloc::MemoryManager m(&topology); + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // Instantiating Pthread-based host (CPU) communication manager - HiCR::backend::pthreads::CommunicationManager c(1); + HiCR::backend::pthreads::CommunicationManager c(sharedMemory); // Initializing HWLoc-based host (CPU) topology manager HiCR::backend::hwloc::TopologyManager tm(&topology); @@ -117,8 +122,12 @@ TEST(ConsumerChannel, PeekPop) // Instantiating HWloc-based host (CPU) memory manager HiCR::backend::hwloc::MemoryManager m(&topology); + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // Instantiating Pthread-based host (CPU) communication manager - HiCR::backend::pthreads::CommunicationManager c(1); + HiCR::backend::pthreads::CommunicationManager c(sharedMemory); // Initializing HWLoc-based host (CPU) topology manager HiCR::backend::hwloc::TopologyManager tm(&topology); @@ -206,8 +215,12 @@ TEST(ConsumerChannel, PeekOrderPop) // Instantiating HWloc-based host (CPU) memory manager HiCR::backend::hwloc::MemoryManager m(&topology); + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // Instantiating Pthread-based host (CPU) communication manager - HiCR::backend::pthreads::CommunicationManager c(1); + HiCR::backend::pthreads::CommunicationManager c(sharedMemory); // Initializing HWLoc-based host (CPU) topology manager HiCR::backend::hwloc::TopologyManager tm(&topology); @@ -278,8 +291,12 @@ TEST(ConsumerChannel, PeekOrder) // Instantiating HWloc-based host (CPU) memory manager HiCR::backend::hwloc::MemoryManager m(&topology); + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // Instantiating Pthread-based host (CPU) communication manager - HiCR::backend::pthreads::CommunicationManager c(1); + HiCR::backend::pthreads::CommunicationManager c(sharedMemory); // Initializing HWLoc-based host (CPU) topology manager HiCR::backend::hwloc::TopologyManager tm(&topology); @@ -346,8 +363,12 @@ TEST(ConsumerChannel, PeekWait) // Instantiating HWloc-based host (CPU) memory manager HiCR::backend::hwloc::MemoryManager m(&topology); + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // Instantiating Pthread-based host (CPU) communication manager - HiCR::backend::pthreads::CommunicationManager c(1); + HiCR::backend::pthreads::CommunicationManager c(sharedMemory); // Initializing HWLoc-based host (CPU) topology manager HiCR::backend::hwloc::TopologyManager tm(&topology); diff --git a/tests/frontends/channel/fixedSize/spsc/producer.cpp b/tests/frontends/channel/fixedSize/spsc/producer.cpp index 9d793405..a57b42f6 100644 --- a/tests/frontends/channel/fixedSize/spsc/producer.cpp +++ b/tests/frontends/channel/fixedSize/spsc/producer.cpp @@ -25,6 +25,7 @@ #include "gtest/gtest.h" #include #include +#include #include #include #include @@ -46,8 +47,12 @@ TEST(ProducerChannel, Construction) // Instantiating HWloc-based host (CPU) memory manager HiCR::backend::hwloc::MemoryManager m(&topology); + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // Instantiating Pthread-based host (CPU) communication manager - HiCR::backend::pthreads::CommunicationManager c(1); + HiCR::backend::pthreads::CommunicationManager c(sharedMemory); // Initializing HWLoc-based host (CPU) topology manager HiCR::backend::hwloc::TopologyManager tm(&topology); @@ -110,8 +115,12 @@ TEST(ProducerChannel, Push) // Instantiating HWloc-based host (CPU) memory manager HiCR::backend::hwloc::MemoryManager m(&topology); + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // Instantiating Pthread-based host (CPU) communication manager - HiCR::backend::pthreads::CommunicationManager c(1); + HiCR::backend::pthreads::CommunicationManager c(sharedMemory); // Initializing HWLoc-based host (CPU) topology manager HiCR::backend::hwloc::TopologyManager tm(&topology); @@ -195,8 +204,12 @@ TEST(ProducerChannel, PushWait) // Instantiating HWloc-based host (CPU) memory manager HiCR::backend::hwloc::MemoryManager m(&topology); + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // Instantiating Pthread-based host (CPU) communication manager - HiCR::backend::pthreads::CommunicationManager c(1); + HiCR::backend::pthreads::CommunicationManager c(sharedMemory); // Initializing HWLoc-based host (CPU) topology manager HiCR::backend::hwloc::TopologyManager tm(&topology); diff --git a/tests/frontends/objectStore/objectStore.cpp b/tests/frontends/objectStore/objectStore.cpp index dec3ecda..201ee871 100644 --- a/tests/frontends/objectStore/objectStore.cpp +++ b/tests/frontends/objectStore/objectStore.cpp @@ -17,6 +17,7 @@ #include #include #include +#include #include @@ -81,8 +82,12 @@ TEST_F(ObjectStoreTest, PublishTest) // Test get method TEST_F(ObjectStoreTest, GetTest) { + // Create shared memory + auto sharedMemoryFactory = HiCR::backend::pthreads::SharedMemoryFactory(); + auto &sharedMemory = sharedMemoryFactory.get(0, 1); + // We need a real communication manager for this test - HiCR::backend::pthreads::CommunicationManager communicationManager; + HiCR::backend::pthreads::CommunicationManager communicationManager(sharedMemory); ObjectStore store(communicationManager, tag, memoryManager, memorySpace, instanceId); char data[8] = "test 12";