Skip to content

Commit

Permalink
enable local hook just when cuda profiling is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
wffpy committed Nov 24, 2024
1 parent a36b60e commit 1288637
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/dump/DumpHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ std::string LaunchInfo::to_string(const TensorMap& tensor_map, const int64_t cap
DLOG() << " prointer_level: " << parsed_type.prointer_level;
// memory ptr
if (parsed_type.prointer_level > 0) {
char* cpu_ptr = ((char*)params_.data()) + pos;
// input memory
if (parsed_type.is_const) {
char* cpu_ptr = ((char*)params_.data()) + pos;
LOG() << "input memory " << index << ": " << std::hex << *((int64_t*)cpu_ptr);
uint64_t dev_ptr = *((uint64_t*)cpu_ptr);
int64_t bytes = 0;
Expand Down Expand Up @@ -242,6 +242,8 @@ std::string LaunchInfo::to_string(const TensorMap& tensor_map, const int64_t cap

free(host_data);
}
} else {
LOG() << "output memory " << index << ": " << std::hex << *((int64_t*)cpu_ptr);
}
pos = pos + 8;
} else if (parsed_type.base_type == "int64_t" || parsed_type.base_type == "long") {
Expand Down
8 changes: 8 additions & 0 deletions lib/hook/LocalHook/LocalHook.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
#include <sys/mman.h>
#include <unistd.h>

#ifdef USE_CAPSTONE
#include "capstone/capstone.h"
#include "capstone/x86.h"
#endif

#include "hook/CFuncHook.h"
#include "utils/Log/Log.h"
Expand Down Expand Up @@ -73,6 +75,7 @@ uintptr_t find_free_address(uintptr_t aligned_addr, size_t size) {
// return mmap_addr;
// }

#ifdef USE_CAPSTONE
struct X64Instructions {
cs_insn *instructions;
uint32_t numInstructions;
Expand Down Expand Up @@ -821,7 +824,12 @@ void install_local_hook(void *hooked_func, void *payload_func,
}
}
}
#else

void install_local_hook(void *hooked_func, void *payload_func,
void **trampoline_ptr) {}

#endif
void LocalHookRegistrar::add(LocalHookInfo info) { hooks.emplace_back(info); }

void LocalHookRegistrar::install() {
Expand Down
4 changes: 3 additions & 1 deletion python/module_logging/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ target_link_libraries(Hook PRIVATE GpuHook)
target_link_libraries(Hook PRIVATE LocalHook)
target_link_libraries(Hook PRIVATE Dump)

target_link_libraries(Hook PRIVATE capstone)
if (USE_CAPSTONE STREQUAL TRUE)
target_link_libraries(Hook PRIVATE capstone)
endif()

target_include_directories(Hook PUBLIC ${Python3_INCLUDE_DIRS})

Expand Down
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ def build_extension(self, ext):
# '-DPYTHON_LIBRARY=' + os.environ.get('PYTHON_LIBRARY'),
# f'-B {os.path.join(script_dir, "build")}',
]
# up to now, local hook is just used for cuda Profiling
if enable_cuda == "true":
cmake_args.append("-DCUDA_DEV=TRUE")
cmake_args.append("-DUSE_CAPSTONE=TRUE")
if enable_xpu == "true":
cmake_args.append("-DXPU_DEV=TRUE")

Expand Down

0 comments on commit 1288637

Please sign in to comment.