1 /**
2 * Copyright (C) Mellanox Technologies Ltd. 2001-2019.  ALL RIGHTS RESERVED.
3 * Copyright (C) UT-Battelle, LLC. 2015. ALL RIGHTS RESERVED.
4 *
5 * See file LICENSE for terms.
6 */
7 
8 #ifndef TEST_UCP_TAG_H_
9 #define TEST_UCP_TAG_H_
10 
11 #include "ucp_test.h"
12 
13 
14 class test_ucp_tag : public ucp_test {
15 public:
16     static ucp_params_t get_ctx_params();
17 
18     enum send_type_t {
19         SEND_NB,
20         SEND_NBR,
21         SEND_B,
22         SEND_SYNC_NB
23     };
24 
25     enum recv_type_t {
26         RECV_NB,
27         RECV_NBR,
28         RECV_B,
29         RECV_BR
30     };
31 
32 protected:
33     enum {
34         RECV_REQ_INTERNAL = DEFAULT_PARAM_VARIANT,
35         RECV_REQ_EXTERNAL   /* for a receive request that was allocated by
36                                the upper layer and not by ucx */
37     };
38 
39     struct request {
40         bool                completed;
41         bool                external;
42         void                *req_mem;
43         ucs_status_t        status;
44         ucp_tag_recv_info_t info;
45     };
46 
47     virtual void init();
48 
49     void enable_tag_mp_offload();
50 
51     static void request_init(void *request);
52 
53     static request* request_alloc();
54 
55     static void request_release(struct request *req);
56 
57     static void request_free(struct request *req);
58 
59     static void send_callback(void *request, ucs_status_t status);
60 
61     static void recv_callback(void *request, ucs_status_t status,
62                                   ucp_tag_recv_info_t *info);
63 
64     request* send(entity &sender, send_type_t type, const void *buffer,
65                   size_t count, ucp_datatype_t datatype, ucp_tag_t tag,
66                   int ep_index = 0);
67 
68     request* send_nb(const void *buffer, size_t count, ucp_datatype_t datatype,
69                      ucp_tag_t tag, int ep_index = 0);
70 
71     request* send_nbr(const void *buffer, size_t count, ucp_datatype_t datatype,
72                       ucp_tag_t tag, int ep_index = 0);
73 
74     void send_b(const void *buffer, size_t count, ucp_datatype_t datatype,
75                 ucp_tag_t tag, int buf_index = 0);
76 
77     request* send_sync_nb(const void *buffer, size_t count, ucp_datatype_t datatype,
78                           ucp_tag_t tag, int buf_index = 0);
79 
80     request* recv(entity &receiver, recv_type_t type, void *buffer,
81                   size_t count, ucp_datatype_t dt, ucp_tag_t tag,
82                   ucp_tag_t tag_mask, ucp_tag_recv_info_t *info,
83                   int buf_index = 0);
84 
85     request* recv_nb(void *buffer, size_t count, ucp_datatype_t dt,
86                      ucp_tag_t tag, ucp_tag_t tag_mask, int buf_index = 0);
87 
88     request* recv_req_nb(void *buffer, size_t count, ucp_datatype_t dt,
89                          ucp_tag_t tag, ucp_tag_t tag_mask, int buf_index = 0);
90 
91     request* recv_cb_nb(void *buffer, size_t count, ucp_datatype_t dt,
92                         ucp_tag_t tag, ucp_tag_t tag_mask, int buf_index = 0);
93 
94     ucs_status_t recv_b(void *buffer, size_t count, ucp_datatype_t datatype,
95                         ucp_tag_t tag, ucp_tag_t tag_mask,
96                         ucp_tag_recv_info_t *info, int buf_index = 0);
97 
98     ucs_status_t recv_req_b(void *buffer, size_t count, ucp_datatype_t datatype,
99                             ucp_tag_t tag, ucp_tag_t tag_mask,
100                             ucp_tag_recv_info_t *info, int buf_index = 0);
101 
102     ucs_status_t recv_cb_b(void *buffer, size_t count, ucp_datatype_t datatype,
103                            ucp_tag_t tag, ucp_tag_t tag_mask,
104                            ucp_tag_recv_info_t *info, int buf_index = 0);
105 
106     void wait(request *req, int buf_index = 0);
107 
108     void wait_and_validate(request *req);
109 
110     void wait_for_unexpected_msg(ucp_worker_h worker, double sec);
111 
112     void check_offload_support(bool offload_required);
113 
114     virtual bool is_external_request();
115 
116     static ucp_context_attr_t ctx_attr;
117     ucs::ptr_vector<ucs::scoped_setenv> m_env;
118 
119 private:
120     int get_worker_index(int buf_index);
121 
122 public:
123     int    count;
124 };
125 
126 #endif
127