intel-clc: move ISA generation to its own function
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Reviewed-by: Kenneth Graunke <kenneth@whitecape.org> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26797>
This commit is contained in:

committed by
Marge Bot

parent
2a1ff08376
commit
2bae1b6b66
@@ -274,6 +274,80 @@ print_usage(char *exec_name, FILE *f)
|
||||
|
||||
#define OPT_PREFIX 1000
|
||||
|
||||
struct intel_clc_params {
|
||||
char *entry_point;
|
||||
char *platform;
|
||||
char *outfile;
|
||||
char *spv_outfile;
|
||||
char *prefix;
|
||||
|
||||
bool print_info;
|
||||
|
||||
void *mem_ctx;
|
||||
|
||||
struct intel_device_info devinfo;
|
||||
};
|
||||
|
||||
static int
|
||||
output_isa(const struct intel_clc_params *params, struct clc_binary *binary)
|
||||
{
|
||||
struct brw_kernel kernel = {};
|
||||
char *error_str;
|
||||
|
||||
struct brw_isa_info _isa, *isa = &_isa;
|
||||
brw_init_isa_info(isa, ¶ms->devinfo);
|
||||
|
||||
struct brw_compiler *compiler = brw_compiler_create(params->mem_ctx,
|
||||
¶ms->devinfo);
|
||||
compiler->shader_debug_log = compiler_log;
|
||||
compiler->shader_perf_log = compiler_log;
|
||||
struct disk_cache *disk_cache = get_disk_cache(compiler);
|
||||
|
||||
if (!brw_kernel_from_spirv(compiler, disk_cache, &kernel, NULL, params->mem_ctx,
|
||||
binary->data, binary->size,
|
||||
params->entry_point, &error_str)) {
|
||||
fprintf(stderr, "Compile failed: %s\n", error_str);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (params->print_info) {
|
||||
fprintf(stdout, "kernel info:\n");
|
||||
fprintf(stdout, " uses_barrier : %u\n", kernel.prog_data.uses_barrier);
|
||||
fprintf(stdout, " uses_num_work_groups : %u\n", kernel.prog_data.uses_num_work_groups);
|
||||
fprintf(stdout, " uses_inline_data : %u\n", kernel.prog_data.uses_inline_data);
|
||||
fprintf(stdout, " local_size : %ux%ux%u\n",
|
||||
kernel.prog_data.local_size[0],
|
||||
kernel.prog_data.local_size[1],
|
||||
kernel.prog_data.local_size[2]);
|
||||
fprintf(stdout, " curb_read_length : %u\n", kernel.prog_data.base.curb_read_length);
|
||||
fprintf(stdout, " total_scratch : %u\n", kernel.prog_data.base.total_scratch);
|
||||
fprintf(stdout, " total_shared : %u\n", kernel.prog_data.base.total_shared);
|
||||
fprintf(stdout, " program_size : %u\n", kernel.prog_data.base.program_size);
|
||||
fprintf(stdout, " const_data_size : %u\n", kernel.prog_data.base.const_data_size);
|
||||
fprintf(stdout, " uses_atomic_load_store : %u\n", kernel.prog_data.base.uses_atomic_load_store);
|
||||
fprintf(stdout, " dispatch_grf_start_reg : %u\n", kernel.prog_data.base.dispatch_grf_start_reg);
|
||||
}
|
||||
|
||||
char *prefix = params->prefix;
|
||||
char prefix_tmp[256];
|
||||
if (prefix == NULL) {
|
||||
bool is_pt_5 = (params->devinfo.verx10 % 10) == 5;
|
||||
snprintf(prefix_tmp, sizeof(prefix_tmp), "gfx%d%s_clc_%s",
|
||||
params->devinfo.ver, is_pt_5 ? "5" : "", params->entry_point);
|
||||
prefix = prefix_tmp;
|
||||
}
|
||||
|
||||
if (params->outfile != NULL) {
|
||||
FILE *fp = fopen(params->outfile, "w");
|
||||
print_kernel(fp, prefix, &kernel, isa);
|
||||
fclose(fp);
|
||||
} else {
|
||||
print_kernel(stdout, prefix, &kernel, isa);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int exit_code = 0;
|
||||
@@ -292,19 +366,19 @@ int main(int argc, char **argv)
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
char *entry_point = NULL, *platform = NULL, *outfile = NULL, *spv_outfile = NULL, *prefix = NULL;
|
||||
struct intel_clc_params params = {};
|
||||
|
||||
struct util_dynarray clang_args;
|
||||
struct util_dynarray input_files;
|
||||
bool print_info = false;
|
||||
|
||||
struct clc_binary spirv_obj = {0};
|
||||
struct clc_parsed_spirv parsed_spirv_data = {0};
|
||||
struct disk_cache *disk_cache = NULL;
|
||||
|
||||
void *mem_ctx = ralloc_context(NULL);
|
||||
params.mem_ctx = ralloc_context(NULL);
|
||||
|
||||
util_dynarray_init(&clang_args, mem_ctx);
|
||||
util_dynarray_init(&input_files, mem_ctx);
|
||||
util_dynarray_init(&clang_args, params.mem_ctx);
|
||||
util_dynarray_init(&input_files, params.mem_ctx);
|
||||
|
||||
int ch;
|
||||
while ((ch = getopt_long(argc, argv, "he:p:s:i:o:v", long_options, NULL)) != -1)
|
||||
@@ -315,25 +389,25 @@ int main(int argc, char **argv)
|
||||
print_usage(argv[0], stdout);
|
||||
goto end;
|
||||
case 'e':
|
||||
entry_point = optarg;
|
||||
params.entry_point = optarg;
|
||||
break;
|
||||
case 'p':
|
||||
platform = optarg;
|
||||
params.platform = optarg;
|
||||
break;
|
||||
case 'o':
|
||||
outfile = optarg;
|
||||
params.outfile = optarg;
|
||||
break;
|
||||
case 'i':
|
||||
util_dynarray_append(&input_files, char *, optarg);
|
||||
break;
|
||||
case 's':
|
||||
spv_outfile = optarg;
|
||||
params.spv_outfile = optarg;
|
||||
break;
|
||||
case 'v':
|
||||
print_info = true;
|
||||
params.print_info = true;
|
||||
break;
|
||||
case OPT_PREFIX:
|
||||
prefix = optarg;
|
||||
params.prefix = optarg;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unrecognized option \"%s\".\n", optarg);
|
||||
@@ -352,33 +426,29 @@ int main(int argc, char **argv)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (platform == NULL) {
|
||||
if (params.platform == NULL) {
|
||||
fprintf(stderr, "No target platform name specified.\n");
|
||||
print_usage(argv[0], stderr);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
int pci_id = intel_device_name_to_pci_device_id(platform);
|
||||
int pci_id = intel_device_name_to_pci_device_id(params.platform);
|
||||
if (pci_id < 0) {
|
||||
fprintf(stderr, "Invalid target platform name: %s\n", platform);
|
||||
fprintf(stderr, "Invalid target platform name: %s\n", params.platform);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
struct intel_device_info _devinfo, *devinfo = &_devinfo;
|
||||
if (!intel_get_device_info_from_pci_id(pci_id, devinfo)) {
|
||||
if (!intel_get_device_info_from_pci_id(pci_id, ¶ms.devinfo)) {
|
||||
fprintf(stderr, "Failed to get device information.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (devinfo->verx10 < 125) {
|
||||
if (params.devinfo.verx10 < 125) {
|
||||
fprintf(stderr, "Platform currently not supported.\n");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
struct brw_isa_info _isa, *isa = &_isa;
|
||||
brw_init_isa_info(isa, devinfo);
|
||||
|
||||
if (entry_point == NULL) {
|
||||
if (params.entry_point == NULL) {
|
||||
fprintf(stderr, "No entry-point name specified.\n");
|
||||
print_usage(argv[0], stderr);
|
||||
goto fail;
|
||||
@@ -400,7 +470,7 @@ int main(int argc, char **argv)
|
||||
|
||||
off_t len = lseek(fd, 0, SEEK_END);
|
||||
size_t new_size = total_size + len;
|
||||
all_inputs = reralloc_size(mem_ctx, all_inputs, new_size + 1);
|
||||
all_inputs = reralloc_size(params.mem_ctx, all_inputs, new_size + 1);
|
||||
if (!all_inputs) {
|
||||
fprintf(stderr, "Failed to allocate memory\n");
|
||||
goto fail;
|
||||
@@ -440,8 +510,8 @@ int main(int argc, char **argv)
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (spv_outfile) {
|
||||
FILE *fp = fopen(spv_outfile, "w");
|
||||
if (params.spv_outfile) {
|
||||
FILE *fp = fopen(params.spv_outfile, "w");
|
||||
fwrite(spirv_obj.data, spirv_obj.size, 1, fp);
|
||||
fclose(fp);
|
||||
}
|
||||
@@ -452,69 +522,22 @@ int main(int argc, char **argv)
|
||||
|
||||
const struct clc_kernel_info *kernel_info = NULL;
|
||||
for (unsigned i = 0; i < parsed_spirv_data.num_kernels; i++) {
|
||||
if (strcmp(parsed_spirv_data.kernels[i].name, entry_point) == 0) {
|
||||
if (strcmp(parsed_spirv_data.kernels[i].name, params.entry_point) == 0) {
|
||||
kernel_info = &parsed_spirv_data.kernels[i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (kernel_info == NULL) {
|
||||
fprintf(stderr, "Kernel entrypoint %s not found\n", entry_point);
|
||||
fprintf(stderr, "Kernel entrypoint %s not found\n", params.entry_point);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
struct brw_kernel kernel = {};
|
||||
char *error_str;
|
||||
|
||||
struct brw_compiler *compiler = brw_compiler_create(mem_ctx, devinfo);
|
||||
compiler->shader_debug_log = compiler_log;
|
||||
compiler->shader_perf_log = compiler_log;
|
||||
disk_cache = get_disk_cache(compiler);
|
||||
|
||||
glsl_type_singleton_init_or_ref();
|
||||
|
||||
if (!brw_kernel_from_spirv(compiler, disk_cache, &kernel, NULL, mem_ctx,
|
||||
spirv_obj.data, spirv_obj.size,
|
||||
entry_point, &error_str)) {
|
||||
fprintf(stderr, "Compile failed: %s\n", error_str);
|
||||
goto fail;
|
||||
}
|
||||
|
||||
if (print_info) {
|
||||
fprintf(stdout, "kernel info:\n");
|
||||
fprintf(stdout, " uses_barrier : %u\n", kernel.prog_data.uses_barrier);
|
||||
fprintf(stdout, " uses_num_work_groups : %u\n", kernel.prog_data.uses_num_work_groups);
|
||||
fprintf(stdout, " uses_inline_data : %u\n", kernel.prog_data.uses_inline_data);
|
||||
fprintf(stdout, " local_size : %ux%ux%u\n",
|
||||
kernel.prog_data.local_size[0],
|
||||
kernel.prog_data.local_size[1],
|
||||
kernel.prog_data.local_size[2]);
|
||||
fprintf(stdout, " curb_read_length : %u\n", kernel.prog_data.base.curb_read_length);
|
||||
fprintf(stdout, " total_scratch : %u\n", kernel.prog_data.base.total_scratch);
|
||||
fprintf(stdout, " total_shared : %u\n", kernel.prog_data.base.total_shared);
|
||||
fprintf(stdout, " program_size : %u\n", kernel.prog_data.base.program_size);
|
||||
fprintf(stdout, " const_data_size : %u\n", kernel.prog_data.base.const_data_size);
|
||||
fprintf(stdout, " uses_atomic_load_store : %u\n", kernel.prog_data.base.uses_atomic_load_store);
|
||||
fprintf(stdout, " dispatch_grf_start_reg : %u\n", kernel.prog_data.base.dispatch_grf_start_reg);
|
||||
}
|
||||
exit_code = output_isa(¶ms, &spirv_obj);
|
||||
|
||||
glsl_type_singleton_decref();
|
||||
|
||||
char prefix_tmp[256];
|
||||
if (prefix == NULL) {
|
||||
bool is_pt_5 = (devinfo->verx10 % 10) == 5;
|
||||
snprintf(prefix_tmp, sizeof(prefix_tmp), "gfx%d%s_clc_%s",
|
||||
devinfo->ver, is_pt_5 ? "5" : "", entry_point);
|
||||
prefix = prefix_tmp;
|
||||
}
|
||||
|
||||
if (outfile != NULL) {
|
||||
FILE *fp = fopen(outfile, "w");
|
||||
print_kernel(fp, prefix, &kernel, isa);
|
||||
fclose(fp);
|
||||
} else {
|
||||
print_kernel(stdout, prefix, &kernel, isa);
|
||||
}
|
||||
|
||||
goto end;
|
||||
|
||||
fail:
|
||||
@@ -524,7 +547,7 @@ end:
|
||||
disk_cache_destroy(disk_cache);
|
||||
clc_free_parsed_spirv(&parsed_spirv_data);
|
||||
clc_free_spirv(&spirv_obj);
|
||||
ralloc_free(mem_ctx);
|
||||
ralloc_free(params.mem_ctx);
|
||||
|
||||
return exit_code;
|
||||
}
|
||||
|
Reference in New Issue
Block a user