From 710d77bea738ef0b688e537d0b4ff66b1ff5ff77 Mon Sep 17 00:00:00 2001 From: FindHao Date: Sat, 19 Mar 2022 20:31:06 -0400 Subject: [PATCH] add cubin_filter --- bin/build.sh | 6 + bin/build_debug.sh | 12 +- bin/gpupunk | 59 ++++--- cubin_filter/CMakeLists.txt | 61 ++++++++ cubin_filter/crypto-hash.c | 296 ++++++++++++++++++++++++++++++++++++ cubin_filter/crypto-hash.h | 155 +++++++++++++++++++ cubin_filter/cubin_filter.c | 90 +++++++++++ cubin_filter/cubin_filter.h | 10 ++ 8 files changed, 667 insertions(+), 22 deletions(-) create mode 100644 cubin_filter/CMakeLists.txt create mode 100644 cubin_filter/crypto-hash.c create mode 100644 cubin_filter/crypto-hash.h create mode 100644 cubin_filter/cubin_filter.c create mode 100644 cubin_filter/cubin_filter.h diff --git a/bin/build.sh b/bin/build.sh index c5d148d..80cffb4 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -52,6 +52,12 @@ cd ${source_path}/drcctprof_clients ./build_clean.sh ; ./build.sh cp -r ./DrCCTProf/build ${install_path}/drcctprof +cd ${source_path}/cubin_filter +rm -rf ${source_path}/cubin_filter/build +mkdir build && cd build +cmake .. -DCMAKE_INSTALL_PREFIX=${install_path}/cubin_filter +make -j 16 +make install -j 4 cd ${source_path} # cp -rf ./bin ${install_path}/ diff --git a/bin/build_debug.sh b/bin/build_debug.sh index ca2a8d6..089c9ad 100755 --- a/bin/build_debug.sh +++ b/bin/build_debug.sh @@ -24,8 +24,7 @@ echo $install_path cd ${source_path}/gpu-patch make clean -make PREFIX=${install_path}/gpu-patch CUDA_PATH=$CUDA_PATH install -j 12 -# make install -j 4 +make PREFIX=${install_path}/gpu-patch CUDA_PATH=$CUDA_PATH install -j 4 cd ${source_path}/redshow make clean @@ -52,8 +51,15 @@ cd ${source_path}/drcctprof_clients ./build_clean.sh ; ./build_debug.sh cp -r ./DrCCTProf/build_debug ${install_path}/drcctprof-debug +cd ${source_path}/cubin_filter +rm -rf ${source_path}/cubin_filter/build +mkdir build && cd build +cmake .. -DCMAKE_INSTALL_PREFIX=${install_path}/cubin_filter +make -j 16 +make install -j 4 cd ${source_path} # cp -rf ./bin ${install_path}/ mkdir ${install_path}/bin -ln -s ${source_path}/bin/gpupunk ${install_path}/bin/gpupunk \ No newline at end of file +ln -s ${source_path}/bin/gpupunk ${install_path}/bin/gpupunk + diff --git a/bin/gpupunk b/bin/gpupunk index 4ef34f2..12f0312 100755 --- a/bin/gpupunk +++ b/bin/gpupunk @@ -20,7 +20,8 @@ export GPUPUNK_WITH_DRRUN=1 export GPUPUNK_WITH_HPCRUN=0 # with detail log export GPUPUNK_VERBOSE=0 - +# filter cubins +export GPUPUNK_CUBIN_FILTER=1 usage() { cat < kernel whitelist for instrumentation. + -cubin_filter [yes|no|y|n] + default is yes. This option will enable cubin filter. + EOF exit 0 } @@ -103,6 +108,17 @@ while test "x$1" != x; do fi shift ;; + -cubin_filter) + if [ $1 == "no" ] || [ $1 == "n" ]; then + export GPUPUNK_CUBIN_FILTER=0 + else + if [ $1 != "yes" ] && [ $1 != "y" ]; then + echo "wrong argument pattern for -cubin_filter" + exit -1 + fi + fi + shift + ;; -v) export GPUPUNK_VERBOSE=1 ;; @@ -147,26 +163,31 @@ else export GPUPUNK_REDIRECT=/dev/null fi -if [ $GPUPUNK_WITH_HPCRUN -eq 1 ]; then - if [ -z $HPCTOOLKIT_PATH ]; then - echo "HPCTOOLKIT_PATH is not set." - exit -1 - fi - MEASUREMENTS=gpupunk-measurements - DATABASE=gpupunk-database - echo "Make sure $MEASUREMENTS and $DATABASE is clean" - rm -rf $MEASUREMENTS - rm -rf $DATABASE - HPCRUN=${HPCTOOLKIT_PATH}/bin/hpcrun - echo "$GPUPUNK_LAUNCHER $HPCRUN -e gpu=nvidia -o $MEASUREMENTS $GPUPUNK_EXEC $GPUPUNK_ARGS &>> $GPUPUNK_REDIRECT" - $GPUPUNK_LAUNCHER $HPCRUN -e gpu=nvidia -o $MEASUREMENTS $GPUPUNK_EXEC $GPUPUNK_ARGS &>>$GPUPUNK_REDIRECT - HPCSTRUCT=${HPCTOOLKIT_PATH}/bin/hpcstruct - $HPCSTRUCT -j 12 $MEASUREMENTS &>>$GPUPUNK_REDIRECT - rm ./cubins ./structs - ln -s $MEASUREMENTS/cubins ./ - ln -s $MEASUREMENTS/structs ./ +if [ $GPUPUNK_CUBIN_FILTER -eq 1 ]; then + rm -rf ./cubins + LD_PRELOAD=${GPUPUNK_PATH}/cubin_filter/libcubin_filter.so $GPUPUNK_EXEC $GPUPUNK_ARGS &>>$GPUPUNK_REDIRECT fi +# if [ $GPUPUNK_WITH_HPCRUN -eq 1 ]; then +# if [ -z $HPCTOOLKIT_PATH ]; then +# echo "HPCTOOLKIT_PATH is not set." +# exit -1 +# fi +# MEASUREMENTS=gpupunk-measurements +# DATABASE=gpupunk-database +# echo "Make sure $MEASUREMENTS and $DATABASE is clean" +# rm -rf $MEASUREMENTS +# rm -rf $DATABASE +# HPCRUN=${HPCTOOLKIT_PATH}/bin/hpcrun +# echo "$GPUPUNK_LAUNCHER $HPCRUN -e gpu=nvidia -o $MEASUREMENTS $GPUPUNK_EXEC $GPUPUNK_ARGS &>> $GPUPUNK_REDIRECT" +# $GPUPUNK_LAUNCHER $HPCRUN -e gpu=nvidia -o $MEASUREMENTS $GPUPUNK_EXEC $GPUPUNK_ARGS &>>$GPUPUNK_REDIRECT +# HPCSTRUCT=${HPCTOOLKIT_PATH}/bin/hpcstruct +# $HPCSTRUCT -j 12 $MEASUREMENTS &>>$GPUPUNK_REDIRECT +# rm ./cubins ./structs +# ln -s $MEASUREMENTS/cubins ./ +# ln -s $MEASUREMENTS/structs ./ +# fi + if [ $GPUPUNK_WITH_DRRUN -eq 1 ]; then # DRRUN="${DRCCTPROF_PATH}/bin64/drrun -dumpcore_mask 0x837f -t drcctlib_cpu_gpu_memory --" DRRUN="${DRCCTPROF_PATH}/bin64/drrun -t drcctlib_cpu_gpu_memory --" diff --git a/cubin_filter/CMakeLists.txt b/cubin_filter/CMakeLists.txt new file mode 100644 index 0000000..76ffb1a --- /dev/null +++ b/cubin_filter/CMakeLists.txt @@ -0,0 +1,61 @@ +cmake_minimum_required(VERSION 3.10) +project(cubin_filter) +include(CheckLanguage) +check_language(CUDA) + +set(CMAKE_CXX_STANDARD 14) +set(CMAKE_CXX_FLAGS " -Wall -Wextra") + +if (NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE "RelWithDebInfo" CACHE STRING + "Default build type: RelWithDebInfo" FORCE) +endif () + +if (${CMAKE_VERSION} VERSION_LESS "3.17.0") + find_package(CUDA REQUIRED) + set(CUDAToolkit_NVCC_EXECUTABLE ${CUDA_TOOLKIT_ROOT_DIR}/bin/nvcc) + set(CUDAToolkit_TARGET_DIR ${CUDA_TOOLKIT_ROOT_DIR}) + if (${CUDA_VERSION} LESS 11.2) + message(FATAL_ERROR "CUDAToolkit mush be newer or equal to 11.2. Your version is " ${CUDA_VERSION}) + endif () +else () + find_package(CUDAToolkit REQUIRED) + if (NOT CMAKE_CUDA_COMPILER) + if (NOT ${CUDAToolkit_NVCC_EXECUTABLE} AND UNIX AND EXISTS "/usr/local/cuda/bin/nvcc") + set(CUDAToolkit_NVCC_EXECUTABLE "/usr/local/cuda/bin/nvcc") + set(CMAKE_CUDA_COMPILER ${CUDAToolkit_NVCC_EXECUTABLE}) + message(WARNING "CMAKE_CUDA_COMPILER guessed: " ${CUDAToolkit_NVCC_EXECUTABLE} "\n" + "Please fix your cuda installation: https://docs.nvidia.com/cuda/cuda-installation-guide-linux/index.html#mandatory-post") + endif () + endif () + if (${CUDAToolkit_VERSION} LESS 11.2) + message(FATAL_ERROR "CUDAToolkit mush be newer or equal to 11.2. Your version is " ${CUDAToolkit_VERSION}) + endif () +endif () +enable_language(CUDA) + + +set(SANITIZER_PATH ${CUDAToolkit_TARGET_DIR}/compute-sanitizer) + +include_directories(${SANITIZER_PATH}/include/ + ${CUDAToolkit_TARGET_DIR}/include/ + ${CMAKE_CURRENT_LIST_DIR}/include/ + ${CMAKE_CURRENT_LIST_DIR}/src/ + ) +message(INFO ${SANITIZER_PATH} ${CUDAToolkit_NVCC_EXECUTABLE}) +add_link_options(-L${SANITIZER_PATH} -fPIC -shared) + +aux_source_directory(${CMAKE_CURRENT_LIST_DIR}/ cubin_filter_src) +file(GLOB cubin_filter_head CONFIGURE_DEPENDS "${CMAKE_CURRENT_LIST_DIR}/*.h" ) + + +add_library(cubin_filter SHARED ${cubin_filter_src} ) + +target_link_libraries(cubin_filter PUBLIC + -lsanitizer-public + -lmbedcrypto +) + + +install(TARGETS cubin_filter DESTINATION ${CMAKE_INSTALL_PREFIX}) +install(FILES ${cubin_filter_head} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/) diff --git a/cubin_filter/crypto-hash.c b/cubin_filter/crypto-hash.c new file mode 100644 index 0000000..fb1c7ce --- /dev/null +++ b/cubin_filter/crypto-hash.c @@ -0,0 +1,296 @@ +// -*-Mode: C++;-*- // technically C99 + +// * BeginRiceCopyright ***************************************************** +// +// $HeadURL$ +// $Id$ +// +// -------------------------------------------------------------------------- +// Part of HPCToolkit (hpctoolkit.org) +// +// Information about sources of support for research and development of +// HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'. +// -------------------------------------------------------------------------- +// +// Copyright ((c)) 2002-2020, Rice University +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of Rice University (RICE) nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// This software is provided by RICE and contributors "as is" and any +// express or implied warranties, including, but not limited to, the +// implied warranties of merchantability and fitness for a particular +// purpose are disclaimed. In no event shall RICE or contributors be +// liable for any direct, indirect, incidental, special, exemplary, or +// consequential damages (including, but not limited to, procurement of +// substitute goods or services; loss of use, data, or profits; or +// business interruption) however caused and on any theory of liability, +// whether in contract, strict liability, or tort (including negligence +// or otherwise) arising in any way out of the use of this software, even +// if advised of the possibility of such damage. +// +// ******************************************************* EndRiceCopyright * + +//*************************************************************************** +// +// File: +// crypto-hash.c +// +// Purpose: +// compute a cryptographic hash of a sequence of bytes. this is used +// to name information presented to hpcrun in memory (e.g. an NVIDIA cubin) +// that needs to be saved for post-mortem analysis. +// +//*************************************************************************** + + +//***************************************************************************** +// system includes +//***************************************************************************** + +#include +#include + +#include // MD5 + +#include "crypto-hash.h" + + + +//***************************************************************************** +// macros +//***************************************************************************** + + + +#define LOWER_NIBBLE_MASK (0x0f) +#define UPPER_NIBBLE(c) ((c >> 4) & LOWER_NIBBLE_MASK) +#define LOWER_NIBBLE(c) (c & LOWER_NIBBLE_MASK) + +#define HEX_TO_ASCII(c) ((c > 9) ? 'a' + (c - 10) : ('0' + c)) + + +//***************************************************************************** +// interface operations +//***************************************************************************** + +//----------------------------------------------------------------------------- +// function: +// crypto_hash_compute +// +// arguments: +// input: +// pointer to a vector of bytes that will be crytographically hashed +// input_length: +// length in bytes of the input +// hash: +// pointer to a vector of bytes of length >= crypto_hash_length() +// +// return value: +// 0: success +// non-zero: failure +//----------------------------------------------------------------------------- +int +crypto_hash_compute +( + const unsigned char *input, + size_t input_length, + unsigned char *hash, + unsigned int hash_length +) +{ + if (hash_length > HASH_LENGTH) { + // failure: caller not prepared to accept a hash of at least the length + // that we will provide + return -1; + } + + // zero the hash result + memset(hash, 0, hash_length); + + // compute an MD5 hash of input + mbedtls_md5_ret(input, input_length, hash); + + return 0; +} + + +//----------------------------------------------------------------------------- +// function: +// crypto_hash_length +// +// arguments: none +// +// return value: +// number of bytes in the crytographic hash +//----------------------------------------------------------------------------- +unsigned int +crypto_hash_length +( + void +) +{ + return HASH_LENGTH; +} + + +//----------------------------------------------------------------------------- +// function: +// crypto_hash_to_hexstring +// +// arguments: +// hash: +// pointer to crytographic hash computed by cryto_hash_compute +// hash_string: +// pointer to character buffer where string equivalent of the hash code +// will be written +// hash_string_length: +// length of the hash string must be > 2 * crypto_hash_length() +// +// return value: +// 0: success +// non-zero: failure +//----------------------------------------------------------------------------- +int +crypto_hash_to_hexstring +( + unsigned char *hash, + char *hash_string, + unsigned int hash_string_length +) +{ + int hex_digits = HASH_LENGTH << 1; + if (hash_string_length < hex_digits + 1) { + return -1; + } + + int chars = HASH_LENGTH; + while (chars-- > 0) { + unsigned char val_u = UPPER_NIBBLE(*hash); + *hash_string++ = HEX_TO_ASCII(val_u); + + unsigned char val_l = LOWER_NIBBLE(*hash); + *hash_string++ = HEX_TO_ASCII(val_l); + hash++; + } + *hash_string++ = 0; + + return 0; +} + + +//----------------------------------------------------------------------------- +// function: +// crypto_hash_self_test +// +// arguments: +// verbose: if non-zero, it prints individual self test results +// +// return value: +// 0: success +// non-zero: failure +//----------------------------------------------------------------------------- +int +crypto_hash_self_test +( + int verbose +) +{ + int status = mbedtls_md5_self_test(verbose); + return status; +} + + + +//****************************************************************************** +// unit test +//****************************************************************************** + +#if UNIT_TEST + +#include +#include + +#include +#include +#include + + +int +main(int argc, char **argv) +{ + int verbose = 1; + int self_test_result = crypto_hash_self_test(verbose); + + if (self_test_result) { + printf("%s crypto hash self test failed\n", argv[0]); + exit(-1); + } else { + printf("%s crypto hash self test succeeded\n", argv[0]); + } + + if (argc < 2) { + printf("usage: %s \n", argv[0]); + exit(-1); + } + + const char *filename = argv[1]; + + // check that the specified file is present + struct stat statbuf; + int stat_result = stat(filename, &statbuf); + if (stat_result != 0) { + printf("%s: stat failed %d\n", argv[0], stat_result); + exit(-1); + } + size_t filesize = statbuf.st_size; + + char *filebuf; + filebuf = (char *) malloc(filesize); + + // read a file to hash + FILE *file = fopen(filename, "r"); + size_t read_result = fread(filebuf, 1, filesize, file); + if (read_result != filesize) { + printf("%s: read failed. expected %ld bytes, got %ld bytes\n", + argv[0], filesize, read_result); + exit(-1); + } + + // allocate space for hash + int hash_len = crypto_hash_length(); + unsigned char *hash = (unsigned char *) malloc(hash_len); + + // compute hash + int crypto_result = crypto_hash_compute(filebuf, filesize, hash, hash_len); + if (crypto_result) { + printf("%s: crypto_hash_compute failed. returned %d bytes\n", + argv[0], filesize, crypto_result); + exit(-1); + } + + // allocate space for ASCII version of hash + int hash_strlen = hash_len << 1 + 1; + char buffer[hash_strlen]; + + // compute ASCII version of hash and dump it + crypto_hash_to_hexstring(hash, buffer, hash_strlen); + printf("hash string = %s\n", buffer); + + return 0; +} + +#endif diff --git a/cubin_filter/crypto-hash.h b/cubin_filter/crypto-hash.h new file mode 100644 index 0000000..39a9d17 --- /dev/null +++ b/cubin_filter/crypto-hash.h @@ -0,0 +1,155 @@ +// -*-Mode: C++;-*- // technically C99 + +// * BeginRiceCopyright ***************************************************** +// +// $HeadURL$ +// $Id$ +// +// -------------------------------------------------------------------------- +// Part of HPCToolkit (hpctoolkit.org) +// +// Information about sources of support for research and development of +// HPCToolkit is at 'hpctoolkit.org' and in 'README.Acknowledgments'. +// -------------------------------------------------------------------------- +// +// Copyright ((c)) 2002-2020, Rice University +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are +// met: +// +// * Redistributions of source code must retain the above copyright +// notice, this list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright +// notice, this list of conditions and the following disclaimer in the +// documentation and/or other materials provided with the distribution. +// +// * Neither the name of Rice University (RICE) nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// This software is provided by RICE and contributors "as is" and any +// express or implied warranties, including, but not limited to, the +// implied warranties of merchantability and fitness for a particular +// purpose are disclaimed. In no event shall RICE or contributors be +// liable for any direct, indirect, incidental, special, exemplary, or +// consequential damages (including, but not limited to, procurement of +// substitute goods or services; loss of use, data, or profits; or +// business interruption) however caused and on any theory of liability, +// whether in contract, strict liability, or tort (including negligence +// or otherwise) arising in any way out of the use of this software, even +// if advised of the possibility of such damage. +// +// ******************************************************* EndRiceCopyright * + +//*************************************************************************** +// +// File: +// crypto-hash.h +// +// Purpose: +// compute a cryptographic hash of a sequence of bytes. this is used +// to name information presented to hpcrun in memory (e.g. an NVIDIA cubin) +// that needs to be saved for post-mortem analysis. +// +//*************************************************************************** + +#ifndef _HPCTOOLKIT_CRYPTO_HASH_H_ +#define _HPCTOOLKIT_CRYPTO_HASH_H_ + +#define MD5_HASH_NBYTES 16 + +#define HASH_LENGTH MD5_HASH_NBYTES + +//***************************************************************************** +// interface operations +//***************************************************************************** + +//----------------------------------------------------------------------------- +// function: +// crypto_hash_compute +// +// arguments: +// input: +// pointer to a vector of bytes that will be crytographically hashed +// input_length: +// length in bytes of the input +// hash: +// pointer to a vector of bytes of length >= crypto_hash_length() +// +// return value: +// 0: success +// non-zero: failure +//----------------------------------------------------------------------------- +int +crypto_hash_compute +( + const unsigned char *input, + size_t input_length, + unsigned char *hash, + unsigned int hash_length +); + + +//----------------------------------------------------------------------------- +// function: +// crypto_hash_length +// +// arguments: none +// +// return value: +// number of bytes in the crytographic hash +//----------------------------------------------------------------------------- +unsigned int +crypto_hash_length +( + void +); + + +//----------------------------------------------------------------------------- +// function: +// crypto_hash_to_hexstring +// +// arguments: +// hash: +// pointer to crytographic hash computed by cryto_hash_compute +// hash_string: +// pointer to character buffer where string equivalent of the hash code +// will be written +// hash_string_length: +// length of the hash string must be > 2 * crypto_hash_length() +// +// return value: +// 0: success +// non-zero: failure +//----------------------------------------------------------------------------- +int +crypto_hash_to_hexstring +( + unsigned char *hash, + char *hash_string, + unsigned int hash_string_length +); + + +//----------------------------------------------------------------------------- +// function: +// crypto_hash_self_test +// +// arguments: +// verbose: if non-zero, it prints individual self test results +// +// return value: +// 0: success +// non-zero: failure +//----------------------------------------------------------------------------- +int +crypto_hash_self_test +( + int verbose +); + +#endif diff --git a/cubin_filter/cubin_filter.c b/cubin_filter/cubin_filter.c new file mode 100644 index 0000000..c63373f --- /dev/null +++ b/cubin_filter/cubin_filter.c @@ -0,0 +1,90 @@ +#include "cubin_filter.h" +#include +#include "crypto-hash.h" +#include +#include +#include +#include // errno +#include // open +#include // close + +#define PRINT(__VA_ARGS__...) fprintf(stderr, __VA_ARGS__) +#define PATH_MAX 4096 /* # chars in a path name including nul */ + +static bool +cuda_write_cubin( + const char *file_name, + const void *cubin, + size_t cubin_size) { + int fd; + errno = 0; + fd = open(file_name, O_WRONLY | O_CREAT | O_EXCL, 0644); + if (errno == EEXIST) { + close(fd); + return true; + } + if (fd >= 0) { + // Success + if (write(fd, cubin, cubin_size) != cubin_size) { + close(fd); + return false; + } else { + close(fd); + return true; + } + } else { + // Failure to open is a fatal error. + fprintf(stderr, "hpctoolkit: unable to open file: '%s'", file_name); + return false; + } +} + +static void ApiTrackerCallback( + void *userdata, + Sanitizer_CallbackDomain domain, + Sanitizer_CallbackId cbid, + const void *cbdata) { + if (domain != SANITIZER_CB_DOMAIN_RESOURCE) + return; + + Sanitizer_CallbackData *pCallbackData = (Sanitizer_CallbackData *) cbdata; + if (cbid == SANITIZER_CBID_RESOURCE_MODULE_LOADED) { + Sanitizer_ResourceModuleData *pModuleLoadedData = (Sanitizer_ResourceModuleData *) pCallbackData; + PRINT("Module loaded: %s\n", pModuleLoadedData->pCubin); + PRINT("cubin size: %zu\n", pModuleLoadedData->cubinSize); + unsigned char hash[0]; + const void *cubin = pModuleLoadedData->pCubin; + unsigned int hash_length = crypto_hash_length(); + crypto_hash_compute(cubin, pModuleLoadedData->cubinSize, hash, hash_length); + uint32_t cubin_id = ((hpctoolkit_cumod_st_t *) pModuleLoadedData->module)->cubin_id; + // Create file name + char file_name[PATH_MAX]; + size_t i; + size_t used = 0; + // @todo fix path + used += sprintf(&file_name[used], "%s", "./"); + used += sprintf(&file_name[used], "%s", "/cubins/"); + mkdir(file_name, S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH); + for (i = 0; i < hash_length; ++i) { + used += sprintf(&file_name[used], "%02x", hash[i]); + } + used += sprintf(&file_name[used], "%s", ".cubin"); + PRINT("Sanitizer-> cubin_id %d hash %s\n", cubin_id, file_name); + cuda_write_cubin(file_name, cubin, pModuleLoadedData->cubinSize); + + } else if (cbid == SANITIZER_CBID_RESOURCE_MODULE_UNLOAD_STARTING) { + Sanitizer_ResourceModuleData *pModuleUnloadedData = (Sanitizer_ResourceModuleData *) pCallbackData; + PRINT("Module unloaded: %s\n", pModuleUnloadedData->pCubin); + } +} + +__attribute__((constructor)) +int InitializeInjection() { + Sanitizer_SubscriberHandle handle; + sanitizerSubscribe(&handle, ApiTrackerCallback, NULL); + sanitizerEnableDomain(1, handle, SANITIZER_CB_DOMAIN_RESOURCE); + return 0; +} + + + diff --git a/cubin_filter/cubin_filter.h b/cubin_filter/cubin_filter.h new file mode 100644 index 0000000..26b5d61 --- /dev/null +++ b/cubin_filter/cubin_filter.h @@ -0,0 +1,10 @@ +#ifndef CUBIN_FILTER_LIBRARY_H +#define CUBIN_FILTER_LIBRARY_H +#include +typedef struct { + uint32_t cubin_id; + uint32_t unknown_field[1]; + uint32_t mod_id; +} hpctoolkit_cumod_st_t; + +#endif //CUBIN_FILTER_LIBRARY_H