aboutsummaryrefslogtreecommitdiffstats
path: root/meta-amdfalconx86/recipes-graphics/drm/files/0032-tests-amdgpu-Add-test-for-multi-GPUs-SVM-test-v3.patch
blob: 388419d8e9b7c0ff02677d433beb95c9f77c60e5 (plain)
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
From ce7de7e34c1a87d56bcc7a8ebeac1a25756c5991 Mon Sep 17 00:00:00 2001
From: Alex Xie <AlexBin.Xie@amd.com>
Date: Fri, 30 Oct 2015 12:04:07 -0400
Subject: [PATCH 032/117] tests/amdgpu: Add test for multi GPUs SVM test v3
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

1. We try to open all GPUs when test starts.
2. Test multi GPUs for SVM
3. Add verbose output option and facility into this unit test app.

v2:
1. Adjust title
2. Use drmGetDevices to get the number of cards available.
3. Add warning output option and facility into this unit test app.
4. Adjust a comment and delete useless C statement when open function call fails.
5. Add two informative outputs in single SVM test.

v3:
1. Use general device name from drmGetDevices instead of fixed name.
2. open devices in a single "for" statement.
3. Create a function to close all devices.

Change-Id: I313c13eabd6f0c2d3107ba37413e8ebd871faa0e
Signed-off-by: Alex Xie <AlexBin.Xie@amd.com>
Acked-by: Christian König <christian.koenig@amd.com>
---
 tests/amdgpu/amdgpu_test.c | 92 +++++++++++++++++++++++++++++++++++++++-------
 tests/amdgpu/amdgpu_test.h |  5 +++
 tests/amdgpu/basic_tests.c | 71 +++++++++++++++++++++++++++++++++++
 3 files changed, 154 insertions(+), 14 deletions(-)

diff --git a/tests/amdgpu/amdgpu_test.c b/tests/amdgpu/amdgpu_test.c
index 71f357c..1e71fbf 100644
--- a/tests/amdgpu/amdgpu_test.c
+++ b/tests/amdgpu/amdgpu_test.c
@@ -56,6 +56,10 @@
  */
 int drm_amdgpu[MAX_CARDS_SUPPORTED];
 
+static int num_devices;
+static bool verbose = false;
+static bool warning = false;
+
 /** The table of all known test suites to run */
 static CU_SuiteInfo suites[] = {
 	{
@@ -106,14 +110,24 @@ static void display_test_suites(void)
 	}
 }
 
+static void amdgpu_close_all()
+{
+	int i;
+	for (i = 0; i < num_devices; i++)
+		if (drm_amdgpu[i] > 0)
+			close(drm_amdgpu[i]);
+}
 
 /** Help string for command line parameters */
-static const char usage[] = "Usage: %s [-hl] [<-s <suite id>> [-t <test id>]]\n"
+static const char usage[] =
+				"Usage: %s [-hlvw] [<-s <suite id>> [-t <test id>]]\n"
 				"where:\n"
 				"       l - Display all suites and their tests\n"
+				"       v - Verbose output\n"
+				"       w - Output warning message\n"
 				"       h - Display this help\n";
 /** Specified options strings for getopt */
-static const char options[]   = "hls:t:";
+static const char options[]   = "hlvws:t:";
 
 /* The main() function for setting up and running the tests.
  * Returns a CUE_SUCCESS on successful running, another
@@ -127,8 +141,10 @@ int main(int argc, char **argv)
 	int test_id  = -1;	/* By default run all tests in the suite */
 	CU_pSuite pSuite = NULL;
 	CU_pTest  pTest  = NULL;
+	drmDevicePtr devices[MAX_CARDS_SUPPORTED];
 
 	int aval = drmAvailable();
+	char card_name[256];
 
 	if (aval == 0) {
 		fprintf(stderr, "DRM driver is not available\n");
@@ -153,6 +169,12 @@ int main(int argc, char **argv)
 		case 't':
 			test_id = atoi(optarg);
 			break;
+		case 'v':
+			verbose = true;
+			break;
+		case 'w':
+			warning = true;
+			break;
 		case '?':
 		case 'h':
 			fprintf(stderr, usage, argv[0]);
@@ -163,17 +185,31 @@ int main(int argc, char **argv)
 		}
 	}
 
-	/* Try to open all possible radeon connections
-	 * Right now: Open only the 0.
+	/* Try to open all possible amdgpu connections
 	 */
-	printf("Try to open the card 0..\n");
-	drm_amdgpu[0] = open("/dev/dri/card0", O_RDWR | O_CLOEXEC);
-
-	if (drm_amdgpu[0] < 0) {
-		perror("Cannot open /dev/dri/card0\n");
+	num_devices = drmGetDevices(devices, MAX_CARDS_SUPPORTED);
+	amdgpu_vprintf("\n Number of DRI devices is %d\n", num_devices);
+	if (num_devices > MAX_CARDS_SUPPORTED)
+		num_devices = MAX_CARDS_SUPPORTED;
+	if (num_devices <= 0) {
+		perror("Cannot query number of DRI devices.\n");
 		exit(EXIT_FAILURE);
 	}
 
+	for (i = 0; i < num_devices; i++) {
+		amdgpu_vprintf("Try to open %s..\n",
+			devices[i]->nodes[DRM_NODE_PRIMARY]);
+		drm_amdgpu[i] = open(devices[i]->nodes[DRM_NODE_PRIMARY],
+			O_RDWR | O_CLOEXEC);
+		if (i == 0 && drm_amdgpu[i] < 0) {
+			drmFreeDevices(devices, num_devices);
+			/* It is essential to open first connection to run any test. */
+			perror("Cannot open first card.\n");
+			exit(EXIT_FAILURE);
+		}
+	}
+	drmFreeDevices(devices, num_devices);
+
 	/** Display version of DRM driver */
 	drmVersionPtr retval = drmGetVersion(drm_amdgpu[0]);
 
@@ -191,7 +227,7 @@ int main(int argc, char **argv)
 
 	/* initialize the CUnit test registry */
 	if (CUE_SUCCESS != CU_initialize_registry()) {
-		close(drm_amdgpu[0]);
+		amdgpu_close_all();
 		return CU_get_error();
 	}
 
@@ -200,7 +236,7 @@ int main(int argc, char **argv)
 		fprintf(stderr, "suite registration failed - %s\n",
 				CU_get_error_msg());
 		CU_cleanup_registry();
-		close(drm_amdgpu[0]);
+		amdgpu_close_all();
 		exit(EXIT_FAILURE);
 	}
 
@@ -222,7 +258,7 @@ int main(int argc, char **argv)
 					fprintf(stderr, "Invalid test id: %d\n",
 								test_id);
 					CU_cleanup_registry();
-					close(drm_amdgpu[0]);
+					amdgpu_close_all();
 					exit(EXIT_FAILURE);
 				}
 			} else
@@ -231,13 +267,41 @@ int main(int argc, char **argv)
 			fprintf(stderr, "Invalid suite id : %d\n",
 					suite_id);
 			CU_cleanup_registry();
-			close(drm_amdgpu[0]);
+			amdgpu_close_all();
 			exit(EXIT_FAILURE);
 		}
 	} else
 		CU_basic_run_tests();
 
 	CU_cleanup_registry();
-	close(drm_amdgpu[0]);
+	amdgpu_close_all();
+
 	return CU_get_error();
 }
+
+void amdgpu_vprintf(char *fmt, ...)
+{
+	va_list args;
+	if (verbose) {
+	    va_start(args, fmt);
+	    vprintf(fmt, args);
+	    va_end(args);
+	}
+}
+
+void amdgpu_warning(bool condition, char *fmt, ...)
+{
+	if (warning && condition)
+	{
+		printf ("WARNING: ");
+		va_list args;
+		va_start(args, fmt);
+		vprintf(fmt, args);
+		va_end(args);
+	}
+}
+
+int amdgpu_num_devices()
+{
+	return num_devices;
+}
diff --git a/tests/amdgpu/amdgpu_test.h b/tests/amdgpu/amdgpu_test.h
index fca92ad..5c47ba3 100644
--- a/tests/amdgpu/amdgpu_test.h
+++ b/tests/amdgpu/amdgpu_test.h
@@ -104,6 +104,11 @@ extern CU_TestInfo vce_tests[];
 /**
  * Helper functions
  */
+
+void amdgpu_vprintf(char *fmt, ...);
+void amdgpu_warning(bool condition, char *fmt, ...);
+int amdgpu_num_devices();
+
 static inline amdgpu_bo_handle gpu_mem_alloc(
 					amdgpu_device_handle device_handle,
 					uint64_t size,
diff --git a/tests/amdgpu/basic_tests.c b/tests/amdgpu/basic_tests.c
index eb73578..23178e0 100644
--- a/tests/amdgpu/basic_tests.c
+++ b/tests/amdgpu/basic_tests.c
@@ -50,6 +50,7 @@ static void amdgpu_command_submission_multi_fence(void);
 static void amdgpu_userptr_test(void);
 static void amdgpu_semaphore_test(void);
 static void amdgpu_svm_test(void);
+static void amdgpu_multi_svm_test(void);
 
 CU_TestInfo basic_tests[] = {
 	{ "Query Info Test",  amdgpu_query_info_test },
@@ -61,6 +62,7 @@ CU_TestInfo basic_tests[] = {
 	{ "Command submission Test (Multi-fence)", amdgpu_command_submission_multi_fence },
 	{ "SW semaphore Test",  amdgpu_semaphore_test },
 	{ "SVM Test", amdgpu_svm_test },
+	{ "SVM Test (multi-GPUs)", amdgpu_multi_svm_test },
 	CU_TEST_INFO_NULL,
 };
 #define BUFFER_SIZE (8 * 1024)
@@ -1094,6 +1096,8 @@ static void amdgpu_svm_test(void)
 	r = amdgpu_va_range_query(device_handle,
 		amdgpu_gpu_va_range_svm, &start, &end);
 	CU_ASSERT_EQUAL(r, 0);
+	amdgpu_vprintf("\n");
+	amdgpu_vprintf("SVM range is from 0x%llx to 0x%llx.\n", start, end);
 
 	/* If there is no SVM range, exit this function.*/
 	if (start == 0ULL && end == 0ULL)
@@ -1108,6 +1112,7 @@ static void amdgpu_svm_test(void)
 					  64 * 1024 * 1024, 1, 0, &svm_mc,
 					  &va_handle[i], 0);
 		CU_ASSERT_EQUAL(r, 0);
+		amdgpu_vprintf("Allocate SVM MC 0x%llx.\n", svm_mc);
 
 		r = amdgpu_svm_commit(va_handle[i], &cpu);
 		CU_ASSERT_EQUAL(r, 0);
@@ -1123,3 +1128,69 @@ static void amdgpu_svm_test(void)
 		CU_ASSERT_EQUAL(r, 0);
 	}
 }
+
+static void amdgpu_multi_svm_test(void)
+{
+	int r;
+	int i;
+	uint64_t svm_mcs[MAX_CARDS_SUPPORTED];
+	amdgpu_va_handle va_handles[MAX_CARDS_SUPPORTED];
+	amdgpu_device_handle device_handles[MAX_CARDS_SUPPORTED];
+	uint32_t major_version;
+	uint32_t minor_version;
+	int num_devices;
+
+	device_handles[0] = device_handle;
+	num_devices = amdgpu_num_devices();
+
+	for (i = 1; i < num_devices; i++)
+		if (drm_amdgpu[i] > 0) {
+			r = amdgpu_device_initialize(drm_amdgpu[i], &major_version,
+					&minor_version, &device_handles[i]);
+			CU_ASSERT_EQUAL(r, 0);
+		}
+
+	amdgpu_vprintf("\n");
+	amdgpu_vprintf("    Testing to alloc and free SVM in all GPUs.\n");
+	amdgpu_vprintf("    The svm_mcs generally are same.\n");
+	for (i = 0; i < num_devices; i++)
+		if (drm_amdgpu[i] > 0) {
+			r = amdgpu_va_range_alloc(device_handles[i],
+						  amdgpu_gpu_va_range_svm,
+						  0x1000000, 1, 0, &svm_mcs[i],
+						  &va_handles[i], 0);
+			CU_ASSERT_EQUAL(r, 0);
+			amdgpu_vprintf("        card %d, svm_mc 0x%llx\n", i, svm_mcs[i]);
+			amdgpu_warning(svm_mcs[i] != svm_mcs[0],
+				"The SVM from different GPUs should be able to be allocated"
+				" from same location.");
+			r = amdgpu_va_range_free(va_handles[i]);
+			CU_ASSERT_EQUAL(r, 0);
+		}
+
+	amdgpu_vprintf("    Testing to alloc SVM in all GPUs.\n");
+	amdgpu_vprintf("    The svm_mcs are generally different by 0x1000000\n");
+	for (i = 0; i < num_devices; i++)
+		if (drm_amdgpu[i] > 0) {
+			r = amdgpu_va_range_alloc(device_handles[i],
+						  amdgpu_gpu_va_range_svm,
+						  0x1000000, 1, 0, &svm_mcs[i],
+						  &va_handles[i], 0);
+			CU_ASSERT_EQUAL(r, 0);
+			amdgpu_vprintf("        card %d, svm_mc 0x%llx\n", i, svm_mcs[i]);
+			amdgpu_warning(svm_mcs[i] - svm_mcs[0] != 0x1000000 * i,
+				"The SVM from GPUs should be allocated sequentially.");
+		}
+
+	for (i = 0; i < num_devices; i++)
+		if (drm_amdgpu[i] > 0) {
+			r = amdgpu_va_range_free(va_handles[i]);
+			CU_ASSERT_EQUAL(r, 0);
+		}
+
+	for (i = 1; i < num_devices; i++)
+		if (drm_amdgpu[i] > 0) {
+			r = amdgpu_device_deinitialize(device_handles[i]);
+			CU_ASSERT_EQUAL(r, 0);
+		}
+}
-- 
2.7.4