-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #31 from lipracer/dev
refine support any linux
- Loading branch information
Showing
9 changed files
with
84 additions
and
60 deletions.
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from setuptools import setup | ||
import os | ||
|
||
os.system("cmake -S . -B build && cmake --build build") | ||
os.system("cd build/lib && ls | grep -v '\<cuda_mock\>' | xargs -I {} rm -rf {}") | ||
setup() |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
|
||
nanobind_add_module(cuda_mock_impl STABLE_ABI cuda_mock_impl.cpp) | ||
add_library(cuda_mock_impl SHARED cuda_mock_impl.cpp) | ||
|
||
target_link_libraries(cuda_mock_impl PRIVATE cuda_mock) | ||
|
||
include_directories(PRIVATE ${CMAKE_SOURCE_DIR}/include) | ||
include_directories(PRIVATE ${CMAKE_SOURCE_DIR}/include) | ||
|
||
set_target_properties(cuda_mock_impl | ||
PROPERTIES | ||
LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib/cuda_mock | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import os | ||
import ctypes | ||
|
||
script_dir = os.path.dirname(os.path.abspath(__file__)) | ||
cuda_mock_impl = ctypes.CDLL(f'{script_dir}/libcuda_mock_impl.so') | ||
|
||
def add(lhs, rhs): | ||
return lhs + rhs | ||
|
||
def initialize(): | ||
return cuda_mock_impl.initialize() | ||
|
||
def internal_install_hook(*args): | ||
new_args = [ctypes.c_char_p(arg.encode('utf-8')) for arg in args] | ||
return cuda_mock_impl.internal_install_hook(*new_args) | ||
|
||
def xpu_initialize(): | ||
return cuda_mock_impl.xpu_initialize() | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,43 @@ | ||
#include <nanobind/nanobind.h> | ||
|
||
#include "cuda_mock.h" | ||
#include "xpu_mock.h" | ||
|
||
namespace nb = nanobind; | ||
using namespace nb::literals; | ||
|
||
NB_MODULE(cuda_mock_impl, m) { | ||
m.def( | ||
"add", [](int a, int b) { return a + b; }, "a"_a, "b"_a); | ||
m.def("initialize", []() { dh_initialize(); }); | ||
m.def("internal_install_hook", [](const char* srcLib, const char* targetLib, | ||
const char* symbolName) { | ||
dh_internal_install_hook(srcLib, targetLib, symbolName); | ||
}); | ||
m.def("internal_install_hook", | ||
[](const char* srcLib, const char* targetLib, const char* symbolName, | ||
const char* hookerLibPath, const char* hookerSymbolName) { | ||
dh_internal_install_hook(srcLib, targetLib, symbolName, | ||
hookerLibPath, hookerSymbolName); | ||
}); | ||
m.def("xpu_initialize", []() { xpu_dh_initialize(); }); | ||
// namespace nb = nanobind; | ||
// using namespace nb::literals; | ||
|
||
// NB_MODULE(cuda_mock_impl, m) { | ||
// m.def( | ||
// "add", [](int a, int b) { return a + b; }, "a"_a, "b"_a); | ||
// m.def("initialize", []() { dh_initialize(); }); | ||
// m.def("internal_install_hook", [](const char* srcLib, const char* | ||
// targetLib, | ||
// const char* symbolName) { | ||
// dh_internal_install_hook(srcLib, targetLib, symbolName); | ||
// }); | ||
// m.def("internal_install_hook", | ||
// [](const char* srcLib, const char* targetLib, const char* | ||
// symbolName, | ||
// const char* hookerLibPath, const char* hookerSymbolName) { | ||
// dh_internal_install_hook(srcLib, targetLib, symbolName, | ||
// hookerLibPath, hookerSymbolName); | ||
// }); | ||
// m.def("xpu_initialize", []() { xpu_dh_initialize(); }); | ||
// } | ||
|
||
typedef const char* PHStr; | ||
|
||
extern "C" { | ||
|
||
HOOK_API int add(int lhs, int rhs) { return lhs + rhs; } | ||
|
||
HOOK_API void initialize() { dh_initialize(); } | ||
|
||
HOOK_API void internal_install_hook(PHStr srcLib, PHStr targetLib, | ||
PHStr symbolName, PHStr hookerLibPath, | ||
PHStr hookerSymbolName) { | ||
dh_internal_install_hook(srcLib, targetLib, symbolName, hookerLibPath, | ||
hookerSymbolName); | ||
} | ||
|
||
HOOK_API void xpu_initialize() { xpu_dh_initialize(); } | ||
} |
Submodule nanobind
deleted from
1c462d