Skip to content

Commit

Permalink
Merge pull request #26 from lipracer/dev
Browse files Browse the repository at this point in the history
fix some issue
  • Loading branch information
lipracer authored Dec 29, 2023
2 parents 11df119 + d58399f commit 49cd39a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 2 additions & 0 deletions include/hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ struct MemberDetector<DerivedT,
return !strcmp(static_cast<DerivedT*>(self)->curSymName(),
std::get<0>(sym));
});
// TODO: if std::get<2>(*iter) is a pointer and it's point to
// std::get<1>(*iter) then there will return nullptr
*std::get<2>(*iter) = info.oldFuncPtr;
return std::get<1>(*iter);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/backtrace.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ bool CallFrames::CollectNative() {
}

bool CallFrames::CollectPython() {
// https://stackoverflow.com/questions/33637423/pygilstate-ensure-after-py-finalize
if (!Py_IsInitialized()) {
LOG(WARN) << "python process finished!";
return false;
}
python_frames_.reserve(kMaxStackDeep);
// Acquire the Global Interpreter Lock (GIL) before calling Python C API
// functions from non-Python threads.
Expand Down
10 changes: 8 additions & 2 deletions lib/xpu_mock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class XpuRuntimeWrapApi {
static int xpuWait(void* devStream);
static int xpuMemcpy(void* dst, const void* src, uint64_t size, int kind);
static int xpuSetDevice(int devId);
static int xpuCurrentDeviceId(int* devIdPtr);

private:
int (*raw_xpu_malloc_)(void**, uint64_t, int){nullptr};
Expand Down Expand Up @@ -254,6 +255,10 @@ int XpuRuntimeWrapApi::xpuSetDevice(int devId) {
return XpuRuntimeWrapApi::instance().raw_xpu_set_device_id_(devId);
}

int XpuRuntimeWrapApi::xpuCurrentDeviceId(int* devIdPtr) {
return XpuRuntimeWrapApi::instance().raw_xpu_current_device_(devIdPtr);
}

struct XpuRuntimeApiHook : public hook::HookInstallerWrap<XpuRuntimeApiHook> {
bool targetLib(const char* name) {
return !strstr(name, "libxpurt.so.1") && !strstr(name, "libxpurt.so");
Expand All @@ -271,7 +276,7 @@ struct XpuRuntimeApiHook : public hook::HookInstallerWrap<XpuRuntimeApiHook> {
// get device id
{"xpu_current_device",
reinterpret_cast<void*>(
XpuRuntimeWrapApi::instance().raw_xpu_current_device_),
XpuRuntimeWrapApi::instance().xpuCurrentDeviceId),
reinterpret_cast<void**>(
&XpuRuntimeWrapApi::instance().raw_xpu_current_device_)},
// sync device
Expand All @@ -288,7 +293,7 @@ struct XpuRuntimeApiHook : public hook::HookInstallerWrap<XpuRuntimeApiHook> {
reinterpret_cast<void**>(
&XpuRuntimeWrapApi::instance().raw_xpu_set_device_id_)}};

void onSuccess() {}
void onSuccess() { LOG(WARN) << "install " << curSymName() << " success"; }
};

} // namespace
Expand All @@ -298,5 +303,6 @@ extern "C" {
void xpu_dh_initialize() {
static auto install_wrap = std::make_shared<XpuRuntimeApiHook>();
install_wrap->install();
LOG(INFO) << "xpu_dh_initialize complete!";
}
}

0 comments on commit 49cd39a

Please sign in to comment.