Created
May 21, 2024 04:27
-
-
Save youkaichao/ed95c221fc9eb059cdf74fc91e3ab358 to your computer and use it in GitHub Desktop.
enable verbose cudagraph dump for pytorch
This file contains 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
#define _GNU_SOURCE | |
#include <stdio.h> | |
#include <link.h> | |
#include <stdbool.h> | |
#include <string.h> | |
#include <stdlib.h> | |
typedef int cudaError_t; | |
typedef void* cudaGraph_t; | |
static cudaError_t (*real_cudaGraphDebugDotPrint)(cudaGraph_t graph, const char* path, unsigned int flags) = NULL; | |
// Hooked function | |
cudaError_t my_cudaGraphDebugDotPrint(cudaGraph_t graph, const char* path, unsigned int flags) { | |
if (real_cudaGraphDebugDotPrint == NULL) { | |
fprintf(stderr, "Error: real_cudaGraphDebugDotPrint is NULL\n"); | |
return -1; | |
} | |
// Call the original function with flags always set to 1 | |
return real_cudaGraphDebugDotPrint(graph, path, 1); | |
} | |
// Callback function for each symbol resolution | |
unsigned int la_version(unsigned int version) { | |
printf("Audit module loaded.\n"); | |
return version; | |
} | |
// Called when a library is bound | |
char *la_objsearch(const char *name, uintptr_t *cookie, unsigned int flag) { | |
return (char *)name; // Return the symbol name to continue searching | |
} | |
unsigned int la_objopen(struct link_map *map, Lmid_t lmid, uintptr_t *cookie) { | |
return LA_FLG_BINDTO | LA_FLG_BINDFROM; | |
} | |
// Called when a symbol is bound | |
uintptr_t la_symbind64(Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook, | |
uintptr_t *defcook, unsigned int *flags, const char *symname) { | |
// Perform any custom actions here | |
if (strcmp(symname, "cudaGraphDebugDotPrint") == 0) { | |
printf("Symbol bound: %s\n", symname); | |
// Set the function pointer to the original function address | |
real_cudaGraphDebugDotPrint = (cudaError_t (*)(cudaGraph_t, const char*, unsigned int))sym->st_value; | |
// Return the address of the hooked function | |
return (uintptr_t)my_cudaGraphDebugDotPrint; | |
} | |
return sym->st_value; // Return the symbol's actual address | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
gcc -fPIC -shared -o audit.so audit.c
LD_AUDIT=./audit.so python test.py
Example script: