diff --git a/.github/workflows/deployr.yml b/.github/workflows/deployr.yml index dc19d89..a3d357e 100644 --- a/.github/workflows/deployr.yml +++ b/.github/workflows/deployr.yml @@ -47,7 +47,7 @@ jobs: run: | echo "Building..." mkdir build - meson setup build -Dengine=mpi -DbuildTests=true -DbuildExamples=true -DcompileWarningsAsErrors=true + meson setup build -Dengines=mpi -DbuildTests=true -DbuildExamples=true -DcompileWarningsAsErrors=true meson compile -C build - name: Running tests run: | diff --git a/examples/deploy/deployment.json b/examples/deploy/deployment.json index bf3f308..e896d20 100644 --- a/examples/deploy/deployment.json +++ b/examples/deploy/deployment.json @@ -15,12 +15,6 @@ "Type": "NUMA Domain", "Compute Resources": [ - { "Type": "Processing Unit" }, - { "Type": "Processing Unit" }, - { "Type": "Processing Unit" }, - { "Type": "Processing Unit" }, - { "Type": "Processing Unit" }, - { "Type": "Processing Unit" }, { "Type": "Processing Unit" }, { "Type": "Processing Unit" } ], @@ -28,7 +22,7 @@ [ { "Type": "RAM", - "Size": 33554432 + "Size": 10000000 } ] } @@ -45,12 +39,6 @@ "Type": "NUMA Domain", "Compute Resources": [ - { "Type": "Processing Unit" }, - { "Type": "Processing Unit" }, - { "Type": "Processing Unit" }, - { "Type": "Processing Unit" }, - { "Type": "Processing Unit" }, - { "Type": "Processing Unit" }, { "Type": "Processing Unit" }, { "Type": "Processing Unit" } ], @@ -58,7 +46,7 @@ [ { "Type": "RAM", - "Size": 33554432 + "Size": 10000000 } ] } diff --git a/extern/HiCR b/extern/HiCR index 38d39f8..6f49ccb 160000 --- a/extern/HiCR +++ b/extern/HiCR @@ -1 +1 @@ -Subproject commit 38d39f8661ba0c7af5c012280dffda757ac382d4 +Subproject commit 6f49ccb094d1d359ac85ffbd970e2b85bb1eff40 diff --git a/extern/cloudrRPC/.gitignore b/extern/cloudrRPC/.gitignore new file mode 100644 index 0000000..84788f4 --- /dev/null +++ b/extern/cloudrRPC/.gitignore @@ -0,0 +1,6 @@ +build +*.patch +~* +.vscode +atlas_*.sh +**/matrix/ diff --git a/extern/cloudrRPC/.gitmodules b/extern/cloudrRPC/.gitmodules new file mode 100644 index 0000000..509637a --- /dev/null +++ b/extern/cloudrRPC/.gitmodules @@ -0,0 +1,6 @@ +[submodule "extern/HiCR"] + path = extern/HiCR + url = https://github.com/Algebraic-Programming/HiCR.git +[submodule "extern/TaskR"] + path = extern/TaskR + url = https://github.com/Algebraic-Programming/TaskR.git diff --git a/extern/cloudrRPC/extern/run-clang-format/.clang-format b/extern/cloudrRPC/extern/run-clang-format/.clang-format new file mode 100644 index 0000000..b875084 --- /dev/null +++ b/extern/cloudrRPC/extern/run-clang-format/.clang-format @@ -0,0 +1,12 @@ +# using clang-format version 5.0.0 +Language: Cpp +BasedOnStyle: LLVM + +AllowShortCaseLabelsOnASingleLine: true +AllowShortFunctionsOnASingleLine: true +AlwaysBreakTemplateDeclarations: true +BinPackArguments: false +BinPackParameters: false +# make adding new members at the end less noisy in diffs +BreakConstructorInitializersBeforeComma: true +ConstructorInitializerAllOnOneLineOrOnePerLine: true diff --git a/extern/cloudrRPC/extern/run-clang-format/.clang-format-ignore b/extern/cloudrRPC/extern/run-clang-format/.clang-format-ignore new file mode 100644 index 0000000..a4767fc --- /dev/null +++ b/extern/cloudrRPC/extern/run-clang-format/.clang-format-ignore @@ -0,0 +1,2 @@ +# ignore third_party code from clang-format checks +src/third_party/* diff --git a/extern/cloudrRPC/extern/run-clang-format/.travis.yml b/extern/cloudrRPC/extern/run-clang-format/.travis.yml new file mode 100644 index 0000000..9f73072 --- /dev/null +++ b/extern/cloudrRPC/extern/run-clang-format/.travis.yml @@ -0,0 +1,12 @@ +language: cpp + +addons: + apt: + sources: + - llvm-toolchain-trusty-5.0 + - key_url: 'http://apt.llvm.org/llvm-snapshot.gpg.key' + packages: + - clang-format-5.0 + +script: + - ./run-clang-format.py -r src diff --git a/extern/cloudrRPC/extern/run-clang-format/LICENSE b/extern/cloudrRPC/extern/run-clang-format/LICENSE new file mode 100644 index 0000000..e728f24 --- /dev/null +++ b/extern/cloudrRPC/extern/run-clang-format/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2017 Guillaume Papin + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/extern/cloudrRPC/extern/run-clang-format/README.rst b/extern/cloudrRPC/extern/run-clang-format/README.rst new file mode 100644 index 0000000..aff45d1 --- /dev/null +++ b/extern/cloudrRPC/extern/run-clang-format/README.rst @@ -0,0 +1,72 @@ +===================== + run-clang-format.py +===================== +---------------------------------------------- + Lint files and directories with clang-format +---------------------------------------------- + +.. contents:: + :local: + +Introduction +============ + +A wrapper script around clang-format, suitable for linting multiple files +and to use for continuous integration. + +This is an alternative API for the clang-format command line. +It runs over multiple files and directories in parallel. +A diff output is produced and a sensible exit code is returned. + +.. image:: screenshot.png + + +How to use? +=========== + +Copy `run-clang-format.py `_ in your project, +then run it recursively on directories, or specific files:: + + ./run-clang-format.py -r src include foo.cpp + +It's possible to exclude paths from the recursive search:: + + ./run-clang-format.py -r \ + --exclude src/third_party \ + --exclude '*_test.cpp' \ + src include foo.cpp + +These exclude rules can be put in a ``.clang-format-ignore`` file, +which also supports comments. + +An example configuration is available in this repo:: + + $ cat .clang-format-ignore + # ignore third_party code from clang-format checks + src/third_party/* + + +Continuous integration +====================== + +Check `.travis.yml <.travis.yml>`_. + +For an example of failure in logs, click the badge (build is broken on purpose): + +.. image:: https://travis-ci.org/Sarcasm/run-clang-format.svg?branch=master + :target: https://travis-ci.org/Sarcasm/run-clang-format + + +FAQ +=== + +Can I check only changed files? +------------------------------- + +No, and this is what this repository was initially about. +However, once working around a few shortcommings of ``git clang-format``, +I opted to try an alternative strategy +which expects the whole project to be correctly formatted. + +It would make sense to support this feature as well, +so that the coding style does not need to be enforced but merely suggested. diff --git a/extern/cloudrRPC/extern/run-clang-format/run-clang-format.py b/extern/cloudrRPC/extern/run-clang-format/run-clang-format.py new file mode 100755 index 0000000..dcabaf1 --- /dev/null +++ b/extern/cloudrRPC/extern/run-clang-format/run-clang-format.py @@ -0,0 +1,408 @@ +#!/usr/bin/env python +"""A wrapper script around clang-format, suitable for linting multiple files +and to use for continuous integration. + +This is an alternative API for the clang-format command line. +It runs over multiple files and directories in parallel. +A diff output is produced and a sensible exit code is returned. + +""" + +from __future__ import print_function, unicode_literals + +import argparse +import codecs +import difflib +import fnmatch +import io +import errno +import multiprocessing +import os +import signal +import subprocess +import sys +import traceback + +from functools import partial + +try: + from subprocess import DEVNULL # py3k +except ImportError: + DEVNULL = open(os.devnull, "wb") + + +DEFAULT_EXTENSIONS = 'c,h,C,H,cpp,hpp,cc,hh,c++,h++,cxx,hxx' +DEFAULT_CLANG_FORMAT_IGNORE = '.clang-format-ignore' + + +class ExitStatus: + SUCCESS = 0 + DIFF = 1 + TROUBLE = 2 + +def excludes_from_file(ignore_file): + excludes = [] + try: + with io.open(ignore_file, 'r', encoding='utf-8') as f: + for line in f: + if line.startswith('#'): + # ignore comments + continue + pattern = line.rstrip() + if not pattern: + # allow empty lines + continue + excludes.append(pattern) + except EnvironmentError as e: + if e.errno != errno.ENOENT: + raise + return excludes; + +def list_files(files, recursive=False, extensions=None, exclude=None): + if extensions is None: + extensions = [] + if exclude is None: + exclude = [] + + out = [] + for file in files: + if recursive and os.path.isdir(file): + for dirpath, dnames, fnames in os.walk(file): + fpaths = [os.path.join(dirpath, fname) for fname in fnames] + for pattern in exclude: + # os.walk() supports trimming down the dnames list + # by modifying it in-place, + # to avoid unnecessary directory listings. + dnames[:] = [ + x for x in dnames + if + not fnmatch.fnmatch(os.path.join(dirpath, x), pattern) + ] + fpaths = [ + x for x in fpaths if not fnmatch.fnmatch(x, pattern) + ] + for f in fpaths: + ext = os.path.splitext(f)[1][1:] + if ext in extensions: + out.append(f) + else: + out.append(file) + return out + + +def make_diff(file, original, reformatted): + return list( + difflib.unified_diff( + original, + reformatted, + fromfile='{}\t(original)'.format(file), + tofile='{}\t(reformatted)'.format(file), + n=3)) + + +class DiffError(Exception): + def __init__(self, message, errs=None): + super(DiffError, self).__init__(message) + self.errs = errs or [] + + +class UnexpectedError(Exception): + def __init__(self, message, exc=None): + super(UnexpectedError, self).__init__(message) + self.formatted_traceback = traceback.format_exc() + self.exc = exc + + +def run_clang_format_diff_wrapper(args, file): + try: + ret = run_clang_format_diff(args, file) + return ret + except DiffError: + raise + except Exception as e: + raise UnexpectedError('{}: {}: {}'.format(file, e.__class__.__name__, + e), e) + + +def run_clang_format_diff(args, file): + try: + with io.open(file, 'r', encoding='utf-8') as f: + original = f.readlines() + except IOError as exc: + raise DiffError(str(exc)) + + if args.in_place: + invocation = [args.clang_format_executable, '-i', file] + else: + invocation = [args.clang_format_executable, file] + + if args.style: + invocation.extend(['--style', args.style]) + + if args.dry_run: + print(" ".join(invocation)) + return [], [] + + # Use of utf-8 to decode the process output. + # + # Hopefully, this is the correct thing to do. + # + # It's done due to the following assumptions (which may be incorrect): + # - clang-format will returns the bytes read from the files as-is, + # without conversion, and it is already assumed that the files use utf-8. + # - if the diagnostics were internationalized, they would use utf-8: + # > Adding Translations to Clang + # > + # > Not possible yet! + # > Diagnostic strings should be written in UTF-8, + # > the client can translate to the relevant code page if needed. + # > Each translation completely replaces the format string + # > for the diagnostic. + # > -- http://clang.llvm.org/docs/InternalsManual.html#internals-diag-translation + # + # It's not pretty, due to Python 2 & 3 compatibility. + encoding_py3 = {} + if sys.version_info[0] >= 3: + encoding_py3['encoding'] = 'utf-8' + + try: + proc = subprocess.Popen( + invocation, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True, + **encoding_py3) + except OSError as exc: + raise DiffError( + "Command '{}' failed to start: {}".format( + subprocess.list2cmdline(invocation), exc + ) + ) + proc_stdout = proc.stdout + proc_stderr = proc.stderr + if sys.version_info[0] < 3: + # make the pipes compatible with Python 3, + # reading lines should output unicode + encoding = 'utf-8' + proc_stdout = codecs.getreader(encoding)(proc_stdout) + proc_stderr = codecs.getreader(encoding)(proc_stderr) + # hopefully the stderr pipe won't get full and block the process + outs = list(proc_stdout.readlines()) + errs = list(proc_stderr.readlines()) + proc.wait() + if proc.returncode: + raise DiffError( + "Command '{}' returned non-zero exit status {}".format( + subprocess.list2cmdline(invocation), proc.returncode + ), + errs, + ) + if args.in_place: + return [], errs + return make_diff(file, original, outs), errs + + +def bold_red(s): + return '\x1b[1m\x1b[31m' + s + '\x1b[0m' + + +def colorize(diff_lines): + def bold(s): + return '\x1b[1m' + s + '\x1b[0m' + + def cyan(s): + return '\x1b[36m' + s + '\x1b[0m' + + def green(s): + return '\x1b[32m' + s + '\x1b[0m' + + def red(s): + return '\x1b[31m' + s + '\x1b[0m' + + for line in diff_lines: + if line[:4] in ['--- ', '+++ ']: + yield bold(line) + elif line.startswith('@@ '): + yield cyan(line) + elif line.startswith('+'): + yield green(line) + elif line.startswith('-'): + yield red(line) + else: + yield line + + +def print_diff(diff_lines, use_color): + if use_color: + diff_lines = colorize(diff_lines) + if sys.version_info[0] < 3: + sys.stdout.writelines((l.encode('utf-8') for l in diff_lines)) + else: + sys.stdout.writelines(diff_lines) + + +def print_trouble(prog, message, use_colors): + error_text = 'error:' + if use_colors: + error_text = bold_red(error_text) + print("{}: {} {}".format(prog, error_text, message), file=sys.stderr) + + +def main(): + parser = argparse.ArgumentParser(description=__doc__) + parser.add_argument( + '--clang-format-executable', + metavar='EXECUTABLE', + help='path to the clang-format executable', + default='clang-format') + parser.add_argument( + '--extensions', + help='comma separated list of file extensions (default: {})'.format( + DEFAULT_EXTENSIONS), + default=DEFAULT_EXTENSIONS) + parser.add_argument( + '-r', + '--recursive', + action='store_true', + help='run recursively over directories') + parser.add_argument( + '-d', + '--dry-run', + action='store_true', + help='just print the list of files') + parser.add_argument( + '-i', + '--in-place', + action='store_true', + help='format file instead of printing differences') + parser.add_argument('files', metavar='file', nargs='+') + parser.add_argument( + '-q', + '--quiet', + action='store_true', + help="disable output, useful for the exit code") + parser.add_argument( + '-j', + metavar='N', + type=int, + default=0, + help='run N clang-format jobs in parallel' + ' (default number of cpus + 1)') + parser.add_argument( + '--color', + default='auto', + choices=['auto', 'always', 'never'], + help='show colored diff (default: auto)') + parser.add_argument( + '-e', + '--exclude', + metavar='PATTERN', + action='append', + default=[], + help='exclude paths matching the given glob-like pattern(s)' + ' from recursive search') + parser.add_argument( + '--style', + help='formatting style to apply (LLVM, Google, Chromium, Mozilla, WebKit)') + + args = parser.parse_args() + + # use default signal handling, like diff return SIGINT value on ^C + # https://bugs.python.org/issue14229#msg156446 + signal.signal(signal.SIGINT, signal.SIG_DFL) + try: + signal.SIGPIPE + except AttributeError: + # compatibility, SIGPIPE does not exist on Windows + pass + else: + signal.signal(signal.SIGPIPE, signal.SIG_DFL) + + colored_stdout = False + colored_stderr = False + if args.color == 'always': + colored_stdout = True + colored_stderr = True + elif args.color == 'auto': + colored_stdout = sys.stdout.isatty() + colored_stderr = sys.stderr.isatty() + + version_invocation = [args.clang_format_executable, str("--version")] + try: + subprocess.check_call(version_invocation, stdout=DEVNULL) + except subprocess.CalledProcessError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + return ExitStatus.TROUBLE + except OSError as e: + print_trouble( + parser.prog, + "Command '{}' failed to start: {}".format( + subprocess.list2cmdline(version_invocation), e + ), + use_colors=colored_stderr, + ) + return ExitStatus.TROUBLE + + retcode = ExitStatus.SUCCESS + + excludes = excludes_from_file(DEFAULT_CLANG_FORMAT_IGNORE) + excludes.extend(args.exclude) + + files = list_files( + args.files, + recursive=args.recursive, + exclude=excludes, + extensions=args.extensions.split(',')) + + if not files: + return + + njobs = args.j + if njobs == 0: + njobs = multiprocessing.cpu_count() + 1 + njobs = min(len(files), njobs) + + if njobs == 1: + # execute directly instead of in a pool, + # less overhead, simpler stacktraces + it = (run_clang_format_diff_wrapper(args, file) for file in files) + pool = None + else: + pool = multiprocessing.Pool(njobs) + it = pool.imap_unordered( + partial(run_clang_format_diff_wrapper, args), files) + pool.close() + while True: + try: + outs, errs = next(it) + except StopIteration: + break + except DiffError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + retcode = ExitStatus.TROUBLE + sys.stderr.writelines(e.errs) + except UnexpectedError as e: + print_trouble(parser.prog, str(e), use_colors=colored_stderr) + sys.stderr.write(e.formatted_traceback) + retcode = ExitStatus.TROUBLE + # stop at the first unexpected error, + # something could be very wrong, + # don't process all files unnecessarily + if pool: + pool.terminate() + break + else: + sys.stderr.writelines(errs) + if outs == []: + continue + if not args.quiet: + print_diff(outs, use_color=colored_stdout) + if retcode == ExitStatus.SUCCESS: + retcode = ExitStatus.DIFF + if pool: + pool.join() + return retcode + + +if __name__ == '__main__': + sys.exit(main()) diff --git a/extern/cloudrRPC/extern/run-clang-format/screenshot.png b/extern/cloudrRPC/extern/run-clang-format/screenshot.png new file mode 100644 index 0000000..f65102d Binary files /dev/null and b/extern/cloudrRPC/extern/run-clang-format/screenshot.png differ diff --git a/extern/cloudrRPC/extern/run-clang-format/src/foo.cpp b/extern/cloudrRPC/extern/run-clang-format/src/foo.cpp new file mode 100644 index 0000000..f98b5c1 --- /dev/null +++ b/extern/cloudrRPC/extern/run-clang-format/src/foo.cpp @@ -0,0 +1,7 @@ +#include + +std::string foo(const std::string &a, const std::string &b) { + std::string sum; + sum = a + b; + return sum; +} diff --git a/extern/cloudrRPC/extern/run-clang-format/src/third_party/qux.cpp b/extern/cloudrRPC/extern/run-clang-format/src/third_party/qux.cpp new file mode 100644 index 0000000..c6c5efa --- /dev/null +++ b/extern/cloudrRPC/extern/run-clang-format/src/third_party/qux.cpp @@ -0,0 +1,9 @@ +// This code is ignored by the .clang-format-ignore file. + +int qux(bool cond) { + if (cond) { + return -1; + } + + return 0; +} diff --git a/extern/cloudrRPC/include/hicr/backends/cloudr/communicationManager.hpp b/extern/cloudrRPC/include/hicr/backends/cloudr/communicationManager.hpp new file mode 100644 index 0000000..b74699f --- /dev/null +++ b/extern/cloudrRPC/include/hicr/backends/cloudr/communicationManager.hpp @@ -0,0 +1,331 @@ +/* + * 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 communicationManager.hpp + * @brief This file implements the communication manager class for the CloudR backend + * @author S. M. Martin & L. Terracciano + * @date 19/12/2023 + */ + +#pragma once + +#include +#include +#include +#include +#include +#include "instanceManager.hpp" + +namespace HiCR::backend::cloudr +{ + +/** + * Implementation of the CloudR backend + */ +class CommunicationManager final : public HiCR::CommunicationManager +{ + public: + + /** + * Constructor for the cloudr backend. + * + * \param[in] communicationManager working communication manager to implement the required functionalities (e.g, MPI instance manager) + * \param[in] instanceManager working instance manager to handle the virtualized resources and trigger RPC for all the instances (free and non) + */ + CommunicationManager(HiCR::CommunicationManager *communicationManager, HiCR::backend::cloudr::InstanceManager *instanceManager) + : HiCR::CommunicationManager(), + _communicationManager(communicationManager), + _instanceManager(instanceManager) + {} + + ~CommunicationManager() override = default; + + /** + * Forward call to getGlobalMemorySlotImpl + * + * \param[in] tag Tag that identifies a subset of all global memory slots + * \param[in] globalKey The sorting key inside the tag subset that distinguished between registered slots + * \return The map of registered global memory slots, filtered by tag and mapped by key + */ + std::shared_ptr getGlobalMemorySlotImpl(GlobalMemorySlot::tag_t tag, GlobalMemorySlot::globalKey_t globalKey) override + { + // Forward call to base communication manager + return _communicationManager->getGlobalMemorySlot(tag, globalKey); + } + + /** + * Forward call to exchangeGlobalMemorySlots + * + * \param[in] tag Tag that identifies a subset of all global memory slots + * \param[in] memorySlots memory slots to exchange + */ + __INLINE__ void exchangeGlobalMemorySlotsImpl(HiCR::GlobalMemorySlot::tag_t tag, const std::vector &memorySlots) override + { + // Request non active instances to participate in the exchange + if (_instanceManager->getCurrentInstance()->isRootInstance()) _instanceManager->requestExchangeGlobalMemorySlots(tag); + + // Initiate the exchange + _communicationManager->exchangeGlobalMemorySlots(tag, memorySlots); + + // Keep track of the initiated exchange + _isExchangePending = true; + } + + /** + * Forward call to queryMemorySlotUpdatesImpl + * + * \param[in] memorySlot memory slots to query + */ + void queryMemorySlotUpdatesImpl(std::shared_ptr memorySlot) override + { + // Forward call to base communication manager + _communicationManager->queryMemorySlotUpdates(memorySlot); + } + + /** + * Forward call to destroyGlobalMemorySlotImpl + * + * \param[in] memorySlot memory slots to destroy + */ + void destroyGlobalMemorySlotImpl(std::shared_ptr memorySlot) override + { + // Forward call to base communication manager + _communicationManager->destroyGlobalMemorySlot(memorySlot); + } + + /** + * Forward call to fenceImpl + * + * \param[in] tag tag on which fence should be performed + */ + __INLINE__ void fenceImpl(HiCR::GlobalMemorySlot::tag_t tag) override + { + // Request non active instances to participate in the fence + if (_instanceManager->getCurrentInstance()->isRootInstance()) _instanceManager->requestFence(tag); + + // Execute the fence + _communicationManager->fence(tag); + + // If any exchange operation was initiated + if (_isExchangePending == true) + { + // Get the global memory slot tag-key map + const auto &globalMap = _communicationManager->getGlobalMemorySlotTagKeyMap(); + + // Update CloudR global memory slot tag-key map + setGlobalMemorySlotTagKeyMap(globalMap); + + // All the changes of the exchange operations are reflected in CloudR + _isExchangePending = false; + } + } + + /** + * Forward call to acquireGlobalLockImpl + * + * \param[in] memorySlot memory slots to lock + * + * \return bool if the operation was successful + */ + bool acquireGlobalLockImpl(std::shared_ptr memorySlot) override + { + // Forward call to base communication manager + return _communicationManager->acquireGlobalLock(memorySlot); + } + + /** + * Forward call to releaseGlobalLockImpl + * + * \param[in] memorySlot memory slots to unlock + */ + void releaseGlobalLockImpl(std::shared_ptr memorySlot) override + { + // Forward call to base communication manager + return _communicationManager->releaseGlobalLock(memorySlot); + } + + /** + * Forward call to serializeGlobalMemorySlot + * + * \param[in] globalSlot global memory slot to serialize + * + * \return pointer to the serialized versoin + */ + uint8_t *serializeGlobalMemorySlot(const std::shared_ptr &globalSlot) const override + { + // Forward call to base communication manager + return _communicationManager->serializeGlobalMemorySlot(globalSlot); + } + + /** + * Forward call to deserializeGlobalMemorySlot + * + * \param[in] buffer the serialize global memory slot + * \param[in] tag global memory slot tag + * + * \return a deserialized global memory slot + */ + std::shared_ptr deserializeGlobalMemorySlot(uint8_t *buffer, GlobalMemorySlot::tag_t tag) override + { + // Forward call to base communication manager + return _communicationManager->deserializeGlobalMemorySlot(buffer, tag); + } + + /** + * Forward call to promoteLocalMemorySlot + * + * \param[in] localMemorySlot memory slot to promote + * \param[in] tag the tag where it should be promoted + * + * \return global memory slot + */ + std::shared_ptr promoteLocalMemorySlot(const std::shared_ptr &localMemorySlot, GlobalMemorySlot::tag_t tag) override + { + // Forward call to base communication manager + return _communicationManager->promoteLocalMemorySlot(localMemorySlot, tag); + } + + /** + * Forward call to destroyPromotedGlobalMemorySlot + * + * \param[in] memorySlot memory slots to destroy + */ + void destroyPromotedGlobalMemorySlot(const std::shared_ptr &memorySlot) override + { + // Forward call to base communication manager + _communicationManager->destroyGlobalMemorySlot(memorySlot); + } + + /** + * Forward call to flushReceived + */ + void flushReceived() override + { + // Forward call to base communication manager + _communicationManager->flushReceived(); + } + + /** + * Forward call to flushSent + */ + void flushSent() override + { + // Forward call to base communication manager + _communicationManager->flushSent(); + } + + /** + * Forward call to deregisterGlobalMemorySlotImpl + * + * \param[in] memorySlot memory slots to deregister + */ + void deregisterGlobalMemorySlotImpl(const std::shared_ptr &memorySlot) override + { + // Forward call to base communication manager + _communicationManager->deregisterGlobalMemorySlot(memorySlot); + } + + /** + * Forward call to memcpyImpl + * + * \param[in] destination + * \param[in] dst_offset + * \param[in] source + * \param[in] src_offset + * \param[in] size + */ + void memcpyImpl(const std::shared_ptr &destination, size_t dst_offset, const std::shared_ptr &source, size_t src_offset, size_t size) override + { + // Forward call to base communication manager + _communicationManager->memcpy(destination, dst_offset, source, src_offset, size); + } + + /** + * Forward call to memcpyImpl + * + * \param[in] destination + * \param[in] dst_offset + * \param[in] source + * \param[in] src_offset + * \param[in] size + */ + void memcpyImpl(const std::shared_ptr &destination, size_t dst_offset, const std::shared_ptr &source, size_t src_offset, size_t size) override + { + // Forward call to base communication manager + _communicationManager->memcpy(destination, dst_offset, source, src_offset, size); + } + + /** + * Forward call to memcpyImpl + * + * \param[in] destination + * \param[in] dst_offset + * \param[in] source + * \param[in] src_offset + * \param[in] size + */ + void memcpyImpl(const std::shared_ptr &destination, size_t dst_offset, const std::shared_ptr &source, size_t src_offset, size_t size) override + { + // Forward call to base communication manager + _communicationManager->memcpy(destination, dst_offset, source, src_offset, size); + } + + /** + * Forward call to fenceImpl + * + * \param[in] slot + * \param[in] expectedSent + * \param[in] expectedRcvd + */ + void fenceImpl(const std::shared_ptr &slot, size_t expectedSent, size_t expectedRcvd) override + { + // Forward call to base communication manager + _communicationManager->fence(slot, expectedSent, expectedRcvd); + } + + /** + * Forward call to fenceImpl + * + * \param[in] slot + * \param[in] expectedSent + * \param[in] expectedRcvd + */ + void fenceImpl(const std::shared_ptr &slot, size_t expectedSent, size_t expectedRcvd) override + { + // Forward call to base communication manager + _communicationManager->fence(slot, expectedSent, expectedRcvd); + } + + private: + + /** + * HiCR Communication manager that does the actual operations + */ + HiCR::CommunicationManager *const _communicationManager; + + /** + * HiCR Instance manager to check whether this is a root instance + */ + HiCR::backend::cloudr::InstanceManager *const _instanceManager; + + /** + * Keep track if there are pending exchanges operations + */ + bool _isExchangePending = false; +}; + +} // namespace HiCR::backend::cloudr diff --git a/extern/cloudrRPC/include/hicr/backends/cloudr/instance.hpp b/extern/cloudrRPC/include/hicr/backends/cloudr/instance.hpp new file mode 100644 index 0000000..4a6d3f6 --- /dev/null +++ b/extern/cloudrRPC/include/hicr/backends/cloudr/instance.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 instance.hpp + * @brief Provides a definition for the instance class for the CloudR backend + * @author S. M. Martin + * @date 18/06/2025 + */ +#pragma once + +#include +#include + +namespace HiCR::backend::cloudr +{ + +/** + * This class represents an abstract definition for a HICR instance as represented by the Cloudr backend: + */ +class Instance final : public HiCR::Instance +{ + public: + + /** + * Constructor for a Instance class for the CloudR backend + * \param[in] instanceId The instance identifier corresponding to this HiCR instance + * \param[in] baseInstance The base instance corresponding to this HiCR instance + * \param[in] isRoot whether the instance is root + */ + Instance(const instanceId_t instanceId, HiCR::Instance *const baseInstance, const bool isRoot) + : HiCR::Instance(instanceId), + _baseInstance(baseInstance), + _isRoot(isRoot) + {} + + /** + * Default destructor + */ + ~Instance() override = default; + + /** + * \return whether the current instance is root + */ + [[nodiscard]] __INLINE__ bool isRootInstance() const override { return _isRoot; }; + + /** + * Set the instance topology + * + * \param[in] topology + */ + __INLINE__ void setTopology(const HiCR::Topology &topology) { _topology = topology; } + + /** + * Topology getter + * + * \return instance topology + */ + __INLINE__ HiCR::Topology getTopology() const { return _topology; } + + /** + * Checks whether this instance satisfied a certain instance type. + * That is, whether it contains the requested devices in the instance type provided + * + * The devices are checked in order. That is the first instance device that satisfies a requested device + * will be removed from the list when checking the next requested device. + * + * @param[in] requestedTopology The topology to check for + * + * @return true, if this instance satisfies the instance type; false, otherwise. + */ + [[nodiscard]] __INLINE__ bool isCompatible(const HiCR::Topology requestedTopology) { return _topology.isSubset(_topology, requestedTopology); } + + /** + * Getter for base instance, not the emulated one + * + * \return pointer to instance + */ + __INLINE__ HiCR::Instance *getBaseInstance() const { return _baseInstance; } + + private: + + /// Emulated topology for this instance + HiCR::Topology _topology; + + /// Underlying instance implementing this instance + HiCR::Instance *const _baseInstance; + + /// A flag that determines whether this instance is root + const bool _isRoot; + + /// A flag that indicates this instance is currently deployed + bool _isDeployed = false; +}; + +} // namespace HiCR::backend::cloudr diff --git a/extern/cloudrRPC/include/hicr/backends/cloudr/instanceManager.hpp b/extern/cloudrRPC/include/hicr/backends/cloudr/instanceManager.hpp new file mode 100644 index 0000000..4ab077e --- /dev/null +++ b/extern/cloudrRPC/include/hicr/backends/cloudr/instanceManager.hpp @@ -0,0 +1,399 @@ + +#pragma once + +#include +#include +#include +#include +#include +#include +#include "instance.hpp" + +namespace HiCR::backend::cloudr +{ + +class CommunicationManager; +class TopologyManager; + +/** + * Instance manager for CloudR +*/ +class InstanceManager final : public HiCR::InstanceManager +{ + friend TopologyManager; + friend CommunicationManager; + + public: + +#define __CLOUDR_GATHER_TOPOLOGIES_RPC_NAME "[CloudR] Gather Topologies" +#define __CLOUDR_LAUNCH_ENTRY_POINT_RPC_NAME "[CloudR] Launch Main" +#define __CLOUDR_RELINQUISH_INSTANCE_RPC_NAME "[CloudR] Relinquish Instance" +#define __CLOUDR_FINALIZE_WORKER_RPC_NAME "[CloudR] Finalize Worker" +#define __CLOUDR_EXCHANGE_GLOBAL_MEMORY_SLOTS_RPC_NAME "[CloudR] Exchange Global Memory Slots" +#define __CLOUDR_FENCE_RPC_NAME "[CloudR] Fence" + + /** + * Type for any entrypoint function + */ + typedef std::function entryPoint_t; + + /** + * Constructor + * + * @param[in] rpcEngine + * @param[in] localTopology + * @param[in] entryPoint + */ + InstanceManager(HiCR::frontend::RPCEngine *rpcEngine, const HiCR::Topology localTopology, entryPoint_t entryPoint) + : HiCR::InstanceManager(), + _rpcEngine(rpcEngine), + _localTopology(localTopology), + _entryPoint(entryPoint) + {} + + ~InstanceManager() = default; + + /** + * Initialize the instance manager. Registers RPCs, stores available instances, detects the root instance, executes the entrypoint + */ + __INLINE__ void initialize() + { + // Registering Topology gathering function + auto gatherTopologiesExecutionUnit = HiCR::backend::pthreads::ComputeManager::createExecutionUnit([this](void *) { gatherTopologies(); }); + _rpcEngine->addRPCTarget(__CLOUDR_GATHER_TOPOLOGIES_RPC_NAME, gatherTopologiesExecutionUnit); + + // Registering launch function + auto launchEntryPointExecutionUnit = HiCR::backend::pthreads::ComputeManager::createExecutionUnit([this](void *) { _entryPoint(); }); + _rpcEngine->addRPCTarget(__CLOUDR_LAUNCH_ENTRY_POINT_RPC_NAME, launchEntryPointExecutionUnit); + + // Registering relinquish instance function + auto relinquishInstanceExecutionUnit = HiCR::backend::pthreads::ComputeManager::createExecutionUnit([this](void *) { relinquishInstance(); }); + _rpcEngine->addRPCTarget(__CLOUDR_RELINQUISH_INSTANCE_RPC_NAME, relinquishInstanceExecutionUnit); + + // Registering finalize function + auto finalizeWorkerExecutionUnit = HiCR::backend::pthreads::ComputeManager::createExecutionUnit([this](void *) { finalizeWorker(); }); + _rpcEngine->addRPCTarget(__CLOUDR_FINALIZE_WORKER_RPC_NAME, finalizeWorkerExecutionUnit); + + // Registering exchange global memory slots RPC + auto exchangeGlobalMemorySlotsExecutionUnit = HiCR::backend::pthreads::ComputeManager::createExecutionUnit([this](void *) { exchangeGlobalMemorySlotsRPC(); }); + _rpcEngine->addRPCTarget(__CLOUDR_EXCHANGE_GLOBAL_MEMORY_SLOTS_RPC_NAME, exchangeGlobalMemorySlotsExecutionUnit); + + // Registering global fence + auto fenceExecutionUnit = HiCR::backend::pthreads::ComputeManager::createExecutionUnit([this](void *) { fenceRPC(); }); + _rpcEngine->addRPCTarget(__CLOUDR_FENCE_RPC_NAME, fenceExecutionUnit); + + // Creating instance objects from the initially found instances now + HiCR::Instance::instanceId_t instanceIdCounter = 0; + for (auto &instance : _rpcEngine->getInstanceManager()->getInstances()) + { + // Only the current instance is the root one + const bool isRoot = _rpcEngine->getInstanceManager()->getRootInstanceId() == instance->getId(); + + // Creating new cloudr instance object (contains all the emulated information) + auto newInstance = std::make_shared(instanceIdCounter, instance.get(), isRoot); + + // Adding new instance to the internal storage + _cloudrInstances.push_back(newInstance); + + // If this is the current instance, set it now + if (instance->getId() == _rpcEngine->getInstanceManager()->getCurrentInstance()->getId()) + { + // Set as current instance + setCurrentInstance(newInstance); + + // Assigning its topology + newInstance->setTopology(_localTopology); + } + + // If it's root, store its pointer + if (isRoot) + { + // Store root instance pointer for later referencing + _rootInstance = newInstance.get(); + + // Adding instance to the collection of currently active instances + addInstance(newInstance); + } + + // If not root, add to the list of free instances (can be activated later) + if (isRoot == false) _freeInstances.insert(newInstance.get()); + + // Linking base instance id to the respective cloudr instance + _baseIdsToCloudrInstanceMap[instance->getId()] = newInstance.get(); + + // Increasing cloudr instance Id + instanceIdCounter++; + } + // printf("[CloudR] Worker %lu finished.\n", _rpcEngine->getInstanceManager()->getCurrentInstance()->getId()); + + ///// Now deploying + + // If I'm worker, all I need to do is listen for incoming RPCs + if (_rpcEngine->getInstanceManager()->getCurrentInstance()->isRootInstance() == false) + { + while (_continueListening) + { + // printf("[CloudR] Worker %lu listening...\n", _rpcEngine->getInstanceManager()->getCurrentInstance()->getId()); + _rpcEngine->listen(); + // printf("[CloudR] Worker %lu back from listening...\n", _rpcEngine->getInstanceManager()->getCurrentInstance()->getId()); + } + } + else // If I am root, do the following instead + { + // Gather the topologies of all other instances + for (auto &instance : _freeInstances) + { + // Requesting the root + _rpcEngine->requestRPC(instance->getId(), __CLOUDR_GATHER_TOPOLOGIES_RPC_NAME); + + // Getting return value (topology) + auto returnValue = _rpcEngine->getReturnValue(); + + // Receiving raw serialized topology information from the worker + std::string serializedTopology = (char *)returnValue->getPointer(); + + // Parsing serialized raw topology into a json object + auto topologyJson = nlohmann::json::parse(serializedTopology); + + // Freeing return value + _rpcEngine->getMemoryManager()->freeLocalMemorySlot(returnValue); + + // Updating current instance's topology + instance->setTopology(topologyJson); + } + + // Then go straight to the entry point + _entryPoint(); + + // printf("[Root %lu] Exited entry point...\n", _rpcEngine->getInstanceManager()->getCurrentInstance()->getId()); + } + } + + /** + * This function is the RPC that a running instance receives when it is relinquished. + * + * It does not terminate the worker, but simply confirms the instance is not running. + */ + __INLINE__ void relinquishInstance() + { + // printf("Relinquishing...\n"); + + // Returning confirmation that we are no longer running a function (idle) + int returnOkMessage = 0; + _rpcEngine->submitReturnValue((void *)&returnOkMessage, sizeof(returnOkMessage)); + } + + __INLINE__ void terminateInstanceImpl(const std::shared_ptr instance) override + { + // Requesting relinquish RPC execution on the requested instance + _rpcEngine->requestRPC(instance->getId(), __CLOUDR_RELINQUISH_INSTANCE_RPC_NAME); + + // Getting return value. It's enough to know a value was returned to know it is idling + const auto returnValue = _rpcEngine->getReturnValue(); + + // Adding instance back to free instances + _freeInstances.insert(_baseIdsToCloudrInstanceMap[instance->getId()]); + } + + /** + * Finalization procedure. Send rpc termination to all the non root instances + */ + __INLINE__ void finalize() override + { + // printf("[Instance %lu] Finalizing CloudR...\n", _rpcEngine->getInstanceManager()->getCurrentInstance()->getId()); + + // The following only be ran by the root rank, send an RPC to all others to finalize them + if (_rpcEngine->getInstanceManager()->getCurrentInstance()->isRootInstance()) + { + for (auto &instance : _cloudrInstances) + if (instance->isRootInstance() == false) _rpcEngine->requestRPC(instance->getId(), __CLOUDR_FINALIZE_WORKER_RPC_NAME); + } + } + + /** + * Abort execution with the specifies error code + * + * @param[in] errorCode + */ + __INLINE__ void abort(int errorCode) override { _rpcEngine->getInstanceManager()->abort(errorCode); } + + /** + * Getter for root instance id + * + * @return root instance id + */ + [[nodiscard]] __INLINE__ HiCR::Instance::instanceId_t getRootInstanceId() const override { return _rootInstance->getId(); } + + /** + * Getter for rpc engine + * + * @return rpc engine + */ + [[nodiscard]] __INLINE__ auto getRPCEngine() const { return _rpcEngine; } + + /** + * Getter for free instances + * + * @return free instances + */ + [[nodiscard]] __INLINE__ const auto &getFreeInstances() const { return _freeInstances; } + + private: + + /** + * Response to gather topology rpc + */ + __INLINE__ void gatherTopologies() + { + // Getting my current instance's topology + auto topology = static_cast(getCurrentInstance().get())->getTopology(); + + // Serializing topology information + const auto serializedTopology = topology.serialize().dump(); + + // Returning serialized topology + _rpcEngine->submitReturnValue((void *)serializedTopology.c_str(), serializedTopology.size() + 1); + } + + __INLINE__ std::shared_ptr createInstanceImpl(const HiCR::InstanceTemplate instanceTemplate) override + { + // If no more free instances available, fail now + // Commented out because we don't want to fail, simply return a nullptr + // if (_freeInstances.empty()) HICR_THROW_LOGIC("Requested the creation of a new instances, but CloudR has ran out of free instances"); + + // Creating instance object to return + std::shared_ptr newInstance = nullptr; + + // Getting requested topology from the instance template + const auto &topology = instanceTemplate.getTopology(); + + // Iterating over free instances to get the first one that satisfies the request + for (const auto &instance : _freeInstances) + if (instance->isCompatible(topology)) + { + // Assigning it as compatible instance + newInstance = std::make_shared(*instance); + + // Erasing it from the list of free instances + _freeInstances.erase(instance); + + // Stop looking into the others + break; + } + + // Commented out because we don't want to fail, simply return a nullptr + // if (newInstance == nullptr) HICR_THROW_LOGIC("Tried to create new instance but did not find any free instances that meet the required topology"); + + // If successful, initialize the new instance + if (newInstance != nullptr) + { + // Request the execution of the main driver function + _rpcEngine->requestRPC(newInstance->getBaseInstance()->getId(), __CLOUDR_LAUNCH_ENTRY_POINT_RPC_NAME); + } + + // Returning result. Nullptr, if no instance was created + return newInstance; + } + + __INLINE__ std::shared_ptr addInstanceImpl(HiCR::Instance::instanceId_t instanceId) override + { + HICR_THROW_LOGIC("The Host backend does not currently support the detection of new instances during runtime"); + } + + /** + * Request exchange memory slots rpc + * + * @param[in] tag the global memory slot tag to exchange + */ + __INLINE__ void requestExchangeGlobalMemorySlots(HiCR::GlobalMemorySlot::tag_t tag) + { + // Asking free instances to run the exchange RPC + for (const auto &instance : _freeInstances) _rpcEngine->requestRPC(instance->getId(), __CLOUDR_EXCHANGE_GLOBAL_MEMORY_SLOTS_RPC_NAME, tag); + } + + /** + * Request fence rpc + * + * @param[in] tag the global memory slot tag to fence + */ + __INLINE__ void requestFence(HiCR::GlobalMemorySlot::tag_t tag) + { + // Asking free instances to run the exchange RPC + for (const auto &instance : _freeInstances) _rpcEngine->requestRPC(instance->getId(), __CLOUDR_FENCE_RPC_NAME, tag); + } + + /** + * Response to request topology rpc + */ + __INLINE__ void requestTopology() + { + // Getting a pointer to the base instance who made the request + auto baseRequesterInstance = _rpcEngine->getRPCRequester(); + + // Getting base instance id + const auto baseInstanceId = baseRequesterInstance->getId(); + + // Getting cloudr instance from the base instance id + const auto cloudrInstance = _baseIdsToCloudrInstanceMap.at(baseInstanceId); + + // Serializing topology information + const auto serializedTopology = cloudrInstance->getTopology().serialize().dump(); + + // Returning serialized topology + _rpcEngine->submitReturnValue((void *)serializedTopology.c_str(), serializedTopology.size() + 1); + } + + /** + * Exit the worker rpc main loop and terminate execution + */ + __INLINE__ void finalizeWorker() + { + // Do not continue listening + // printf("[CloudR] Worker %lu running finalizeWorker() RPC.\n", _rpcEngine->getInstanceManager()->getCurrentInstance()->getId()); + _continueListening = false; + } + + /** + * rpc for exchange memory slots + */ + __INLINE__ void exchangeGlobalMemorySlotsRPC() + { + const auto exchangeTag = _rpcEngine->getRPCArgument(); + _rpcEngine->getCommunicationManager()->exchangeGlobalMemorySlots(exchangeTag, {}); + } + + /** + * rpc for fence + */ + __INLINE__ void fenceRPC() + { + const auto exchangeTag = _rpcEngine->getRPCArgument(); + _rpcEngine->getCommunicationManager()->fence(exchangeTag); + } + + /// RPC engine + HiCR::frontend::RPCEngine *const _rpcEngine; + + /// Storage for this instance's emulated topology + const HiCR::Topology _localTopology; + + /// Storage for the main function to run when a new instance runs + const entryPoint_t _entryPoint; + + // Pointer to the root instance + HiCR::backend::cloudr::Instance *_rootInstance; + + // Flag to signal non-root instances to finish listening + bool _continueListening = true; + + // Map that links the underlying instance ids with the cloudr instances + std::map _baseIdsToCloudrInstanceMap; + + /// Internal collection of cloudr instances + std::vector> _cloudrInstances; + + /// A collection of ready-to-use instances currently on standby + std::set _freeInstances; +}; // class CloudR + +} // namespace HiCR::backend::cloudr \ No newline at end of file diff --git a/extern/cloudrRPC/meson.build b/extern/cloudrRPC/meson.build new file mode 100644 index 0000000..d21ef90 --- /dev/null +++ b/extern/cloudrRPC/meson.build @@ -0,0 +1,65 @@ +project('CloudR', [ 'cpp'], + subproject_dir : 'extern', + default_options : [ + 'cpp_std=c++20', + 'buildtype=release' + ] +) + +CloudRDependencies = [ ] + +####### Getting HiCR dependency (if this is a standalone project) + +CloudRHiCRBackends = [ 'mpi', 'hwloc', 'pthreads' ] +CloudRHiCRFrontends = [ 'RPCEngine', 'channel' ] + +if meson.is_subproject() == false + +# Selecting default HiCR Backends +HiCRProject = subproject('HiCR', required: true, default_options: [ 'backends=' + ','.join(CloudRHiCRBackends), 'frontends=' + ','.join(CloudRHiCRFrontends) ]) +HiCRBuildDep = HiCRProject.get_variable('hicrBuildDep') +mpirunExecutable = HiCRProject.get_variable('mpirunExecutable') +CloudRDependencies += HiCRBuildDep + +endif + +####### Creating CloudR dependency + +# Warning handling option +warningAsErrorFlags=[] +if get_option('compileWarningsAsErrors') == true + warningAsErrorFlags=[ '-Werror' ] +endif + +CloudRBuildCppArgs = [ + '-Wfatal-errors', + warningAsErrorFlags + ] + +CloudRBuildIncludes = include_directories([ + 'include' + ]) + +####### Collect the dependencies + +CloudRBuildDep = declare_dependency( + compile_args: CloudRBuildCppArgs, + include_directories: CloudRBuildIncludes, + dependencies: CloudRDependencies + ) + +####### Build test / example targets only if HiCR is being loaded as a subproject + +if meson.is_subproject() == false + + # Build example targets + if get_option('buildExamples') + subdir('examples') + endif + + # Build test targets + if get_option('buildTests') + subdir('tests') + endif + +endif diff --git a/extern/cloudrRPC/meson_options.txt b/extern/cloudrRPC/meson_options.txt new file mode 100644 index 0000000..e25ec89 --- /dev/null +++ b/extern/cloudrRPC/meson_options.txt @@ -0,0 +1,11 @@ +option('buildTests', type : 'boolean', value : false, + description: 'Indicates whether to build tests' +) + +option('buildExamples', type : 'boolean', value : false, + description: 'Indicates whether to build example apps' +) + +option('compileWarningsAsErrors', type : 'boolean', value : false, + description: 'Indicates whether a compilation warning should result in a fatal error. This is useful for CI testing but may result in inconveniences for normal users, hence it should be false by default' +) diff --git a/include/deployr/deployr.hpp b/include/deployr/deployr.hpp index 8678c23..6f8feec 100644 --- a/include/deployr/deployr.hpp +++ b/include/deployr/deployr.hpp @@ -114,7 +114,7 @@ class DeployR final } // Sending RPC - _rpcEngine->requestRPC(*instance, initialFcName, runnerId); + _rpcEngine->requestRPC(instance->getId(), initialFcName, runnerId); } // Running initial function, if one has been assigned to the coordinator @@ -209,10 +209,10 @@ class DeployR final else // If not, it's another instance: send RPC and deserialize return value { // Requesting RPC from the remote instance - _rpcEngine->requestRPC(*instance, __DEPLOYR_GET_TOPOLOGY_RPC_NAME); + _rpcEngine->requestRPC(instance->getId(), __DEPLOYR_GET_TOPOLOGY_RPC_NAME); // Getting return value as a memory slot - auto returnValue = _rpcEngine->getReturnValue(*instance); + auto returnValue = _rpcEngine->getReturnValue(); // Receiving raw serialized topology information from the worker std::string serializedTopology = (char *)returnValue->getPointer(); diff --git a/meson.build b/meson.build index 390ad32..ac4d6f0 100644 --- a/meson.build +++ b/meson.build @@ -40,7 +40,7 @@ endif if 'cloudr' in engines mpirunExecutable = find_program('mpirun', '/usr/bin/mpirun', '/usr/local/bin/mpirun', required : true) - CloudRProject = subproject('cloudr', required: true, default_options: [ ]) + CloudRProject = subproject('cloudrRPC', required: true, default_options: [ ]) CloudRBuildDep = CloudRProject.get_variable('CloudRBuildDep') deployrDependencies += CloudRBuildDep DeployRDistributedCppFlag = '-D_DEPLOYR_DISTRIBUTED_ENGINE_CLOUDR'