1 /**
2  * Copyright (c) UT-Battelle, LLC. 2017. ALL RIGHTS RESERVED.
3  * Copyright (c) Los Alamos National Security, LLC. 2018. ALL RIGHTS RESERVED.
4  * See file LICENSE for terms.
5  */
6 
7 #ifndef UCT_UGNI_DEF_H
8 #define UCT_UGNI_DEF_H
9 
10 #ifdef HAVE_CONFIG_H
11 #  include "config.h"
12 #endif
13 
14 #include <uct/base/uct_worker.h>
15 #include <ucs/async/async.h>
16 
17 #define UCT_UGNI_MD_NAME        "ugni"
18 #define UCT_UGNI_HASH_SIZE      256
19 #define UCT_UGNI_MAX_DEVICES    2
20 #define UCT_UGNI_LOCAL_CQ       8192
21 #define UCT_UGNI_RKEY_MAGIC     0xdeadbeefLL
22 #define UCT_UGNI_MAX_TYPE_NAME  10
23 #define LEN_64                  (sizeof(uint64_t))
24 #define LEN_32                  (sizeof(uint32_t))
25 #define UGNI_GET_ALIGN          4
26 #define UCT_UGNI_INIT_FLUSH     1
27 #define UCT_UGNI_INIT_FLUSH_REQ 2
28 
29 #define UCT_UGNI_ZERO_LENGTH_POST(len)              \
30 if (0 == len) {                                     \
31     ucs_trace_data("Zero length request: skip it"); \
32     return UCS_OK;                                  \
33 }
34 
35 #define uct_ugni_enter_async(x) \
36 do {\
37     ucs_trace_async("Taking lock on worker %p", (x)->super.worker); \
38     UCS_ASYNC_BLOCK((x)->super.worker->async);                      \
39 } while(0)
40 
41 #define uct_ugni_leave_async(x) \
42 do {\
43     ucs_trace_async("Releasing lock on worker %p", (x)->super.worker);  \
44     UCS_ASYNC_UNBLOCK((x)->super.worker->async);                        \
45 } while(0)
46 
47 #if ENABLE_MT
48 #define uct_ugni_check_lock_needed(_cdm) UCS_THREAD_MODE_MULTI == (_cdm)->thread_mode
49 #define uct_ugni_cdm_init_lock(_cdm) ucs_recursive_spinlock_init(&(_cdm)->lock, 0)
50 #define uct_ugni_cdm_destroy_lock(_cdm) \
51     do { \
52         ucs_status_t status; \
53         \
54         status = ucs_recursive_spinlock_destroy(&(_cdm)->lock); \
55         if (status != UCS_OK) {\
56             ucs_warn("ucs_recursive_spinlock_destroy() failed (%d)", status); \
57         } \
58     } while(0)
59 #define uct_ugni_cdm_lock(_cdm) \
60 if (uct_ugni_check_lock_needed(_cdm)) {  \
61     ucs_trace_async("Taking lock");      \
62     ucs_recursive_spin_lock(&(_cdm)->lock);   \
63 }
64 #define uct_ugni_cdm_unlock(_cdm) \
65 if (uct_ugni_check_lock_needed(_cdm)) {    \
66     ucs_trace_async("Releasing lock");        \
67     ucs_recursive_spin_unlock(&(_cdm)->lock);   \
68 }
69 #else
70 #define uct_ugni_cdm_init_lock(x) UCS_OK
71 #define uct_ugni_cdm_destroy_lock(x) {}
72 #define uct_ugni_cdm_lock(x)
73 #define uct_ugni_cdm_unlock(x)
74 #define uct_ugni_check_lock_needed(x) 0
75 #endif
76 
77 #endif
78