okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

Niko1221Merge branch 'f-139b-arc' into f-139-relad33b8074

main
2.0 KiB56 linesraw
1//==--------------- shmem_utils.hpp ---------------*- C++ -*----------------==//
2//
3// Copyright (C) Intel Corporation
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5// See https://llvm.org/LICENSE.txt for license information.
6//
7//===----------------------------------------------------------------------===//
8
9#ifndef __DPCT_SHMEM_UTILS_HPP__
10#define __DPCT_SHMEM_UTILS_HPP__
11
12namespace dpct::shmemx {
13
14enum flags { RUNTIME_MPI = 1 << 1, RUNTIME_OPENSHMEM = 1 << 2 };
15
16/// Initialize Intel SHMEM library based on exisiting communicator
17/// \param [in] runtime_flags specify the underlying communicator like MPI/
18/// OpenSHMEM to initialize iSHMEM for launcher agnostic bootstrapping
19/// \param [in] attr Additional attributes for initializing the iSHMEM library.
20void init_attr(unsigned runtime_flags, ishmemx_attr_t *attr) {
21  if (runtime_flags == 0) {
22    // if no runtime flags are present, initialize iSHMEM normally
23    ishmem_init();
24  } else {
25    unsigned ishmem_runtime_flags = 0;
26
27    if (runtime_flags & RUNTIME_MPI)
28      ishmem_runtime_flags |= ISHMEMX_RUNTIME_MPI;
29    if (runtime_flags & RUNTIME_OPENSHMEM)
30      ishmem_runtime_flags |= ISHMEMX_RUNTIME_OPENSHMEM;
31
32    attr->runtime = static_cast<ishmemx_runtime_type_t>(ishmem_runtime_flags);
33    ishmemx_init_attr(attr);
34  }
35}
36
37/// Update signal address with signal using signal operation
38/// \param [out] sig_addr Symmetric address of the signal data object to be
39/// updated on the remote PE.
40/// \param [in] signal Unsigned 64-bit value that is used for updating the
41/// remote sig_addr signal data object.
42/// \param [in] sig_op Operator used to update signal data object
43/// \param [in] pe Processing element
44void signal_op(uint64_t *sig_addr, uint64_t signal, int sig_op, int pe) {
45  if (sig_op == ISHMEM_SIGNAL_SET) {
46    ishmemx_signal_set(sig_addr, signal, pe);
47  } else if (sig_op == ISHMEM_SIGNAL_ADD) {
48    ishmemx_signal_add(sig_addr, signal, pe);
49  } else {
50    throw std::runtime_error("Unsupported signal operator!");
51  }
52}
53
54} // namespace dpct::shmemx
55
56#endif // __DPCT_SHMEM_UTILS_HPP__