|
| 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 | +} |
0 commit comments