Skip to content

Commit 31377a7

Browse files
committed
[Comgr] Refactor nested kernel behavior into separate test
OpenCL allows a kernel function to be called from another kernel function, and this behavior is featured in the primary OpenCL files used in the Comgr tests. However, this behavior is atypical and rarely-used. In this patch, we refactor this behavior into a separate test, and restructure the primary tests to not call nested kernels. This will allow us to more quickly identify issues specifically with nested kernels without failing a large array of tests. Change-Id: I1772db85b770977012798940dd2cba5fc2cdf8ac
1 parent 6d3333a commit 31377a7

14 files changed

+338
-19
lines changed

amd/comgr/docs/ReleaseNotes.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ unbundling.
129129
output for Comgr actions. This can help us debug issues more quickly in cases
130130
where reporters provide Comgr logs.
131131
- Fix multiple bugs with mangled names test
132+
- Refactor nested kernel behavior into new test, as this behavior is less common
133+
and shouldn't be featured in the baseline tests
132134

133135
New Targets
134136
-----------

amd/comgr/test/CMakeLists.txt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,13 @@ add_test_input_binary(shared-debug source/shared.cl source/shared-debug.so -g -m
7474

7575
configure_file("source/source1.cl" "source/source1.cl" COPYONLY)
7676
configure_file("source/source2.cl" "source/source2.cl" COPYONLY)
77+
configure_file("source/nested-kernel1.cl" "source/nested-kernel1.cl" COPYONLY)
78+
configure_file("source/nested-kernel2.cl" "source/nested-kernel2.cl" COPYONLY)
79+
configure_file("source/shared.cl" "source/shared.cl" COPYONLY)
7780
configure_file("source/device_libs.cl" "source/device_libs.cl" COPYONLY)
78-
configure_file("source/include-a.h" "source/include-a.h" COPYONLY)
81+
configure_file("source/include-macro.h" "source/include-macro.h" COPYONLY)
82+
configure_file("source/include-nested.h" "source/include-nested.h" COPYONLY)
7983
configure_file("source/source1.s" "source/source1.s" COPYONLY)
80-
configure_file("source/shared.cl" "source/shared.cl" COPYONLY)
8184
configure_file("source/source1.hip" "source/source1.hip" COPYONLY)
8285
configure_file("source/source2.hip" "source/source2.hip" COPYONLY)
8386
configure_file("source/name-expression.hip" "source/name_expression.hip" COPYONLY)
@@ -175,6 +178,7 @@ add_comgr_test(symbolize_test c)
175178
add_comgr_test(mangled_names_test c)
176179
add_comgr_test(multithread_test cpp)
177180
add_comgr_test(name_expression_map_test c)
181+
add_comgr_test(nested_kernel_test c)
178182
add_comgr_test(map_elf_virtual_address_test c)
179183

180184
# Test : Compile HIP tests only if HIP-Clang is installed.

amd/comgr/test/compile_minimal_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) {
5454

5555
SizeSource1 = setBuf(TEST_OBJ_DIR "/source1.cl", &BufSource1);
5656
SizeSource2 = setBuf(TEST_OBJ_DIR "/source2.cl", &BufSource2);
57-
SizeInclude = setBuf(TEST_OBJ_DIR "/include-a.h", &BufInclude);
57+
SizeInclude = setBuf(TEST_OBJ_DIR "/include-macro.h", &BufInclude);
5858

5959
Status = amd_comgr_create_data_set(&DataSetIn);
6060
checkError(Status, "amd_comgr_create_data_set");
@@ -81,7 +81,7 @@ int main(int argc, char *argv[]) {
8181
checkError(Status, "amd_comgr_create_data");
8282
Status = amd_comgr_set_data(DataInclude, SizeInclude, BufInclude);
8383
checkError(Status, "amd_comgr_set_data");
84-
Status = amd_comgr_set_data_name(DataInclude, "include-a.h");
84+
Status = amd_comgr_set_data_name(DataInclude, "include-macro.h");
8585
checkError(Status, "amd_comgr_set_data_name");
8686
Status = amd_comgr_data_set_add(DataSetIn, DataInclude);
8787
checkError(Status, "amd_comgr_data_set_add");

amd/comgr/test/compile_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) {
5454

5555
SizeSource1 = setBuf(TEST_OBJ_DIR "/source1.cl", &BufSource1);
5656
SizeSource2 = setBuf(TEST_OBJ_DIR "/source2.cl", &BufSource2);
57-
SizeInclude = setBuf(TEST_OBJ_DIR "/include-a.h", &BufInclude);
57+
SizeInclude = setBuf(TEST_OBJ_DIR "/include-macro.h", &BufInclude);
5858

5959
Status = amd_comgr_create_data_set(&DataSetIn);
6060
checkError(Status, "amd_comgr_create_data_set");
@@ -81,7 +81,7 @@ int main(int argc, char *argv[]) {
8181
checkError(Status, "amd_comgr_create_data");
8282
Status = amd_comgr_set_data(DataInclude, SizeInclude, BufInclude);
8383
checkError(Status, "amd_comgr_set_data");
84-
Status = amd_comgr_set_data_name(DataInclude, "include-a.h");
84+
Status = amd_comgr_set_data_name(DataInclude, "include-macro.h");
8585
checkError(Status, "amd_comgr_set_data_name");
8686
Status = amd_comgr_data_set_add(DataSetIn, DataInclude);
8787
checkError(Status, "amd_comgr_data_set_add");

amd/comgr/test/mangled_names_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ int main(int argc, char *argv[]) {
5454

5555
SizeSource1 = setBuf(TEST_OBJ_DIR "/source1.cl", &BufSource1);
5656
SizeSource2 = setBuf(TEST_OBJ_DIR "/source2.cl", &BufSource2);
57-
SizeInclude = setBuf(TEST_OBJ_DIR "/include-a.h", &BufInclude);
57+
SizeInclude = setBuf(TEST_OBJ_DIR "/include-macro.h", &BufInclude);
5858

5959
Status = amd_comgr_create_data_set(&DataSetIn);
6060
checkError(Status, "amd_comgr_create_data_set");
@@ -81,7 +81,7 @@ int main(int argc, char *argv[]) {
8181
checkError(Status, "amd_comgr_create_data");
8282
Status = amd_comgr_set_data(DataInclude, SizeInclude, BufInclude);
8383
checkError(Status, "amd_comgr_set_data");
84-
Status = amd_comgr_set_data_name(DataInclude, "include-a.h");
84+
Status = amd_comgr_set_data_name(DataInclude, "include-macro.h");
8585
checkError(Status, "amd_comgr_set_data_name");
8686
Status = amd_comgr_data_set_add(DataSetIn, DataInclude);
8787
checkError(Status, "amd_comgr_data_set_add");

amd/comgr/test/multithread_test.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ int compile_min(int index) {
5858

5959
SizeSource1 = setBuf(TEST_OBJ_DIR "/source1.cl", &BufSource1);
6060
SizeSource2 = setBuf(TEST_OBJ_DIR "/source2.cl", &BufSource2);
61-
SizeInclude = setBuf(TEST_OBJ_DIR "/include-a.h", &BufInclude);
61+
SizeInclude = setBuf(TEST_OBJ_DIR "/include-macro.h", &BufInclude);
6262

6363
Status = amd_comgr_create_data_set(&DataSetIn);
6464
checkError(Status, "amd_comgr_create_data_set");
@@ -85,7 +85,7 @@ int compile_min(int index) {
8585
checkError(Status, "amd_comgr_create_data");
8686
Status = amd_comgr_set_data(DataInclude, SizeInclude, BufInclude);
8787
checkError(Status, "amd_comgr_set_data");
88-
Status = amd_comgr_set_data_name(DataInclude, "include-a.h");
88+
Status = amd_comgr_set_data_name(DataInclude, "include-macro.h");
8989
checkError(Status, "amd_comgr_set_data_name");
9090
Status = amd_comgr_data_set_add(DataSetIn, DataInclude);
9191
checkError(Status, "amd_comgr_data_set_add");

amd/comgr/test/nested_kernel_test.c

Lines changed: 197 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,197 @@
1+
/*******************************************************************************
2+
*
3+
* University of Illinois/NCSA
4+
* Open Source License
5+
*
6+
* Copyright (c) 2018 Advanced Micro Devices, Inc. All Rights Reserved.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* with the Software without restriction, including without limitation the
11+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12+
* sell copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* * Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimers.
17+
*
18+
* * Redistributions in binary form must reproduce the above copyright
19+
* notice, this list of conditions and the following disclaimers in the
20+
* documentation and/or other materials provided with the distribution.
21+
*
22+
* * Neither the names of Advanced Micro Devices, Inc. nor the names of its
23+
* contributors may be used to endorse or promote products derived from
24+
* this Software without specific prior written permission.
25+
*
26+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+
* CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
32+
* THE SOFTWARE.
33+
*
34+
******************************************************************************/
35+
36+
#include "amd_comgr.h"
37+
#include "common.h"
38+
#include <stdio.h>
39+
#include <stdlib.h>
40+
#include <string.h>
41+
42+
int main(int argc, char *argv[]) {
43+
char *BufSource1, *BufSource2, *BufInclude;
44+
size_t SizeSource1, SizeSource2, SizeInclude;
45+
amd_comgr_data_t DataSource1, DataSource2, DataInclude;
46+
amd_comgr_data_set_t DataSetIn, DataSetBc, DataSetLinked, DataSetReloc,
47+
DataSetExec;
48+
amd_comgr_action_info_t DataAction;
49+
amd_comgr_status_t Status;
50+
size_t Count;
51+
const char *CodeGenOptions[] = {"-mllvm", "-amdgpu-early-inline-all"};
52+
size_t CodeGenOptionsCount =
53+
sizeof(CodeGenOptions) / sizeof(CodeGenOptions[0]);
54+
55+
SizeSource1 = setBuf(TEST_OBJ_DIR "/nested-kernel1.cl", &BufSource1);
56+
SizeSource2 = setBuf(TEST_OBJ_DIR "/nested-kernel2.cl", &BufSource2);
57+
SizeInclude = setBuf(TEST_OBJ_DIR "/include-nested.h", &BufInclude);
58+
59+
Status = amd_comgr_create_data_set(&DataSetIn);
60+
checkError(Status, "amd_comgr_create_data_set");
61+
62+
Status = amd_comgr_create_data(AMD_COMGR_DATA_KIND_SOURCE, &DataSource1);
63+
checkError(Status, "amd_comgr_create_data");
64+
Status = amd_comgr_set_data(DataSource1, SizeSource1, BufSource1);
65+
checkError(Status, "amd_comgr_set_data");
66+
Status = amd_comgr_set_data_name(DataSource1, "nested-kernel1.cl");
67+
checkError(Status, "amd_comgr_set_data_name");
68+
Status = amd_comgr_data_set_add(DataSetIn, DataSource1);
69+
checkError(Status, "amd_comgr_data_set_add");
70+
71+
Status = amd_comgr_create_data(AMD_COMGR_DATA_KIND_SOURCE, &DataSource2);
72+
checkError(Status, "amd_comgr_create_data");
73+
Status = amd_comgr_set_data(DataSource2, SizeSource2, BufSource2);
74+
checkError(Status, "amd_comgr_set_data");
75+
Status = amd_comgr_set_data_name(DataSource2, "nested-kernel2.cl");
76+
checkError(Status, "amd_comgr_set_data_name");
77+
Status = amd_comgr_data_set_add(DataSetIn, DataSource2);
78+
checkError(Status, "amd_comgr_data_set_add");
79+
80+
Status = amd_comgr_create_data(AMD_COMGR_DATA_KIND_INCLUDE, &DataInclude);
81+
checkError(Status, "amd_comgr_create_data");
82+
Status = amd_comgr_set_data(DataInclude, SizeInclude, BufInclude);
83+
checkError(Status, "amd_comgr_set_data");
84+
Status = amd_comgr_set_data_name(DataInclude, "include-nested.h");
85+
checkError(Status, "amd_comgr_set_data_name");
86+
Status = amd_comgr_data_set_add(DataSetIn, DataInclude);
87+
checkError(Status, "amd_comgr_data_set_add");
88+
89+
Status = amd_comgr_create_action_info(&DataAction);
90+
checkError(Status, "amd_comgr_create_action_info");
91+
Status = amd_comgr_action_info_set_language(DataAction,
92+
AMD_COMGR_LANGUAGE_OPENCL_1_2);
93+
checkError(Status, "amd_comgr_action_info_set_language");
94+
Status = amd_comgr_action_info_set_isa_name(DataAction,
95+
"amdgcn-amd-amdhsa--gfx803");
96+
checkError(Status, "amd_comgr_action_info_set_isa_name");
97+
Status = amd_comgr_action_info_set_option_list(DataAction, CodeGenOptions,
98+
CodeGenOptionsCount);
99+
checkError(Status, "amd_comgr_action_info_set_option_list");
100+
101+
Status = amd_comgr_create_data_set(&DataSetBc);
102+
checkError(Status, "amd_comgr_create_data_set");
103+
104+
Status = amd_comgr_do_action(AMD_COMGR_ACTION_COMPILE_SOURCE_TO_BC,
105+
DataAction, DataSetIn, DataSetBc);
106+
checkError(Status, "amd_comgr_do_action");
107+
108+
Status =
109+
amd_comgr_action_data_count(DataSetBc, AMD_COMGR_DATA_KIND_BC, &Count);
110+
checkError(Status, "amd_comgr_action_data_count");
111+
112+
if (Count != 2) {
113+
printf("AMD_COMGR_ACTION_COMPILE_SOURCE_TO_BC Failed: "
114+
"produced %zu BC objects (expected 2)\n",
115+
Count);
116+
exit(1);
117+
}
118+
119+
Status = amd_comgr_create_data_set(&DataSetLinked);
120+
checkError(Status, "amd_comgr_create_data_set");
121+
122+
Status = amd_comgr_do_action(AMD_COMGR_ACTION_LINK_BC_TO_BC, DataAction,
123+
DataSetBc, DataSetLinked);
124+
checkError(Status, "amd_comgr_do_action");
125+
126+
Status = amd_comgr_action_data_count(DataSetLinked, AMD_COMGR_DATA_KIND_BC,
127+
&Count);
128+
checkError(Status, "amd_comgr_action_data_count");
129+
130+
if (Count != 1) {
131+
printf("AMD_COMGR_ACTION_LINK_BC_TO_BC Failed: "
132+
"produced %zu BC objects (expected 1)\n",
133+
Count);
134+
exit(1);
135+
}
136+
137+
Status = amd_comgr_create_data_set(&DataSetReloc);
138+
checkError(Status, "amd_comgr_create_data_set");
139+
140+
Status = amd_comgr_do_action(AMD_COMGR_ACTION_CODEGEN_BC_TO_RELOCATABLE,
141+
DataAction, DataSetLinked, DataSetReloc);
142+
checkError(Status, "amd_comgr_do_action");
143+
144+
Status = amd_comgr_action_data_count(DataSetReloc,
145+
AMD_COMGR_DATA_KIND_RELOCATABLE, &Count);
146+
checkError(Status, "amd_comgr_action_data_count");
147+
148+
if (Count != 1) {
149+
printf("AMD_COMGR_ACTION_CODEGEN_BC_TO_RELOCATABLE Failed: "
150+
"produced %zu source objects (expected 1)\n",
151+
Count);
152+
exit(1);
153+
}
154+
155+
Status = amd_comgr_create_data_set(&DataSetExec);
156+
checkError(Status, "amd_comgr_create_data_set");
157+
158+
Status = amd_comgr_action_info_set_option_list(DataAction, NULL, 0);
159+
checkError(Status, "amd_comgr_action_info_set_option_list");
160+
161+
Status = amd_comgr_do_action(AMD_COMGR_ACTION_LINK_RELOCATABLE_TO_EXECUTABLE,
162+
DataAction, DataSetReloc, DataSetExec);
163+
checkError(Status, "amd_comgr_do_action");
164+
165+
Status = amd_comgr_action_data_count(DataSetExec,
166+
AMD_COMGR_DATA_KIND_EXECUTABLE, &Count);
167+
checkError(Status, "amd_comgr_action_data_count");
168+
169+
if (Count != 1) {
170+
printf("AMD_COMGR_ACTION_LINK_RELOCATABLE_TO_EXECUTABLE Failed: "
171+
"produced %zu executable objects (expected 1)\n",
172+
Count);
173+
exit(1);
174+
}
175+
176+
Status = amd_comgr_release_data(DataSource1);
177+
checkError(Status, "amd_comgr_release_data");
178+
Status = amd_comgr_release_data(DataSource2);
179+
checkError(Status, "amd_comgr_release_data");
180+
Status = amd_comgr_release_data(DataInclude);
181+
checkError(Status, "amd_comgr_release_data");
182+
Status = amd_comgr_destroy_data_set(DataSetIn);
183+
checkError(Status, "amd_comgr_destroy_data_set");
184+
Status = amd_comgr_destroy_data_set(DataSetBc);
185+
checkError(Status, "amd_comgr_destroy_data_set");
186+
Status = amd_comgr_destroy_data_set(DataSetLinked);
187+
checkError(Status, "amd_comgr_destroy_data_set");
188+
Status = amd_comgr_destroy_data_set(DataSetReloc);
189+
checkError(Status, "amd_comgr_destroy_data_set");
190+
Status = amd_comgr_destroy_data_set(DataSetExec);
191+
checkError(Status, "amd_comgr_destroy_data_set");
192+
Status = amd_comgr_destroy_action_info(DataAction);
193+
checkError(Status, "amd_comgr_destroy_action_info");
194+
free(BufSource1);
195+
free(BufSource2);
196+
free(BufInclude);
197+
}

amd/comgr/test/options_test.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void testFlatSplitting() {
197197
amd_comgr_status_t Status;
198198

199199
SizeSource = setBuf(TEST_OBJ_DIR "/source1.cl", &BufSource);
200-
SizeInclude = setBuf(TEST_OBJ_DIR "/include-a.h", &BufInclude);
200+
SizeInclude = setBuf(TEST_OBJ_DIR "/include-macro.h", &BufInclude);
201201

202202
Status = amd_comgr_create_data_set(&DataSetIn);
203203
checkError(Status, "amd_comgr_create_data_set");
@@ -215,7 +215,7 @@ void testFlatSplitting() {
215215
checkError(Status, "amd_comgr_create_data");
216216
Status = amd_comgr_set_data(DataInclude, SizeInclude, BufInclude);
217217
checkError(Status, "amd_comgr_set_data");
218-
Status = amd_comgr_set_data_name(DataInclude, "include-a.h");
218+
Status = amd_comgr_set_data_name(DataInclude, "include-macro.h");
219219
checkError(Status, "amd_comgr_set_data_name");
220220
Status = amd_comgr_data_set_add(DataSetIn, DataInclude);
221221
checkError(Status, "amd_comgr_data_set_add");

amd/comgr/test/source/include-macro.h

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*******************************************************************************
2+
*
3+
* University of Illinois/NCSA
4+
* Open Source License
5+
*
6+
* Copyright (c) 2018 Advanced Micro Devices, Inc. All Rights Reserved.
7+
*
8+
* Permission is hereby granted, free of charge, to any person obtaining a copy
9+
* of this software and associated documentation files (the "Software"), to deal
10+
* with the Software without restriction, including without limitation the
11+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12+
* sell copies of the Software, and to permit persons to whom the Software is
13+
* furnished to do so, subject to the following conditions:
14+
*
15+
* * Redistributions of source code must retain the above copyright notice,
16+
* this list of conditions and the following disclaimers.
17+
*
18+
* * Redistributions in binary form must reproduce the above copyright
19+
* notice, this list of conditions and the following disclaimers in the
20+
* documentation and/or other materials provided with the distribution.
21+
*
22+
* * Neither the names of Advanced Micro Devices, Inc. nor the names of its
23+
* contributors may be used to endorse or promote products derived from
24+
* this Software without specific prior written permission.
25+
*
26+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
27+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
28+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
29+
* CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
30+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
31+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH
32+
* THE SOFTWARE.
33+
*
34+
******************************************************************************/
35+
36+
#define FOO 1

amd/comgr/test/source/include-a.h renamed to amd/comgr/test/source/include-nested.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535

3636
#define FOO 1
3737

38-
void kernel source1(__global int *j);
39-
void kernel source2(__global int *j);
38+
void kernel nested1(__global int *j);
39+
void kernel nested2(__global int *j);

0 commit comments

Comments
 (0)