Last active
December 16, 2019 14:08
-
-
Save W4RH4WK/f41c969a2a7ed2f7f20e98a494ab6da1 to your computer and use it in GitHub Desktop.
OpenCL Dump Kernels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void dump_kernels(size_t num_devices) | |
{ | |
size_t num_binaries = num_devices; | |
size_t *sizes = malloc(num_binaries * sizeof(sizes[0])); | |
assert(sizes); | |
clGetProgramInfo(clProgram, CL_PROGRAM_BINARY_SIZES, num_binaries * sizeof(sizes[0]), sizes, NULL); | |
unsigned char **binaries = malloc(num_binaries * sizeof(binaries[0])); | |
assert(binaries); | |
for (size_t i = 0; i < num_binaries; i++) { | |
binaries[i] = malloc(sizes[i] * sizeof(binaries[i][0])); | |
assert(binaries[i]); | |
} | |
clGetProgramInfo(clProgram, CL_PROGRAM_BINARIES, num_binaries * sizeof(binaries[0]), binaries, NULL); | |
for (size_t i = 0; i < num_binaries; i++) { | |
char filename[64]; | |
snprintf(filename, sizeof(filename), "dump_%ld.bin", i); | |
FILE *dump = fopen(filename, "wb"); | |
fwrite(binaries[i], sizeof(unsigned char), sizes[i], dump); | |
fclose(dump); | |
free(binaries[i]); | |
} | |
free(binaries); | |
free(sizes); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment