Debian Codegraph @

prov/efa/test/efa_unit_test_hmem.c

raw
1 /* SPDX-License-Identifier: BSD-2-Clause OR GPL-2.0-only */
2 /* SPDX-FileCopyrightText: Copyright Amazon.com, Inc. or its affiliates. All rights reserved. */
3
4 #include "efa_unit_tests.h"
5
6
7 #if HAVE_NEURON
8 /**
9 * @brief Verify when neuron_alloc failed (return null),
10 * efa_hmem_info_initialize will still return 0 but leave
11 * efa_hmem_info[FI_HMEM_NEURON].initialized and
12 * efa_hmem_info[FI_HMEM_NEURON].p2p_supported_by_device as false.
13 *
14 * @param[in] state struct efa_resource that is managed by the framework
15 */
16 void test_efa_hmem_info_update_neuron(struct efa_resource **state)
17 {
18 int ret;
19 struct efa_resource *resource = *state;
20 uint32_t efa_device_caps_orig;
21 bool neuron_initialized_orig;
22
23 resource->hints = efa_unit_test_alloc_hints(FI_EP_RDM, EFA_FABRIC_NAME);
24 assert_non_null(resource->hints);
25
26 ret = fi_getinfo(FI_VERSION(1, 14), NULL, NULL, 0ULL, resource->hints, &resource->info);
27 assert_int_equal(ret, 0);
28
29 neuron_initialized_orig = hmem_ops[FI_HMEM_NEURON].initialized;
30 hmem_ops[FI_HMEM_NEURON].initialized = true;
31 efa_device_caps_orig = g_device_list[0].device_caps;
32 g_device_list[0].device_caps |= EFADV_DEVICE_ATTR_CAPS_RDMA_READ;
33 g_efa_unit_test_mocks.neuron_alloc = &efa_mock_neuron_alloc_return_null;
34
35 ret = efa_hmem_info_initialize();
36
37 /* recover the modified global variables before doing check */
38 hmem_ops[FI_HMEM_NEURON].initialized = neuron_initialized_orig;
39 g_device_list[0].device_caps = efa_device_caps_orig;
40
41 assert_int_equal(ret, 0);
42 assert_false(g_efa_hmem_info[FI_HMEM_NEURON].initialized);
43 assert_false(g_efa_hmem_info[FI_HMEM_NEURON].p2p_supported_by_device);
44 }
45
46 /**
47 * @brief Verify when p2p is disabled, we don't check p2p support with neuron_alloc.
48 * Just leave p2p_supported_by_device to false.
49 *
50 * @param[in] state struct efa_resource that is managed by the framework
51 */
52 void test_efa_hmem_info_disable_p2p_neuron(struct efa_resource **state)
53 {
54 int ret;
55 struct efa_resource *resource = *state;
56 uint32_t efa_device_caps_orig;
57 bool neuron_initialized_orig;
58
59 ofi_hmem_disable_p2p = 1;
60
61 resource->hints = efa_unit_test_alloc_hints(FI_EP_RDM, EFA_FABRIC_NAME);
62 assert_non_null(resource->hints);
63
64 ret = fi_getinfo(FI_VERSION(1, 14), NULL, NULL, 0ULL, resource->hints, &resource->info);
65 assert_int_equal(ret, 0);
66
67 neuron_initialized_orig = hmem_ops[FI_HMEM_NEURON].initialized;
68 hmem_ops[FI_HMEM_NEURON].initialized = true;
69 efa_device_caps_orig = g_device_list[0].device_caps;
70 g_device_list[0].device_caps |= EFADV_DEVICE_ATTR_CAPS_RDMA_READ;
71 /* neuron_alloc should not be called when p2p is disabled. efa_mock_neuron_alloc_return_mock will fail the test when it is called. */
72 g_efa_unit_test_mocks.neuron_alloc = efa_mock_neuron_alloc_return_mock;
73
74 ret = efa_hmem_info_initialize();
75
76 /* recover the modified global variables before doing check */
77 ofi_hmem_disable_p2p = 0;
78 g_device_list[0].device_caps = efa_device_caps_orig;
79 hmem_ops[FI_HMEM_NEURON].initialized = neuron_initialized_orig;
80
81 assert_int_equal(ret, 0);
82 assert_true(g_efa_hmem_info[FI_HMEM_NEURON].initialized);
83 assert_false(g_efa_hmem_info[FI_HMEM_NEURON].p2p_supported_by_device);
84 }
85 #else
86 void test_efa_hmem_info_update_neuron()
87 {
88 skip();
89 }
90
91 void test_efa_hmem_info_disable_p2p_neuron()
92 {
93 skip();
94 }
95 #endif /* HAVE_NEURON */
96
97 #if HAVE_CUDA
98 /**
99 * @brief Verify when p2p is disabled, we don't check p2p support with ofi_cudaMalloc.
100 * Just leave p2p_supported_by_device to false for cuda.
101 *
102 * @param[in] state struct efa_resource that is managed by the framework
103 */
104 void test_efa_hmem_info_disable_p2p_cuda(struct efa_resource **state)
105 {
106 int ret;
107 struct efa_resource *resource = *state;
108 bool cuda_initialized_orig;
109
110 ofi_hmem_disable_p2p = 1;
111
112 resource->hints = efa_unit_test_alloc_hints(FI_EP_RDM, EFA_FABRIC_NAME);
113 assert_non_null(resource->hints);
114
115 ret = fi_getinfo(FI_VERSION(1, 14), NULL, NULL, 0ULL, resource->hints, &resource->info);
116 assert_int_equal(ret, 0);
117
118 cuda_initialized_orig = hmem_ops[FI_HMEM_CUDA].initialized;
119 hmem_ops[FI_HMEM_CUDA].initialized = true;
120 /* ofi_cudaMalloc should not be called when p2p is disabled. efa_mock_ofi_cudaMalloc_return_mock will fail the test when it is called. */
121 g_efa_unit_test_mocks.ofi_cudaMalloc = efa_mock_ofi_cudaMalloc_return_mock;
122
123 ret = efa_hmem_info_initialize();
124
125 /* recover the modified global variables before doing check */
126 ofi_hmem_disable_p2p = 0;
127 hmem_ops[FI_HMEM_CUDA].initialized = cuda_initialized_orig;
128
129 assert_int_equal(ret, 0);
130 assert_true(g_efa_hmem_info[FI_HMEM_CUDA].initialized);
131 assert_false(g_efa_hmem_info[FI_HMEM_CUDA].p2p_supported_by_device);
132 }
133 #else
134 void test_efa_hmem_info_disable_p2p_cuda()
135 {
136 skip();
137 }
138 #endif /* HAVE_CUDA */