Skip to content

Instantly share code, notes, and snippets.

@W4RH4WK
Last active December 16, 2019 14:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save W4RH4WK/f41c969a2a7ed2f7f20e98a494ab6da1 to your computer and use it in GitHub Desktop.
Save W4RH4WK/f41c969a2a7ed2f7f20e98a494ab6da1 to your computer and use it in GitHub Desktop.
OpenCL Dump Kernels
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