File: btl_ugni_atomic.c

package info (click to toggle)
openmpi 5.0.8-4
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 201,684 kB
  • sloc: ansic: 613,078; makefile: 42,353; sh: 11,194; javascript: 9,244; f90: 7,052; java: 6,404; perl: 5,179; python: 1,859; lex: 740; fortran: 61; cpp: 20; tcl: 12
file content (172 lines) | stat: -rw-r--r-- 7,075 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */
/*
 * Copyright (c) 2014-2018 Los Alamos National Security, LLC. All rights
 *                         reserved.
 * Copyright (c) 2019      Triad National Security, LLC. All rights
 *                         reserved.
 * Copyright (c) 2019      Google, LLC. All rights reserved.
 * Copyright (c) 2021      Nanook Consulting.  All rights reserved.
 * $COPYRIGHT$
 *
 * Additional copyrights may follow
 *
 * $HEADER$
 */

#include "btl_ugni_rdma.h"

static gni_fma_cmd_type_t amo_cmds[][MCA_BTL_ATOMIC_LAST] = {
    [PMIX_INT32] =
        {
            [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_IADD_S,
            [MCA_BTL_ATOMIC_LAND] = GNI_FMA_ATOMIC2_AND_S,
            [MCA_BTL_ATOMIC_LOR] = GNI_FMA_ATOMIC2_OR_S,
            [MCA_BTL_ATOMIC_LXOR] = GNI_FMA_ATOMIC2_XOR_S,
            [MCA_BTL_ATOMIC_SWAP] = GNI_FMA_ATOMIC2_SWAP_S,
            [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_IMIN_S,
            [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_IMAX_S,
        },
    [PMIX_INT64] =
        {
            [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC_ADD,
            [MCA_BTL_ATOMIC_AND] = GNI_FMA_ATOMIC_AND,
            [MCA_BTL_ATOMIC_OR] = GNI_FMA_ATOMIC_OR,
            [MCA_BTL_ATOMIC_XOR] = GNI_FMA_ATOMIC_XOR,
            [MCA_BTL_ATOMIC_SWAP] = GNI_FMA_ATOMIC2_SWAP,
            [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_IMIN,
            [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_IMAX,
        },
    [PMIX_FLOAT] =
        {
            [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FPADD_S,
            [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FPMIN_S,
            [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FPMAX_S,
        },
    [PMIX_DOUBLE] =
        {
            [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FPADD,
            [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FPMIN,
            [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FPMAX,
        },
};

static gni_fma_cmd_type_t famo_cmds[][MCA_BTL_ATOMIC_LAST] = {
    [PMIX_INT32] =
        {
            [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FIADD_S,
            [MCA_BTL_ATOMIC_LAND] = GNI_FMA_ATOMIC2_FAND_S,
            [MCA_BTL_ATOMIC_LOR] = GNI_FMA_ATOMIC2_FOR_S,
            [MCA_BTL_ATOMIC_LXOR] = GNI_FMA_ATOMIC2_FXOR_S,
            [MCA_BTL_ATOMIC_SWAP] = GNI_FMA_ATOMIC2_FSWAP_S,
            [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FIMIN_S,
            [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FIMAX_S,
        },
    [PMIX_INT64] =
        {
            [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC_FADD,
            [MCA_BTL_ATOMIC_AND] = GNI_FMA_ATOMIC_FAND,
            [MCA_BTL_ATOMIC_OR] = GNI_FMA_ATOMIC_FOR,
            [MCA_BTL_ATOMIC_XOR] = GNI_FMA_ATOMIC_FXOR,
            [MCA_BTL_ATOMIC_SWAP] = GNI_FMA_ATOMIC2_FSWAP,
            [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FIMIN,
            [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FIMAX,
        },
    [PMIX_FLOAT] =
        {
            [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FFPADD_S,
            [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FFPMIN_S,
            [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FFPMAX_S,
        },
    [PMIX_DOUBLE] =
        {
            [MCA_BTL_ATOMIC_ADD] = GNI_FMA_ATOMIC2_FFPADD,
            [MCA_BTL_ATOMIC_MIN] = GNI_FMA_ATOMIC2_FFPMIN,
            [MCA_BTL_ATOMIC_MAX] = GNI_FMA_ATOMIC2_FFPMAX,
        },
};

int mca_btl_ugni_aop(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint,
                     uint64_t remote_address, mca_btl_base_registration_handle_t *remote_handle,
                     mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order,
                     mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata)
{
    gni_mem_handle_t dummy = {0, 0};
    mca_btl_ugni_post_descriptor_t post_desc;
    int gni_op, type;
    size_t size;

    size = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? 4 : 8;
    if (MCA_BTL_ATOMIC_FLAG_FLOAT & flags) {
        type = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? PMIX_FLOAT : PMIX_DOUBLE;
    } else {
        type = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? PMIX_INT32 : PMIX_INT64;
    }

    gni_op = amo_cmds[type][op];
    if (0 == gni_op) {
        return OPAL_ERR_NOT_SUPPORTED;
    }

    init_post_desc(&post_desc, endpoint, order, GNI_POST_AMO, 0, dummy, remote_address,
                   remote_handle->gni_handle, size, 0, cbfunc, cbcontext, cbdata, NULL);
    post_desc.gni_desc.amo_cmd = gni_op;
    post_desc.gni_desc.first_operand = operand;

    return mca_btl_ugni_endpoint_post_fma(endpoint, &post_desc);
}

int mca_btl_ugni_afop(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint,
                      void *local_address, uint64_t remote_address,
                      mca_btl_base_registration_handle_t *local_handle,
                      mca_btl_base_registration_handle_t *remote_handle,
                      mca_btl_base_atomic_op_t op, uint64_t operand, int flags, int order,
                      mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata)
{
    mca_btl_ugni_post_descriptor_t post_desc;
    int gni_op, type;
    size_t size;

    size = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? 4 : 8;
    if (MCA_BTL_ATOMIC_FLAG_FLOAT & flags) {
        type = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? PMIX_FLOAT : PMIX_DOUBLE;
    } else {
        type = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? PMIX_INT32 : PMIX_INT64;
    }

    gni_op = famo_cmds[type][op];
    if (0 == gni_op) {
        return OPAL_ERR_NOT_SUPPORTED;
    }

    init_post_desc(&post_desc, endpoint, order, GNI_POST_AMO, (intptr_t) local_address,
                   local_handle->gni_handle, remote_address, remote_handle->gni_handle, size, 0,
                   cbfunc, cbcontext, cbdata, local_handle);
    post_desc.gni_desc.amo_cmd = gni_op;
    post_desc.gni_desc.first_operand = operand;

    return mca_btl_ugni_endpoint_post_fma(endpoint, &post_desc);
}

int mca_btl_ugni_acswap(struct mca_btl_base_module_t *btl, struct mca_btl_base_endpoint_t *endpoint,
                        void *local_address, uint64_t remote_address,
                        mca_btl_base_registration_handle_t *local_handle,
                        mca_btl_base_registration_handle_t *remote_handle, uint64_t compare,
                        uint64_t value, int flags, int order,
                        mca_btl_base_rdma_completion_fn_t cbfunc, void *cbcontext, void *cbdata)
{
    mca_btl_ugni_post_descriptor_t post_desc;
    size_t size;
    int gni_op;

    gni_op = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? GNI_FMA_ATOMIC2_FCSWAP_S : GNI_FMA_ATOMIC_CSWAP;
    size = (MCA_BTL_ATOMIC_FLAG_32BIT & flags) ? 4 : 8;

    init_post_desc(&post_desc, endpoint, order, GNI_POST_AMO, (intptr_t) local_address,
                   local_handle->gni_handle, remote_address, remote_handle->gni_handle, size, 0,
                   cbfunc, cbcontext, cbdata, local_handle);
    post_desc.gni_desc.amo_cmd = gni_op;
    post_desc.gni_desc.first_operand = compare;
    post_desc.gni_desc.second_operand = value;

    return mca_btl_ugni_endpoint_post_fma(endpoint, &post_desc);
}