File: setopt_test.c

package info (click to toggle)
mpich 4.3.2-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 101,184 kB
  • sloc: ansic: 1,040,629; cpp: 82,270; javascript: 40,763; perl: 27,933; python: 16,041; sh: 14,676; xml: 14,418; f90: 12,916; makefile: 9,270; fortran: 8,046; java: 4,635; asm: 324; ruby: 103; awk: 27; lisp: 19; php: 8; sed: 4
file content (167 lines) | stat: -rw-r--r-- 4,278 bytes parent folder | download | duplicates (3)
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
/*
 * Copyright (c) Amazon Inc.  All rights reserved.
 *
 * This software is available to you under a choice of one of two
 * licenses.  You may choose to be licensed under the terms of the GNU
 * General Public License (GPL) Version 2, available from the file
 * COPYING in the main directory of this source tree, or the
 * BSD license below:
 *
 *     Redistribution and use in source and binary forms, with or
 *     without modification, are permitted provided that the following
 *     conditions are met:
 *
 *      - Redistributions of source code must retain the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer.
 *
 *      - Redistributions in binary form must reproduce the above
 *        copyright notice, this list of conditions and the following
 *        disclaimer in the documentation and/or other materials
 *        provided with the distribution.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
#include <stdio.h>
#include <rdma/fi_domain.h>
#include <rdma/fi_errno.h>

#include "unit_common.h"
#include "hmem.h"
#include "shared.h"

char err_buf[512];

int test_setopt_cuda_api_permmitted()
{
	bool optval = true;
	int err, ret;

	hints->caps |= FI_HMEM;
	hints->domain_attr->mr_mode |= FI_MR_HMEM;

	err = fi_getinfo(FT_FIVERSION, NULL,
			 0, 0, hints, &fi);
	if (err) {
		if (err == -FI_ENODATA) {
			ret = SKIPPED;
			FT_UNIT_STRERR(err_buf,
				       "no HMEM support",
				       err);
		} else {
			ret = FAIL;
			FT_UNIT_STRERR(err_buf,
				       "fi_getinfo failed!",
				       err);
		}

		goto out;
	}

	err = ft_open_fabric_res();
	if (err) {
		ret = FAIL;
		FT_UNIT_STRERR(err_buf,
			       "open fabric resource failed!",
			       err);
		goto out;
	}

	err = fi_endpoint(domain, fi, &ep, NULL);
	if (err) {
		ret = FAIL;
		FT_UNIT_STRERR(err_buf,
			       "open endpoint failed!",
			       err);
		goto out;
	}

	err = fi_setopt(&ep->fid, FI_OPT_ENDPOINT,
			FI_OPT_CUDA_API_PERMITTED,
			&optval, sizeof(optval) );
	if (err == -FI_ENOPROTOOPT) {
		/* Per document, any provider that claim
		 * support FI_HMEM capability is required
		 * to implement this option
		 */
		ret = FAIL;
		FT_UNIT_STRERR(err_buf,
			       "FI_OPT_CUDA_API_PERMITTED was not implemented!",
			       err);
	} else if (err == -FI_EOPNOTSUPP || err == -FI_EINVAL || err == 0) {
		/* per document, both -FI_EOPNOTSUPP and
		 * -FI_EINVAL are valid return for setting
		 * this option:
		 *	-FI_EOPNOTSUPP means the provider's HMEM CUDA
		 *	support rely on calling CUDA API.
		 *	-FI_EINVAL means there is no CUDA device
		 *	 or CUDA library available
		 */
		ret = PASS;
	} else {
		FT_UNIT_STRERR(err_buf, "fi_setopt failed!", err);
		ret = FAIL;
	}

out:
	ft_close_fids(); /* close ep, eq, domain, fabric */
	return ret;
}

static void usage(char *name)
{
        ft_unit_usage(name, "Unit test for fi_setopt");
}

int main(int argc, char **argv)
{
	int op;
	struct test_entry test_array[] = {
		TEST_ENTRY(test_setopt_cuda_api_permmitted, "Test FI_OPT_CUDA_API_PERMITTED"),
		TEST_ENTRY(NULL, ""),
	};

	int failed;

	hints = fi_allocinfo();
	if (!hints) {
		FT_UNIT_STRERR(err_buf,
			       "hints allocationed failed!",
			       -FI_ENOMEM);
		return FAIL;
	}

	while ((op = getopt(argc, argv, FAB_OPTS HMEM_OPTS "h")) != -1) {
		switch (op) {
		default:
			ft_parseinfo(op, optarg, hints, &opts);
			break;
		case '?':
		case 'h':
			usage(argv[0]);
			return EXIT_FAILURE;
		}
	}

	hints->mode = ~0;
	hints->domain_attr->mode = ~0;
	hints->domain_attr->mr_mode = ~(FI_MR_BASIC | FI_MR_SCALABLE);
	hints->caps |= FI_MSG;

	failed = run_tests(test_array, err_buf);
	if (failed > 0) {
		printf("Summary: %d tests failed\n", failed);
	} else {
		printf("Summary: all tests passed\n");
	}

	ft_free_res();
	return (failed > 0) ? EXIT_FAILURE : EXIT_SUCCESS;
}